aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorEmiliano Ciavatta2020-10-12 19:33:40 +0000
committerEmiliano Ciavatta2020-10-12 19:33:40 +0000
commit09cb0a1518feb2221ccd8c10dced859c010e9991 (patch)
treed70efa91eb0c6911242e2d77c8f4fa5a834de138 /frontend
parenta44b70943ea4fce61261fc5fadf84a2a98fd2435 (diff)
Add rules statistics
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/components/Timeline.js32
1 files changed, 17 insertions, 15 deletions
diff --git a/frontend/src/components/Timeline.js b/frontend/src/components/Timeline.js
index 615203f..6b8806f 100644
--- a/frontend/src/components/Timeline.js
+++ b/frontend/src/components/Timeline.js
@@ -102,23 +102,24 @@ class Timeline extends Component {
ports.forEach(s => urlParams.append("ports", s));
const metrics = (await backend.get("/api/statistics?" + urlParams)).json;
+ if (metrics.length === 0) {
+ return;
+ }
+
const zeroFilledMetrics = [];
const toTime = m => new Date(m["range_start"]).getTime();
-
- if (metrics.length > 0) {
- let i = 0;
- for (let interval = toTime(metrics[0]); interval <= toTime(metrics[metrics.length - 1]); interval += minutes) {
- if (interval === toTime(metrics[i])) {
- const m = metrics[i++];
- m["range_start"] = new Date(m["range_start"]);
- zeroFilledMetrics.push(m);
- } else {
- const m = {};
- m["range_start"] = new Date(interval);
- m[metric] = {};
- ports.forEach(p => m[metric][p] = 0);
- zeroFilledMetrics.push(m);
- }
+ let i = 0;
+ for (let interval = toTime(metrics[0]); interval <= toTime(metrics[metrics.length - 1]); interval += minutes) {
+ if (interval === toTime(metrics[i])) {
+ const m = metrics[i++];
+ m["range_start"] = new Date(m["range_start"]);
+ zeroFilledMetrics.push(m);
+ } else {
+ const m = {};
+ m["range_start"] = new Date(interval);
+ m[metric] = {};
+ ports.forEach(p => m[metric][p] = 0);
+ zeroFilledMetrics.push(m);
}
}
@@ -127,6 +128,7 @@ class Timeline extends Component {
columns: ["time"].concat(ports),
points: zeroFilledMetrics.map(m => [m["range_start"]].concat(ports.map(p => m[metric][p] || 0)))
});
+
const start = series.range().begin();
const end = series.range().end();
start.setTime(start.getTime() - minutes);