1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

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

This commit is contained in:
Sonja Happ 2020-05-20 13:52:16 +02:00
parent a4dea3d6a9
commit a7e0cb27a2
2 changed files with 31 additions and 36 deletions

View file

@ -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') {

View file

@ -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: [],
};
}
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);
const ic = props.config.icID;
// sig is a selected signal, get data
// determine ID of infrastructure component related to signal (via config)
let icID = props.icIDs[sig.id]
// 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;
// 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
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: [],
};
}
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>;
}
}