@eox/chart 2.0.0-alpha8 → 2.0.0-beta1
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/README.md +22 -4
- package/dist/eox-chart.js +15368 -0
- package/dist/eox-chart.umd.cjs +142 -0
- package/package.json +7 -30
- package/test/general.cy.ts +36 -0
- package/{dist/test.html → test/general.html} +5 -9
- package/test/responsiveSize.cy.ts +184 -0
- package/test/sh.json +417 -0
- package/test/shDisplay.cy.ts +22 -0
- package/test/signalsEndpoint.cy.ts +172 -0
- package/dist/assets/main-0d4938a0.js +0 -25
- package/dist/index.html +0 -83
- package/dist/interface.mjs +0 -108
- package/dist/interface.umd.js +0 -1
- package/scripts/watch.mjs +0 -34
- package/src/chartControls.ts +0 -201
- package/src/interface.ts +0 -93
- package/src/main.ts +0 -111
- package/src/signalsDataManager.ts +0 -573
- package/src/vite-env.d.ts +0 -1
- package/typings/global.d.ts +0 -9
package/dist/index.html
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<title>EOxElements Chart</title>
|
|
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
|
-
}
|
|
14
|
-
html,
|
|
15
|
-
body {
|
|
16
|
-
margin: 0;
|
|
17
|
-
padding: 0;
|
|
18
|
-
}
|
|
19
|
-
html,
|
|
20
|
-
body,
|
|
21
|
-
.chart {
|
|
22
|
-
width: 100%;
|
|
23
|
-
height: 100%;
|
|
24
|
-
}
|
|
25
|
-
.hidden {
|
|
26
|
-
visibility: hidden;
|
|
27
|
-
}
|
|
28
|
-
.loader {
|
|
29
|
-
position: absolute;
|
|
30
|
-
top: 5px;
|
|
31
|
-
right: 30px;
|
|
32
|
-
width: 24px;
|
|
33
|
-
height: 24px;
|
|
34
|
-
border-radius: 50%;
|
|
35
|
-
display: inline-block;
|
|
36
|
-
border-top: 4px solid #000;
|
|
37
|
-
border-right: 4px solid transparent;
|
|
38
|
-
box-sizing: border-box;
|
|
39
|
-
animation: rotation 1s linear infinite;
|
|
40
|
-
}
|
|
41
|
-
.loader::after {
|
|
42
|
-
content: "";
|
|
43
|
-
box-sizing: border-box;
|
|
44
|
-
position: absolute;
|
|
45
|
-
left: 0;
|
|
46
|
-
top: 0;
|
|
47
|
-
width: 24px;
|
|
48
|
-
height: 24px;
|
|
49
|
-
border-radius: 50%;
|
|
50
|
-
border-left: 4px solid #004170;
|
|
51
|
-
border-bottom: 4px solid transparent;
|
|
52
|
-
animation: rotation 0.5s linear infinite reverse;
|
|
53
|
-
}
|
|
54
|
-
@keyframes rotation {
|
|
55
|
-
0% {
|
|
56
|
-
transform: rotate(0deg);
|
|
57
|
-
}
|
|
58
|
-
100% {
|
|
59
|
-
transform: rotate(360deg);
|
|
60
|
-
}
|
|
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
|
-
}
|
|
75
|
-
</style>
|
|
76
|
-
<script type="module" crossorigin src="./assets/main-0d4938a0.js"></script>
|
|
77
|
-
</head>
|
|
78
|
-
<body>
|
|
79
|
-
<div id="controls" class="controls" data-cy="controls"></div>
|
|
80
|
-
<canvas id="chart" class="chart" data-cy="chart"></canvas>
|
|
81
|
-
|
|
82
|
-
</body>
|
|
83
|
-
</html>
|
package/dist/interface.mjs
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
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 {
|
|
58
|
-
constructor(t) {
|
|
59
|
-
h(this, "iframe");
|
|
60
|
-
this.iframe = t;
|
|
61
|
-
}
|
|
62
|
-
setData(t) {
|
|
63
|
-
n.postMessage({ type: "setData", body: { data: t } });
|
|
64
|
-
}
|
|
65
|
-
setSignalsData(t) {
|
|
66
|
-
n.postMessage({ type: "setSignalsData", body: { data: t } });
|
|
67
|
-
}
|
|
68
|
-
setSignalsEndpoint(t) {
|
|
69
|
-
n.postMessage({ type: "setSignalsEndpoint", body: { options: t } });
|
|
70
|
-
}
|
|
71
|
-
setSignalsGeometry(t) {
|
|
72
|
-
n.postMessage({ type: "setSignalsGeometry", body: { geometry: t } });
|
|
73
|
-
}
|
|
74
|
-
setOptions(t) {
|
|
75
|
-
n.postMessage({ type: "setOptions", body: { options: t } });
|
|
76
|
-
}
|
|
77
|
-
getFoo() {
|
|
78
|
-
return new Promise((t) => {
|
|
79
|
-
const e = Date.now();
|
|
80
|
-
n.onmessage = (o) => {
|
|
81
|
-
o.data.ts === e && t(o.data.body);
|
|
82
|
-
}, n.postMessage({ ts: e, type: "getFoo", body: "hello world" });
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
const $ = (s) => s ? new Promise((t) => {
|
|
87
|
-
var a, c, p, l;
|
|
88
|
-
const e = document.createElement("iframe");
|
|
89
|
-
if (e.style.cssText = "width: 100%; height: 100%; display: block; margin: 0; border: none;", e.setAttribute(
|
|
90
|
-
"src",
|
|
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;
|
|
101
|
-
e.onload = () => {
|
|
102
|
-
var r;
|
|
103
|
-
o || ((r = e.contentWindow) == null || r.postMessage("init", "*", [u.port2]), o = !0, t(new k(e)));
|
|
104
|
-
};
|
|
105
|
-
}) : (console.error("no div selected"), null);
|
|
106
|
-
export {
|
|
107
|
-
$ as createChart
|
|
108
|
-
};
|
package/dist/interface.umd.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
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/scripts/watch.mjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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);
|
package/src/chartControls.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { DateTime } from "luxon";
|
|
2
|
-
import SignalsDataManager, { SDMOptions } from "./signalsDataManager";
|
|
3
|
-
|
|
4
|
-
export interface ChartControlOptions {}
|
|
5
|
-
|
|
6
|
-
class ChartControls {
|
|
7
|
-
element: HTMLElement;
|
|
8
|
-
sdm: SignalsDataManager;
|
|
9
|
-
sdmOptions: SDMOptions;
|
|
10
|
-
options?: ChartControlOptions;
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
13
|
-
element: HTMLElement,
|
|
14
|
-
sdm: SignalsDataManager,
|
|
15
|
-
sdmOptions: SDMOptions,
|
|
16
|
-
options?: ChartControlOptions
|
|
17
|
-
) {
|
|
18
|
-
this.element = element;
|
|
19
|
-
this.sdm = sdm;
|
|
20
|
-
this.options = options;
|
|
21
|
-
this.sdmOptions = sdmOptions;
|
|
22
|
-
this.generateTimeAggregationOptions();
|
|
23
|
-
this.addNormalizeCheckbox();
|
|
24
|
-
this.addShowMinMax();
|
|
25
|
-
this.addCSVDownload();
|
|
26
|
-
this.generateTimeSelectionOptions();
|
|
27
|
-
const spinner = document.createElement("span");
|
|
28
|
-
spinner.id = "loadingIndicator";
|
|
29
|
-
spinner.className = "loader hidden";
|
|
30
|
-
this.element.appendChild(spinner);
|
|
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
|
-
|
|
72
|
-
private addNormalizeCheckbox() {
|
|
73
|
-
var checkbox = document.createElement("input");
|
|
74
|
-
checkbox.type = "checkbox";
|
|
75
|
-
checkbox.id = "normalize";
|
|
76
|
-
checkbox.value = "normalize";
|
|
77
|
-
checkbox.checked = this.sdmOptions.normalize;
|
|
78
|
-
|
|
79
|
-
var label = document.createElement("label");
|
|
80
|
-
label.htmlFor = "normalize";
|
|
81
|
-
label.appendChild(document.createTextNode("normalize"));
|
|
82
|
-
|
|
83
|
-
this.element.appendChild(label);
|
|
84
|
-
this.element.appendChild(checkbox);
|
|
85
|
-
checkbox.addEventListener("change", () => {
|
|
86
|
-
this.sdm.setNormalize(checkbox.checked);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private addShowMinMax() {
|
|
91
|
-
var checkbox = document.createElement("input");
|
|
92
|
-
checkbox.type = "checkbox";
|
|
93
|
-
checkbox.id = "showMinMax";
|
|
94
|
-
checkbox.value = "showMinMax";
|
|
95
|
-
checkbox.checked = this.sdmOptions.showMinMax;
|
|
96
|
-
|
|
97
|
-
var label = document.createElement("label");
|
|
98
|
-
label.htmlFor = "showMinMax";
|
|
99
|
-
label.appendChild(document.createTextNode("show min/max"));
|
|
100
|
-
|
|
101
|
-
this.element.appendChild(label);
|
|
102
|
-
this.element.appendChild(checkbox);
|
|
103
|
-
checkbox.addEventListener("change", () => {
|
|
104
|
-
this.sdm.setShowMinMax(checkbox.checked);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
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
|
-
|
|
119
|
-
private generateTimeSelectionOptions() {
|
|
120
|
-
const options = [
|
|
121
|
-
{ text: "3 months back", value: "month-3" },
|
|
122
|
-
{ text: "6 months back", value: "month-6" },
|
|
123
|
-
{ text: "1 year back", value: "year-1" },
|
|
124
|
-
{ text: "2 years back", value: "year-2" },
|
|
125
|
-
{ text: "3 years back", value: "year-3" },
|
|
126
|
-
{ text: "custom", value: "custom" },
|
|
127
|
-
];
|
|
128
|
-
const selectEl = document.createElement("select");
|
|
129
|
-
options.forEach((entry) => {
|
|
130
|
-
const option = document.createElement("option");
|
|
131
|
-
option.text = entry.text;
|
|
132
|
-
option.value = entry.value;
|
|
133
|
-
selectEl.appendChild(option);
|
|
134
|
-
});
|
|
135
|
-
this.element.appendChild(selectEl);
|
|
136
|
-
selectEl.addEventListener("change", (evt) => {
|
|
137
|
-
const currDate = DateTime.now();
|
|
138
|
-
const [type, val] = (evt.target as HTMLSelectElement).value.split("-");
|
|
139
|
-
this.removeStartEndInputs();
|
|
140
|
-
switch (type) {
|
|
141
|
-
case "month":
|
|
142
|
-
this.sdm.setTimeInterval(
|
|
143
|
-
currDate.minus({ month: Number(val) }),
|
|
144
|
-
currDate
|
|
145
|
-
);
|
|
146
|
-
break;
|
|
147
|
-
case "year":
|
|
148
|
-
this.sdm.setTimeInterval(
|
|
149
|
-
currDate.minus({ year: Number(val) }),
|
|
150
|
-
currDate
|
|
151
|
-
);
|
|
152
|
-
break;
|
|
153
|
-
case "custom":
|
|
154
|
-
this.addStartEndInputs();
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
private generateTimeAggregationOptions() {
|
|
161
|
-
const options = [
|
|
162
|
-
{ text: "no aggregation", value: "none" },
|
|
163
|
-
{ text: "1 week", value: "week-1" },
|
|
164
|
-
{ text: "2 weeks", value: "week-2" },
|
|
165
|
-
{ text: "1 month", value: "month-1" },
|
|
166
|
-
{ text: "3 months", value: "month-3" },
|
|
167
|
-
{ text: "6 months", value: "month-6" },
|
|
168
|
-
];
|
|
169
|
-
const selectEl = document.createElement("select");
|
|
170
|
-
options.forEach((entry) => {
|
|
171
|
-
const option = document.createElement("option");
|
|
172
|
-
option.text = entry.text;
|
|
173
|
-
option.value = entry.value;
|
|
174
|
-
selectEl.appendChild(option);
|
|
175
|
-
});
|
|
176
|
-
this.element.appendChild(selectEl);
|
|
177
|
-
selectEl.addEventListener("change", (evt) => {
|
|
178
|
-
const [type, val] = (evt.target as HTMLSelectElement).value.split("-");
|
|
179
|
-
switch (type) {
|
|
180
|
-
case "none":
|
|
181
|
-
this.sdm.setTimeAggregation(null);
|
|
182
|
-
break;
|
|
183
|
-
case "week":
|
|
184
|
-
this.sdm.setTimeAggregation({ week: Number(val) });
|
|
185
|
-
break;
|
|
186
|
-
case "month":
|
|
187
|
-
this.sdm.setTimeAggregation({ month: Number(val) });
|
|
188
|
-
break;
|
|
189
|
-
case "year":
|
|
190
|
-
this.sdm.setTimeAggregation({ year: Number(val) });
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
const spinner = document.createElement("span");
|
|
195
|
-
spinner.id = "loadingIndicator";
|
|
196
|
-
spinner.className = "loader hidden";
|
|
197
|
-
this.element.appendChild(spinner);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export default ChartControls;
|
package/src/interface.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import pkg from "../package.json";
|
|
2
|
-
|
|
3
|
-
const channel = new MessageChannel();
|
|
4
|
-
const port1 = channel.port1;
|
|
5
|
-
|
|
6
|
-
class EOxChart {
|
|
7
|
-
iframe: HTMLIFrameElement;
|
|
8
|
-
constructor(frame: HTMLIFrameElement) {
|
|
9
|
-
this.iframe = frame;
|
|
10
|
-
}
|
|
11
|
-
setData(data: object) {
|
|
12
|
-
port1.postMessage({ type: "setData", body: { data } });
|
|
13
|
-
}
|
|
14
|
-
setSignalsData(data: object) {
|
|
15
|
-
port1.postMessage({ type: "setSignalsData", body: { data } });
|
|
16
|
-
}
|
|
17
|
-
setSignalsEndpoint(options: {
|
|
18
|
-
source: string;
|
|
19
|
-
endpoint: string;
|
|
20
|
-
active: string[];
|
|
21
|
-
features: string[][];
|
|
22
|
-
geometry: object;
|
|
23
|
-
timeInterval: object;
|
|
24
|
-
startTime?: string;
|
|
25
|
-
endTime?: string;
|
|
26
|
-
colors?: string[];
|
|
27
|
-
}) {
|
|
28
|
-
port1.postMessage({ type: "setSignalsEndpoint", body: { options } });
|
|
29
|
-
}
|
|
30
|
-
setSignalsGeometry(geometry: object) {
|
|
31
|
-
port1.postMessage({ type: "setSignalsGeometry", body: { geometry } });
|
|
32
|
-
}
|
|
33
|
-
setOptions(options: object) {
|
|
34
|
-
port1.postMessage({ type: "setOptions", body: { options } });
|
|
35
|
-
}
|
|
36
|
-
getFoo() {
|
|
37
|
-
return new Promise((resolve) => {
|
|
38
|
-
const ts = Date.now();
|
|
39
|
-
port1.onmessage = (event) => {
|
|
40
|
-
if (event.data.ts === ts) {
|
|
41
|
-
resolve(event.data.body);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
port1.postMessage({ ts, type: "getFoo", body: "hello world" });
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const createChart = (div: HTMLElement | null) => {
|
|
50
|
-
if (!div) {
|
|
51
|
-
console.error("no div selected");
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
return new Promise<EOxChart>((resolve) => {
|
|
55
|
-
const iframe = document.createElement("iframe");
|
|
56
|
-
iframe.style.cssText =
|
|
57
|
-
"width: 100%; height: 100%; display: block; margin: 0; border: none;";
|
|
58
|
-
iframe.setAttribute(
|
|
59
|
-
"src",
|
|
60
|
-
import.meta?.url?.includes("localhost")
|
|
61
|
-
? "http://localhost:5173/index.html"
|
|
62
|
-
: "about:blank"
|
|
63
|
-
);
|
|
64
|
-
iframe.setAttribute("id", "EOxChart");
|
|
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
|
-
}
|
|
79
|
-
let iframeLoaded = false;
|
|
80
|
-
iframe.onload = () => {
|
|
81
|
-
// store if the iFrame has already loaded, since in Cypress hovering over the test triggers
|
|
82
|
-
// the onload event multiple times, causing an error with the previously neutered port2
|
|
83
|
-
if (iframeLoaded) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
iframe.contentWindow?.postMessage("init", "*", [channel.port2]);
|
|
87
|
-
iframeLoaded = true;
|
|
88
|
-
resolve(new EOxChart(iframe));
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export { createChart };
|
package/src/main.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
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
|
-
],
|
|
36
|
-
}
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
let sdmInstance: SignalsDataManager | null = null;
|
|
40
|
-
|
|
41
|
-
let application: MessagePort;
|
|
42
|
-
|
|
43
|
-
window.addEventListener("message", (event) => {
|
|
44
|
-
if (event.data === "init") {
|
|
45
|
-
application = event.ports[0];
|
|
46
|
-
application.onmessage = onMessage;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
const onMessage = (event: MessageEvent) => {
|
|
51
|
-
if (event.data.ts) {
|
|
52
|
-
switch (event.data.type) {
|
|
53
|
-
case "getFoo":
|
|
54
|
-
console.log(event.data.body);
|
|
55
|
-
application.postMessage({ ts: event.data.ts, body: "foo bar" });
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
switch (event.data.type) {
|
|
60
|
-
case "setData":
|
|
61
|
-
eoxchart.data = event.data.body.data;
|
|
62
|
-
eoxchart.update("none");
|
|
63
|
-
break;
|
|
64
|
-
case "setSignalsEndpoint":
|
|
65
|
-
setSignalsEndpoint(event.data.body.options);
|
|
66
|
-
break;
|
|
67
|
-
case "setSignalsGeometry":
|
|
68
|
-
setSignalsGeometry(event.data.body.options);
|
|
69
|
-
break;
|
|
70
|
-
case "setSignalsData":
|
|
71
|
-
eoxchart.data = {
|
|
72
|
-
datasets: Object.entries(event.data.body.data).map(
|
|
73
|
-
([key, item]): ChartDataset => {
|
|
74
|
-
return {
|
|
75
|
-
type: "line",
|
|
76
|
-
label: key,
|
|
77
|
-
data: <number[]>item,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
),
|
|
81
|
-
};
|
|
82
|
-
eoxchart.update("none");
|
|
83
|
-
break;
|
|
84
|
-
case "setOptions":
|
|
85
|
-
eoxchart.options = event.data.body.options;
|
|
86
|
-
eoxchart.update("none");
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const setSignalsEndpoint = (options: {
|
|
93
|
-
source: string;
|
|
94
|
-
endpoint: string;
|
|
95
|
-
active: string[];
|
|
96
|
-
features: string[][];
|
|
97
|
-
geometry: object;
|
|
98
|
-
timeInterval: object;
|
|
99
|
-
startTime?: string;
|
|
100
|
-
endTime?: string;
|
|
101
|
-
}) => {
|
|
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
|
-
}
|
|
111
|
-
};
|