Commit a7e0cb27 authored by Sonja Happ's avatar Sonja Happ

Plot Widget: fix in the same way as PlotTable Widget, now plotting signals #218

parent a4dea3d6
......@@ -130,7 +130,7 @@ class Widget extends React.Component {
} else if (widget.type === 'Value') {
return <WidgetValue widget={widget} data={this.state.icData} dummy={this.state.sequence} signals={this.state.signals} icIDs={this.state.icIDs} />
} else if (widget.type === 'Plot') {
return <WidgetPlot widget={widget} data={this.state.icData} dummy={this.state.sequence} paused={this.props.paused} />
return <WidgetPlot widget={widget} data={this.state.icData} dummy={this.state.sequence} signals={this.state.signals} icIDs={this.state.icIDs} paused={this.props.paused} />
} else if (widget.type === 'Table') {
return <WidgetTable widget={widget} data={this.state.icData} dummy={this.state.sequence} signals={this.state.signals} icIDs={this.state.icIDs} />
} else if (widget.type === 'Label') {
......
......@@ -26,49 +26,44 @@ class WidgetPlot extends React.Component {
this.state = {
data: [],
legend: []
signals: []
};
}
static getDerivedStateFromProps(props, state){
if (props.config == null) {
return{
data: [],
legend: [],
};
}
const ic = props.config.icID;
// Proceed if a config and a IC are available
if (ic && props.data[ic] != null && props.data[ic] != null && props.data[ic].output != null && props.data[ic].output.values != null) {
const chosenSignals = props.widget.customProperties.signals;
const data = props.data[ic].output.values.filter((values, index) => (
props.widget.customProperties.signals.findIndex(value => value === index) !== -1
));
// Query the signals that will be displayed in the legend
const legend = props.config.outputMapping.reduce( (accum, signal, signal_index) => {
if (chosenSignals.includes(signal_index)) {
accum.push({ index: signal_index, name: signal.name, type: signal.unit });
}
return accum;
}, []);
return{
data: data,
legend: legend,
};
} else {
return{
data: [],
legend: [],
};
}
let intersection = []
let data = [];
let signalID, sig;
for (signalID of props.widget.signalIDs) {
for (sig of props.signals) {
if (signalID === sig.id) {
intersection.push(sig);
// sig is a selected signal, get data
// determine ID of infrastructure component related to signal (via config)
let icID = props.icIDs[sig.id]
// distinguish between input and output signals
if (sig.direction === "out") {
if (props.data[icID] != null && props.data[icID].output != null && props.data[icID].output.values != null) {
if (props.data[icID].output.values[sig.index-1] !== undefined) {
data.push(props.data[icID].output.values[sig.index-1]);
}
}
} else if (sig.direction === "in") {
if (props.data[icID] != null && props.data[icID].input != null && props.data[icID].input.values != null) {
if (props.data[icID].input.values[sig.index-1] !== undefined) {
data.push(props.data[icID].input.values[sig.index-1]);
}
}
}
} // sig is selected signal
} // loop over props.signals
} // loop over selected signals
return {signals: intersection, data: data}
}
......@@ -87,7 +82,7 @@ class WidgetPlot extends React.Component {
yLabel={this.props.widget.customProperties.ylabel}
/>
</div>
<PlotLegend signals={this.state.legend} />
<PlotLegend signals={this.state.signals} />
</div>;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment