diff --git a/src/components/widget-plot-table.js b/src/components/widget-plot-table.js index 0507b3f..7862a05 100644 --- a/src/components/widget-plot-table.js +++ b/src/components/widget-plot-table.js @@ -45,7 +45,7 @@ class WidgetPlotTable extends Component { // Identify if there was a change in the preselected signals if (nextProps.simulation && (JSON.stringify(nextProps.widget.preselectedSignals) !== JSON.stringify(this.props.widget.preselectedSignals) || this.state.preselectedSignals.length === 0)) { - + // Update the currently selected signals by intersecting with the preselected signals // Do the same with the plot values var intersection = this.computeIntersection(nextProps.widget.preselectedSignals, nextProps.widget.signals); @@ -54,20 +54,19 @@ class WidgetPlotTable extends Component { this.updatePreselectedSignalsState(nextProps); return; } - } // Perform the intersection of the lists, alternatively could be done with Sets ensuring unique values computeIntersection(preselectedSignals, selectedSignals) { return preselectedSignals.filter( s => selectedSignals.includes(s)); } - + updatePreselectedSignalsState(nextProps) { const simulator = nextProps.widget.simulator; // get simulation model const simulationModel = nextProps.simulation.models.find((model) => { - return (model.simulator === simulator); + return (model.simulator.node === simulator.node && model.simulator.simulator === simulator.simulator); }); let preselectedSignals = []; @@ -89,13 +88,13 @@ class WidgetPlotTable extends Component { return accum; }, []); } - + this.setState({ preselectedSignals: preselectedSignals }); } updateSignalSelection(signal_index, checked) { // Update the selected signals and propagate to parent component - var new_widget = Object.assign({}, this.props.widget, { + var new_widget = Object.assign({}, this.props.widget, { signals: checked? this.state.signals.concat(signal_index) : this.state.signals.filter( (idx) => idx !== signal_index ) }); this.props.onWidgetChange(new_widget); @@ -106,31 +105,37 @@ class WidgetPlotTable extends Component { // Data passed to plot let simulator = this.props.widget.simulator; - let simulatorData = this.props.data[simulator]; + let simulatorData = []; + + if (this.props.data[simulator.node] != null && this.props.data[simulator.node][simulator.simulator] != null) { + simulatorData = this.props.data[simulator.node][simulator.simulator]; + } if (this.state.preselectedSignals && this.state.preselectedSignals.length > 0) { // Create checkboxes using the signal indices from simulation model checkBoxes = this.state.preselectedSignals.map( (signal) => { - var checked = this.state.signals.indexOf(signal.index) > -1; - var chkBxClasses = classNames({ - 'btn': true, - 'btn-default': true, - 'active': checked - }); - return this.updateSignalSelection(signal.index, e.target.checked) } > { signal.name } - }); + var checked = this.state.signals.indexOf(signal.index) > -1; + var chkBxClasses = classNames({ + 'btn': true, + 'btn-default': true, + 'active': checked + }); + return this.updateSignalSelection(signal.index, e.target.checked) } > { signal.name } + }); } // Prepare an array with the signals to show in the legend var legendSignals = this.state.preselectedSignals.reduce( (accum, signal, i) => { - if (this.state.signals.includes(signal.index)) { - accum.push({ - index: signal.index, - name: signal.name - }) - } - return accum; - }, []); + if (this.state.signals.includes(signal.index)) { + accum.push({ + index: signal.index, + name: signal.name + }); + } + return accum; + }, []); + + return (
diff --git a/src/components/widget-plot/plot.js b/src/components/widget-plot/plot.js index 6bae9d0..7b0c3aa 100644 --- a/src/components/widget-plot/plot.js +++ b/src/components/widget-plot/plot.js @@ -14,7 +14,7 @@ import { scaleOrdinal, schemeCategory10 } from 'd3-scale'; class Plot extends Component { constructor(props) { super(props); - + this.chartWrapper = null; // Initialize plot size and data @@ -24,7 +24,7 @@ class Plot extends Component { ); } - // Get an object with 'invisible' init data for the last minute. + // Get an object with 'invisible' init data for the last minute. // Include start/end timestamps if required. getPlotInitData(withRangeTimestamps = false) { @@ -32,8 +32,8 @@ class Plot extends Component { 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, } : + let output = withRangeTimestamps? + { sequence: 0, values: values, firstTimestamp: initFirstTime, latestTimestamp: initSecondTime, } : { sequence: 0, values: values }; return output; @@ -58,19 +58,19 @@ class Plot extends Component { // Identify simulation reset 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; } - + this.updatePlotData(nextProps); } signalsWereJustCleared(nextProps) { - return this.props.signals && - nextProps.signals && - this.props.signals.length > 0 && + return this.props.signals && + nextProps.signals && + this.props.signals.length > 0 && nextProps.signals.length === 0; } @@ -102,7 +102,7 @@ class Plot extends Component { nextProps.signals.forEach((signal_index, i, arr) => ( // Include signal index, useful to relate them to the signal selection values.push( - { + { index: signal_index, values: nextData.values[signal_index].slice(firstIndex, nextData.values[signal_index].length - 1)}) )); @@ -138,4 +138,4 @@ class Plot extends Component { } -export default Plot; \ No newline at end of file +export default Plot;