mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Initial blank plot and allocate fixed initial height to legend (avoid resizing)
This commit is contained in:
parent
fe1c924836
commit
3be7fdcd35
2 changed files with 47 additions and 17 deletions
|
@ -17,13 +17,26 @@ class Plot extends Component {
|
|||
|
||||
this.chartWrapper = null;
|
||||
|
||||
this.state = {
|
||||
size: { w: 0, h: 0 },
|
||||
firstTimestamp: 0,
|
||||
latestTimestamp: 0,
|
||||
sequence: null,
|
||||
values: []
|
||||
};
|
||||
// Initialize plot size and data
|
||||
this.state = Object.assign(
|
||||
{ size: { w: 0, h: 0 } },
|
||||
this.getPlotInitData(true)
|
||||
);
|
||||
}
|
||||
|
||||
// Get an object with 'invisible' init data for the last minute.
|
||||
// Include start/end timestamps if required.
|
||||
getPlotInitData(withRangeTimestamps = false) {
|
||||
|
||||
const initSecondTime = Date.now();
|
||||
const initFirstTime = initSecondTime - 1000 * 60; // Decrease 1 min
|
||||
const values = [{ values: [{x: initFirstTime, y: 0}], strokeWidth: 0 }];
|
||||
|
||||
let output = withRangeTimestamps?
|
||||
{ sequence: 0, values: values, firstTimestamp: initFirstTime, latestTimestamp: initSecondTime, } :
|
||||
{ sequence: 0, values: values };
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
@ -37,22 +50,34 @@ class Plot extends Component {
|
|||
this.setState({size: { w, h } });
|
||||
}
|
||||
|
||||
// If signals were cleared, clear the plot (triggers a new state)
|
||||
if (this.signalsWereJustCleared(nextProps)) { this.clearPlot(); return; }
|
||||
|
||||
// If no signals have been selected, just leave
|
||||
if (nextProps.signals == null || nextProps.signals.length === 0) { return; }
|
||||
|
||||
// Identify simulation reset
|
||||
if (nextData == null || nextData.length === 0 || nextData.values[0].length === 0) {
|
||||
// clear values
|
||||
this.setState({ values: [], sequence: null });
|
||||
return;
|
||||
}
|
||||
if (nextData == null || nextData.length === 0 || nextData.values[0].length === 0) { this.clearPlot(); return; }
|
||||
|
||||
// check if new data, otherwise skip
|
||||
if (this.state.sequence >= nextData.sequence) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.state.sequence >= nextData.sequence) { return; }
|
||||
|
||||
this.updatePlotData(nextProps);
|
||||
|
||||
}
|
||||
|
||||
signalsWereJustCleared(nextProps) {
|
||||
|
||||
return this.props.signals &&
|
||||
nextProps.signals &&
|
||||
this.props.signals.length > 0 &&
|
||||
nextProps.signals.length === 0;
|
||||
}
|
||||
|
||||
clearPlot() {
|
||||
this.setState( this.getPlotInitData(false) );
|
||||
}
|
||||
|
||||
updatePlotData(nextProps) {
|
||||
let nextData = nextProps.simulatorData;
|
||||
|
||||
|
@ -91,7 +116,7 @@ class Plot extends Component {
|
|||
|
||||
return (
|
||||
<div className="chart-wrapper" ref={ (domNode) => this.chartWrapper = domNode }>
|
||||
{this.state.sequence &&
|
||||
{this.state.sequence != null &&
|
||||
<LineChart
|
||||
width={ this.state.size.w || 100 }
|
||||
height={ this.state.size.h || 100 }
|
||||
|
|
|
@ -226,6 +226,9 @@ div[class*="-widget"] .btn[disabled], .btn.disabled, div[class*="-widget"] input
|
|||
.plot-legend {
|
||||
display: -webkit-flex;
|
||||
display: flex;
|
||||
flex-basis: 20px; /* Enough to allocate one row */
|
||||
max-height: 40px; /* Allocate up to two rows */
|
||||
flex-shrink: 0;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-around;
|
||||
margin-bottom: 5px;
|
||||
|
@ -234,6 +237,8 @@ div[class*="-widget"] .btn[disabled], .btn.disabled, div[class*="-widget"] input
|
|||
.signal-legend {
|
||||
font-size: 0.8em;
|
||||
font-weight: 700;
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue