@kiwibit/chart 16.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,19 +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 * as i1 from '@angular/common';
5
- import { CommonModule } from '@angular/common';
6
- import * as i2 from 'ngx-echarts';
7
- import { NgxEchartsModule } from 'ngx-echarts';
2
+ import { EventEmitter, Directive, Input, Output, HostListener, Component } from '@angular/core';
8
3
  import * as echarts from 'echarts/core';
4
+ import { init } from 'echarts';
9
5
  import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, DataZoomComponent, ToolboxComponent } from 'echarts/components';
10
- import { LineChart, ScatterChart } from 'echarts/charts';
6
+ import { LineChart } from 'echarts/charts';
11
7
  import { CanvasRenderer } from 'echarts/renderers';
12
8
 
13
- 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==";
14
- const ADD_POINT_IMG_OFF_DARK = "image://data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABmJLR0QA/wD/AP+gvaeTAAADgUlEQVR4nO2bz04TURTGvzNtaQOVB1BgYVhZDbSUDixZYwLoTlzXB5CI8QUM4ANQXeOCqCkJiUuWtpNCIaG6gRWoeyx/CmGOC5hyZ/izmDJzgM5vdefMafudr/femd65BQKaG7rqZKVSadndORhjohGAUwB1AGjzSZtbdgHeBmiFmPNt7bF8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sgnGHyYA+MwgocC0PLFzqJ4Qz99i0Puy1ymBkNQ3MVbk0sxh30QdGs01Ndb4ruiEe9ufvK8spScTC+5uAACE4/kRAg04LVQCAobSseATNVbxHJBdDA4CNOKeLJcgGk4vBp5WhPfKDycKPQQeASPgrDKHIRTAGFAve2v3PoQTmTrgTA8Y3QSEsbXB+bA/IK0AWGAgS0CKaXki2x/ZkBblcVj5D1vBAfS1aXiGAAAAAElFTkSuQmCC";
16
-
17
9
  var TraceType;
18
10
  (function (TraceType) {
19
11
  TraceType["LINE"] = "line";
@@ -42,16 +34,42 @@ var ShapeVariant;
42
34
  ShapeVariant[ShapeVariant["TRACE"] = 0] = "TRACE";
43
35
  })(ShapeVariant || (ShapeVariant = {}));
44
36
 
45
- // Angular General
46
- class KiwiChartComponent {
47
- constructor(cd) {
48
- 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;
49
67
  /**
50
68
  * The Chart Object rendered by the canvas. For all the available options refer
51
69
  * to Chart interface in the models folder.
52
70
  *
53
71
  * @type {(Chart | null)}
54
- * @memberof KiwiChartComponent
72
+ * @memberof KiwiChartDirective
55
73
  */
56
74
  this.chart = null;
57
75
  /**
@@ -60,26 +78,18 @@ class KiwiChartComponent {
60
78
  * of the chart can take the whole available space in the page.
61
79
  *
62
80
  * @type {string}
63
- * @memberof KiwiChartComponent
81
+ * @memberof KiwiChartDirective
64
82
  */
65
83
  this.width = '100%';
66
84
  this.height = '480px';
67
- /**
68
- * This property simply activates or not the dark theme of the chart
69
- * defined by the Echarts library. In addition the background color can be custom
70
- * so that the chart can match the background of the application in which it's used.
71
- *
72
- * @type {boolean}
73
- * @memberof KiwiChartComponent
74
- */
75
- this.darkTheme = false;
85
+ this.chartInit = new EventEmitter();
76
86
  /**
77
87
  * Output event used to emit to the father component the coordinates
78
88
  * of the point clicked in the chart area. This functionality to be used must
79
89
  * have the property "clickToAddPoint" in the Chart object set to true.
80
90
  *
81
91
  * @type {EventEmitter<BasePoint>}
82
- * @memberof KiwiChartComponent
92
+ * @memberof KiwiChartDirective
83
93
  */
84
94
  this.addPoint = new EventEmitter();
85
95
  /**
@@ -87,158 +97,68 @@ class KiwiChartComponent {
87
97
  * x and y coordinates relative to the chart reference system.
88
98
  *
89
99
  * @type {EventEmitter<BasePoint>}
90
- * @memberof KiwiChartComponent
100
+ * @memberof KiwiChartDirective
91
101
  */
92
102
  this.chartHover = new EventEmitter();
93
103
  /**
94
- * The object used by echarts to initially create the Chart.
95
- * 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.
96
107
  *
97
- * @type {EChartsOption}
98
- * @memberof KiwiChartComponent
108
+ * @type {boolean}
109
+ * @memberof KiwiChartDirective
99
110
  */
100
- this.chartOption = {
101
- title: {
102
- text: 'Kiwi Chart'
103
- },
104
- xAxis: {
105
- name: 'X'
106
- },
107
- yAxis: {
108
- name: 'Y'
109
- },
110
- series: [
111
- {
112
- type: TraceType.LINE,
113
- data: [[0, 0]]
114
- }
115
- ]
116
- };
111
+ this.darkTheme = false;
112
+ this.darkThemeBackground = null;
117
113
  /**
118
114
  * The instance of the Chart.
119
115
  *
120
- * @type {(ECharts | null)}
121
- * @memberof KiwiChartComponent
116
+ * @type {ECharts}
117
+ * @memberof KiwiChartDirective
122
118
  */
123
119
  this.echartsInstance = null;
124
- /**
125
- * Used to perform actions (as point addition based on the cursor position) on the chart.
126
- *
127
- * @type {(zrender.ZRenderType | null)}
128
- * @memberof KiwiChartComponent
129
- */
130
- this.zr = null;
131
- /**
132
- * Subject used to unsubscribe once the component gets destroyed.
133
- *
134
- * @private
135
- * @type {Subject<void>}
136
- * @memberof KiwiChartComponent
137
- */
138
- this.destroyed$ = new Subject();
139
120
  /**
140
121
  * Default number of decimals that can have
141
122
  * the values on the x and y axes.
142
123
  *
143
124
  * @private
144
125
  * @type {number}
145
- * @memberof KiwiChartComponent
126
+ * @memberof KiwiChartDirective
146
127
  */
147
128
  this.MAX_DECIMALS = 3;
148
129
  this.legendSelected = {};
149
130
  this.isLegendClicked = false;
150
- }
151
- ngOnInit() {
152
- /**
153
- * This is a manual change detection running every 200ms, the memory should not be much afflicted.
154
- * It's necessary because when interacting with the chart (for example addPoint),
155
- * Angular loses the change detection and the point is not added in the chart canvas.
156
- */
157
- interval(200)
158
- .pipe(takeUntil(this.destroyed$))
159
- .subscribe({
160
- next: () => {
161
- this.cd.detectChanges();
162
- }
163
- });
164
- }
165
- onChartInit(ec) {
166
- this.echartsInstance = ec;
167
- this.setupZrEventHandler(ec);
168
- this.setupLegendEventHandler(ec);
169
- }
170
- /**
171
- * intercept a selection change event on the legend and save the state
172
- * of all selections on the supporting variable legendSelected
173
- *
174
- * @param ec
175
- */
176
- setupLegendEventHandler(ec) {
177
- if (this.echartsInstance != null) {
178
- this.echartsInstance.on('legendselectchanged', (params) => {
179
- this.isLegendClicked = true;
180
- this.legendSelected = params.selected;
181
- });
182
- }
183
- }
184
- setupZrEventHandler(ec) {
185
- this.zr = ec.getZr();
186
- /**
187
- * Intercepts the click event on the chart (if the clickToAddPoint property is set to true)
188
- * and emits the point coordinates to the father component.
189
- */
190
- this.zr.on('click', params => {
191
- let option = ec.getOption();
192
- let active = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
193
- if (active && this.chart?.clickToAddPoint) {
194
- const pointInPixel = [params.offsetX, params.offsetY];
195
- const pointInGrid = ec.convertFromPixel('grid', pointInPixel);
196
- if (ec.containPixel('grid', pointInPixel) && pointInGrid) {
197
- let newPoint = {
198
- x: +pointInGrid[0].toFixed(3),
199
- y: +pointInGrid[1].toFixed(3)
200
- };
201
- this.addPoint.emit(newPoint);
202
- }
203
- }
204
- });
205
131
  /**
206
- * 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
207
136
  */
208
- this.zr.on('mousemove', params => {
209
- const pointInPixel = [params.offsetX, params.offsetY];
210
- const pointInGrid = ec.convertFromPixel('grid', pointInPixel);
211
- /*
212
- * Logic to emit to the father component the x and y cdinates when the
213
- * cursor is hovering the chart area .
214
- */
215
- if (ec.containPixel('grid', pointInPixel) && pointInGrid) {
216
- let newPoint = {
217
- x: +pointInGrid[0].toFixed(3),
218
- y: +pointInGrid[1].toFixed(3)
219
- };
220
- this.chartHover.emit(newPoint);
221
- }
222
- /* Logic to change the cursor icon when the "Click to Add Point" feature is active and viceversa. */
223
- const option = ec.getOption();
224
- const addPointIsActive = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
225
- if (addPointIsActive) {
226
- this.zr?.setCursorStyle(ec.containPixel('grid', pointInPixel) ? 'copy' : 'default');
227
- }
228
- });
137
+ this.zr = null;
229
138
  }
230
- getLegendItemSelection(shape) {
231
- if (this.isLegendClicked) {
232
- return this.legendSelected[shape.name] ?? true;
233
- }
234
- else {
235
- return shape.selectedByDefault ?? true;
139
+ ngAfterViewInit() {
140
+ if (this.chart) {
141
+ this.renderChart(this.chart);
236
142
  }
237
143
  }
238
144
  ngOnChanges(changes) {
239
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
+ });
240
160
  if (chart) {
241
- this.chartOption = {
161
+ this.echartsInstance.setOption({
242
162
  title: {
243
163
  text: chart.title,
244
164
  },
@@ -266,46 +186,64 @@ class KiwiChartComponent {
266
186
  },
267
187
  emphasis: {
268
188
  iconStyle: {
269
- textPosition: 'top'
189
+ textPosition: 'top',
190
+ textPadding: 5
270
191
  }
271
- }
192
+ },
193
+ icon: {
194
+ zoom: ZOOM_IN,
195
+ back: ZOOM_OUT
196
+ },
272
197
  },
273
198
  saveAsImage: {
274
199
  emphasis: {
275
200
  iconStyle: {
276
- textPosition: 'top'
201
+ textPosition: 'top',
202
+ textPadding: 5
277
203
  }
278
- }
204
+ },
205
+ icon: SAVE_AS_SVG,
279
206
  },
280
207
  restore: {
281
208
  emphasis: {
282
209
  iconStyle: {
283
- textPosition: 'top'
210
+ textPosition: 'top',
211
+ textPadding: 5
284
212
  }
285
- }
213
+ },
214
+ icon: RESTORE,
286
215
  },
287
216
  myAddPoint: {
288
217
  show: chart.clickToAddPoint ?? false,
289
218
  title: chart.addPointCustomName ?? 'Add Point',
290
- icon: this.darkTheme ? ADD_POINT_IMG_OFF_DARK : ADD_POINT_IMG_OFF_LIGHT,
291
- iconStatus: false,
219
+ icon: ADD_POINT,
292
220
  onclick: () => {
293
- let option = this.echartsInstance?.getOption();
294
- let status = option.toolbox[0].feature.myAddPoint.iconStatus;
295
- this.echartsInstance?.setOption({
296
- toolbox: {
297
- feature: {
298
- myAddPoint: {
299
- iconStatus: !status,
300
- 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
+ }
301
238
  }
302
- }
239
+ });
303
240
  }
304
- });
241
+ }
305
242
  },
306
243
  emphasis: {
307
244
  iconStyle: {
308
- textPosition: 'top'
245
+ textPosition: 'top',
246
+ textPadding: 5
309
247
  }
310
248
  }
311
249
  }
@@ -317,14 +255,14 @@ class KiwiChartComponent {
317
255
  xAxisIndex: [0],
318
256
  throttle: 0,
319
257
  filterMode: 'none',
320
- disabled: !chart.scrollToZoom ?? true
258
+ disabled: !chart.scrollToZoom
321
259
  },
322
260
  {
323
261
  type: 'inside',
324
262
  yAxisIndex: [0],
325
263
  throttle: 0,
326
264
  filterMode: 'none',
327
- disabled: !chart.scrollToZoom ?? true
265
+ disabled: !chart.scrollToZoom
328
266
  },
329
267
  ],
330
268
  legend: {
@@ -378,10 +316,12 @@ class KiwiChartComponent {
378
316
  },
379
317
  series: this.createSeries(chart.shapes),
380
318
  animation: chart.hasAnimations,
381
- animationDuration: chart.animationDuration ?? 500,
319
+ animationDuration: chart.animationDuration ?? 250,
382
320
  animationEasing: 'cubicOut'
383
- };
321
+ }, true, true);
384
322
  }
323
+ this.setupZrEventHandler(this.echartsInstance);
324
+ this.setupLegendEventHandler(this.echartsInstance);
385
325
  }
386
326
  createSeries(shapes) {
387
327
  let series = [];
@@ -442,40 +382,185 @@ class KiwiChartComponent {
442
382
  smooth: trace.smooth ?? false
443
383
  };
444
384
  }
445
- ngOnDestroy() {
446
- this.destroyed$.next();
447
- 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();
448
532
  }
449
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: KiwiChartComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component }); }
450
- static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: KiwiChartComponent, 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: `
451
535
  <div
452
- echarts
453
- [options]="chartOption"
454
- [ngStyle]="{
455
- 'width': width,
456
- 'height': height
457
- }"
458
- (chartInit)="onChartInit($event)"
459
- [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)"
460
544
  ></div>
461
- `, isInline: true, styles: [""], dependencies: [{ kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i2.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"] }] }); }
545
+ `, isInline: true, styles: [""], dependencies: [{ kind: "directive", type: KiwiChartDirective, selector: "div[kiwi-chart]", inputs: ["chart", "width", "height", "darkTheme", "darkThemeBackground"], outputs: ["chartInit", "addPoint", "chartHover"] }] }); }
462
546
  }
463
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: KiwiChartComponent, decorators: [{
547
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.1", ngImport: i0, type: KiwiChartComponent, decorators: [{
464
548
  type: Component,
465
549
  args: [{ selector: 'kiwi-chart', template: `
466
550
  <div
467
- echarts
468
- [options]="chartOption"
469
- [ngStyle]="{
470
- 'width': width,
471
- 'height': height
472
- }"
473
- (chartInit)="onChartInit($event)"
474
- [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)"
475
559
  ></div>
476
- ` }]
477
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { chart: [{
478
- type: Input
560
+ `, standalone: true, imports: [KiwiChartDirective] }]
561
+ }], propDecorators: { chart: [{
562
+ type: Input,
563
+ args: [{ required: true }]
479
564
  }], width: [{
480
565
  type: Input
481
566
  }], height: [{
@@ -490,39 +575,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
490
575
  type: Output
491
576
  }] } });
492
577
 
493
- echarts.use([
494
- TitleComponent,
495
- TooltipComponent,
496
- GridComponent,
497
- LineChart,
498
- CanvasRenderer,
499
- LegendComponent,
500
- DataZoomComponent,
501
- ToolboxComponent,
502
- ScatterChart
503
- ]);
504
- class KiwiChartModule {
505
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: KiwiChartModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
506
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "16.2.12", ngImport: i0, type: KiwiChartModule, declarations: [KiwiChartComponent], imports: [CommonModule, i2.NgxEchartsModule], exports: [KiwiChartComponent] }); }
507
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: KiwiChartModule, imports: [CommonModule,
508
- NgxEchartsModule.forRoot({ echarts })] }); }
509
- }
510
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: KiwiChartModule, decorators: [{
511
- type: NgModule,
512
- args: [{
513
- declarations: [
514
- KiwiChartComponent
515
- ],
516
- imports: [
517
- CommonModule,
518
- NgxEchartsModule.forRoot({ echarts })
519
- ],
520
- exports: [
521
- KiwiChartComponent
522
- ]
523
- }]
524
- }] });
525
-
526
578
  /*
527
579
  * Public API Surface of chart
528
580
  */
@@ -531,5 +583,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
531
583
  * Generated bundle index. Do not edit.
532
584
  */
533
585
 
534
- 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 };
535
587
  //# sourceMappingURL=kiwibit-chart.mjs.map