@eox/chart 2.0.0-alpha2 → 2.0.0-alpha3
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/dist/index.html
CHANGED
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
padding-top: 30px;
|
|
62
62
|
}
|
|
63
63
|
</style>
|
|
64
|
-
<script type="module" crossorigin src="./assets/main-
|
|
64
|
+
<script type="module" crossorigin src="./assets/main-d9b1cb92.js"></script>
|
|
65
65
|
</head>
|
|
66
66
|
<body>
|
|
67
67
|
<div id="controls" class="controls" data-cy="controls"></div>
|
package/package.json
CHANGED
package/src/chartControls.ts
CHANGED
|
@@ -1,36 +1,58 @@
|
|
|
1
1
|
import { DateTime } from "luxon";
|
|
2
|
-
import SignalsDataManager from "./signalsDataManager";
|
|
2
|
+
import SignalsDataManager, { SDMOptions } from "./signalsDataManager";
|
|
3
3
|
|
|
4
4
|
export interface ChartControlOptions {}
|
|
5
5
|
|
|
6
6
|
class ChartControls {
|
|
7
7
|
element: HTMLElement;
|
|
8
8
|
sdm: SignalsDataManager;
|
|
9
|
+
sdmOptions: SDMOptions;
|
|
9
10
|
options?: ChartControlOptions;
|
|
10
11
|
|
|
11
12
|
constructor(
|
|
12
13
|
element: HTMLElement,
|
|
13
14
|
sdm: SignalsDataManager,
|
|
15
|
+
sdmOptions: SDMOptions,
|
|
14
16
|
options?: ChartControlOptions
|
|
15
17
|
) {
|
|
16
18
|
this.element = element;
|
|
17
19
|
this.sdm = sdm;
|
|
18
20
|
this.options = options;
|
|
21
|
+
this.sdmOptions = sdmOptions;
|
|
19
22
|
this.generateTimeSelectionOptions();
|
|
20
23
|
this.generateTimeAggregationOptions();
|
|
24
|
+
this.addNormalizeCheckbox();
|
|
21
25
|
const spinner = document.createElement("span");
|
|
22
26
|
spinner.id = "loadingIndicator";
|
|
23
27
|
spinner.className = "loader hidden";
|
|
24
28
|
this.element.appendChild(spinner);
|
|
25
29
|
}
|
|
26
30
|
|
|
31
|
+
private addNormalizeCheckbox() {
|
|
32
|
+
var checkbox = document.createElement("input");
|
|
33
|
+
checkbox.type = "checkbox";
|
|
34
|
+
checkbox.id = "normalize";
|
|
35
|
+
checkbox.value = "normalize";
|
|
36
|
+
checkbox.checked = this.sdmOptions.normalize;
|
|
37
|
+
|
|
38
|
+
var label = document.createElement("label");
|
|
39
|
+
label.htmlFor = "normalize";
|
|
40
|
+
label.appendChild(document.createTextNode("Normalize"));
|
|
41
|
+
|
|
42
|
+
this.element.appendChild(label);
|
|
43
|
+
this.element.appendChild(checkbox);
|
|
44
|
+
checkbox.addEventListener("change", () => {
|
|
45
|
+
this.sdm.setNormalize(checkbox.checked);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
27
49
|
private generateTimeSelectionOptions() {
|
|
28
50
|
const options = [
|
|
29
|
-
{ text: "3 months back", value: "
|
|
30
|
-
{ text: "6 months back", value: "
|
|
31
|
-
{ text: "1 year back", value: "
|
|
32
|
-
{ text: "2 years back", value: "
|
|
33
|
-
{ text: "3 years back", value: "
|
|
51
|
+
{ text: "3 months back", value: "months-3" },
|
|
52
|
+
{ text: "6 months back", value: "months-6" },
|
|
53
|
+
{ text: "1 year back", value: "year-1" },
|
|
54
|
+
{ text: "2 years back", value: "year-2" },
|
|
55
|
+
{ text: "3 years back", value: "year-3" },
|
|
34
56
|
];
|
|
35
57
|
const selectEl = document.createElement("select");
|
|
36
58
|
options.forEach((entry) => {
|
|
@@ -42,21 +64,19 @@ class ChartControls {
|
|
|
42
64
|
this.element.appendChild(selectEl);
|
|
43
65
|
selectEl.addEventListener("change", (evt) => {
|
|
44
66
|
const currDate = DateTime.now();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
case "year1":
|
|
53
|
-
this.sdm.setTimeInterval(currDate.minus({ years: 1 }), currDate);
|
|
54
|
-
break;
|
|
55
|
-
case "year2":
|
|
56
|
-
this.sdm.setTimeInterval(currDate.minus({ years: 2 }), currDate);
|
|
67
|
+
const [type, val] = (evt.target as HTMLSelectElement).value.split("-");
|
|
68
|
+
switch (type) {
|
|
69
|
+
case "month":
|
|
70
|
+
this.sdm.setTimeInterval(
|
|
71
|
+
currDate.minus({ month: Number(val) }),
|
|
72
|
+
currDate
|
|
73
|
+
);
|
|
57
74
|
break;
|
|
58
|
-
case "
|
|
59
|
-
this.sdm.setTimeInterval(
|
|
75
|
+
case "year":
|
|
76
|
+
this.sdm.setTimeInterval(
|
|
77
|
+
currDate.minus({ year: Number(val) }),
|
|
78
|
+
currDate
|
|
79
|
+
);
|
|
60
80
|
break;
|
|
61
81
|
}
|
|
62
82
|
});
|
package/src/main.ts
CHANGED
|
@@ -77,7 +77,7 @@ const setSignalsEndpoint = (options: {
|
|
|
77
77
|
endTime?: string;
|
|
78
78
|
}) => {
|
|
79
79
|
sdmInstance = new SignalsDataManager(eoxchart, options);
|
|
80
|
-
new ChartControls(document.getElementById("controls"), sdmInstance);
|
|
80
|
+
new ChartControls(document.getElementById("controls"), sdmInstance, options);
|
|
81
81
|
sdmInstance.setActiveFields(options.active);
|
|
82
82
|
};
|
|
83
83
|
|
|
@@ -48,6 +48,8 @@ export interface SDMOptions {
|
|
|
48
48
|
startTime?: string;
|
|
49
49
|
endTime?: string;
|
|
50
50
|
timeAggregation?: object;
|
|
51
|
+
retries?: number;
|
|
52
|
+
normalize?: boolean;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
class SignalsDataManager {
|
|
@@ -74,6 +76,10 @@ class SignalsDataManager {
|
|
|
74
76
|
if (this.options.timeAggregation) {
|
|
75
77
|
this.timeAggregation = this.options.timeAggregation;
|
|
76
78
|
}
|
|
79
|
+
this.options.retries = this.options.retries ? this.options.retries : 5;
|
|
80
|
+
this.options.normalize = this.options.normalize
|
|
81
|
+
? this.options.normalize
|
|
82
|
+
: false;
|
|
77
83
|
this.dataStorage = {};
|
|
78
84
|
// Initialize data storage
|
|
79
85
|
this.options.features.forEach((_, idx) => (this.dataStorage[idx] = {}));
|
|
@@ -166,7 +172,7 @@ class SignalsDataManager {
|
|
|
166
172
|
`Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`
|
|
167
173
|
);
|
|
168
174
|
},
|
|
169
|
-
retries:
|
|
175
|
+
retries: this.options.retries,
|
|
170
176
|
}).then(function (res) {
|
|
171
177
|
return res.json();
|
|
172
178
|
});
|
|
@@ -205,9 +211,17 @@ class SignalsDataManager {
|
|
|
205
211
|
});
|
|
206
212
|
|
|
207
213
|
let actualDataAdded = false;
|
|
214
|
+
let max = Number.MIN_VALUE;
|
|
215
|
+
let min = Number.MAX_VALUE;
|
|
208
216
|
let signalData = <any>data.map((datapoint) => {
|
|
209
217
|
let ds = {};
|
|
210
218
|
if (datapoint && datapoint.date !== "missing") {
|
|
219
|
+
if (datapoint.basicStats.mean < min) {
|
|
220
|
+
min = datapoint.basicStats.mean;
|
|
221
|
+
}
|
|
222
|
+
if (datapoint.basicStats.mean > max) {
|
|
223
|
+
max = datapoint.basicStats.mean;
|
|
224
|
+
}
|
|
211
225
|
ds = {
|
|
212
226
|
x: DateTime.fromISO(datapoint.date).setZone("UTC"),
|
|
213
227
|
y: datapoint.basicStats.mean,
|
|
@@ -219,8 +233,6 @@ class SignalsDataManager {
|
|
|
219
233
|
return ds;
|
|
220
234
|
});
|
|
221
235
|
if (actualDataAdded && this.timeAggregation) {
|
|
222
|
-
console.log("applying aggregation");
|
|
223
|
-
console.log(signalData);
|
|
224
236
|
const aggrData = [];
|
|
225
237
|
let currDataIdx = 0;
|
|
226
238
|
let currDate = DateTime.fromObject({
|
|
@@ -259,6 +271,20 @@ class SignalsDataManager {
|
|
|
259
271
|
signalData = aggrData;
|
|
260
272
|
}
|
|
261
273
|
|
|
274
|
+
if (actualDataAdded && this.options.normalize) {
|
|
275
|
+
signalData = signalData.map(
|
|
276
|
+
(dp: {
|
|
277
|
+
x: DateTime;
|
|
278
|
+
y: number;
|
|
279
|
+
yMin: number[];
|
|
280
|
+
yMax: number[];
|
|
281
|
+
}) => {
|
|
282
|
+
dp.y = (dp.y - min) / (max - min);
|
|
283
|
+
return dp;
|
|
284
|
+
}
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
262
288
|
datasets.push({
|
|
263
289
|
// type: "lineWithErrorBars",
|
|
264
290
|
type: "line",
|
|
@@ -360,6 +386,11 @@ class SignalsDataManager {
|
|
|
360
386
|
this.updateChart();
|
|
361
387
|
}
|
|
362
388
|
|
|
389
|
+
setNormalize(normalize: boolean) {
|
|
390
|
+
this.options.normalize = normalize;
|
|
391
|
+
this.updateChart();
|
|
392
|
+
}
|
|
393
|
+
|
|
363
394
|
setTimeAggregation(
|
|
364
395
|
aggregation: {
|
|
365
396
|
day?: number;
|