diff --git a/src/widget/widget-plot/plot-legend.js b/src/widget/widget-plot/plot-legend.js index 22aba64..f3f4cd6 100644 --- a/src/widget/widget-plot/plot-legend.js +++ b/src/widget/widget-plot/plot-legend.js @@ -26,7 +26,7 @@ class PlotLegend extends React.Component { return
, prevState: Readonly, snapshot: SS): void {
- // Identify if there was a change in the selected signals
- if (JSON.stringify(prevProps.widget.signalIDs) !== JSON.stringify(this.props.widget.signalIDs)
- || this.state.signals.length === 0) {
- // Update the currently selected signals
- let intersection = []
- let signalID, sig;
- for (signalID of this.props.widget.signalIDs) {
- for (sig of this.props.signals) {
- if (signalID === sig.id) {
- intersection.push(sig);
- }
+ static getDerivedStateFromProps(props, state){
+ let intersection = []
+ let signalID, sig;
+ for (signalID of props.widget.signalIDs) {
+ for (sig of props.signals) {
+ if (signalID === sig.id) {
+ intersection.push(sig);
}
}
-
- this.setState({signals: intersection});
}
+
+ return {signals: intersection}
}
- updateSignalSelection(signal_index, checked) {
+ updateSignalSelection(signal, checked) {
// Update the selected signals and propagate to parent component
var new_widget = Object.assign({}, this.props.widget, {
- signals: checked ? this.state.signals.concat(signal_index) : this.state.signals.filter((idx) => idx !== signal_index)
+ checkedSignals: checked ? this.state.signals.concat(signal) : this.state.signals.filter((idx) => idx !== signal)
});
this.props.onWidgetChange(new_widget);
}
@@ -63,7 +55,6 @@ class WidgetPlotTable extends Component {
let checkBoxes = [];
let icData = [];
let showLegend = false;
-
if (this.state.signals.length > 0) {
showLegend = true;
@@ -75,24 +66,35 @@ class WidgetPlotTable extends Component {
// determine ID of infrastructure component related to signal (via config)
let icID = this.props.icIDs[signal.id]
- if (this.props.data[icID] != null && this.props.data[icID].output != null && this.props.data[icID].output.values != null) {
- if (this.props.data[icID].output.values[signal.index] !== undefined){
- icData.push(this.props.data[icID].output.values[signal.index]);
+ // distinguish between input and output signals
+ if (signal.direction === "out"){
+ if (this.props.data[icID] != null && this.props.data[icID].output != null && this.props.data[icID].output.values != null) {
+ if (this.props.data[icID].output.values[signal.index] !== undefined){
+ icData.push(this.props.data[icID].output.values[signal.index]);
+ }
+ }
+ } else if (signal.direction === "in"){
+ if (this.props.data[icID] != null && this.props.data[icID].input != null && this.props.data[icID].input.values != null) {
+ if (this.props.data[icID].input.values[signal.index] !== undefined){
+ icData.push(this.props.data[icID].input.values[signal.index]);
+ }
}
}
+
+
}
// Create checkboxes using the signal indices from component config
- checkBoxes = this.state.signals.map((signal) => {
- let checked = this.state.signals.indexOf(signal.index) > -1;
- let chkBxClasses = classNames({
- 'btn': true,
- 'btn-default': true,
- 'active': checked
- });
- return