@eox/chart 2.0.0-alpha1 → 2.0.0-alpha11

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.
@@ -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-alpha9", 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-alpha9",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-alpha11",
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",
@@ -0,0 +1,206 @@
1
+ <template>
2
+ <div ref="chartControls" id="controls" class="controls" data-cy="controls"></div>
3
+ <canvas ref="chartCanvas" id="chart" class="chart" data-cy="chart"></canvas>
4
+ </template>
5
+
6
+ <script setup lang="ts">
7
+ import { ref, onMounted } from 'vue'
8
+ import Chart, { ChartDataset } from "chart.js/auto";
9
+ import "chartjs-adapter-luxon";
10
+ import SignalsDataManager from "./signalsDataManager";
11
+ import ChartControls from "./chartControls";
12
+
13
+ const chartCanvas = ref(null)
14
+ const chartControls = ref(null)
15
+ const props = defineProps([
16
+ 'data',
17
+ 'options',
18
+ 'signalsdata',
19
+ 'signalsendpoint'
20
+ ])
21
+
22
+ let eoxchart
23
+ let sdmInstance: SignalsDataManager | null = null;
24
+
25
+ onMounted(() => {
26
+ eoxchart = new Chart(
27
+ <HTMLCanvasElement>chartCanvas.value,
28
+ {
29
+ data: {
30
+ labels: [],
31
+ datasets: [],
32
+ },
33
+ plugins: [
34
+ {
35
+ id: "selectionLineHighlight",
36
+ afterDraw: (chart) => {
37
+ if (chart && chart.tooltip) {
38
+ const active = chart.tooltip.getActiveElements();
39
+ if (active?.length) {
40
+ let x = active[0].element.x;
41
+ let yAxis = chart.scales.y;
42
+ let ctx = chart.ctx;
43
+ ctx.save();
44
+ ctx.beginPath();
45
+ ctx.moveTo(x, yAxis.top);
46
+ ctx.lineTo(x, yAxis.bottom);
47
+ ctx.lineWidth = 1;
48
+ ctx.strokeStyle = "rgba(0, 0, 255, 0.4)";
49
+ ctx.stroke();
50
+ ctx.restore();
51
+ }
52
+ }
53
+ },
54
+ },
55
+ ],
56
+ }
57
+ );
58
+ // TODO remove timeout hack
59
+ setTimeout(() => {
60
+ if (props.data) {
61
+ eoxchart.data = JSON.parse(props.data)
62
+ }
63
+ if (props.signalsdata) {
64
+ eoxchart.data = {
65
+ datasets: Object.entries(JSON.parse(props.signalsdata)).map(
66
+ ([key, item]): ChartDataset => {
67
+ return {
68
+ type: "line",
69
+ label: key,
70
+ data: <number[]>item,
71
+ };
72
+ }
73
+ ),
74
+ };
75
+ }
76
+ if (props.options) {
77
+ eoxchart.options = JSON.parse(props.options)
78
+ }
79
+ if (props.signalsendpoint) {
80
+ setSignalsEndpoint(JSON.parse(props.signalsendpoint));
81
+ }
82
+ eoxchart.update("none")
83
+ }, 0)
84
+ })
85
+
86
+ const setSignalsEndpoint = (options: {
87
+ source: string;
88
+ endpoint: string;
89
+ active: string[];
90
+ features: string[][];
91
+ geometry: object;
92
+ timeInterval: object;
93
+ startTime?: string;
94
+ endTime?: string;
95
+ }) => {
96
+ sdmInstance = new SignalsDataManager(eoxchart, options);
97
+ new ChartControls(chartControls.value, sdmInstance, options);
98
+ sdmInstance.setActiveFields(options.active);
99
+ };
100
+
101
+ const setSignalsGeometry = (geometry: object) => {
102
+ if (sdmInstance) {
103
+ sdmInstance.setGeometry(geometry);
104
+ }
105
+ };
106
+
107
+
108
+ // export default {
109
+ // props: {
110
+ // data: String,
111
+ // },
112
+ // data: () => ({
113
+ // eoxchart: undefined
114
+ // }),
115
+ // computed: {
116
+ // parsedData() {
117
+ // if (!this.data) {
118
+ // return
119
+ // }
120
+ // return JSON.parse(this.data)
121
+ // }
122
+ // },
123
+ // watch: {
124
+ // parsedData(newData) {
125
+ // // setTimeout(() => {
126
+ // // this.eoxchart.data = newData
127
+ // // console.log(this.eoxchart.update)
128
+ // this.eoxchart.update();
129
+ // // }, 3000)
130
+ // }
131
+ // },
132
+ // mounted() {
133
+ // }
134
+ // }
135
+ </script>
136
+
137
+ <style>
138
+ * {
139
+ font-family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif";
140
+ font-size: 0.95em;
141
+ }
142
+ label {
143
+ margin-top: 2.5px;
144
+ }
145
+ html,
146
+ body {
147
+ margin: 0;
148
+ padding: 0;
149
+ }
150
+ html,
151
+ body,
152
+ .chart {
153
+ width: 100%;
154
+ height: 100%;
155
+ }
156
+ .hidden {
157
+ visibility: hidden;
158
+ }
159
+ .loader {
160
+ position: absolute;
161
+ top: 5px;
162
+ right: 30px;
163
+ width: 24px;
164
+ height: 24px;
165
+ border-radius: 50%;
166
+ display: inline-block;
167
+ border-top: 4px solid #000;
168
+ border-right: 4px solid transparent;
169
+ box-sizing: border-box;
170
+ animation: rotation 1s linear infinite;
171
+ }
172
+ .loader::after {
173
+ content: "";
174
+ box-sizing: border-box;
175
+ position: absolute;
176
+ left: 0;
177
+ top: 0;
178
+ width: 24px;
179
+ height: 24px;
180
+ border-radius: 50%;
181
+ border-left: 4px solid #004170;
182
+ border-bottom: 4px solid transparent;
183
+ animation: rotation 0.5s linear infinite reverse;
184
+ }
185
+ @keyframes rotation {
186
+ 0% {
187
+ transform: rotate(0deg);
188
+ }
189
+ 100% {
190
+ transform: rotate(360deg);
191
+ }
192
+ }
193
+ #controls {
194
+ position: absolute;
195
+ width: 100%;
196
+ display: flex;
197
+ gap: 5px;
198
+ flex-direction: row;
199
+ }
200
+ .parsingError {
201
+ background-color: #ff6d6d;
202
+ }
203
+ #chart {
204
+ padding-top: 30px;
205
+ }
206
+ </style>
@@ -0,0 +1,111 @@
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.geometry);
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
+ };