From f794d14aad24088694620b9b027d7e487142af59 Mon Sep 17 00:00:00 2001 From: Markus Grigull Date: Fri, 4 May 2018 10:14:05 +0200 Subject: [PATCH] Upgrade missing widgets to simulation model data --- src/components/widget-lamp.js | 8 +++-- src/components/widget-plot-table.js | 55 +++++++++++++---------------- src/components/widget-plot.js | 12 ++++--- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/components/widget-lamp.js b/src/components/widget-lamp.js index 60f3b73..c969fa0 100644 --- a/src/components/widget-lamp.js +++ b/src/components/widget-lamp.js @@ -34,9 +34,13 @@ class WidgetLamp extends Component { } componentWillReceiveProps(nextProps) { - // update value - const simulator = nextProps.widget.simulator; + if (nextProps.simulationModel == null) { + return; + } + const simulator = nextProps.simulationModel.simulator; + + // update value if (nextProps.data == null || nextProps.data[simulator] == null || nextProps.data[simulator].output.values == null) { this.setState({ value: '' }); return; diff --git a/src/components/widget-plot-table.js b/src/components/widget-plot-table.js index 55992b1..59d729b 100644 --- a/src/components/widget-plot-table.js +++ b/src/components/widget-plot-table.js @@ -37,13 +37,17 @@ class WidgetPlotTable extends Component { } componentWillReceiveProps(nextProps) { + if (nextProps.simulationModel == null) { + return; + } + // Update internal selected signals state with props (different array objects) if (this.props.widget.signals !== nextProps.widget.signals) { this.setState( {signals: nextProps.widget.signals}); } // 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)) { + if (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); @@ -60,35 +64,24 @@ class WidgetPlotTable extends Component { } updatePreselectedSignalsState(nextProps) { - const simulator = nextProps.widget.simulator; + // Create checkboxes using the signal indices from simulation model + const preselectedSignals = nextProps.simulationModel.outputMapping.reduce( + // Loop through simulation model signals + (accum, model_signal, signal_index) => { + // Append them if they belong to the current selected type + if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) { + accum.push( + { + index: signal_index, + name: model_signal.name, + type: model_signal.type + } + ) + } + return accum; + }, []); - // get simulation model - const simulationModel = nextProps.simulation.models.find((model) => { - return (model.simulator === simulator); - }); - - let preselectedSignals = []; - // Proceed if a simulation model is available - if (simulationModel) { - // Create checkboxes using the signal indices from simulation model - preselectedSignals = simulationModel.outputMapping.reduce( - // Loop through simulation model signals - (accum, model_signal, signal_index) => { - // Append them if they belong to the current selected type - if (nextProps.widget.preselectedSignals.indexOf(signal_index) > -1) { - accum.push( - { - index: signal_index, - name: model_signal.name, - type: model_signal.type - } - ) - } - return accum; - }, []); - } - - this.setState({ preselectedSignals: preselectedSignals }); + this.setState({ preselectedSignals }); } updateSignalSelection(signal_index, checked) { @@ -100,10 +93,10 @@ class WidgetPlotTable extends Component { } render() { - var checkBoxes = []; + let checkBoxes = []; // Data passed to plot - let simulator = this.props.widget.simulator; + const simulator = this.props.simulationModel.simulator; let simulatorData = []; if (this.props.data[simulator] != null) { diff --git a/src/components/widget-plot.js b/src/components/widget-plot.js index b6cf423..7187829 100644 --- a/src/components/widget-plot.js +++ b/src/components/widget-plot.js @@ -35,12 +35,14 @@ class WidgetPlot extends React.Component { } componentWillReceiveProps(nextProps) { - const simulator = nextProps.widget.simulator; - const simulation = nextProps.simulation; + if (nextProps.simulationModel == null) { + return; + } + + const simulator = nextProps.simulationModel.simulator; // Proceed if a simulation with models and a simulator are available - if (simulator && nextProps.data[simulator] != null && nextProps.data[simulator] != null && simulation && simulation.models.length > 0) { - const model = simulation.models.find(model => model.simulator === simulator); + if (simulator && nextProps.data[simulator] != null && nextProps.data[simulator] != null) { const chosenSignals = nextProps.widget.signals; const data = nextProps.data[simulator].output.values.filter((values, index) => ( @@ -48,7 +50,7 @@ class WidgetPlot extends React.Component { )); // Query the signals that will be displayed in the legend - const legend = model.outputMapping.reduce( (accum, model_signal, signal_index) => { + const legend = nextProps.simulationModel.outputMapping.reduce( (accum, model_signal, signal_index) => { if (chosenSignals.includes(signal_index)) { accum.push({ index: signal_index, name: model_signal.name, type: model_signal.type }); }