@eox/chart 2.0.0-alpha10 → 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,7 +1,7 @@
1
1
  var f = Object.defineProperty;
2
2
  var x = (s, t, e) => t in s ? f(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e;
3
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 = {
4
+ const b = "@eox/chart", w = "2.0.0-alpha9", v = {
5
5
  "chart.js": "^4.2.1",
6
6
  "chartjs-adapter-luxon": "^1.3.1",
7
7
  "chartjs-chart-error-bars": "^4.1.2"
@@ -1 +1 @@
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"})});
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/chart",
3
- "version": "2.0.0-alpha10",
3
+ "version": "2.0.0-alpha11",
4
4
  "dependencies": {
5
5
  "chart.js": "^4.2.1",
6
6
  "chartjs-adapter-luxon": "^1.3.1",
@@ -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
+ };
@@ -17,9 +17,6 @@ class ChartControls {
17
17
  ) {
18
18
  this.element = element;
19
19
  this.sdm = sdm;
20
- this.sdm.on("ready", (info) => {
21
- console.log(info);
22
- });
23
20
  this.options = options;
24
21
  this.sdmOptions = sdmOptions;
25
22
  this.generateTimeAggregationOptions();
@@ -33,12 +30,6 @@ class ChartControls {
33
30
  this.element.appendChild(spinner);
34
31
  }
35
32
 
36
- private createMessagesElements() {
37
- const messages = document.createElement("div");
38
- messages.id = "messages";
39
- this.element.appendChild(messages);
40
- }
41
-
42
33
  private removeStartEndInputs() {
43
34
  const start = document.getElementById("startInput");
44
35
  const end = document.getElementById("endInput");
package/src/main.ts CHANGED
@@ -65,7 +65,7 @@ const onMessage = (event: MessageEvent) => {
65
65
  setSignalsEndpoint(event.data.body.options);
66
66
  break;
67
67
  case "setSignalsGeometry":
68
- setSignalsGeometry(event.data.body.options);
68
+ setSignalsGeometry(event.data.body.geometry);
69
69
  break;
70
70
  case "setSignalsData":
71
71
  eoxchart.data = {
@@ -15,8 +15,6 @@ import {
15
15
  PointWithErrorBar,
16
16
  } from "chartjs-chart-error-bars";
17
17
 
18
- import { EventEmitter } from "events";
19
-
20
18
  Chart.register(
21
19
  LineWithErrorBarsController,
22
20
  LineWithErrorBarsChart,
@@ -64,7 +62,7 @@ export interface SDMOptions {
64
62
  additionalYAxis?: yAxisObject[];
65
63
  }
66
64
 
67
- class SignalsDataManager extends EventEmitter {
65
+ class SignalsDataManager {
68
66
  chart: Chart;
69
67
  startTime: DateTime;
70
68
  endTime: DateTime;
@@ -77,7 +75,6 @@ class SignalsDataManager extends EventEmitter {
77
75
  additionalYAxis: yAxisObject[] | null;
78
76
 
79
77
  constructor(chart: Chart, options: SDMOptions) {
80
- super();
81
78
  this.chart = chart;
82
79
  this.options = options;
83
80
  this.startTime = DateTime.now().minus(options.timeInterval);
@@ -165,7 +162,6 @@ class SignalsDataManager extends EventEmitter {
165
162
  position: "right",
166
163
  };
167
164
  }
168
- this.emit("ready", "someinfo");
169
165
  }
170
166
 
171
167
  private checkLoadingStatus() {
@@ -215,7 +211,6 @@ class SignalsDataManager extends EventEmitter {
215
211
  console.log(
216
212
  `Attempt ${error.attemptNumber} failed. There are ${error.retriesLeft} retries left.`
217
213
  );
218
- throw new Error();
219
214
  },
220
215
  retries: this.options.retries,
221
216
  }).then(function (res) {