diff --git a/src/components/widget-plot.js b/src/components/widget-plot.js
index 56b5b2a..2fb5b93 100644
--- a/src/components/widget-plot.js
+++ b/src/components/widget-plot.js
@@ -28,24 +28,24 @@ class WidgetPlot extends React.Component {
render() {
const simulator = this.props.widget.simulator;
const simulation = this.props.simulation;
- let legendSignals = [];
+ //let legendSignals = [];
let simulatorData = [];
// Proceed if a simulation with models and a simulator are available
if (simulator && simulation && simulation.models.length > 0) {
- const model = simulation.models.find( model => model.simulator.node === simulator.node && model.simulator.simulator === simulator.simulator );
- const chosenSignals = this.props.widget.signals;
+ //const model = simulation.models.find( model => model.simulator.node === simulator.node && model.simulator.simulator === simulator.simulator );
+ //const chosenSignals = this.props.widget.signals;
simulatorData = this.props.data[simulator.node][simulator.simulator].values[0];
// Query the signals that will be displayed in the legend
- legendSignals = model.mapping.reduce( (accum, model_signal, signal_index) => {
+ /*legendSignals = model.mapping.reduce( (accum, model_signal, signal_index) => {
if (chosenSignals.includes(signal_index)) {
accum.push({ index: signal_index, name: model_signal.name });
}
return accum;
- }, []);
+ }, []);*/
}
return (
@@ -53,10 +53,11 @@ class WidgetPlot extends React.Component {
{this.props.widget.name}
diff --git a/src/components/widget-plot/plot.js b/src/components/widget-plot/plot.js
index ee29df4..ce30589 100644
--- a/src/components/widget-plot/plot.js
+++ b/src/components/widget-plot/plot.js
@@ -9,24 +9,37 @@
import React from 'react';
import { scaleLinear, scaleTime } from 'd3-scale';
-import { extent, max } from 'd3-array';
+import { extent } from 'd3-array';
import { line } from 'd3-shape';
import { axisBottom, axisLeft } from 'd3-axis';
import { select } from 'd3-selection';
class Plot extends React.Component {
render() {
- const leftMargin = 30;
- const bottomMargin = 20;
- const values = 100;
-
+ // check if data is valid
+ if (this.props.data == null || this.props.data.length === 0) return false;
+
+ // only show data in requested time
let data = this.props.data;
- if (data.length > values) {
- data = data.slice(data.length - values);
+ const firstTimestamp = data[data.length - 1].x - this.props.time * 1000;
+ if (data[0].x < firstTimestamp) {
+ const index = data.findIndex(value => value.x >= firstTimestamp - 100);
+ if (index > 0) {
+ data = data.slice(index - 1);
+ }
}
- const xScale = scaleTime().domain(extent(data, p => new Date(p.x))).range([leftMargin, this.props.width]);
+ // calculate paths for data
+ const leftMargin = 30;
+ const bottomMargin = 20;
+
+ let xRange = extent(data, p => new Date(p.x));
+ if (xRange[1] - xRange[0] < this.props.time * 1000) {
+ xRange[0] = xRange[1] - this.props.time * 1000;
+ }
+
+ const xScale = scaleTime().domain(xRange).range([leftMargin, this.props.width]);
const yScale = scaleLinear().domain(extent(data, p => p.y)).range([this.props.height, bottomMargin]);
const xAxis = axisBottom().scale(xScale).ticks(5);