@eox/chart 2.0.0-alpha4 → 2.0.0-alpha5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cypress/e2e/signalsEndpoint.cy.ts +1 -1
- package/dist/assets/{main-998f4938.js → main-3b62be28.js} +7 -5
- package/dist/index.html +12 -9
- package/index.html +11 -8
- package/package.json +1 -1
- package/src/chartControls.ts +59 -3
- package/src/main.ts +21 -0
- package/src/signalsDataManager.ts +108 -2
package/dist/index.html
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<title>EOxElements Chart</title>
|
|
6
6
|
<style>
|
|
7
|
-
*{
|
|
8
|
-
|
|
9
|
-
font-size: 0.
|
|
10
|
-
display: inline-block;
|
|
11
|
-
vertical-align: middle;
|
|
7
|
+
*{
|
|
8
|
+
font-family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
|
|
9
|
+
font-size: 0.95em;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
label{
|
|
12
|
+
margin-top: 2.5px;
|
|
15
13
|
}
|
|
16
14
|
html,
|
|
17
15
|
body {
|
|
@@ -64,13 +62,18 @@
|
|
|
64
62
|
#controls {
|
|
65
63
|
position: absolute;
|
|
66
64
|
width: 100%;
|
|
67
|
-
|
|
65
|
+
display: flex;
|
|
66
|
+
gap: 5px;
|
|
67
|
+
flex-direction: row;
|
|
68
|
+
}
|
|
69
|
+
.parsingError {
|
|
70
|
+
background-color : #ff6d6d;
|
|
68
71
|
}
|
|
69
72
|
#chart {
|
|
70
73
|
padding-top: 30px;
|
|
71
74
|
}
|
|
72
75
|
</style>
|
|
73
|
-
<script type="module" crossorigin src="./assets/main-
|
|
76
|
+
<script type="module" crossorigin src="./assets/main-3b62be28.js"></script>
|
|
74
77
|
</head>
|
|
75
78
|
<body>
|
|
76
79
|
<div id="controls" class="controls" data-cy="controls"></div>
|
package/index.html
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<title>EOxElements Chart</title>
|
|
6
6
|
<style>
|
|
7
|
-
*{
|
|
8
|
-
|
|
9
|
-
font-size: 0.
|
|
10
|
-
display: inline-block;
|
|
11
|
-
vertical-align: middle;
|
|
7
|
+
*{
|
|
8
|
+
font-family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
|
|
9
|
+
font-size: 0.95em;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
label{
|
|
12
|
+
margin-top: 2.5px;
|
|
15
13
|
}
|
|
16
14
|
html,
|
|
17
15
|
body {
|
|
@@ -64,7 +62,12 @@
|
|
|
64
62
|
#controls {
|
|
65
63
|
position: absolute;
|
|
66
64
|
width: 100%;
|
|
67
|
-
|
|
65
|
+
display: flex;
|
|
66
|
+
gap: 5px;
|
|
67
|
+
flex-direction: row;
|
|
68
|
+
}
|
|
69
|
+
.parsingError {
|
|
70
|
+
background-color : #ff6d6d;
|
|
68
71
|
}
|
|
69
72
|
#chart {
|
|
70
73
|
padding-top: 30px;
|
package/package.json
CHANGED
package/src/chartControls.ts
CHANGED
|
@@ -19,16 +19,56 @@ class ChartControls {
|
|
|
19
19
|
this.sdm = sdm;
|
|
20
20
|
this.options = options;
|
|
21
21
|
this.sdmOptions = sdmOptions;
|
|
22
|
-
this.generateTimeSelectionOptions();
|
|
23
22
|
this.generateTimeAggregationOptions();
|
|
24
23
|
this.addNormalizeCheckbox();
|
|
25
24
|
this.addShowMinMax();
|
|
25
|
+
this.addCSVDownload();
|
|
26
|
+
this.generateTimeSelectionOptions();
|
|
26
27
|
const spinner = document.createElement("span");
|
|
27
28
|
spinner.id = "loadingIndicator";
|
|
28
29
|
spinner.className = "loader hidden";
|
|
29
30
|
this.element.appendChild(spinner);
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
private removeStartEndInputs() {
|
|
34
|
+
const start = document.getElementById("startInput");
|
|
35
|
+
const end = document.getElementById("endInput");
|
|
36
|
+
const button = document.getElementById("setTime");
|
|
37
|
+
if (start && end && button) {
|
|
38
|
+
start.remove();
|
|
39
|
+
end.remove();
|
|
40
|
+
button.remove();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
private addStartEndInputs() {
|
|
44
|
+
const startEl = document.createElement("input");
|
|
45
|
+
startEl.id = "startInput";
|
|
46
|
+
startEl.size = 8;
|
|
47
|
+
startEl.value = this.sdm.startTime.toISODate();
|
|
48
|
+
const endEl = document.createElement("input");
|
|
49
|
+
endEl.id = "endInput";
|
|
50
|
+
endEl.size = 8;
|
|
51
|
+
endEl.value = this.sdm.endTime.toISODate();
|
|
52
|
+
this.element.appendChild(startEl);
|
|
53
|
+
this.element.appendChild(endEl);
|
|
54
|
+
var button = document.createElement("button");
|
|
55
|
+
button.id = "setTime";
|
|
56
|
+
button.textContent = "ok";
|
|
57
|
+
|
|
58
|
+
this.element.appendChild(button);
|
|
59
|
+
button.addEventListener("click", () => {
|
|
60
|
+
const startDate = DateTime.fromISO(startEl.value);
|
|
61
|
+
const endDate = DateTime.fromISO(endEl.value);
|
|
62
|
+
if (startDate.isValid && endDate.isValid) {
|
|
63
|
+
this.sdm.setTimeInterval(startDate, endDate);
|
|
64
|
+
this.removeStartEndInputs();
|
|
65
|
+
} else {
|
|
66
|
+
startEl.className = startDate.isValid ? "" : "parsingError";
|
|
67
|
+
endEl.className = endDate.isValid ? "" : "parsingError";
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
32
72
|
private addNormalizeCheckbox() {
|
|
33
73
|
var checkbox = document.createElement("input");
|
|
34
74
|
checkbox.type = "checkbox";
|
|
@@ -65,13 +105,25 @@ class ChartControls {
|
|
|
65
105
|
});
|
|
66
106
|
}
|
|
67
107
|
|
|
108
|
+
private addCSVDownload() {
|
|
109
|
+
var button = document.createElement("button");
|
|
110
|
+
button.id = "csvDownload";
|
|
111
|
+
button.textContent = "download csv";
|
|
112
|
+
|
|
113
|
+
this.element.appendChild(button);
|
|
114
|
+
button.addEventListener("click", () => {
|
|
115
|
+
this.sdm.triggerCSVDownload();
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
68
119
|
private generateTimeSelectionOptions() {
|
|
69
120
|
const options = [
|
|
70
|
-
{ text: "3 months back", value: "
|
|
71
|
-
{ text: "6 months back", value: "
|
|
121
|
+
{ text: "3 months back", value: "month-3" },
|
|
122
|
+
{ text: "6 months back", value: "month-6" },
|
|
72
123
|
{ text: "1 year back", value: "year-1" },
|
|
73
124
|
{ text: "2 years back", value: "year-2" },
|
|
74
125
|
{ text: "3 years back", value: "year-3" },
|
|
126
|
+
{ text: "custom", value: "custom" },
|
|
75
127
|
];
|
|
76
128
|
const selectEl = document.createElement("select");
|
|
77
129
|
options.forEach((entry) => {
|
|
@@ -84,6 +136,7 @@ class ChartControls {
|
|
|
84
136
|
selectEl.addEventListener("change", (evt) => {
|
|
85
137
|
const currDate = DateTime.now();
|
|
86
138
|
const [type, val] = (evt.target as HTMLSelectElement).value.split("-");
|
|
139
|
+
this.removeStartEndInputs();
|
|
87
140
|
switch (type) {
|
|
88
141
|
case "month":
|
|
89
142
|
this.sdm.setTimeInterval(
|
|
@@ -97,6 +150,9 @@ class ChartControls {
|
|
|
97
150
|
currDate
|
|
98
151
|
);
|
|
99
152
|
break;
|
|
153
|
+
case "custom":
|
|
154
|
+
this.addStartEndInputs();
|
|
155
|
+
break;
|
|
100
156
|
}
|
|
101
157
|
});
|
|
102
158
|
}
|
package/src/main.ts
CHANGED
|
@@ -10,6 +10,27 @@ const eoxchart = new Chart(
|
|
|
10
10
|
labels: [],
|
|
11
11
|
datasets: [],
|
|
12
12
|
},
|
|
13
|
+
plugins: [
|
|
14
|
+
{
|
|
15
|
+
id: "selectionLineHighlight",
|
|
16
|
+
afterDraw: (chart) => {
|
|
17
|
+
const active = chart.tooltip.getActiveElements();
|
|
18
|
+
if (active?.length) {
|
|
19
|
+
let x = active[0].element.x;
|
|
20
|
+
let yAxis = chart.scales.y;
|
|
21
|
+
let ctx = chart.ctx;
|
|
22
|
+
ctx.save();
|
|
23
|
+
ctx.beginPath();
|
|
24
|
+
ctx.moveTo(x, yAxis.top);
|
|
25
|
+
ctx.lineTo(x, yAxis.bottom);
|
|
26
|
+
ctx.lineWidth = 1;
|
|
27
|
+
ctx.strokeStyle = "rgba(0, 0, 255, 0.4)";
|
|
28
|
+
ctx.stroke();
|
|
29
|
+
ctx.restore();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
13
34
|
}
|
|
14
35
|
);
|
|
15
36
|
|
|
@@ -103,6 +103,11 @@ class SignalsDataManager {
|
|
|
103
103
|
},
|
|
104
104
|
},
|
|
105
105
|
},
|
|
106
|
+
interaction: {
|
|
107
|
+
axis: "x",
|
|
108
|
+
mode: "nearest",
|
|
109
|
+
intersect: false,
|
|
110
|
+
},
|
|
106
111
|
plugins: {
|
|
107
112
|
legend: {
|
|
108
113
|
labels: {
|
|
@@ -123,6 +128,20 @@ class SignalsDataManager {
|
|
|
123
128
|
}
|
|
124
129
|
},
|
|
125
130
|
},
|
|
131
|
+
tooltip: {
|
|
132
|
+
callbacks: {
|
|
133
|
+
title: (tooltipItem) => {
|
|
134
|
+
const raw: any = tooltipItem[0]?.raw;
|
|
135
|
+
return raw.x.toISODate();
|
|
136
|
+
},
|
|
137
|
+
label: (tooltipItem) => {
|
|
138
|
+
const raw: any = tooltipItem.raw;
|
|
139
|
+
return `${tooltipItem.dataset.label}: ↔ ${raw.y.toPrecision(
|
|
140
|
+
3
|
|
141
|
+
)}; ↓ ${raw.yMin.toPrecision(3)}, ↑ ${raw.yMax.toPrecision(3)}`;
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
126
145
|
},
|
|
127
146
|
};
|
|
128
147
|
}
|
|
@@ -253,14 +272,16 @@ class SignalsDataManager {
|
|
|
253
272
|
let maxSum = 0;
|
|
254
273
|
while (
|
|
255
274
|
currDataIdx < signalData.length &&
|
|
256
|
-
signalData[currDataIdx].
|
|
275
|
+
(Object.keys(signalData[currDataIdx]).length === 0 ||
|
|
276
|
+
signalData[currDataIdx].x < currDate)
|
|
257
277
|
) {
|
|
258
278
|
currDataIdx++;
|
|
259
279
|
}
|
|
260
280
|
const x1 = currDataIdx;
|
|
261
281
|
while (
|
|
262
282
|
currDataIdx < signalData.length &&
|
|
263
|
-
signalData[currDataIdx].
|
|
283
|
+
(Object.keys(signalData[currDataIdx]).length === 0 ||
|
|
284
|
+
signalData[currDataIdx].x < currDate.plus(this.timeAggregation))
|
|
264
285
|
) {
|
|
265
286
|
const sd = signalData[currDataIdx];
|
|
266
287
|
dataSum += sd.y;
|
|
@@ -413,6 +434,91 @@ class SignalsDataManager {
|
|
|
413
434
|
}
|
|
414
435
|
}
|
|
415
436
|
|
|
437
|
+
triggerCSVDownload() {
|
|
438
|
+
const completeData: {
|
|
439
|
+
date: string;
|
|
440
|
+
basicStats?: { mean: number; min: number; max: number };
|
|
441
|
+
}[][] = [];
|
|
442
|
+
const headers: string[] = [];
|
|
443
|
+
const allSignals = this.activeFields;
|
|
444
|
+
allSignals.forEach((key, signalIdx) => {
|
|
445
|
+
// Find group
|
|
446
|
+
let groupIndex: number = -1;
|
|
447
|
+
this.options.features.forEach((group, idx) => {
|
|
448
|
+
if (group.includes(key)) {
|
|
449
|
+
groupIndex = idx;
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
if (groupIndex !== -1) {
|
|
453
|
+
let data: {
|
|
454
|
+
date: string;
|
|
455
|
+
basicStats?: { mean: number; min: number; max: number };
|
|
456
|
+
}[] = [];
|
|
457
|
+
Object.keys(this.dataStorage[groupIndex]).forEach((timekey) => {
|
|
458
|
+
const dsEntry = this.dataStorage[groupIndex][timekey];
|
|
459
|
+
if (dsEntry.status === "finished") {
|
|
460
|
+
if (
|
|
461
|
+
Object.keys(dsEntry.data).length !== 0 &&
|
|
462
|
+
Object.keys(dsEntry.data).includes(key)
|
|
463
|
+
) {
|
|
464
|
+
data.push(...dsEntry.data[key]);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
if (data.length > 0) {
|
|
469
|
+
headers.push(allSignals[signalIdx]);
|
|
470
|
+
completeData.push(data);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
// We need to try and bring the different timed datasets into "same timegrid" lets do some binning
|
|
475
|
+
const binnedData: {
|
|
476
|
+
[key: string]: {
|
|
477
|
+
[key: string]: {
|
|
478
|
+
mean: number;
|
|
479
|
+
max: number;
|
|
480
|
+
min: number;
|
|
481
|
+
};
|
|
482
|
+
};
|
|
483
|
+
} = {};
|
|
484
|
+
headers.forEach((datakey, idx) => {
|
|
485
|
+
completeData[idx].forEach((dp) => {
|
|
486
|
+
if (binnedData[dp.date]) {
|
|
487
|
+
binnedData[dp.date][datakey] = dp.basicStats;
|
|
488
|
+
} else {
|
|
489
|
+
binnedData[dp.date] = {};
|
|
490
|
+
binnedData[dp.date][datakey] = dp.basicStats;
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
// Now we try to construct the csv adding empty values when timestamp not available for a dataset
|
|
496
|
+
let csv = "time,";
|
|
497
|
+
const allHeaders = headers.map((val) => [val, `${val}_max`, `${val}_min`]);
|
|
498
|
+
csv += allHeaders.flat().join(",");
|
|
499
|
+
csv += "\n";
|
|
500
|
+
Object.keys(binnedData).forEach((dateKey) => {
|
|
501
|
+
const row: (string | number)[] = [dateKey];
|
|
502
|
+
headers.forEach((signalKey) => {
|
|
503
|
+
const stats = binnedData[dateKey][signalKey]
|
|
504
|
+
? binnedData[dateKey][signalKey]
|
|
505
|
+
: null;
|
|
506
|
+
if (stats != null) {
|
|
507
|
+
row.push(...[stats.mean, stats.max, stats.min]);
|
|
508
|
+
} else {
|
|
509
|
+
row.push(...["", "", ""]);
|
|
510
|
+
}
|
|
511
|
+
});
|
|
512
|
+
csv += row.join(",");
|
|
513
|
+
csv += "\n";
|
|
514
|
+
});
|
|
515
|
+
var hiddenElement = document.createElement("a");
|
|
516
|
+
hiddenElement.href = "data:text/csv;charset=utf-8," + encodeURI(csv);
|
|
517
|
+
hiddenElement.target = "_blank";
|
|
518
|
+
hiddenElement.download = "chart_data.csv";
|
|
519
|
+
hiddenElement.click();
|
|
520
|
+
}
|
|
521
|
+
|
|
416
522
|
setGeometry(geometry: object) {
|
|
417
523
|
// Clear all currently saved data
|
|
418
524
|
this.dataStorage = {};
|