@kiwibit/chart 17.0.0 → 17.0.1

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,18 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { EventEmitter, Component, Input, Output, NgModule } from '@angular/core';
3
- import { Subject, interval, takeUntil } from 'rxjs';
4
- import { NgStyle, CommonModule } from '@angular/common';
5
- import * as i1 from 'ngx-echarts';
6
- import { NgxEchartsDirective, NgxEchartsModule } from 'ngx-echarts';
2
+ import { EventEmitter, Directive, Input, Output, HostListener, Component } from '@angular/core';
7
3
  import * as echarts from 'echarts/core';
4
+ import { init } from 'echarts';
8
5
  import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, DataZoomComponent, ToolboxComponent } from 'echarts/components';
9
- import { LineChart, ScatterChart } from 'echarts/charts';
6
+ import { LineChart } from 'echarts/charts';
10
7
  import { CanvasRenderer } from 'echarts/renderers';
11
8
 
12
- const ADD_POINT_IMG_OFF_LIGHT = "image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QA/wD/AP+gvaeTAAADkUlEQVR4nO2bz0sUYRjHv8/otviDGDuWrhKdskBaQZi57MmLgVpIkJ06bH9AEdF/kF46dEg726liBSGwBEFnTm0oaF3s4lhdh1BhNuTpsDPLu+MvmHXm0ZzP6X2feWfn+3x33nf3fXlfIOV8Q0dd7O3tvaDr+igzDxPRLQCdANqSkRaZHQBbzPyViEqu65bW19crhzU+1ADDMO4S0QSAq3GoTJAfAJ5alvXhoItN4cDY2FiTruuTRPQSQEfc6hLgEoB7uVyu3XGcBQCsXtxngJ/846TUJYjR3d3dsrm5+VkN1nUB/7V/F7rRI6IpAG9bW1vX5ufnd+JW2giDg4Ntu7u7N5h5HEARQFa9rmna6NLSUimo1wzwB7zvqO/zP4loaHl5eTVu4XFgGEYfEc0BuKKEN1zX7Q0GRi2I6ro+ivrkvbOcPADYtr3CzLcBeEr4WkdHx3BQqRnAzMPqzUQ0dZaTD7BtewXAGzWm5lozgIjyaqO9vb2Z2NUlRziX/qCgKcHLaotsNvstTkVJkslk1kKh2pigGtCutlhcXNyOU1SSHJBLLVcN55xmqQcbhjFERNMA9gA8sizro4QOsTdA07TXqI47XQCmxHRIPZiZO5Vql5SOcz8GpAZIC5AmNUBagDSpAdICpEkNkBYgTWqAtABpUgOkBUgTeT3An89PoX7JOTKmafLxrfZDRFvMXIy6nhD5DfDn8yeSfCP40+rI6wnnvgtENoCZi0S0dZJiIuIQUTHqzZHHAL/PRV7JCfd5y7KO3KsQF2kXkBYgTWqAtABpUgOkBUiTGiAtQJrUAGkB0qQGSAuQJjVA6sGhqbQjpUNyg0SwntDQfL5RxPYINbqecFKkY4BSrttLVygU2vGfMDAwcDEU+hMUVAN+qS08z7sep6gkaW5uDufyOyiom6XLagtN0x7ErCtJxkP1L0FB3SxdCjUqGobRF6eqJPBzqPuVYeZarjUDXNctoXrAKCBLRHNn2QTlwMQFJbzhed5sUKlbijZN8w6A96HPqQCYBjCTyWTWTvsm6kKh0F6pVG4S0X1Uv3k1eTDziG3bBxsAAKZpTgJ4ErtSAZj5hW3bz9TYvlNjjuMs5HK5VgBmYsoSgIgmLMt6juOOzQFgx3E+9fT0rDJzP6rn7s4yG8z80LKsVwglDxxzdDafz2daWlpG/DM2eVSPzp72P0jbALYAlJm55HnebLlc/istKuW08g8wjAev/BoR3wAAAABJRU5ErkJggg==";
13
- const ADD_POINT_IMG_OFF_DARK = "image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QA/wD/AP+gvaeTAAADgUlEQVR4nO2bz04TURTGvzNtaQOVB1BgYVhZDbSUDixZYwLoTlzXB5CI8QUM4ANQXeOCqCkJiUuWtpNCIaG6gRWoeyx/CmGOC5hyZ/izmDJzgM5vdefMafudr/femd65BQKaG7rqZKVSadndORhjohGAUwB1AGjzSZtbdgHeBmiFmPNt7bF8I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gnGHyYA+MwgocC0PLFzqJ4Qz99i0Puy1ymBkNQ3MVbk0sxh30QdGs01Ndb4ruiEe9ufvK8spScTC+5uAACE4/kRAg04LVQCAobSseATNVbxHJBdDA4CNOKeLJcgGk4vBp5WhPfKDycKPQQeASPgrDKHIRTAGFAve2v3PoQTmTrgTA8Y3QSEsbXB+bA/IK0AWGAgS0CKaXki2x/ZkBblcVj5D1vBAfS1aXiGAAAAAElFTkSuQmCC";
15
-
16
9
  var TraceType;
17
10
  (function (TraceType) {
18
11
  TraceType["LINE"] = "line";
@@ -41,16 +34,42 @@ var ShapeVariant;
41
34
  ShapeVariant[ShapeVariant["TRACE"] = 0] = "TRACE";
42
35
  })(ShapeVariant || (ShapeVariant = {}));
43
36
 
44
- // Angular General
45
- class KiwiChartComponent {
46
- constructor(cd) {
47
- this.cd = cd;
37
+ const ZOOM_IN = "M39.35 40.45 26.6 27.7q-1.55 1.35-3.6 2.025-2.05.675-4 .675-4.9 0-8.225-3.325Q7.45 23.75 7.45 18.9q0-4.9 3.325-8.225Q14.1 7.35 18.95 7.35q4.85 0 8.225 3.325t3.375 8.175q0 2.1-.725 4.1-.725 2-2.025 3.45l12.8 12.75ZM19 28.65q4.15 0 6.975-2.8 2.825-2.8 2.825-7 0-4.15-2.825-6.95T19 9.1q-4.2 0-7 2.8t-2.8 6.95q0 4.2 2.8 7t7 2.8Zm-.9-5.1V19.7h-3.85v-1.75h3.85v-3.8h1.75v3.8h3.8v1.75h-3.8v3.85Z";
38
+ const ZOOM_OUT = "M41.25 39.35 29.55 27.7q-1.5 1.25-3.525 1.975Q24 30.4 22.05 30.4q-2.1 0-3.975-.725T14.9 27.65l1.2-1.2q1.2 1.1 2.65 1.65 1.45.55 3.25.55 4.2 0 7-2.8t2.8-7q0-4.15-2.8-6.95t-7-2.8q-4.15 0-7 2.8-2.85 2.8-2.75 6.95l3.2-3.4 1.3 1.3-5.35 5.35-5.3-5.35 1.3-1.3 3.05 3.3q0-4.85 3.4-8.125Q17.25 7.35 22 7.35q4.9 0 8.225 3.325Q33.55 14 33.55 18.85q0 2.1-.75 4.1-.75 2-1.95 3.45L42.5 38.05Z";
39
+ const SAVE_AS_SVG = "M11.3 40.05q-1.35 0-2.35-1t-1-2.35V11.3q0-1.4 1-2.375 1-.975 2.35-.975h25.4q1.4 0 2.375.975.975.975.975 2.375v25.4q0 1.35-.975 2.35t-2.375 1Zm0-1.75h25.4q.6 0 1.1-.5.5-.5.5-1.1V11.3q0-.6-.5-1.1-.5-.5-1.1-.5H11.3q-.6 0-1.1.5-.5.5-.5 1.1v25.4q0 .6.5 1.1.5.5 1.1.5Zm4.1-5.15h17.65l-5.5-7.3-5.2 6.45-3.3-3.85ZM9.7 38.3V9.7v28.6Z";
40
+ const RESTORE = "M24.2 25.65q-.65 0-1.125-.475T22.6 24q0-.7.475-1.2t1.175-.5q.65 0 1.175.525T25.95 24q0 .7-.55 1.175-.55.475-1.2.475Zm.1 14.55q-6.4 0-11.1-4.25Q8.5 31.7 8.1 25.4h1.8q.5 5.55 4.6 9.3 4.1 3.75 9.75 3.75 6.05 0 10.225-4.225T38.65 24.05q0-6.05-4.2-10.275Q30.25 9.55 24.3 9.55q-3.2 0-6.025 1.3t-4.875 3.6h4.95v1.75H10.4v-8h1.75v5.05q2.25-2.6 5.475-4.025Q20.85 7.8 24.3 7.8q3.3 0 6.225 1.25t5.125 3.475q2.2 2.225 3.475 5.175Q40.4 20.65 40.4 24q0 3.35-1.275 6.3-1.275 2.95-3.475 5.175-2.2 2.225-5.125 3.475T24.3 40.2Z";
41
+ const ADD_POINT = "M222.895-189.538q-22.456 0-37.906-15.451-15.451-15.45-15.451-37.906v-474.21q0-22.456 15.451-37.906 15.45-15.451 38.088-15.451h322.346v28.924H223.077q-10.769 0-17.692 6.923t-6.923 17.692v473.846q0 10.769 6.923 17.692t17.692 6.923h473.846q10.77 0 17.693-6.923 6.923-6.923 6.923-17.692v-322.346h28.923v322.346q0 22.638-15.451 38.088-15.45 15.451-37.906 15.451h-474.21Zm78.028-121.539h28.923v-243.077h-28.923v243.077Zm144.923 0h28.923v-337.846h-28.923v337.846Zm144.308 0h28.923v-148.308h-28.923v148.308Zm100-327.692v-71.385h-71.385v-28.923h71.385v-71.385h28.923v71.385h71.385v28.923h-71.385v71.385h-28.923ZM460-480Z";
42
+
43
+ // Angular Imports
44
+ echarts.use([
45
+ TitleComponent,
46
+ TooltipComponent,
47
+ GridComponent,
48
+ LineChart,
49
+ CanvasRenderer,
50
+ LegendComponent,
51
+ DataZoomComponent,
52
+ ToolboxComponent,
53
+ ]);
54
+ class KiwiChartDirective {
55
+ /**
56
+ * If you resize the page, the chart is automatically re-rendered wiht the right proportions.
57
+ *
58
+ * @memberof EnchartingDirective
59
+ */
60
+ onResize() {
61
+ if (this.echartsInstance) {
62
+ this.echartsInstance.resize();
63
+ }
64
+ }
65
+ constructor(el) {
66
+ this.el = el;
48
67
  /**
49
68
  * The Chart Object rendered by the canvas. For all the available options refer
50
69
  * to Chart interface in the models folder.
51
70
  *
52
71
  * @type {(Chart | null)}
53
- * @memberof KiwiChartComponent
72
+ * @memberof KiwiChartDirective
54
73
  */
55
74
  this.chart = null;
56
75
  /**
@@ -59,26 +78,18 @@ class KiwiChartComponent {
59
78
  * of the chart can take the whole available space in the page.
60
79
  *
61
80
  * @type {string}
62
- * @memberof KiwiChartComponent
81
+ * @memberof KiwiChartDirective
63
82
  */
64
83
  this.width = '100%';
65
84
  this.height = '480px';
66
- /**
67
- * This property simply activates or not the dark theme of the chart
68
- * defined by the Echarts library. In addition the background color can be custom
69
- * so that the chart can match the background of the application in which it's used.
70
- *
71
- * @type {boolean}
72
- * @memberof KiwiChartComponent
73
- */
74
- this.darkTheme = false;
85
+ this.chartInit = new EventEmitter();
75
86
  /**
76
87
  * Output event used to emit to the father component the coordinates
77
88
  * of the point clicked in the chart area. This functionality to be used must
78
89
  * have the property "clickToAddPoint" in the Chart object set to true.
79
90
  *
80
91
  * @type {EventEmitter<BasePoint>}
81
- * @memberof KiwiChartComponent
92
+ * @memberof KiwiChartDirective
82
93
  */
83
94
  this.addPoint = new EventEmitter();
84
95
  /**
@@ -86,158 +97,68 @@ class KiwiChartComponent {
86
97
  * x and y coordinates relative to the chart reference system.
87
98
  *
88
99
  * @type {EventEmitter<BasePoint>}
89
- * @memberof KiwiChartComponent
100
+ * @memberof KiwiChartDirective
90
101
  */
91
102
  this.chartHover = new EventEmitter();
92
103
  /**
93
- * The object used by echarts to initially create the Chart.
94
- * Has a default configuration that can be totally overrided using specific properties.
104
+ * This property simply activates or not the dark theme of the chart
105
+ * defined by the Echarts library. In addition the background color can be custom
106
+ * so that the chart can match the background of the application in which it's used.
95
107
  *
96
- * @type {EChartsOption}
97
- * @memberof KiwiChartComponent
108
+ * @type {boolean}
109
+ * @memberof KiwiChartDirective
98
110
  */
99
- this.chartOption = {
100
- title: {
101
- text: 'Kiwi Chart'
102
- },
103
- xAxis: {
104
- name: 'X'
105
- },
106
- yAxis: {
107
- name: 'Y'
108
- },
109
- series: [
110
- {
111
- type: TraceType.LINE,
112
- data: [[0, 0]]
113
- }
114
- ]
115
- };
111
+ this.darkTheme = false;
112
+ this.darkThemeBackground = null;
116
113
  /**
117
114
  * The instance of the Chart.
118
115
  *
119
- * @type {(ECharts | null)}
120
- * @memberof KiwiChartComponent
116
+ * @type {ECharts}
117
+ * @memberof KiwiChartDirective
121
118
  */
122
119
  this.echartsInstance = null;
123
- /**
124
- * Used to perform actions (as point addition based on the cursor position) on the chart.
125
- *
126
- * @type {(zrender.ZRenderType | null)}
127
- * @memberof KiwiChartComponent
128
- */
129
- this.zr = null;
130
- /**
131
- * Subject used to unsubscribe once the component gets destroyed.
132
- *
133
- * @private
134
- * @type {Subject<void>}
135
- * @memberof KiwiChartComponent
136
- */
137
- this.destroyed$ = new Subject();
138
120
  /**
139
121
  * Default number of decimals that can have
140
122
  * the values on the x and y axes.
141
123
  *
142
124
  * @private
143
125
  * @type {number}
144
- * @memberof KiwiChartComponent
126
+ * @memberof KiwiChartDirective
145
127
  */
146
128
  this.MAX_DECIMALS = 3;
147
129
  this.legendSelected = {};
148
130
  this.isLegendClicked = false;
149
- }
150
- ngOnInit() {
151
- /**
152
- * This is a manual change detection running every 200ms, the memory should not be much afflicted.
153
- * It's necessary because when interacting with the chart (for example addPoint),
154
- * Angular loses the change detection and the point is not added in the chart canvas.
155
- */
156
- interval(200)
157
- .pipe(takeUntil(this.destroyed$))
158
- .subscribe({
159
- next: () => {
160
- this.cd.detectChanges();
161
- }
162
- });
163
- }
164
- onChartInit(ec) {
165
- this.echartsInstance = ec;
166
- this.setupZrEventHandler(ec);
167
- this.setupLegendEventHandler(ec);
168
- }
169
- /**
170
- * intercept a selection change event on the legend and save the state
171
- * of all selections on the supporting variable legendSelected
172
- *
173
- * @param ec
174
- */
175
- setupLegendEventHandler(ec) {
176
- if (this.echartsInstance != null) {
177
- this.echartsInstance.on('legendselectchanged', (params) => {
178
- this.isLegendClicked = true;
179
- this.legendSelected = params.selected;
180
- });
181
- }
182
- }
183
- setupZrEventHandler(ec) {
184
- this.zr = ec.getZr();
185
- /**
186
- * Intercepts the click event on the chart (if the clickToAddPoint property is set to true)
187
- * and emits the point coordinates to the father component.
188
- */
189
- this.zr.on('click', params => {
190
- let option = ec.getOption();
191
- let active = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
192
- if (active && this.chart?.clickToAddPoint) {
193
- const pointInPixel = [params.offsetX, params.offsetY];
194
- const pointInGrid = ec.convertFromPixel('grid', pointInPixel);
195
- if (ec.containPixel('grid', pointInPixel) && pointInGrid) {
196
- let newPoint = {
197
- x: +pointInGrid[0].toFixed(3),
198
- y: +pointInGrid[1].toFixed(3)
199
- };
200
- this.addPoint.emit(newPoint);
201
- }
202
- }
203
- });
204
131
  /**
205
- * This is used perform custom actions when the mouse is hovering the chart area
132
+ * Used to perform actions (as point addition based on the cursor position) on the chart.
133
+ *
134
+ * @type {(zrender.ZRenderType | null)}
135
+ * @memberof KiwiChartComponent
206
136
  */
207
- this.zr.on('mousemove', params => {
208
- const pointInPixel = [params.offsetX, params.offsetY];
209
- const pointInGrid = ec.convertFromPixel('grid', pointInPixel);
210
- /*
211
- * Logic to emit to the father component the x and y cdinates when the
212
- * cursor is hovering the chart area .
213
- */
214
- if (ec.containPixel('grid', pointInPixel) && pointInGrid) {
215
- let newPoint = {
216
- x: +pointInGrid[0].toFixed(3),
217
- y: +pointInGrid[1].toFixed(3)
218
- };
219
- this.chartHover.emit(newPoint);
220
- }
221
- /* Logic to change the cursor icon when the "Click to Add Point" feature is active and viceversa. */
222
- const option = ec.getOption();
223
- const addPointIsActive = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
224
- if (addPointIsActive) {
225
- this.zr?.setCursorStyle(ec.containPixel('grid', pointInPixel) ? 'copy' : 'default');
226
- }
227
- });
137
+ this.zr = null;
228
138
  }
229
- getLegendItemSelection(shape) {
230
- if (this.isLegendClicked) {
231
- return this.legendSelected[shape.name] ?? true;
232
- }
233
- else {
234
- return shape.selectedByDefault ?? true;
139
+ ngAfterViewInit() {
140
+ if (this.chart) {
141
+ this.renderChart(this.chart);
235
142
  }
236
143
  }
237
144
  ngOnChanges(changes) {
238
145
  let chart = changes['chart']?.currentValue;
146
+ if (this.echartsInstance) {
147
+ // Every time we have an external change we
148
+ // destroy the chart and re-initialize it
149
+ this.echartsInstance.dispose();
150
+ this.renderChart(chart);
151
+ }
152
+ }
153
+ renderChart(chart) {
154
+ // Update ElementRef styles
155
+ this.el.nativeElement.style.width = this.width;
156
+ this.el.nativeElement.style.height = this.height;
157
+ this.echartsInstance = init(this.el.nativeElement, this.darkTheme ? 'dark' : 'default', {
158
+ renderer: 'svg'
159
+ });
239
160
  if (chart) {
240
- this.chartOption = {
161
+ this.echartsInstance.setOption({
241
162
  title: {
242
163
  text: chart.title,
243
164
  },
@@ -265,46 +186,64 @@ class KiwiChartComponent {
265
186
  },
266
187
  emphasis: {
267
188
  iconStyle: {
268
- textPosition: 'top'
189
+ textPosition: 'top',
190
+ textPadding: 5
269
191
  }
270
- }
192
+ },
193
+ icon: {
194
+ zoom: ZOOM_IN,
195
+ back: ZOOM_OUT
196
+ },
271
197
  },
272
198
  saveAsImage: {
273
199
  emphasis: {
274
200
  iconStyle: {
275
- textPosition: 'top'
201
+ textPosition: 'top',
202
+ textPadding: 5
276
203
  }
277
- }
204
+ },
205
+ icon: SAVE_AS_SVG,
278
206
  },
279
207
  restore: {
280
208
  emphasis: {
281
209
  iconStyle: {
282
- textPosition: 'top'
210
+ textPosition: 'top',
211
+ textPadding: 5
283
212
  }
284
- }
213
+ },
214
+ icon: RESTORE,
285
215
  },
286
216
  myAddPoint: {
287
217
  show: chart.clickToAddPoint ?? false,
288
218
  title: chart.addPointCustomName ?? 'Add Point',
289
- icon: this.darkTheme ? ADD_POINT_IMG_OFF_DARK : ADD_POINT_IMG_OFF_LIGHT,
290
- iconStatus: false,
219
+ icon: ADD_POINT,
291
220
  onclick: () => {
292
- let option = this.echartsInstance?.getOption();
293
- let status = option.toolbox[0].feature.myAddPoint.iconStatus;
294
- this.echartsInstance?.setOption({
295
- toolbox: {
296
- feature: {
297
- myAddPoint: {
298
- iconStatus: !status,
299
- icon: !status ? ADD_POINT_IMG_ON : this.darkTheme ? ADD_POINT_IMG_OFF_DARK : ADD_POINT_IMG_OFF_LIGHT
221
+ if (this.echartsInstance) {
222
+ const option = this.echartsInstance.getOption();
223
+ const toolbox = option.toolbox;
224
+ if (toolbox) {
225
+ const status = toolbox[0].feature?.['myAddPoint']?.iconStatus;
226
+ const offColor = 'rgb(102,102,102)';
227
+ const highlightColor = 'rgb(62,152,197)';
228
+ this.echartsInstance.setOption({
229
+ toolbox: {
230
+ feature: {
231
+ myAddPoint: {
232
+ iconStatus: !status,
233
+ iconStyle: {
234
+ borderColor: !status ? highlightColor : offColor
235
+ }
236
+ }
237
+ }
300
238
  }
301
- }
239
+ });
302
240
  }
303
- });
241
+ }
304
242
  },
305
243
  emphasis: {
306
244
  iconStyle: {
307
- textPosition: 'top'
245
+ textPosition: 'top',
246
+ textPadding: 5
308
247
  }
309
248
  }
310
249
  }
@@ -377,10 +316,12 @@ class KiwiChartComponent {
377
316
  },
378
317
  series: this.createSeries(chart.shapes),
379
318
  animation: chart.hasAnimations,
380
- animationDuration: chart.animationDuration ?? 500,
319
+ animationDuration: chart.animationDuration ?? 250,
381
320
  animationEasing: 'cubicOut'
382
- };
321
+ }, true, true);
383
322
  }
323
+ this.setupZrEventHandler(this.echartsInstance);
324
+ this.setupLegendEventHandler(this.echartsInstance);
384
325
  }
385
326
  createSeries(shapes) {
386
327
  let series = [];
@@ -441,40 +382,185 @@ class KiwiChartComponent {
441
382
  smooth: trace.smooth ?? false
442
383
  };
443
384
  }
444
- ngOnDestroy() {
445
- this.destroyed$.next();
446
- this.destroyed$.complete();
385
+ getLegendItemSelection(shape) {
386
+ if (this.isLegendClicked) {
387
+ return this.legendSelected[shape.name] ?? true;
388
+ }
389
+ else {
390
+ return shape.selectedByDefault ?? true;
391
+ }
392
+ }
393
+ /**
394
+ * intercept a selection change event on the legend and save the state
395
+ * of all selections on the supporting variable legendSelected
396
+ *
397
+ * @param ec
398
+ */
399
+ setupLegendEventHandler(ec) {
400
+ if (this.echartsInstance != null) {
401
+ this.echartsInstance.on('legendselectchanged', (params) => {
402
+ this.isLegendClicked = true;
403
+ this.legendSelected = params.selected;
404
+ });
405
+ }
406
+ }
407
+ setupZrEventHandler(ec) {
408
+ this.zr = ec.getZr();
409
+ /**
410
+ * Intercepts the click event on the chart (if the clickToAddPoint property is set to true)
411
+ * and emits the point coordinates to the father component.
412
+ */
413
+ this.zr.on('click', params => {
414
+ let option = ec.getOption();
415
+ let active = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
416
+ if (active && this.chart?.clickToAddPoint) {
417
+ const pointInPixel = [params.offsetX, params.offsetY];
418
+ const pointInGrid = ec.convertFromPixel('grid', pointInPixel);
419
+ if (ec.containPixel('grid', pointInPixel) && pointInGrid) {
420
+ let newPoint = {
421
+ x: +pointInGrid[0].toFixed(3),
422
+ y: +pointInGrid[1].toFixed(3)
423
+ };
424
+ this.addPoint.emit(newPoint);
425
+ }
426
+ }
427
+ });
428
+ /**
429
+ * This is used perform custom actions when the mouse is hovering the chart area
430
+ */
431
+ this.zr.on('mousemove', params => {
432
+ const pointInPixel = [params.offsetX, params.offsetY];
433
+ const pointInGrid = ec.convertFromPixel('grid', pointInPixel);
434
+ /*
435
+ * Logic to emit to the father component the x and y cdinates when the
436
+ * cursor is hovering the chart area .
437
+ */
438
+ if (ec.containPixel('grid', pointInPixel) && pointInGrid) {
439
+ let newPoint = {
440
+ x: +pointInGrid[0].toFixed(3),
441
+ y: +pointInGrid[1].toFixed(3)
442
+ };
443
+ this.chartHover.emit(newPoint);
444
+ }
445
+ /* Logic to change the cursor icon when the "Click to Add Point" feature is active and viceversa. */
446
+ const option = ec.getOption();
447
+ const addPointIsActive = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
448
+ if (addPointIsActive) {
449
+ this.zr?.setCursorStyle(ec.containPixel('grid', pointInPixel) ? 'copy' : 'default');
450
+ }
451
+ });
452
+ }
453
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); }
454
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.3.1", type: KiwiChartDirective, isStandalone: true, selector: "div[kiwi-chart]", inputs: { chart: "chart", width: "width", height: "height", darkTheme: "darkTheme", darkThemeBackground: "darkThemeBackground" }, outputs: { chartInit: "chartInit", addPoint: "addPoint", chartHover: "chartHover" }, host: { listeners: { "window:resize": "onResize($event)" } }, usesOnChanges: true, ngImport: i0 }); }
455
+ }
456
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartDirective, decorators: [{
457
+ type: Directive,
458
+ args: [{
459
+ selector: 'div[kiwi-chart]',
460
+ standalone: true
461
+ }]
462
+ }], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { chart: [{
463
+ type: Input,
464
+ args: [{ required: true }]
465
+ }], width: [{
466
+ type: Input
467
+ }], height: [{
468
+ type: Input
469
+ }], chartInit: [{
470
+ type: Output
471
+ }], addPoint: [{
472
+ type: Output
473
+ }], chartHover: [{
474
+ type: Output
475
+ }], darkTheme: [{
476
+ type: Input
477
+ }], darkThemeBackground: [{
478
+ type: Input
479
+ }], onResize: [{
480
+ type: HostListener,
481
+ args: ['window:resize', ['$event']]
482
+ }] } });
483
+
484
+ // Angular General
485
+ class KiwiChartComponent {
486
+ constructor() {
487
+ /**
488
+ * The Chart Object rendered by the canvas. For all the available options refer
489
+ * to Chart interface in the models folder.
490
+ *
491
+ * @type {(Chart | null)}
492
+ * @memberof KiwiChartComponent
493
+ */
494
+ this.chart = null;
495
+ /**
496
+ * Width and Height of the chart area. The dimensions refer to the father component
497
+ * into which the kiwi-chart is inserted. For example in an empty page the width/height
498
+ * of the chart can take the whole available space in the page.
499
+ *
500
+ * @type {string}
501
+ * @memberof KiwiChartComponent
502
+ */
503
+ this.width = '100%';
504
+ this.height = '480px';
505
+ /**
506
+ * This property simply activates or not the dark theme of the chart
507
+ * defined by the Echarts library. In addition the background color can be custom
508
+ * so that the chart can match the background of the application in which it's used.
509
+ *
510
+ * @type {boolean}
511
+ * @memberof KiwiChartComponent
512
+ */
513
+ this.darkTheme = false;
514
+ this.darkThemeBackground = null;
515
+ /**
516
+ * Output event used to emit to the father component the coordinates
517
+ * of the point clicked in the chart area. This functionality to be used must
518
+ * have the property "clickToAddPoint" in the Chart object set to true.
519
+ *
520
+ * @type {EventEmitter<BasePoint>}
521
+ * @memberof KiwiChartComponent
522
+ */
523
+ this.addPoint = new EventEmitter();
524
+ /**
525
+ * When the cursor hovers the chart area it emits to the father component the
526
+ * x and y coordinates relative to the chart reference system.
527
+ *
528
+ * @type {EventEmitter<BasePoint>}
529
+ * @memberof KiwiChartComponent
530
+ */
531
+ this.chartHover = new EventEmitter();
447
532
  }
448
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
449
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.1", type: KiwiChartComponent, isStandalone: true, selector: "kiwi-chart", inputs: { chart: "chart", width: "width", height: "height", darkTheme: "darkTheme", darkThemeBackground: "darkThemeBackground" }, outputs: { addPoint: "addPoint", chartHover: "chartHover" }, usesOnChanges: true, ngImport: i0, template: `
533
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
534
+ static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.3.1", type: KiwiChartComponent, isStandalone: true, selector: "kiwi-chart", inputs: { chart: "chart", width: "width", height: "height", darkTheme: "darkTheme", darkThemeBackground: "darkThemeBackground" }, outputs: { addPoint: "addPoint", chartHover: "chartHover" }, ngImport: i0, template: `
450
535
  <div
451
- echarts
452
- [options]="chartOption"
453
- [ngStyle]="{
454
- 'width': width,
455
- 'height': height
456
- }"
457
- (chartInit)="onChartInit($event)"
458
- [theme]="darkTheme ? 'dark' : ''"
536
+ kiwi-chart
537
+ [chart]="chart"
538
+ [width]="width"
539
+ [height]="height"
540
+ [darkTheme]="darkTheme"
541
+ [darkThemeBackground]="darkThemeBackground"
542
+ (addPoint)="addPoint.emit($event)"
543
+ (chartHover)="chartHover.emit($event)"
459
544
  ></div>
460
- `, isInline: true, styles: [""], dependencies: [{ kind: "directive", type: NgxEchartsDirective, selector: "echarts, [echarts]", inputs: ["options", "theme", "initOpts", "merge", "autoResize", "loading", "loadingType", "loadingOpts"], outputs: ["chartInit", "optionsError", "chartClick", "chartDblClick", "chartMouseDown", "chartMouseMove", "chartMouseUp", "chartMouseOver", "chartMouseOut", "chartGlobalOut", "chartContextMenu", "chartHighlight", "chartDownplay", "chartSelectChanged", "chartLegendSelectChanged", "chartLegendSelected", "chartLegendUnselected", "chartLegendLegendSelectAll", "chartLegendLegendInverseSelect", "chartLegendScroll", "chartDataZoom", "chartDataRangeSelected", "chartGraphRoam", "chartGeoRoam", "chartTreeRoam", "chartTimelineChanged", "chartTimelinePlayChanged", "chartRestore", "chartDataViewChanged", "chartMagicTypeChanged", "chartGeoSelectChanged", "chartGeoSelected", "chartGeoUnselected", "chartAxisAreaSelected", "chartBrush", "chartBrushEnd", "chartBrushSelected", "chartGlobalCursorTaken", "chartRendered", "chartFinished"], exportAs: ["echarts"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] }); }
545
+ `, isInline: true, styles: [""], dependencies: [{ kind: "directive", type: KiwiChartDirective, selector: "div[kiwi-chart]", inputs: ["chart", "width", "height", "darkTheme", "darkThemeBackground"], outputs: ["chartInit", "addPoint", "chartHover"] }] }); }
461
546
  }
462
547
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartComponent, decorators: [{
463
548
  type: Component,
464
549
  args: [{ selector: 'kiwi-chart', template: `
465
550
  <div
466
- echarts
467
- [options]="chartOption"
468
- [ngStyle]="{
469
- 'width': width,
470
- 'height': height
471
- }"
472
- (chartInit)="onChartInit($event)"
473
- [theme]="darkTheme ? 'dark' : ''"
551
+ kiwi-chart
552
+ [chart]="chart"
553
+ [width]="width"
554
+ [height]="height"
555
+ [darkTheme]="darkTheme"
556
+ [darkThemeBackground]="darkThemeBackground"
557
+ (addPoint)="addPoint.emit($event)"
558
+ (chartHover)="chartHover.emit($event)"
474
559
  ></div>
475
- `, standalone: true, imports: [NgxEchartsDirective, NgStyle] }]
476
- }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { chart: [{
477
- type: Input
560
+ `, standalone: true, imports: [KiwiChartDirective] }]
561
+ }], propDecorators: { chart: [{
562
+ type: Input,
563
+ args: [{ required: true }]
478
564
  }], width: [{
479
565
  type: Input
480
566
  }], height: [{
@@ -489,37 +575,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImpor
489
575
  type: Output
490
576
  }] } });
491
577
 
492
- echarts.use([
493
- TitleComponent,
494
- TooltipComponent,
495
- GridComponent,
496
- LineChart,
497
- CanvasRenderer,
498
- LegendComponent,
499
- DataZoomComponent,
500
- ToolboxComponent,
501
- ScatterChart
502
- ]);
503
- class KiwiChartModule {
504
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
505
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartModule, imports: [CommonModule, i1.NgxEchartsModule, KiwiChartComponent], exports: [KiwiChartComponent] }); }
506
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartModule, imports: [CommonModule,
507
- NgxEchartsModule.forRoot({ echarts })] }); }
508
- }
509
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartModule, decorators: [{
510
- type: NgModule,
511
- args: [{
512
- imports: [
513
- CommonModule,
514
- NgxEchartsModule.forRoot({ echarts }),
515
- KiwiChartComponent
516
- ],
517
- exports: [
518
- KiwiChartComponent
519
- ]
520
- }]
521
- }] });
522
-
523
578
  /*
524
579
  * Public API Surface of chart
525
580
  */
@@ -528,5 +583,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImpor
528
583
  * Generated bundle index. Do not edit.
529
584
  */
530
585
 
531
- export { ADD_POINT_IMG_OFF_DARK, ADD_POINT_IMG_OFF_LIGHT, ADD_POINT_IMG_ON, AxisType, KiwiChartComponent, KiwiChartModule, PointSymbol, ShapeVariant, TraceStyle, TraceType };
586
+ export { AxisType, KiwiChartComponent, PointSymbol, ShapeVariant, TraceStyle, TraceType };
532
587
  //# sourceMappingURL=kiwibit-chart.mjs.map