@eox/chart 2.0.0-alpha1 → 2.0.0-alpha10

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
@@ -2,8 +2,15 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <title>Simple Chart</title>
5
+ <title>EOxElements Chart</title>
6
6
  <style>
7
+ * {
8
+ font-family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
9
+ font-size: 0.95em;
10
+ }
11
+ label {
12
+ margin-top: 2.5px;
13
+ }
7
14
  html,
8
15
  body {
9
16
  margin: 0;
@@ -19,7 +26,7 @@
19
26
  visibility: hidden;
20
27
  }
21
28
  .loader {
22
- position: absolute;
29
+ position: absolute;
23
30
  top: 5px;
24
31
  right: 30px;
25
32
  width: 24px;
@@ -32,7 +39,7 @@
32
39
  animation: rotation 1s linear infinite;
33
40
  }
34
41
  .loader::after {
35
- content: '';
42
+ content: "";
36
43
  box-sizing: border-box;
37
44
  position: absolute;
38
45
  left: 0;
@@ -51,9 +58,22 @@
51
58
  100% {
52
59
  transform: rotate(360deg);
53
60
  }
54
- }
61
+ }
62
+ #controls {
63
+ position: absolute;
64
+ width: 100%;
65
+ display: flex;
66
+ gap: 5px;
67
+ flex-direction: row;
68
+ }
69
+ .parsingError {
70
+ background-color: #ff6d6d;
71
+ }
72
+ #chart {
73
+ padding-top: 30px;
74
+ }
55
75
  </style>
56
- <script type="module" crossorigin src="./assets/main-800e32b1.js"></script>
76
+ <script type="module" crossorigin src="./assets/main-ec32ac01.js"></script>
57
77
  </head>
58
78
  <body>
59
79
  <div id="controls" class="controls" data-cy="controls"></div>
@@ -1,46 +1,108 @@
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);
4
- const p = new MessageChannel(), o = p.port1;
5
- class h {
1
+ var f = Object.defineProperty;
2
+ var x = (s, t, e) => t in s ? f(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
+ var h = (s, t, e) => (x(s, typeof t != "symbol" ? t + "" : t, e), e);
4
+ const b = "@eox/chart", w = "2.0.0-alpha8", v = {
5
+ "chart.js": "^4.2.1",
6
+ "chartjs-adapter-luxon": "^1.3.1",
7
+ "chartjs-chart-error-bars": "^4.1.2"
8
+ }, D = {
9
+ "@eox/eslint-config": "^1.0.0",
10
+ "@types/luxon": "^3.2.0",
11
+ "@typescript-eslint/eslint-plugin": "^5.50.0",
12
+ "@typescript-eslint/parser": "^5.50.0",
13
+ cypress: "^12.6.0",
14
+ "cypress-vite": "^1.3.0",
15
+ "eslint-plugin-cypress": "^2.12.1",
16
+ "eslint-plugin-typescript": "^0.14.0",
17
+ install: "^0.13.0",
18
+ luxon: "^3.3.0",
19
+ npm: "^9.6.3",
20
+ "p-retry": "^5.1.2",
21
+ "pre-commit": "^1.2.2",
22
+ "start-server-and-test": "^1.15.2",
23
+ typescript: "^4.9.3",
24
+ vite: "^4.0.0"
25
+ }, M = {
26
+ npm: ">=8.0.0",
27
+ node: ">=18.0.0"
28
+ }, j = [
29
+ "dist",
30
+ "scripts",
31
+ "src",
32
+ "typings"
33
+ ], S = "./dist/interface.mjs", C = {
34
+ start: "vite",
35
+ build: "tsc && vite build --config vite.config.interface.ts && vite build --config vite.config.map.ts",
36
+ watch: "node scripts/watch.mjs",
37
+ preview: "vite preview",
38
+ format: "prettier --write .",
39
+ lint: "eslint --ext .js,.ts .",
40
+ "lint:fix": "eslint --ext .js,.ts . --fix",
41
+ cypress: "start-server-and-test start 5173 'cypress open'",
42
+ test: "start-server-and-test start 5173 'cypress run'"
43
+ }, E = {
44
+ name: b,
45
+ version: w,
46
+ dependencies: v,
47
+ devDependencies: D,
48
+ engines: M,
49
+ files: j,
50
+ main: S,
51
+ scripts: C,
52
+ "pre-commit": [
53
+ "format",
54
+ "lint:fix"
55
+ ]
56
+ }, u = new MessageChannel(), n = u.port1;
57
+ class k {
6
58
  constructor(t) {
7
- l(this, "iframe");
59
+ h(this, "iframe");
8
60
  this.iframe = t;
9
61
  }
10
62
  setData(t) {
11
- o.postMessage({ type: "setData", body: { data: t } });
63
+ n.postMessage({ type: "setData", body: { data: t } });
12
64
  }
13
65
  setSignalsData(t) {
14
- o.postMessage({ type: "setSignalsData", body: { data: t } });
66
+ n.postMessage({ type: "setSignalsData", body: { data: t } });
15
67
  }
16
68
  setSignalsEndpoint(t) {
17
- o.postMessage({ type: "setSignalsEndpoint", body: { options: t } });
69
+ n.postMessage({ type: "setSignalsEndpoint", body: { options: t } });
70
+ }
71
+ setSignalsGeometry(t) {
72
+ n.postMessage({ type: "setSignalsGeometry", body: { geometry: t } });
18
73
  }
19
74
  setOptions(t) {
20
- o.postMessage({ type: "setOptions", body: { options: t } });
75
+ n.postMessage({ type: "setOptions", body: { options: t } });
21
76
  }
22
77
  getFoo() {
23
78
  return new Promise((t) => {
24
79
  const e = Date.now();
25
- o.onmessage = (a) => {
26
- a.data.ts === e && t(a.data.body);
27
- }, o.postMessage({ ts: e, type: "getFoo", body: "hello world" });
80
+ n.onmessage = (o) => {
81
+ o.data.ts === e && t(o.data.body);
82
+ }, n.postMessage({ ts: e, type: "getFoo", body: "hello world" });
28
83
  });
29
84
  }
30
85
  }
31
- const m = (s) => s ? new Promise((t) => {
32
- var n, r;
86
+ const $ = (s) => s ? new Promise((t) => {
87
+ var a, c, p, l;
33
88
  const e = document.createElement("iframe");
34
- e.style.cssText = "width: 100%; height: 100%; display: block; margin: 0; border: none;", e.setAttribute(
89
+ if (e.style.cssText = "width: 100%; height: 100%; display: block; margin: 0; border: none;", e.setAttribute(
35
90
  "src",
36
- (r = (n = import.meta) == null ? void 0 : n.url) != null && r.includes("localhost") ? "http://localhost:5173/index.html" : "https://www.unpkg.com/@eox/chart/dist/index.html"
37
- ), e.setAttribute("id", "EOxChart"), s == null || s.appendChild(e);
38
- let a = !1;
91
+ (c = (a = import.meta) == null ? void 0 : a.url) != null && c.includes("localhost") ? "http://localhost:5173/index.html" : "about:blank"
92
+ ), e.setAttribute("id", "EOxChart"), s == null || s.appendChild(e), !((l = (p = import.meta) == null ? void 0 : p.url) != null && l.includes("localhost"))) {
93
+ const r = `https://www.unpkg.com/@eox/chart@${E.version}/dist`;
94
+ fetch(`${r}/index.html`).then((i) => i.text()).then((i) => {
95
+ var d, m, g;
96
+ const y = i.replace("./assets/", `${r}/assets/`);
97
+ (d = e.contentDocument) == null || d.open(), (m = e.contentDocument) == null || m.write(y), (g = e.contentDocument) == null || g.close();
98
+ });
99
+ }
100
+ let o = !1;
39
101
  e.onload = () => {
40
- var i;
41
- a || ((i = e.contentWindow) == null || i.postMessage("init", "*", [p.port2]), a = !0, t(new h(e)));
102
+ var r;
103
+ o || ((r = e.contentWindow) == null || r.postMessage("init", "*", [u.port2]), o = !0, t(new k(e)));
42
104
  };
43
105
  }) : (console.error("no div selected"), null);
44
106
  export {
45
- m as createChart
107
+ $ as createChart
46
108
  };
@@ -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,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(n=typeof globalThis<"u"?globalThis:n||self,s(n.Interface={}))})(this,function(n){"use strict";var v=Object.defineProperty;var S=(n,s,o)=>s in n?v(n,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[s]=o;var y=(n,s,o)=>(S(n,typeof s!="symbol"?s+"":s,o),o);const g={name:"@eox/chart",version:"2.0.0-alpha8",dependencies:{"chart.js":"^4.2.1","chartjs-adapter-luxon":"^1.3.1","chartjs-chart-error-bars":"^4.1.2"},devDependencies:{"@eox/eslint-config":"^1.0.0","@types/luxon":"^3.2.0","@typescript-eslint/eslint-plugin":"^5.50.0","@typescript-eslint/parser":"^5.50.0",cypress:"^12.6.0","cypress-vite":"^1.3.0","eslint-plugin-cypress":"^2.12.1","eslint-plugin-typescript":"^0.14.0",install:"^0.13.0",luxon:"^3.3.0",npm:"^9.6.3","p-retry":"^5.1.2","pre-commit":"^1.2.2","start-server-and-test":"^1.15.2",typescript:"^4.9.3",vite:"^4.0.0"},engines:{npm:">=8.0.0",node:">=18.0.0"},files:["dist","scripts","src","typings"],main:"./dist/interface.mjs",scripts:{start:"vite",build:"tsc && vite build --config vite.config.interface.ts && vite build --config vite.config.map.ts",watch:"node scripts/watch.mjs",preview:"vite preview",format:"prettier --write .",lint:"eslint --ext .js,.ts .","lint:fix":"eslint --ext .js,.ts . --fix",cypress:"start-server-and-test start 5173 'cypress open'",test:"start-server-and-test start 5173 'cypress run'"},"pre-commit":["format","lint:fix"]},d=new MessageChannel,i=d.port1;class b{constructor(e){y(this,"iframe");this.iframe=e}setData(e){i.postMessage({type:"setData",body:{data:e}})}setSignalsData(e){i.postMessage({type:"setSignalsData",body:{data:e}})}setSignalsEndpoint(e){i.postMessage({type:"setSignalsEndpoint",body:{options:e}})}setSignalsGeometry(e){i.postMessage({type:"setSignalsGeometry",body:{geometry:e}})}setOptions(e){i.postMessage({type:"setOptions",body:{options:e}})}getFoo(){return new Promise(e=>{const t=Date.now();i.onmessage=c=>{c.data.ts===t&&e(c.data.body)},i.postMessage({ts:t,type:"getFoo",body:"hello world"})})}}const w=r=>r?new Promise(e=>{var l,u;const t=document.createElement("iframe");if(t.style.cssText="width: 100%; height: 100%; display: block; margin: 0; border: none;",t.setAttribute("src",(l=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&&l.includes("localhost")?"http://localhost:5173/index.html":"about:blank"),t.setAttribute("id","EOxChart"),r==null||r.appendChild(t),!((u=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&&u.includes("localhost"))){const a=`https://www.unpkg.com/@eox/chart@${g.version}/dist`;fetch(`${a}/index.html`).then(p=>p.text()).then(p=>{var f,m,h;const x=p.replace("./assets/",`${a}/assets/`);(f=t.contentDocument)==null||f.open(),(m=t.contentDocument)==null||m.write(x),(h=t.contentDocument)==null||h.close()})}let c=!1;t.onload=()=>{var a;c||((a=t.contentWindow)==null||a.postMessage("init","*",[d.port2]),c=!0,e(new b(t)))}}):(console.error("no div selected"),null);n.createChart=w,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@eox/chart",
3
- "version": "2.0.0-alpha1",
3
+ "version": "2.0.0-alpha10",
4
4
  "dependencies": {
5
5
  "chart.js": "^4.2.1",
6
6
  "chartjs-adapter-luxon": "^1.3.1",
7
- "chartjs-chart-error-bars": "^4.1.1"
7
+ "chartjs-chart-error-bars": "^4.1.2"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@eox/eslint-config": "^1.0.0",
@@ -28,6 +28,13 @@
28
28
  "npm": ">=8.0.0",
29
29
  "node": ">=18.0.0"
30
30
  },
31
+ "files": [
32
+ "dist",
33
+ "scripts",
34
+ "src",
35
+ "typings"
36
+ ],
37
+ "main": "./dist/interface.mjs",
31
38
  "scripts": {
32
39
  "start": "vite",
33
40
  "build": "tsc && vite build --config vite.config.interface.ts && vite build --config vite.config.map.ts",
@@ -1,31 +1,138 @@
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;
20
+ this.sdm.on("ready", (info) => {
21
+ console.log(info);
22
+ });
18
23
  this.options = options;
19
- this.generateSelectionOptions();
24
+ this.sdmOptions = sdmOptions;
25
+ this.generateTimeAggregationOptions();
26
+ this.addNormalizeCheckbox();
27
+ this.addShowMinMax();
28
+ this.addCSVDownload();
29
+ this.generateTimeSelectionOptions();
30
+ const spinner = document.createElement("span");
31
+ spinner.id = "loadingIndicator";
32
+ spinner.className = "loader hidden";
33
+ this.element.appendChild(spinner);
34
+ }
35
+
36
+ private createMessagesElements() {
37
+ const messages = document.createElement("div");
38
+ messages.id = "messages";
39
+ this.element.appendChild(messages);
40
+ }
41
+
42
+ private removeStartEndInputs() {
43
+ const start = document.getElementById("startInput");
44
+ const end = document.getElementById("endInput");
45
+ const button = document.getElementById("setTime");
46
+ if (start && end && button) {
47
+ start.remove();
48
+ end.remove();
49
+ button.remove();
50
+ }
51
+ }
52
+ private addStartEndInputs() {
53
+ const startEl = document.createElement("input");
54
+ startEl.id = "startInput";
55
+ startEl.size = 8;
56
+ startEl.value = this.sdm.startTime.toISODate();
57
+ const endEl = document.createElement("input");
58
+ endEl.id = "endInput";
59
+ endEl.size = 8;
60
+ endEl.value = this.sdm.endTime.toISODate();
61
+ this.element.appendChild(startEl);
62
+ this.element.appendChild(endEl);
63
+ var button = document.createElement("button");
64
+ button.id = "setTime";
65
+ button.textContent = "ok";
66
+
67
+ this.element.appendChild(button);
68
+ button.addEventListener("click", () => {
69
+ const startDate = DateTime.fromISO(startEl.value);
70
+ const endDate = DateTime.fromISO(endEl.value);
71
+ if (startDate.isValid && endDate.isValid) {
72
+ this.sdm.setTimeInterval(startDate, endDate);
73
+ this.removeStartEndInputs();
74
+ } else {
75
+ startEl.className = startDate.isValid ? "" : "parsingError";
76
+ endEl.className = endDate.isValid ? "" : "parsingError";
77
+ }
78
+ });
79
+ }
80
+
81
+ private addNormalizeCheckbox() {
82
+ var checkbox = document.createElement("input");
83
+ checkbox.type = "checkbox";
84
+ checkbox.id = "normalize";
85
+ checkbox.value = "normalize";
86
+ checkbox.checked = this.sdmOptions.normalize;
87
+
88
+ var label = document.createElement("label");
89
+ label.htmlFor = "normalize";
90
+ label.appendChild(document.createTextNode("normalize"));
91
+
92
+ this.element.appendChild(label);
93
+ this.element.appendChild(checkbox);
94
+ checkbox.addEventListener("change", () => {
95
+ this.sdm.setNormalize(checkbox.checked);
96
+ });
97
+ }
98
+
99
+ private addShowMinMax() {
100
+ var checkbox = document.createElement("input");
101
+ checkbox.type = "checkbox";
102
+ checkbox.id = "showMinMax";
103
+ checkbox.value = "showMinMax";
104
+ checkbox.checked = this.sdmOptions.showMinMax;
105
+
106
+ var label = document.createElement("label");
107
+ label.htmlFor = "showMinMax";
108
+ label.appendChild(document.createTextNode("show min/max"));
109
+
110
+ this.element.appendChild(label);
111
+ this.element.appendChild(checkbox);
112
+ checkbox.addEventListener("change", () => {
113
+ this.sdm.setShowMinMax(checkbox.checked);
114
+ });
20
115
  }
21
116
 
22
- private generateSelectionOptions() {
117
+ private addCSVDownload() {
118
+ var button = document.createElement("button");
119
+ button.id = "csvDownload";
120
+ button.textContent = "download csv";
121
+
122
+ this.element.appendChild(button);
123
+ button.addEventListener("click", () => {
124
+ this.sdm.triggerCSVDownload();
125
+ });
126
+ }
127
+
128
+ private generateTimeSelectionOptions() {
23
129
  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" },
130
+ { text: "3 months back", value: "month-3" },
131
+ { text: "6 months back", value: "month-6" },
132
+ { text: "1 year back", value: "year-1" },
133
+ { text: "2 years back", value: "year-2" },
134
+ { text: "3 years back", value: "year-3" },
135
+ { text: "custom", value: "custom" },
29
136
  ];
30
137
  const selectEl = document.createElement("select");
31
138
  options.forEach((entry) => {
@@ -37,25 +144,64 @@ class ChartControls {
37
144
  this.element.appendChild(selectEl);
38
145
  selectEl.addEventListener("change", (evt) => {
39
146
  const currDate = DateTime.now();
40
- switch ((evt.target as HTMLSelectElement).value) {
41
- case "months3":
42
- this.sdm.setTimeInterval(currDate.minus({ months: 3 }), currDate);
147
+ const [type, val] = (evt.target as HTMLSelectElement).value.split("-");
148
+ this.removeStartEndInputs();
149
+ switch (type) {
150
+ case "month":
151
+ this.sdm.setTimeInterval(
152
+ currDate.minus({ month: Number(val) }),
153
+ currDate
154
+ );
155
+ break;
156
+ case "year":
157
+ this.sdm.setTimeInterval(
158
+ currDate.minus({ year: Number(val) }),
159
+ currDate
160
+ );
161
+ break;
162
+ case "custom":
163
+ this.addStartEndInputs();
43
164
  break;
44
- case "months6":
45
- this.sdm.setTimeInterval(currDate.minus({ months: 6 }), currDate);
165
+ }
166
+ });
167
+ }
168
+
169
+ private generateTimeAggregationOptions() {
170
+ const options = [
171
+ { text: "no aggregation", value: "none" },
172
+ { text: "1 week", value: "week-1" },
173
+ { text: "2 weeks", value: "week-2" },
174
+ { text: "1 month", value: "month-1" },
175
+ { text: "3 months", value: "month-3" },
176
+ { text: "6 months", value: "month-6" },
177
+ ];
178
+ const selectEl = document.createElement("select");
179
+ options.forEach((entry) => {
180
+ const option = document.createElement("option");
181
+ option.text = entry.text;
182
+ option.value = entry.value;
183
+ selectEl.appendChild(option);
184
+ });
185
+ this.element.appendChild(selectEl);
186
+ selectEl.addEventListener("change", (evt) => {
187
+ const [type, val] = (evt.target as HTMLSelectElement).value.split("-");
188
+ switch (type) {
189
+ case "none":
190
+ this.sdm.setTimeAggregation(null);
46
191
  break;
47
- case "year1":
48
- this.sdm.setTimeInterval(currDate.minus({ years: 1 }), currDate);
192
+ case "week":
193
+ this.sdm.setTimeAggregation({ week: Number(val) });
49
194
  break;
50
- case "year2":
51
- this.sdm.setTimeInterval(currDate.minus({ years: 2 }), currDate);
195
+ case "month":
196
+ this.sdm.setTimeAggregation({ month: Number(val) });
52
197
  break;
53
- case "year3":
54
- this.sdm.setTimeInterval(currDate.minus({ years: 3 }), currDate);
198
+ case "year":
199
+ this.sdm.setTimeAggregation({ year: Number(val) });
55
200
  break;
56
201
  }
57
202
  });
58
203
  const spinner = document.createElement("span");
204
+ spinner.id = "loadingIndicator";
59
205
  spinner.className = "loader hidden";
60
206
  this.element.appendChild(spinner);
61
207
  }
package/src/interface.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import pkg from "../package.json";
2
+
1
3
  const channel = new MessageChannel();
2
4
  const port1 = channel.port1;
3
5
 
@@ -21,9 +23,13 @@ class EOxChart {
21
23
  timeInterval: object;
22
24
  startTime?: string;
23
25
  endTime?: string;
26
+ colors?: string[];
24
27
  }) {
25
28
  port1.postMessage({ type: "setSignalsEndpoint", body: { options } });
26
29
  }
30
+ setSignalsGeometry(geometry: object) {
31
+ port1.postMessage({ type: "setSignalsGeometry", body: { geometry } });
32
+ }
27
33
  setOptions(options: object) {
28
34
  port1.postMessage({ type: "setOptions", body: { options } });
29
35
  }
@@ -53,10 +59,23 @@ const createChart = (div: HTMLElement | null) => {
53
59
  "src",
54
60
  import.meta?.url?.includes("localhost")
55
61
  ? "http://localhost:5173/index.html"
56
- : "https://www.unpkg.com/@eox/chart/dist/index.html"
62
+ : "about:blank"
57
63
  );
58
64
  iframe.setAttribute("id", "EOxChart");
59
65
  div?.appendChild(iframe);
66
+ if (!import.meta?.url?.includes("localhost")) {
67
+ const hostUrl = `https://www.unpkg.com/@eox/chart@${pkg.version}/dist`;
68
+ fetch(`${hostUrl}/index.html`)
69
+ .then((response) => {
70
+ return response.text();
71
+ })
72
+ .then((text) => {
73
+ const html = text.replace("./assets/", `${hostUrl}/assets/`);
74
+ iframe.contentDocument?.open();
75
+ iframe.contentDocument?.write(html);
76
+ iframe.contentDocument?.close();
77
+ });
78
+ }
60
79
  let iframeLoaded = false;
61
80
  iframe.onload = () => {
62
81
  // store if the iFrame has already loaded, since in Cypress hovering over the test triggers
package/src/main.ts CHANGED
@@ -10,9 +10,34 @@ const eoxchart = new Chart(
10
10
  labels: [],
11
11
  datasets: [],
12
12
  },
13
+ plugins: [
14
+ {
15
+ id: "selectionLineHighlight",
16
+ afterDraw: (chart) => {
17
+ if (chart && chart.tooltip) {
18
+ const active = chart.tooltip.getActiveElements();
19
+ if (active?.length) {
20
+ let x = active[0].element.x;
21
+ let yAxis = chart.scales.y;
22
+ let ctx = chart.ctx;
23
+ ctx.save();
24
+ ctx.beginPath();
25
+ ctx.moveTo(x, yAxis.top);
26
+ ctx.lineTo(x, yAxis.bottom);
27
+ ctx.lineWidth = 1;
28
+ ctx.strokeStyle = "rgba(0, 0, 255, 0.4)";
29
+ ctx.stroke();
30
+ ctx.restore();
31
+ }
32
+ }
33
+ },
34
+ },
35
+ ],
13
36
  }
14
37
  );
15
38
 
39
+ let sdmInstance: SignalsDataManager | null = null;
40
+
16
41
  let application: MessagePort;
17
42
 
18
43
  window.addEventListener("message", (event) => {
@@ -39,6 +64,9 @@ const onMessage = (event: MessageEvent) => {
39
64
  case "setSignalsEndpoint":
40
65
  setSignalsEndpoint(event.data.body.options);
41
66
  break;
67
+ case "setSignalsGeometry":
68
+ setSignalsGeometry(event.data.body.options);
69
+ break;
42
70
  case "setSignalsData":
43
71
  eoxchart.data = {
44
72
  datasets: Object.entries(event.data.body.data).map(
@@ -71,7 +99,13 @@ const setSignalsEndpoint = (options: {
71
99
  startTime?: string;
72
100
  endTime?: string;
73
101
  }) => {
74
- const sdm = new SignalsDataManager(eoxchart, options);
75
- new ChartControls(document.getElementById("controls"), sdm);
76
- sdm.setActiveFields(options.active);
102
+ sdmInstance = new SignalsDataManager(eoxchart, options);
103
+ new ChartControls(document.getElementById("controls"), sdmInstance, options);
104
+ sdmInstance.setActiveFields(options.active);
105
+ };
106
+
107
+ const setSignalsGeometry = (geometry: object) => {
108
+ if (sdmInstance) {
109
+ sdmInstance.setGeometry(geometry);
110
+ }
77
111
  };