@eox/chart 2.0.0-alpha1
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/.eslintignore +2 -0
- package/.eslintrc.js +9 -0
- package/.prettierignore +2 -0
- package/README.md +9 -0
- package/cypress/e2e/general.cy.ts +34 -0
- package/cypress/e2e/sh.json +417 -0
- package/cypress/e2e/shDisplay.cy.ts +26 -0
- package/cypress/e2e/signalsEndpoint.cy.ts +100 -0
- package/cypress.config.ts +11 -0
- package/dist/assets/main-800e32b1.js +23 -0
- package/dist/index.html +63 -0
- package/dist/interface.mjs +46 -0
- package/dist/interface.umd.js +1 -0
- package/dist/test.html +23 -0
- package/index.html +62 -0
- package/package.json +46 -0
- package/public/interface.mjs +46 -0
- package/public/interface.umd.js +1 -0
- package/public/test.html +23 -0
- package/scripts/watch.mjs +34 -0
- package/src/chartControls.ts +64 -0
- package/src/interface.ts +74 -0
- package/src/main.ts +77 -0
- package/src/signalsDataManager.ts +282 -0
- package/src/vite-env.d.ts +1 -0
- package/test.html +23 -0
- package/tsconfig.json +21 -0
- package/typings/global.d.ts +9 -0
- package/vite.config.interface.ts +19 -0
- package/vite.config.map.ts +15 -0
package/dist/index.html
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>Simple Chart</title>
|
|
6
|
+
<style>
|
|
7
|
+
html,
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
html,
|
|
13
|
+
body,
|
|
14
|
+
.chart {
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
}
|
|
18
|
+
.hidden {
|
|
19
|
+
visibility: hidden;
|
|
20
|
+
}
|
|
21
|
+
.loader {
|
|
22
|
+
position: absolute;
|
|
23
|
+
top: 5px;
|
|
24
|
+
right: 30px;
|
|
25
|
+
width: 24px;
|
|
26
|
+
height: 24px;
|
|
27
|
+
border-radius: 50%;
|
|
28
|
+
display: inline-block;
|
|
29
|
+
border-top: 4px solid #000;
|
|
30
|
+
border-right: 4px solid transparent;
|
|
31
|
+
box-sizing: border-box;
|
|
32
|
+
animation: rotation 1s linear infinite;
|
|
33
|
+
}
|
|
34
|
+
.loader::after {
|
|
35
|
+
content: '';
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
position: absolute;
|
|
38
|
+
left: 0;
|
|
39
|
+
top: 0;
|
|
40
|
+
width: 24px;
|
|
41
|
+
height: 24px;
|
|
42
|
+
border-radius: 50%;
|
|
43
|
+
border-left: 4px solid #004170;
|
|
44
|
+
border-bottom: 4px solid transparent;
|
|
45
|
+
animation: rotation 0.5s linear infinite reverse;
|
|
46
|
+
}
|
|
47
|
+
@keyframes rotation {
|
|
48
|
+
0% {
|
|
49
|
+
transform: rotate(0deg);
|
|
50
|
+
}
|
|
51
|
+
100% {
|
|
52
|
+
transform: rotate(360deg);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
56
|
+
<script type="module" crossorigin src="./assets/main-800e32b1.js"></script>
|
|
57
|
+
</head>
|
|
58
|
+
<body>
|
|
59
|
+
<div id="controls" class="controls" data-cy="controls"></div>
|
|
60
|
+
<canvas id="chart" class="chart" data-cy="chart"></canvas>
|
|
61
|
+
|
|
62
|
+
</body>
|
|
63
|
+
</html>
|
|
@@ -0,0 +1,46 @@
|
|
|
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 {
|
|
6
|
+
constructor(t) {
|
|
7
|
+
l(this, "iframe");
|
|
8
|
+
this.iframe = t;
|
|
9
|
+
}
|
|
10
|
+
setData(t) {
|
|
11
|
+
o.postMessage({ type: "setData", body: { data: t } });
|
|
12
|
+
}
|
|
13
|
+
setSignalsData(t) {
|
|
14
|
+
o.postMessage({ type: "setSignalsData", body: { data: t } });
|
|
15
|
+
}
|
|
16
|
+
setSignalsEndpoint(t) {
|
|
17
|
+
o.postMessage({ type: "setSignalsEndpoint", body: { options: t } });
|
|
18
|
+
}
|
|
19
|
+
setOptions(t) {
|
|
20
|
+
o.postMessage({ type: "setOptions", body: { options: t } });
|
|
21
|
+
}
|
|
22
|
+
getFoo() {
|
|
23
|
+
return new Promise((t) => {
|
|
24
|
+
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" });
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const m = (s) => s ? new Promise((t) => {
|
|
32
|
+
var n, r;
|
|
33
|
+
const e = document.createElement("iframe");
|
|
34
|
+
e.style.cssText = "width: 100%; height: 100%; display: block; margin: 0; border: none;", e.setAttribute(
|
|
35
|
+
"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;
|
|
39
|
+
e.onload = () => {
|
|
40
|
+
var i;
|
|
41
|
+
a || ((i = e.contentWindow) == null || i.postMessage("init", "*", [p.port2]), a = !0, t(new h(e)));
|
|
42
|
+
};
|
|
43
|
+
}) : (console.error("no div selected"), null);
|
|
44
|
+
export {
|
|
45
|
+
m as createChart
|
|
46
|
+
};
|
|
@@ -0,0 +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"})});
|
package/dist/test.html
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>Simple Chart</title>
|
|
6
|
+
<style>
|
|
7
|
+
html,
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
html,
|
|
13
|
+
body,
|
|
14
|
+
.chart {
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="chart" class="chart" data-cy="chart"></div>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
package/index.html
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>Simple Chart</title>
|
|
6
|
+
<style>
|
|
7
|
+
html,
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
html,
|
|
13
|
+
body,
|
|
14
|
+
.chart {
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
}
|
|
18
|
+
.hidden {
|
|
19
|
+
visibility: hidden;
|
|
20
|
+
}
|
|
21
|
+
.loader {
|
|
22
|
+
position: absolute;
|
|
23
|
+
top: 5px;
|
|
24
|
+
right: 30px;
|
|
25
|
+
width: 24px;
|
|
26
|
+
height: 24px;
|
|
27
|
+
border-radius: 50%;
|
|
28
|
+
display: inline-block;
|
|
29
|
+
border-top: 4px solid #000;
|
|
30
|
+
border-right: 4px solid transparent;
|
|
31
|
+
box-sizing: border-box;
|
|
32
|
+
animation: rotation 1s linear infinite;
|
|
33
|
+
}
|
|
34
|
+
.loader::after {
|
|
35
|
+
content: '';
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
position: absolute;
|
|
38
|
+
left: 0;
|
|
39
|
+
top: 0;
|
|
40
|
+
width: 24px;
|
|
41
|
+
height: 24px;
|
|
42
|
+
border-radius: 50%;
|
|
43
|
+
border-left: 4px solid #004170;
|
|
44
|
+
border-bottom: 4px solid transparent;
|
|
45
|
+
animation: rotation 0.5s linear infinite reverse;
|
|
46
|
+
}
|
|
47
|
+
@keyframes rotation {
|
|
48
|
+
0% {
|
|
49
|
+
transform: rotate(0deg);
|
|
50
|
+
}
|
|
51
|
+
100% {
|
|
52
|
+
transform: rotate(360deg);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
56
|
+
</head>
|
|
57
|
+
<body>
|
|
58
|
+
<div id="controls" class="controls" data-cy="controls"></div>
|
|
59
|
+
<canvas id="chart" class="chart" data-cy="chart"></canvas>
|
|
60
|
+
<script type="module" src="./src/main.ts"></script>
|
|
61
|
+
</body>
|
|
62
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eox/chart",
|
|
3
|
+
"version": "2.0.0-alpha1",
|
|
4
|
+
"dependencies": {
|
|
5
|
+
"chart.js": "^4.2.1",
|
|
6
|
+
"chartjs-adapter-luxon": "^1.3.1",
|
|
7
|
+
"chartjs-chart-error-bars": "^4.1.1"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@eox/eslint-config": "^1.0.0",
|
|
11
|
+
"@types/luxon": "^3.2.0",
|
|
12
|
+
"@typescript-eslint/eslint-plugin": "^5.50.0",
|
|
13
|
+
"@typescript-eslint/parser": "^5.50.0",
|
|
14
|
+
"cypress": "^12.6.0",
|
|
15
|
+
"cypress-vite": "^1.3.0",
|
|
16
|
+
"eslint-plugin-cypress": "^2.12.1",
|
|
17
|
+
"eslint-plugin-typescript": "^0.14.0",
|
|
18
|
+
"install": "^0.13.0",
|
|
19
|
+
"luxon": "^3.3.0",
|
|
20
|
+
"npm": "^9.6.3",
|
|
21
|
+
"p-retry": "^5.1.2",
|
|
22
|
+
"pre-commit": "^1.2.2",
|
|
23
|
+
"start-server-and-test": "^1.15.2",
|
|
24
|
+
"typescript": "^4.9.3",
|
|
25
|
+
"vite": "^4.0.0"
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"npm": ">=8.0.0",
|
|
29
|
+
"node": ">=18.0.0"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"start": "vite",
|
|
33
|
+
"build": "tsc && vite build --config vite.config.interface.ts && vite build --config vite.config.map.ts",
|
|
34
|
+
"watch": "node scripts/watch.mjs",
|
|
35
|
+
"preview": "vite preview",
|
|
36
|
+
"format": "prettier --write .",
|
|
37
|
+
"lint": "eslint --ext .js,.ts .",
|
|
38
|
+
"lint:fix": "eslint --ext .js,.ts . --fix",
|
|
39
|
+
"cypress": "start-server-and-test start 5173 'cypress open'",
|
|
40
|
+
"test": "start-server-and-test start 5173 'cypress run'"
|
|
41
|
+
},
|
|
42
|
+
"pre-commit": [
|
|
43
|
+
"format",
|
|
44
|
+
"lint:fix"
|
|
45
|
+
]
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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 {
|
|
6
|
+
constructor(t) {
|
|
7
|
+
l(this, "iframe");
|
|
8
|
+
this.iframe = t;
|
|
9
|
+
}
|
|
10
|
+
setData(t) {
|
|
11
|
+
o.postMessage({ type: "setData", body: { data: t } });
|
|
12
|
+
}
|
|
13
|
+
setSignalsData(t) {
|
|
14
|
+
o.postMessage({ type: "setSignalsData", body: { data: t } });
|
|
15
|
+
}
|
|
16
|
+
setSignalsEndpoint(t) {
|
|
17
|
+
o.postMessage({ type: "setSignalsEndpoint", body: { options: t } });
|
|
18
|
+
}
|
|
19
|
+
setOptions(t) {
|
|
20
|
+
o.postMessage({ type: "setOptions", body: { options: t } });
|
|
21
|
+
}
|
|
22
|
+
getFoo() {
|
|
23
|
+
return new Promise((t) => {
|
|
24
|
+
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" });
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const m = (s) => s ? new Promise((t) => {
|
|
32
|
+
var n, r;
|
|
33
|
+
const e = document.createElement("iframe");
|
|
34
|
+
e.style.cssText = "width: 100%; height: 100%; display: block; margin: 0; border: none;", e.setAttribute(
|
|
35
|
+
"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;
|
|
39
|
+
e.onload = () => {
|
|
40
|
+
var i;
|
|
41
|
+
a || ((i = e.contentWindow) == null || i.postMessage("init", "*", [p.port2]), a = !0, t(new h(e)));
|
|
42
|
+
};
|
|
43
|
+
}) : (console.error("no div selected"), null);
|
|
44
|
+
export {
|
|
45
|
+
m as createChart
|
|
46
|
+
};
|
|
@@ -0,0 +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"})});
|
package/public/test.html
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>Simple Chart</title>
|
|
6
|
+
<style>
|
|
7
|
+
html,
|
|
8
|
+
body {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
html,
|
|
13
|
+
body,
|
|
14
|
+
.chart {
|
|
15
|
+
width: 100%;
|
|
16
|
+
height: 100%;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="chart" class="chart" data-cy="chart"></div>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createServer, build } from "vite";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {(server: import('vite').ViteDevServer) => Promise<import('rollup').RollupWatcher>}
|
|
5
|
+
*/
|
|
6
|
+
function watchInterface(server) {
|
|
7
|
+
return build({
|
|
8
|
+
configFile: "vite.config.interface.ts",
|
|
9
|
+
mode: "development",
|
|
10
|
+
build: {
|
|
11
|
+
watch: {},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @type {(server: import('vite').ViteDevServer) => Promise<import('rollup').RollupWatcher>}
|
|
18
|
+
*/
|
|
19
|
+
function watchMain(server) {
|
|
20
|
+
return build({
|
|
21
|
+
configFile: "vite.config.map.ts",
|
|
22
|
+
mode: "development",
|
|
23
|
+
build: {
|
|
24
|
+
watch: {},
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// bootstrap
|
|
30
|
+
const server = await createServer({ configFile: "vite.config.map.ts" });
|
|
31
|
+
|
|
32
|
+
await server.listen();
|
|
33
|
+
await watchInterface(server); // outputs to public/interface.js, so run first
|
|
34
|
+
await watchMain(server);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { DateTime } from "luxon";
|
|
2
|
+
import SignalsDataManager from "./signalsDataManager";
|
|
3
|
+
|
|
4
|
+
export interface ChartControlOptions {}
|
|
5
|
+
|
|
6
|
+
class ChartControls {
|
|
7
|
+
element: HTMLElement;
|
|
8
|
+
sdm: SignalsDataManager;
|
|
9
|
+
options?: ChartControlOptions;
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
element: HTMLElement,
|
|
13
|
+
sdm: SignalsDataManager,
|
|
14
|
+
options?: ChartControlOptions
|
|
15
|
+
) {
|
|
16
|
+
this.element = element;
|
|
17
|
+
this.sdm = sdm;
|
|
18
|
+
this.options = options;
|
|
19
|
+
this.generateSelectionOptions();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private generateSelectionOptions() {
|
|
23
|
+
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" },
|
|
29
|
+
];
|
|
30
|
+
const selectEl = document.createElement("select");
|
|
31
|
+
options.forEach((entry) => {
|
|
32
|
+
const option = document.createElement("option");
|
|
33
|
+
option.text = entry.text;
|
|
34
|
+
option.value = entry.value;
|
|
35
|
+
selectEl.appendChild(option);
|
|
36
|
+
});
|
|
37
|
+
this.element.appendChild(selectEl);
|
|
38
|
+
selectEl.addEventListener("change", (evt) => {
|
|
39
|
+
const currDate = DateTime.now();
|
|
40
|
+
switch ((evt.target as HTMLSelectElement).value) {
|
|
41
|
+
case "months3":
|
|
42
|
+
this.sdm.setTimeInterval(currDate.minus({ months: 3 }), currDate);
|
|
43
|
+
break;
|
|
44
|
+
case "months6":
|
|
45
|
+
this.sdm.setTimeInterval(currDate.minus({ months: 6 }), currDate);
|
|
46
|
+
break;
|
|
47
|
+
case "year1":
|
|
48
|
+
this.sdm.setTimeInterval(currDate.minus({ years: 1 }), currDate);
|
|
49
|
+
break;
|
|
50
|
+
case "year2":
|
|
51
|
+
this.sdm.setTimeInterval(currDate.minus({ years: 2 }), currDate);
|
|
52
|
+
break;
|
|
53
|
+
case "year3":
|
|
54
|
+
this.sdm.setTimeInterval(currDate.minus({ years: 3 }), currDate);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const spinner = document.createElement("span");
|
|
59
|
+
spinner.className = "loader hidden";
|
|
60
|
+
this.element.appendChild(spinner);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default ChartControls;
|
package/src/interface.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const channel = new MessageChannel();
|
|
2
|
+
const port1 = channel.port1;
|
|
3
|
+
|
|
4
|
+
class EOxChart {
|
|
5
|
+
iframe: HTMLIFrameElement;
|
|
6
|
+
constructor(frame: HTMLIFrameElement) {
|
|
7
|
+
this.iframe = frame;
|
|
8
|
+
}
|
|
9
|
+
setData(data: object) {
|
|
10
|
+
port1.postMessage({ type: "setData", body: { data } });
|
|
11
|
+
}
|
|
12
|
+
setSignalsData(data: object) {
|
|
13
|
+
port1.postMessage({ type: "setSignalsData", body: { data } });
|
|
14
|
+
}
|
|
15
|
+
setSignalsEndpoint(options: {
|
|
16
|
+
source: string;
|
|
17
|
+
endpoint: string;
|
|
18
|
+
active: string[];
|
|
19
|
+
features: string[][];
|
|
20
|
+
geometry: object;
|
|
21
|
+
timeInterval: object;
|
|
22
|
+
startTime?: string;
|
|
23
|
+
endTime?: string;
|
|
24
|
+
}) {
|
|
25
|
+
port1.postMessage({ type: "setSignalsEndpoint", body: { options } });
|
|
26
|
+
}
|
|
27
|
+
setOptions(options: object) {
|
|
28
|
+
port1.postMessage({ type: "setOptions", body: { options } });
|
|
29
|
+
}
|
|
30
|
+
getFoo() {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
const ts = Date.now();
|
|
33
|
+
port1.onmessage = (event) => {
|
|
34
|
+
if (event.data.ts === ts) {
|
|
35
|
+
resolve(event.data.body);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
port1.postMessage({ ts, type: "getFoo", body: "hello world" });
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const createChart = (div: HTMLElement | null) => {
|
|
44
|
+
if (!div) {
|
|
45
|
+
console.error("no div selected");
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
return new Promise<EOxChart>((resolve) => {
|
|
49
|
+
const iframe = document.createElement("iframe");
|
|
50
|
+
iframe.style.cssText =
|
|
51
|
+
"width: 100%; height: 100%; display: block; margin: 0; border: none;";
|
|
52
|
+
iframe.setAttribute(
|
|
53
|
+
"src",
|
|
54
|
+
import.meta?.url?.includes("localhost")
|
|
55
|
+
? "http://localhost:5173/index.html"
|
|
56
|
+
: "https://www.unpkg.com/@eox/chart/dist/index.html"
|
|
57
|
+
);
|
|
58
|
+
iframe.setAttribute("id", "EOxChart");
|
|
59
|
+
div?.appendChild(iframe);
|
|
60
|
+
let iframeLoaded = false;
|
|
61
|
+
iframe.onload = () => {
|
|
62
|
+
// store if the iFrame has already loaded, since in Cypress hovering over the test triggers
|
|
63
|
+
// the onload event multiple times, causing an error with the previously neutered port2
|
|
64
|
+
if (iframeLoaded) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
iframe.contentWindow?.postMessage("init", "*", [channel.port2]);
|
|
68
|
+
iframeLoaded = true;
|
|
69
|
+
resolve(new EOxChart(iframe));
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export { createChart };
|
package/src/main.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Chart, { ChartDataset } from "chart.js/auto";
|
|
2
|
+
import "chartjs-adapter-luxon";
|
|
3
|
+
import SignalsDataManager from "./signalsDataManager";
|
|
4
|
+
import ChartControls from "./chartControls";
|
|
5
|
+
|
|
6
|
+
const eoxchart = new Chart(
|
|
7
|
+
<HTMLCanvasElement>document.getElementById("chart"),
|
|
8
|
+
{
|
|
9
|
+
data: {
|
|
10
|
+
labels: [],
|
|
11
|
+
datasets: [],
|
|
12
|
+
},
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
let application: MessagePort;
|
|
17
|
+
|
|
18
|
+
window.addEventListener("message", (event) => {
|
|
19
|
+
if (event.data === "init") {
|
|
20
|
+
application = event.ports[0];
|
|
21
|
+
application.onmessage = onMessage;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const onMessage = (event: MessageEvent) => {
|
|
26
|
+
if (event.data.ts) {
|
|
27
|
+
switch (event.data.type) {
|
|
28
|
+
case "getFoo":
|
|
29
|
+
console.log(event.data.body);
|
|
30
|
+
application.postMessage({ ts: event.data.ts, body: "foo bar" });
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
} else {
|
|
34
|
+
switch (event.data.type) {
|
|
35
|
+
case "setData":
|
|
36
|
+
eoxchart.data = event.data.body.data;
|
|
37
|
+
eoxchart.update("none");
|
|
38
|
+
break;
|
|
39
|
+
case "setSignalsEndpoint":
|
|
40
|
+
setSignalsEndpoint(event.data.body.options);
|
|
41
|
+
break;
|
|
42
|
+
case "setSignalsData":
|
|
43
|
+
eoxchart.data = {
|
|
44
|
+
datasets: Object.entries(event.data.body.data).map(
|
|
45
|
+
([key, item]): ChartDataset => {
|
|
46
|
+
return {
|
|
47
|
+
type: "line",
|
|
48
|
+
label: key,
|
|
49
|
+
data: <number[]>item,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
),
|
|
53
|
+
};
|
|
54
|
+
eoxchart.update("none");
|
|
55
|
+
break;
|
|
56
|
+
case "setOptions":
|
|
57
|
+
eoxchart.options = event.data.body.options;
|
|
58
|
+
eoxchart.update("none");
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const setSignalsEndpoint = (options: {
|
|
65
|
+
source: string;
|
|
66
|
+
endpoint: string;
|
|
67
|
+
active: string[];
|
|
68
|
+
features: string[][];
|
|
69
|
+
geometry: object;
|
|
70
|
+
timeInterval: object;
|
|
71
|
+
startTime?: string;
|
|
72
|
+
endTime?: string;
|
|
73
|
+
}) => {
|
|
74
|
+
const sdm = new SignalsDataManager(eoxchart, options);
|
|
75
|
+
new ChartControls(document.getElementById("controls"), sdm);
|
|
76
|
+
sdm.setActiveFields(options.active);
|
|
77
|
+
};
|