@eox/chart 2.0.0-alpha1 → 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
@@ -51,9 +51,17 @@
51
51
  100% {
52
52
  transform: rotate(360deg);
53
53
  }
54
- }
54
+ }
55
+ #controls {
56
+ position: absolute;
57
+ width: 100%;
58
+ height: 30px;
59
+ }
60
+ #chart {
61
+ padding-top: 30px;
62
+ }
55
63
  </style>
56
- <script type="module" crossorigin src="./assets/main-800e32b1.js"></script>
64
+ <script type="module" crossorigin src="./assets/main-d9b1cb92.js"></script>
57
65
  </head>
58
66
  <body>
59
67
  <div id="controls" class="controls" data-cy="controls"></div>
@@ -1,8 +1,8 @@
1
- var c = Object.defineProperty;
2
- var d = (s, t, e) => t in s ? c(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var l = (s, t, e) => (d(s, typeof t != "symbol" ? t + "" : t, e), e);
1
+ var d = Object.defineProperty;
2
+ var c = (s, t, e) => t in s ? d(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var l = (s, t, e) => (c(s, typeof t != "symbol" ? t + "" : t, e), e);
4
4
  const p = new MessageChannel(), o = p.port1;
5
- class h {
5
+ class g {
6
6
  constructor(t) {
7
7
  l(this, "iframe");
8
8
  this.iframe = t;
@@ -16,6 +16,9 @@ class h {
16
16
  setSignalsEndpoint(t) {
17
17
  o.postMessage({ type: "setSignalsEndpoint", body: { options: t } });
18
18
  }
19
+ setSignalsGeometry(t) {
20
+ o.postMessage({ type: "setSignalsGeometry", body: { geometry: t } });
21
+ }
19
22
  setOptions(t) {
20
23
  o.postMessage({ type: "setOptions", body: { options: t } });
21
24
  }
@@ -38,7 +41,7 @@ const m = (s) => s ? new Promise((t) => {
38
41
  let a = !1;
39
42
  e.onload = () => {
40
43
  var i;
41
- a || ((i = e.contentWindow) == null || i.postMessage("init", "*", [p.port2]), a = !0, t(new h(e)));
44
+ a || ((i = e.contentWindow) == null || i.postMessage("init", "*", [p.port2]), a = !0, t(new g(e)));
42
45
  };
43
46
  }) : (console.error("no div selected"), null);
44
47
  export {
@@ -1 +1 @@
1
- (function(n,e){typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.Interface={}))})(this,function(n){"use strict";var u=Object.defineProperty;var f=(n,e,o)=>e in n?u(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o;var c=(n,e,o)=>(f(n,typeof e!="symbol"?e+"":e,o),o);const e=new MessageChannel,o=e.port1;class l{constructor(t){c(this,"iframe");this.iframe=t}setData(t){o.postMessage({type:"setData",body:{data:t}})}setSignalsData(t){o.postMessage({type:"setSignalsData",body:{data:t}})}setSignalsEndpoint(t){o.postMessage({type:"setSignalsEndpoint",body:{options:t}})}setOptions(t){o.postMessage({type:"setOptions",body:{options:t}})}getFoo(){return new Promise(t=>{const s=Date.now();o.onmessage=a=>{a.data.ts===s&&t(a.data.body)},o.postMessage({ts:s,type:"getFoo",body:"hello world"})})}}const p=r=>r?new Promise(t=>{var i;const s=document.createElement("iframe");s.style.cssText="width: 100%; height: 100%; display: block; margin: 0; border: none;",s.setAttribute("src",(i=typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||new URL("interface.umd.js",document.baseURI).href)!=null&&i.includes("localhost")?"http://localhost:5173/index.html":"https://www.unpkg.com/@eox/chart/dist/index.html"),s.setAttribute("id","EOxChart"),r==null||r.appendChild(s);let a=!1;s.onload=()=>{var d;a||((d=s.contentWindow)==null||d.postMessage("init","*",[e.port2]),a=!0,t(new l(s)))}}):(console.error("no div selected"),null);n.createChart=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(n=typeof globalThis<"u"?globalThis:n||self,t(n.Interface={}))})(this,function(n){"use strict";var u=Object.defineProperty;var f=(n,t,o)=>t in n?u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o;var c=(n,t,o)=>(f(n,typeof t!="symbol"?t+"":t,o),o);const t=new MessageChannel,o=t.port1;class l{constructor(e){c(this,"iframe");this.iframe=e}setData(e){o.postMessage({type:"setData",body:{data:e}})}setSignalsData(e){o.postMessage({type:"setSignalsData",body:{data:e}})}setSignalsEndpoint(e){o.postMessage({type:"setSignalsEndpoint",body:{options:e}})}setSignalsGeometry(e){o.postMessage({type:"setSignalsGeometry",body:{geometry:e}})}setOptions(e){o.postMessage({type:"setOptions",body:{options:e}})}getFoo(){return new Promise(e=>{const s=Date.now();o.onmessage=r=>{r.data.ts===s&&e(r.data.body)},o.postMessage({ts:s,type:"getFoo",body:"hello world"})})}}const p=a=>a?new Promise(e=>{var i;const s=document.createElement("iframe");s.style.cssText="width: 100%; height: 100%; display: block; margin: 0; border: none;",s.setAttribute("src",(i=typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||new URL("interface.umd.js",document.baseURI).href)!=null&&i.includes("localhost")?"http://localhost:5173/index.html":"https://www.unpkg.com/@eox/chart/dist/index.html"),s.setAttribute("id","EOxChart"),a==null||a.appendChild(s);let r=!1;s.onload=()=>{var d;r||((d=s.contentWindow)==null||d.postMessage("init","*",[t.port2]),r=!0,e(new l(s)))}}):(console.error("no div selected"),null);n.createChart=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
package/index.html CHANGED
@@ -51,7 +51,15 @@
51
51
  100% {
52
52
  transform: rotate(360deg);
53
53
  }
54
- }
54
+ }
55
+ #controls {
56
+ position: absolute;
57
+ width: 100%;
58
+ height: 30px;
59
+ }
60
+ #chart {
61
+ padding-top: 30px;
62
+ }
55
63
  </style>
56
64
  </head>
57
65
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/chart",
3
- "version": "2.0.0-alpha1",
3
+ "version": "2.0.0-alpha3",
4
4
  "dependencies": {
5
5
  "chart.js": "^4.2.1",
6
6
  "chartjs-adapter-luxon": "^1.3.1",
@@ -1,8 +1,8 @@
1
- var c = Object.defineProperty;
2
- var d = (s, t, e) => t in s ? c(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
- var l = (s, t, e) => (d(s, typeof t != "symbol" ? t + "" : t, e), e);
1
+ var d = Object.defineProperty;
2
+ var c = (s, t, e) => t in s ? d(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var l = (s, t, e) => (c(s, typeof t != "symbol" ? t + "" : t, e), e);
4
4
  const p = new MessageChannel(), o = p.port1;
5
- class h {
5
+ class g {
6
6
  constructor(t) {
7
7
  l(this, "iframe");
8
8
  this.iframe = t;
@@ -16,6 +16,9 @@ class h {
16
16
  setSignalsEndpoint(t) {
17
17
  o.postMessage({ type: "setSignalsEndpoint", body: { options: t } });
18
18
  }
19
+ setSignalsGeometry(t) {
20
+ o.postMessage({ type: "setSignalsGeometry", body: { geometry: t } });
21
+ }
19
22
  setOptions(t) {
20
23
  o.postMessage({ type: "setOptions", body: { options: t } });
21
24
  }
@@ -38,7 +41,7 @@ const m = (s) => s ? new Promise((t) => {
38
41
  let a = !1;
39
42
  e.onload = () => {
40
43
  var i;
41
- a || ((i = e.contentWindow) == null || i.postMessage("init", "*", [p.port2]), a = !0, t(new h(e)));
44
+ a || ((i = e.contentWindow) == null || i.postMessage("init", "*", [p.port2]), a = !0, t(new g(e)));
42
45
  };
43
46
  }) : (console.error("no div selected"), null);
44
47
  export {
@@ -1 +1 @@
1
- (function(n,e){typeof exports=="object"&&typeof module<"u"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.Interface={}))})(this,function(n){"use strict";var u=Object.defineProperty;var f=(n,e,o)=>e in n?u(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o;var c=(n,e,o)=>(f(n,typeof e!="symbol"?e+"":e,o),o);const e=new MessageChannel,o=e.port1;class l{constructor(t){c(this,"iframe");this.iframe=t}setData(t){o.postMessage({type:"setData",body:{data:t}})}setSignalsData(t){o.postMessage({type:"setSignalsData",body:{data:t}})}setSignalsEndpoint(t){o.postMessage({type:"setSignalsEndpoint",body:{options:t}})}setOptions(t){o.postMessage({type:"setOptions",body:{options:t}})}getFoo(){return new Promise(t=>{const s=Date.now();o.onmessage=a=>{a.data.ts===s&&t(a.data.body)},o.postMessage({ts:s,type:"getFoo",body:"hello world"})})}}const p=r=>r?new Promise(t=>{var i;const s=document.createElement("iframe");s.style.cssText="width: 100%; height: 100%; display: block; margin: 0; border: none;",s.setAttribute("src",(i=typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||new URL("interface.umd.js",document.baseURI).href)!=null&&i.includes("localhost")?"http://localhost:5173/index.html":"https://www.unpkg.com/@eox/chart/dist/index.html"),s.setAttribute("id","EOxChart"),r==null||r.appendChild(s);let a=!1;s.onload=()=>{var d;a||((d=s.contentWindow)==null||d.postMessage("init","*",[e.port2]),a=!0,t(new l(s)))}}):(console.error("no div selected"),null);n.createChart=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(n=typeof globalThis<"u"?globalThis:n||self,t(n.Interface={}))})(this,function(n){"use strict";var u=Object.defineProperty;var f=(n,t,o)=>t in n?u(n,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[t]=o;var c=(n,t,o)=>(f(n,typeof t!="symbol"?t+"":t,o),o);const t=new MessageChannel,o=t.port1;class l{constructor(e){c(this,"iframe");this.iframe=e}setData(e){o.postMessage({type:"setData",body:{data:e}})}setSignalsData(e){o.postMessage({type:"setSignalsData",body:{data:e}})}setSignalsEndpoint(e){o.postMessage({type:"setSignalsEndpoint",body:{options:e}})}setSignalsGeometry(e){o.postMessage({type:"setSignalsGeometry",body:{geometry:e}})}setOptions(e){o.postMessage({type:"setOptions",body:{options:e}})}getFoo(){return new Promise(e=>{const s=Date.now();o.onmessage=r=>{r.data.ts===s&&e(r.data.body)},o.postMessage({ts:s,type:"getFoo",body:"hello world"})})}}const p=a=>a?new Promise(e=>{var i;const s=document.createElement("iframe");s.style.cssText="width: 100%; height: 100%; display: block; margin: 0; border: none;",s.setAttribute("src",(i=typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:document.currentScript&&document.currentScript.src||new URL("interface.umd.js",document.baseURI).href)!=null&&i.includes("localhost")?"http://localhost:5173/index.html":"https://www.unpkg.com/@eox/chart/dist/index.html"),s.setAttribute("id","EOxChart"),a==null||a.appendChild(s);let r=!1;s.onload=()=>{var d;r||((d=s.contentWindow)==null||d.postMessage("init","*",[t.port2]),r=!0,e(new l(s)))}}):(console.error("no div selected"),null);n.createChart=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
@@ -1,31 +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;
19
- this.generateSelectionOptions();
21
+ this.sdmOptions = sdmOptions;
22
+ this.generateTimeSelectionOptions();
23
+ this.generateTimeAggregationOptions();
24
+ this.addNormalizeCheckbox();
25
+ const spinner = document.createElement("span");
26
+ spinner.id = "loadingIndicator";
27
+ spinner.className = "loader hidden";
28
+ this.element.appendChild(spinner);
29
+ }
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
+ });
20
47
  }
21
48
 
22
- private generateSelectionOptions() {
49
+ private generateTimeSelectionOptions() {
23
50
  const options = [
24
- { text: "3 months back", value: "months3" },
25
- { text: "6 months back", value: "months6" },
26
- { text: "1 year back", value: "year1" },
27
- { text: "2 years back", value: "year2" },
28
- { text: "3 years back", value: "year3" },
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" },
29
56
  ];
30
57
  const selectEl = document.createElement("select");
31
58
  options.forEach((entry) => {
@@ -37,25 +64,60 @@ class ChartControls {
37
64
  this.element.appendChild(selectEl);
38
65
  selectEl.addEventListener("change", (evt) => {
39
66
  const currDate = DateTime.now();
40
- switch ((evt.target as HTMLSelectElement).value) {
41
- case "months3":
42
- this.sdm.setTimeInterval(currDate.minus({ months: 3 }), 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
+ );
74
+ break;
75
+ case "year":
76
+ this.sdm.setTimeInterval(
77
+ currDate.minus({ year: Number(val) }),
78
+ currDate
79
+ );
43
80
  break;
44
- case "months6":
45
- this.sdm.setTimeInterval(currDate.minus({ months: 6 }), currDate);
81
+ }
82
+ });
83
+ }
84
+
85
+ private generateTimeAggregationOptions() {
86
+ const options = [
87
+ { text: "no aggregation", value: "none" },
88
+ { text: "1 week", value: "week-1" },
89
+ { text: "2 weeks", value: "week-2" },
90
+ { text: "1 month", value: "month-1" },
91
+ { text: "3 months", value: "month-3" },
92
+ { text: "6 months", value: "month-6" },
93
+ ];
94
+ const selectEl = document.createElement("select");
95
+ options.forEach((entry) => {
96
+ const option = document.createElement("option");
97
+ option.text = entry.text;
98
+ option.value = entry.value;
99
+ selectEl.appendChild(option);
100
+ });
101
+ this.element.appendChild(selectEl);
102
+ selectEl.addEventListener("change", (evt) => {
103
+ const [type, val] = (evt.target as HTMLSelectElement).value.split("-");
104
+ switch (type) {
105
+ case "none":
106
+ this.sdm.setTimeAggregation(null);
46
107
  break;
47
- case "year1":
48
- this.sdm.setTimeInterval(currDate.minus({ years: 1 }), currDate);
108
+ case "week":
109
+ this.sdm.setTimeAggregation({ week: Number(val) });
49
110
  break;
50
- case "year2":
51
- this.sdm.setTimeInterval(currDate.minus({ years: 2 }), currDate);
111
+ case "month":
112
+ this.sdm.setTimeAggregation({ month: Number(val) });
52
113
  break;
53
- case "year3":
54
- this.sdm.setTimeInterval(currDate.minus({ years: 3 }), currDate);
114
+ case "year":
115
+ this.sdm.setTimeAggregation({ year: Number(val) });
55
116
  break;
56
117
  }
57
118
  });
58
119
  const spinner = document.createElement("span");
120
+ spinner.id = "loadingIndicator";
59
121
  spinner.className = "loader hidden";
60
122
  this.element.appendChild(spinner);
61
123
  }
package/src/interface.ts CHANGED
@@ -24,6 +24,9 @@ class EOxChart {
24
24
  }) {
25
25
  port1.postMessage({ type: "setSignalsEndpoint", body: { options } });
26
26
  }
27
+ setSignalsGeometry(geometry: object) {
28
+ port1.postMessage({ type: "setSignalsGeometry", body: { geometry } });
29
+ }
27
30
  setOptions(options: object) {
28
31
  port1.postMessage({ type: "setOptions", body: { options } });
29
32
  }
package/src/main.ts CHANGED
@@ -13,6 +13,8 @@ const eoxchart = new Chart(
13
13
  }
14
14
  );
15
15
 
16
+ let sdmInstance: SignalsDataManager | null = null;
17
+
16
18
  let application: MessagePort;
17
19
 
18
20
  window.addEventListener("message", (event) => {
@@ -39,6 +41,9 @@ const onMessage = (event: MessageEvent) => {
39
41
  case "setSignalsEndpoint":
40
42
  setSignalsEndpoint(event.data.body.options);
41
43
  break;
44
+ case "setSignalsGeometry":
45
+ setSignalsGeometry(event.data.body.options);
46
+ break;
42
47
  case "setSignalsData":
43
48
  eoxchart.data = {
44
49
  datasets: Object.entries(event.data.body.data).map(
@@ -71,7 +76,13 @@ const setSignalsEndpoint = (options: {
71
76
  startTime?: string;
72
77
  endTime?: string;
73
78
  }) => {
74
- const sdm = new SignalsDataManager(eoxchart, options);
75
- new ChartControls(document.getElementById("controls"), sdm);
76
- sdm.setActiveFields(options.active);
79
+ sdmInstance = new SignalsDataManager(eoxchart, options);
80
+ new ChartControls(document.getElementById("controls"), sdmInstance, options);
81
+ sdmInstance.setActiveFields(options.active);
82
+ };
83
+
84
+ const setSignalsGeometry = (geometry: object) => {
85
+ if (sdmInstance) {
86
+ sdmInstance.setGeometry(geometry);
87
+ }
77
88
  };
@@ -47,12 +47,16 @@ export interface SDMOptions {
47
47
  timeInterval: object;
48
48
  startTime?: string;
49
49
  endTime?: string;
50
+ timeAggregation?: object;
51
+ retries?: number;
52
+ normalize?: boolean;
50
53
  }
51
54
 
52
55
  class SignalsDataManager {
53
56
  chart: Chart;
54
57
  startTime: DateTime;
55
58
  endTime: DateTime;
59
+ timeAggregation: object;
56
60
  options: SDMOptions;
57
61
  chartOptions: ChartOptions;
58
62
  dataStorage: DSDict;
@@ -69,6 +73,13 @@ class SignalsDataManager {
69
73
  this.startTime = DateTime.fromISO(options.startTime).setZone("UTC");
70
74
  this.endTime = DateTime.fromISO(options.endTime).setZone("UTC");
71
75
  }
76
+ if (this.options.timeAggregation) {
77
+ this.timeAggregation = this.options.timeAggregation;
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;
72
83
  this.dataStorage = {};
73
84
  // Initialize data storage
74
85
  this.options.features.forEach((_, idx) => (this.dataStorage[idx] = {}));
@@ -91,6 +102,13 @@ class SignalsDataManager {
91
102
  },
92
103
  plugins: {
93
104
  legend: {
105
+ labels: {
106
+ /*
107
+ usePointStyle: true,
108
+ pointStyle: "line",
109
+ */
110
+ sort: (a, b) => a.text.localeCompare(b.text),
111
+ },
94
112
  position: "right",
95
113
  onClick: (_, legendItem) => {
96
114
  if (!legendItem.hidden) {
@@ -106,6 +124,19 @@ class SignalsDataManager {
106
124
  },
107
125
  };
108
126
  }
127
+ private checkLoadingStatus() {
128
+ const spinner = document.getElementById("loadingIndicator");
129
+ let loading = false;
130
+ // TODO: Showing when error state happened
131
+ Object.keys(this.dataStorage).forEach((_, groupIdx) => {
132
+ Object.keys(this.dataStorage[groupIdx]).forEach((timeKey) => {
133
+ if (this.dataStorage[groupIdx][timeKey].status === "fetching") {
134
+ loading = true;
135
+ }
136
+ });
137
+ });
138
+ spinner.className = loading ? "loader" : "loader hidden";
139
+ }
109
140
 
110
141
  private fetchSignals(groupIndex: number, start?: DateTime, end?: DateTime) {
111
142
  const features = this.options.features[groupIndex]
@@ -141,13 +172,15 @@ class SignalsDataManager {
141
172
  `Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`
142
173
  );
143
174
  },
144
- retries: 5,
175
+ retries: this.options.retries,
145
176
  }).then(function (res) {
146
177
  return res.json();
147
178
  });
179
+ this.checkLoadingStatus();
148
180
  }
149
181
 
150
182
  private updateChart() {
183
+ this.checkLoadingStatus();
151
184
  this.chart.options = this.chartOptions;
152
185
  const datasets: ChartDataset[] = [];
153
186
  this.options.features.flat().forEach((key) => {
@@ -176,23 +209,88 @@ class SignalsDataManager {
176
209
  data.push({ date: "missing" });
177
210
  }
178
211
  });
212
+
213
+ let actualDataAdded = false;
214
+ let max = Number.MIN_VALUE;
215
+ let min = Number.MAX_VALUE;
216
+ let signalData = <any>data.map((datapoint) => {
217
+ let ds = {};
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
+ }
225
+ ds = {
226
+ x: DateTime.fromISO(datapoint.date).setZone("UTC"),
227
+ y: datapoint.basicStats.mean,
228
+ yMin: [datapoint.basicStats.min],
229
+ yMax: [datapoint.basicStats.max],
230
+ };
231
+ actualDataAdded = true;
232
+ }
233
+ return ds;
234
+ });
235
+ if (actualDataAdded && this.timeAggregation) {
236
+ const aggrData = [];
237
+ let currDataIdx = 0;
238
+ let currDate = DateTime.fromObject({
239
+ year: this.startTime.year,
240
+ month: this.startTime.month,
241
+ day: this.startTime.day,
242
+ });
243
+ while (currDate < this.endTime) {
244
+ let dataSum = 0;
245
+ while (
246
+ currDataIdx < signalData.length &&
247
+ signalData[currDataIdx].x < currDate
248
+ ) {
249
+ currDataIdx++;
250
+ }
251
+ const x1 = currDataIdx;
252
+ while (
253
+ currDataIdx < signalData.length &&
254
+ signalData[currDataIdx].x < currDate.plus(this.timeAggregation)
255
+ ) {
256
+ dataSum += signalData[currDataIdx].y;
257
+ currDataIdx++;
258
+ }
259
+ const x2 = currDataIdx;
260
+ const count = x2 - x1;
261
+ // If datapoints are within the interval we push the aggregation to the aggregated data
262
+ if (count > 0) {
263
+ // TODO: can we save a time interval here?
264
+ aggrData.push({
265
+ x: currDate,
266
+ y: dataSum / count,
267
+ });
268
+ }
269
+ currDate = currDate.plus(this.timeAggregation);
270
+ }
271
+ signalData = aggrData;
272
+ }
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
+
179
288
  datasets.push({
180
289
  // type: "lineWithErrorBars",
181
290
  type: "line",
182
291
  label: key,
183
292
  // casting to any because an array of object should also be possible
184
- data: <any>data.map((datapoint) => {
185
- let ds = {};
186
- if (datapoint && datapoint.date !== "missing") {
187
- ds = {
188
- x: DateTime.fromISO(datapoint.date).setZone("UTC"),
189
- y: datapoint.basicStats.mean,
190
- yMin: [datapoint.basicStats.min],
191
- yMax: [datapoint.basicStats.max],
192
- };
193
- }
194
- return ds;
195
- }),
293
+ data: signalData,
196
294
  hidden: !this.activeFields.includes(key),
197
295
  });
198
296
  }
@@ -245,11 +343,16 @@ class SignalsDataManager {
245
343
  })
246
344
  .plus({ month: 1 })
247
345
  .minus({ second: 1 })
248
- ).then((data) => {
249
- this.dataStorage[index][timeslot].data = data;
250
- this.dataStorage[index][timeslot].status = "finished";
251
- this.updateChart();
252
- });
346
+ )
347
+ .then((data) => {
348
+ this.dataStorage[index][timeslot].data = data;
349
+ this.dataStorage[index][timeslot].status = "finished";
350
+ this.updateChart();
351
+ })
352
+ .catch(() => {
353
+ this.dataStorage[index][timeslot].status = "failed";
354
+ this.updateChart();
355
+ });
253
356
  this.dataStorage[index][timeslot] = {
254
357
  request,
255
358
  status: "fetching",
@@ -260,6 +363,14 @@ class SignalsDataManager {
260
363
  }
261
364
  }
262
365
 
366
+ setGeometry(geometry: object) {
367
+ // Clear all currently saved data
368
+ this.dataStorage = {};
369
+ this.options.geometry = geometry;
370
+ this.retrieveMissingData();
371
+ this.updateChart();
372
+ }
373
+
263
374
  setActiveFields(activeFields: string[]) {
264
375
  this.activeFields = activeFields;
265
376
  this.retrieveMissingData();
@@ -274,6 +385,23 @@ class SignalsDataManager {
274
385
  this.retrieveMissingData();
275
386
  this.updateChart();
276
387
  }
388
+
389
+ setNormalize(normalize: boolean) {
390
+ this.options.normalize = normalize;
391
+ this.updateChart();
392
+ }
393
+
394
+ setTimeAggregation(
395
+ aggregation: {
396
+ day?: number;
397
+ week?: number;
398
+ month?: number;
399
+ year?: number;
400
+ } | null
401
+ ) {
402
+ this.timeAggregation = aggregation;
403
+ this.updateChart();
404
+ }
277
405
  /*
278
406
  setAggregation(aggregation: string) {}
279
407
  */