@kiwibit/chart 20.0.0 → 21.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/kiwibit-chart.mjs +591 -0
- package/fesm2022/kiwibit-chart.mjs.map +1 -0
- package/package.json +27 -15
- package/{src/lib/models/chart.models.ts → types/kiwibit-chart.d.ts} +229 -183
- package/CHANGELOG.md +0 -164
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -10
- package/src/lib/components/chart.component.ts +0 -76
- package/src/lib/constants/chart.constants.ts +0 -5
- package/src/lib/directives/kiwi-chart.directive.ts +0 -488
- package/src/public-api.ts +0 -6
- package/src/test.ts +0 -15
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { EventEmitter, HostListener, Input, Output, Directive, Component } from '@angular/core';
|
|
3
|
+
import * as echarts from 'echarts/core';
|
|
4
|
+
import { TitleComponent, TooltipComponent, GridComponent, LegendComponent, DataZoomComponent, ToolboxComponent } from 'echarts/components';
|
|
5
|
+
import { LineChart, ScatterChart } from 'echarts/charts';
|
|
6
|
+
import { CanvasRenderer } from 'echarts/renderers';
|
|
7
|
+
|
|
8
|
+
var TraceType;
|
|
9
|
+
(function (TraceType) {
|
|
10
|
+
TraceType["LINE"] = "line";
|
|
11
|
+
TraceType["SCATTER"] = "scatter";
|
|
12
|
+
})(TraceType || (TraceType = {}));
|
|
13
|
+
var PointSymbol;
|
|
14
|
+
(function (PointSymbol) {
|
|
15
|
+
PointSymbol["NONE"] = "none";
|
|
16
|
+
PointSymbol["CIRCLE"] = "circle";
|
|
17
|
+
PointSymbol["TRIANGLE"] = "triangle";
|
|
18
|
+
PointSymbol["PIN"] = "pin";
|
|
19
|
+
PointSymbol["DIAMOND"] = "diamond";
|
|
20
|
+
})(PointSymbol || (PointSymbol = {}));
|
|
21
|
+
var TraceStyle;
|
|
22
|
+
(function (TraceStyle) {
|
|
23
|
+
TraceStyle["SOLID"] = "solid";
|
|
24
|
+
TraceStyle["DASHED"] = "dashed";
|
|
25
|
+
TraceStyle["DOTTED"] = "dotted";
|
|
26
|
+
})(TraceStyle || (TraceStyle = {}));
|
|
27
|
+
var AxisType;
|
|
28
|
+
(function (AxisType) {
|
|
29
|
+
AxisType["VALUE"] = "value";
|
|
30
|
+
})(AxisType || (AxisType = {}));
|
|
31
|
+
var ShapeVariant;
|
|
32
|
+
(function (ShapeVariant) {
|
|
33
|
+
ShapeVariant[ShapeVariant["TRACE"] = 0] = "TRACE";
|
|
34
|
+
})(ShapeVariant || (ShapeVariant = {}));
|
|
35
|
+
|
|
36
|
+
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";
|
|
37
|
+
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";
|
|
38
|
+
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";
|
|
39
|
+
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";
|
|
40
|
+
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";
|
|
41
|
+
const highlightColor = '#98BD13';
|
|
42
|
+
|
|
43
|
+
// Angular Imports
|
|
44
|
+
echarts.use([
|
|
45
|
+
TitleComponent,
|
|
46
|
+
TooltipComponent,
|
|
47
|
+
GridComponent,
|
|
48
|
+
LineChart,
|
|
49
|
+
ScatterChart,
|
|
50
|
+
CanvasRenderer,
|
|
51
|
+
LegendComponent,
|
|
52
|
+
DataZoomComponent,
|
|
53
|
+
ToolboxComponent,
|
|
54
|
+
]);
|
|
55
|
+
class KiwiChartDirective {
|
|
56
|
+
el;
|
|
57
|
+
/**
|
|
58
|
+
* The Chart Object rendered by the canvas. For all the available options refer
|
|
59
|
+
* to Chart interface in the models folder.
|
|
60
|
+
*
|
|
61
|
+
* @type {(Chart | null)}
|
|
62
|
+
* @memberof KiwiChartDirective
|
|
63
|
+
*/
|
|
64
|
+
chart = null;
|
|
65
|
+
/**
|
|
66
|
+
* Width and Height of the chart area. The dimensions refer to the father component
|
|
67
|
+
* into which the kiwi-chart is inserted. For example in an empty page the width/height
|
|
68
|
+
* of the chart can take the whole available space in the page.
|
|
69
|
+
*
|
|
70
|
+
* @type {string}
|
|
71
|
+
* @memberof KiwiChartDirective
|
|
72
|
+
*/
|
|
73
|
+
width = '100%';
|
|
74
|
+
height = '480px';
|
|
75
|
+
chartInit = new EventEmitter();
|
|
76
|
+
/**
|
|
77
|
+
* Output event used to emit to the father component the coordinates
|
|
78
|
+
* of the point clicked in the chart area. This functionality to be used must
|
|
79
|
+
* have the property "clickToAddPoint" in the Chart object set to true.
|
|
80
|
+
*
|
|
81
|
+
* @type {EventEmitter<BasePoint>}
|
|
82
|
+
* @memberof KiwiChartDirective
|
|
83
|
+
*/
|
|
84
|
+
addPoint = new EventEmitter();
|
|
85
|
+
/**
|
|
86
|
+
* When the cursor hovers the chart area it emits to the father component the
|
|
87
|
+
* x and y coordinates relative to the chart reference system.
|
|
88
|
+
*
|
|
89
|
+
* @type {EventEmitter<BasePoint>}
|
|
90
|
+
* @memberof KiwiChartDirective
|
|
91
|
+
*/
|
|
92
|
+
chartHover = new EventEmitter();
|
|
93
|
+
/**
|
|
94
|
+
* This property simply activates or not the dark theme of the chart
|
|
95
|
+
* defined by the Echarts library. In addition the background color can be custom
|
|
96
|
+
* so that the chart can match the background of the application in which it's used.
|
|
97
|
+
*
|
|
98
|
+
* @type {boolean}
|
|
99
|
+
* @memberof KiwiChartDirective
|
|
100
|
+
*/
|
|
101
|
+
darkTheme = false;
|
|
102
|
+
darkThemeBackground = null;
|
|
103
|
+
/**
|
|
104
|
+
* The instance of the Chart.
|
|
105
|
+
*
|
|
106
|
+
* @type {ECharts}
|
|
107
|
+
* @memberof KiwiChartDirective
|
|
108
|
+
*/
|
|
109
|
+
echartsInstance = null;
|
|
110
|
+
/**
|
|
111
|
+
* Default number of decimals that can have
|
|
112
|
+
* the values on the x and y axes.
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
* @type {number}
|
|
116
|
+
* @memberof KiwiChartDirective
|
|
117
|
+
*/
|
|
118
|
+
MAX_DECIMALS = 3;
|
|
119
|
+
legendSelected = {};
|
|
120
|
+
isLegendClicked = false;
|
|
121
|
+
/**
|
|
122
|
+
* Used to perform actions (as point addition based on the cursor position) on the chart.
|
|
123
|
+
*
|
|
124
|
+
* @type {(zrender.ZRenderType | null)}
|
|
125
|
+
* @memberof KiwiChartComponent
|
|
126
|
+
*/
|
|
127
|
+
zr = null;
|
|
128
|
+
/**
|
|
129
|
+
* If you resize the page, the chart is automatically re-rendered wiht the right proportions.
|
|
130
|
+
*
|
|
131
|
+
* @memberof EnchartingDirective
|
|
132
|
+
*/
|
|
133
|
+
onResize() {
|
|
134
|
+
if (this.echartsInstance) {
|
|
135
|
+
this.echartsInstance.resize();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
constructor(el) {
|
|
139
|
+
this.el = el;
|
|
140
|
+
}
|
|
141
|
+
ngAfterViewInit() {
|
|
142
|
+
if (this.chart) {
|
|
143
|
+
this.renderChart(this.chart);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
ngOnChanges(changes) {
|
|
147
|
+
let chart = changes['chart']?.currentValue;
|
|
148
|
+
if (this.echartsInstance) {
|
|
149
|
+
// Every time we have an external change we
|
|
150
|
+
// destroy the chart and re-initialize it
|
|
151
|
+
this.echartsInstance.dispose();
|
|
152
|
+
this.renderChart(chart);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
renderChart(chart) {
|
|
156
|
+
// Update ElementRef styles
|
|
157
|
+
this.el.nativeElement.style.width = this.width;
|
|
158
|
+
this.el.nativeElement.style.height = this.height;
|
|
159
|
+
this.echartsInstance = echarts.init(this.el.nativeElement, this.darkTheme ? 'dark' : 'default', {
|
|
160
|
+
renderer: 'svg'
|
|
161
|
+
});
|
|
162
|
+
if (chart) {
|
|
163
|
+
this.echartsInstance.setOption({
|
|
164
|
+
title: {
|
|
165
|
+
text: chart.title,
|
|
166
|
+
left: 0
|
|
167
|
+
},
|
|
168
|
+
grid: {
|
|
169
|
+
id: 0,
|
|
170
|
+
width: '70%'
|
|
171
|
+
},
|
|
172
|
+
backgroundColor: this.darkTheme ? this.darkThemeBackground ?? '#303030' : 'transparent', tooltip: {
|
|
173
|
+
axisPointer: {
|
|
174
|
+
type: 'cross',
|
|
175
|
+
crossStyle: {
|
|
176
|
+
color: '#bebebe'
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
toolbox: {
|
|
181
|
+
orient: 'horizontal',
|
|
182
|
+
left: 'center',
|
|
183
|
+
top: '25px',
|
|
184
|
+
feature: {
|
|
185
|
+
dataZoom: {
|
|
186
|
+
brushStyle: {
|
|
187
|
+
borderColor: '#000',
|
|
188
|
+
borderWidth: 1,
|
|
189
|
+
borderType: 'dashed'
|
|
190
|
+
},
|
|
191
|
+
emphasis: {
|
|
192
|
+
iconStyle: {
|
|
193
|
+
textPosition: 'top',
|
|
194
|
+
textPadding: 5,
|
|
195
|
+
borderColor: highlightColor
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
icon: {
|
|
199
|
+
zoom: ZOOM_IN,
|
|
200
|
+
back: ZOOM_OUT
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
saveAsImage: {
|
|
204
|
+
emphasis: {
|
|
205
|
+
iconStyle: {
|
|
206
|
+
textPosition: 'top',
|
|
207
|
+
textPadding: 5
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
icon: SAVE_AS_SVG,
|
|
211
|
+
},
|
|
212
|
+
restore: {
|
|
213
|
+
emphasis: {
|
|
214
|
+
iconStyle: {
|
|
215
|
+
textPosition: 'top',
|
|
216
|
+
textPadding: 5
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
icon: RESTORE,
|
|
220
|
+
},
|
|
221
|
+
myAddPoint: {
|
|
222
|
+
show: chart.clickToAddPoint ?? false,
|
|
223
|
+
title: chart.addPointCustomName ?? 'Add Point',
|
|
224
|
+
icon: ADD_POINT,
|
|
225
|
+
onclick: () => {
|
|
226
|
+
if (this.echartsInstance) {
|
|
227
|
+
const option = this.echartsInstance.getOption();
|
|
228
|
+
const toolbox = option.toolbox;
|
|
229
|
+
if (toolbox) {
|
|
230
|
+
const status = toolbox[0].feature?.['myAddPoint']?.iconStatus;
|
|
231
|
+
const offColor = '#6578BA';
|
|
232
|
+
this.echartsInstance.setOption({
|
|
233
|
+
toolbox: {
|
|
234
|
+
feature: {
|
|
235
|
+
myAddPoint: {
|
|
236
|
+
iconStatus: !status,
|
|
237
|
+
iconStyle: {
|
|
238
|
+
borderColor: !status ? highlightColor : offColor
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
emphasis: {
|
|
248
|
+
iconStyle: {
|
|
249
|
+
textPosition: 'top',
|
|
250
|
+
textPadding: 5,
|
|
251
|
+
borderColor: highlightColor
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
dataZoom: [
|
|
258
|
+
{
|
|
259
|
+
type: 'inside',
|
|
260
|
+
xAxisIndex: [0],
|
|
261
|
+
throttle: 0,
|
|
262
|
+
filterMode: 'none',
|
|
263
|
+
disabled: !chart.scrollToZoom
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
type: 'inside',
|
|
267
|
+
yAxisIndex: [0],
|
|
268
|
+
throttle: 0,
|
|
269
|
+
filterMode: 'none',
|
|
270
|
+
disabled: !chart.scrollToZoom
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
legend: {
|
|
274
|
+
inactiveColor: this.darkTheme ? '#8b8b8b' : '#ccc',
|
|
275
|
+
data: chart.shapes.map((shape) => ({
|
|
276
|
+
name: shape.name,
|
|
277
|
+
icon: 'circle',
|
|
278
|
+
})),
|
|
279
|
+
selected: chart.shapes.reduce((accumulator, shape) => ({
|
|
280
|
+
...accumulator,
|
|
281
|
+
[shape.name]: this.getLegendItemSelection(shape),
|
|
282
|
+
}), {}),
|
|
283
|
+
show: chart.showLegend ?? false,
|
|
284
|
+
orient: 'vertical',
|
|
285
|
+
left: 'right',
|
|
286
|
+
top: 0,
|
|
287
|
+
padding: [60, 20],
|
|
288
|
+
type: 'scroll',
|
|
289
|
+
textStyle: {
|
|
290
|
+
width: 120,
|
|
291
|
+
fontWeight: 'bold',
|
|
292
|
+
overflow: 'break'
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
xAxis: {
|
|
296
|
+
type: chart.xAxisType,
|
|
297
|
+
name: chart.xAxisUom ? `${chart.xAxisName} [ ${chart.xAxisUom} ]` : chart.xAxisName,
|
|
298
|
+
nameLocation: 'middle',
|
|
299
|
+
nameGap: 30,
|
|
300
|
+
splitLine: {
|
|
301
|
+
show: chart.showGrid ?? true,
|
|
302
|
+
lineStyle: {
|
|
303
|
+
color: this.darkTheme ? '#595959' : '#ccc'
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
min: chart.xMin?.toFixed(chart.maxAxesDecimals ?? this.MAX_DECIMALS),
|
|
307
|
+
max: chart.xMax?.toFixed(chart.maxAxesDecimals ?? this.MAX_DECIMALS),
|
|
308
|
+
},
|
|
309
|
+
yAxis: {
|
|
310
|
+
type: chart.yAxisType,
|
|
311
|
+
name: chart.yAxisUom ? `${chart.yAxisName} [ ${chart.yAxisUom} ]` : chart.yAxisName,
|
|
312
|
+
nameLocation: 'middle',
|
|
313
|
+
nameGap: 50,
|
|
314
|
+
splitLine: {
|
|
315
|
+
show: chart.showGrid ?? true,
|
|
316
|
+
lineStyle: {
|
|
317
|
+
color: this.darkTheme ? '#595959' : '#ccc'
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
min: chart.yMin?.toFixed(chart.maxAxesDecimals ?? this.MAX_DECIMALS),
|
|
321
|
+
max: chart.yMax?.toFixed(chart.maxAxesDecimals ?? this.MAX_DECIMALS),
|
|
322
|
+
},
|
|
323
|
+
series: this.createSeries(chart.shapes),
|
|
324
|
+
animation: chart.hasAnimations,
|
|
325
|
+
animationDuration: chart.animationDuration ?? 250,
|
|
326
|
+
animationEasing: 'cubicOut'
|
|
327
|
+
}, true, true);
|
|
328
|
+
}
|
|
329
|
+
this.setupZrEventHandler(this.echartsInstance);
|
|
330
|
+
this.setupLegendEventHandler(this.echartsInstance);
|
|
331
|
+
}
|
|
332
|
+
createSeries(shapes) {
|
|
333
|
+
let series = [];
|
|
334
|
+
shapes.forEach((shape) => {
|
|
335
|
+
switch (shape.variant) {
|
|
336
|
+
case ShapeVariant.TRACE:
|
|
337
|
+
series.push(this.createTrace(shape));
|
|
338
|
+
break;
|
|
339
|
+
default:
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
return series;
|
|
344
|
+
}
|
|
345
|
+
createTrace(trace) {
|
|
346
|
+
return {
|
|
347
|
+
type: trace.type,
|
|
348
|
+
name: trace.name,
|
|
349
|
+
data: trace.points.map((point) => ({
|
|
350
|
+
value: [point.x, point.y],
|
|
351
|
+
symbol: point.symbol ?? 'circle',
|
|
352
|
+
name: point.name,
|
|
353
|
+
symbolSize: point.symbolSize ?? 2,
|
|
354
|
+
itemStyle: {
|
|
355
|
+
color: point.color
|
|
356
|
+
},
|
|
357
|
+
emphasis: {
|
|
358
|
+
disabled: true
|
|
359
|
+
},
|
|
360
|
+
label: {
|
|
361
|
+
show: true,
|
|
362
|
+
position: 'bottom',
|
|
363
|
+
align: 'left',
|
|
364
|
+
verticalAlign: 'bottom',
|
|
365
|
+
formatter: () => `${point.name ?? ''}`,
|
|
366
|
+
fontSize: 13,
|
|
367
|
+
padding: [0, 0, 0, 10],
|
|
368
|
+
width: 100,
|
|
369
|
+
overflow: 'truncate',
|
|
370
|
+
ellipsis: '...',
|
|
371
|
+
fontWeight: 'bold',
|
|
372
|
+
color: this.darkTheme ? '#fff' : '#000'
|
|
373
|
+
},
|
|
374
|
+
tooltip: {
|
|
375
|
+
formatter: ({ value }) => `
|
|
376
|
+
<strong>${this.chart?.xAxisName}:</strong> ${value[0].toFixed(3).replace(/[.,]000$/, "")}
|
|
377
|
+
<br>
|
|
378
|
+
<strong>${this.chart?.yAxisName}:</strong> ${value[1].toFixed(3).replace(/[.,]000$/, "")}
|
|
379
|
+
`
|
|
380
|
+
}
|
|
381
|
+
})),
|
|
382
|
+
color: trace.color,
|
|
383
|
+
lineStyle: {
|
|
384
|
+
width: trace.width,
|
|
385
|
+
type: trace.style,
|
|
386
|
+
opacity: trace.opacity ?? 1
|
|
387
|
+
},
|
|
388
|
+
smooth: trace.smooth ?? false
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
getLegendItemSelection(shape) {
|
|
392
|
+
if (this.isLegendClicked) {
|
|
393
|
+
return this.legendSelected[shape.name] ?? true;
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
return shape.selectedByDefault ?? true;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* intercept a selection change event on the legend and save the state
|
|
401
|
+
* of all selections on the supporting variable legendSelected
|
|
402
|
+
*
|
|
403
|
+
* @param ec
|
|
404
|
+
*/
|
|
405
|
+
setupLegendEventHandler(ec) {
|
|
406
|
+
if (this.echartsInstance != null) {
|
|
407
|
+
this.echartsInstance.on('legendselectchanged', (params) => {
|
|
408
|
+
this.isLegendClicked = true;
|
|
409
|
+
this.legendSelected = params.selected;
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
setupZrEventHandler(ec) {
|
|
414
|
+
this.zr = ec.getZr();
|
|
415
|
+
/**
|
|
416
|
+
* Intercepts the click event on the chart (if the clickToAddPoint property is set to true)
|
|
417
|
+
* and emits the point coordinates to the father component.
|
|
418
|
+
*/
|
|
419
|
+
this.zr.on('click', params => {
|
|
420
|
+
let option = ec.getOption();
|
|
421
|
+
let active = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
|
|
422
|
+
if (active && this.chart?.clickToAddPoint) {
|
|
423
|
+
const pointInPixel = [params.offsetX, params.offsetY];
|
|
424
|
+
const pointInGrid = ec.convertFromPixel({ gridIndex: 0 }, pointInPixel);
|
|
425
|
+
if (ec.containPixel({ gridIndex: 0 }, pointInPixel) && pointInGrid) {
|
|
426
|
+
let newPoint = {
|
|
427
|
+
x: +pointInGrid[0].toFixed(3),
|
|
428
|
+
y: +pointInGrid[1].toFixed(3)
|
|
429
|
+
};
|
|
430
|
+
this.addPoint.emit(newPoint);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
/**
|
|
435
|
+
* This is used perform custom actions when the mouse is hovering the chart area
|
|
436
|
+
*/
|
|
437
|
+
this.zr.on('mousemove', params => {
|
|
438
|
+
const pointInPixel = [params.offsetX, params.offsetY];
|
|
439
|
+
const pointInGrid = ec.convertFromPixel({ gridIndex: 0 }, pointInPixel);
|
|
440
|
+
/*
|
|
441
|
+
* Logic to emit to the father component the x and y coordinates when the
|
|
442
|
+
* cursor is hovering the chart area.
|
|
443
|
+
*/
|
|
444
|
+
if (ec.containPixel({ gridIndex: 0 }, pointInPixel) && pointInGrid) {
|
|
445
|
+
let newPoint = {
|
|
446
|
+
x: +pointInGrid[0].toFixed(3),
|
|
447
|
+
y: +pointInGrid[1].toFixed(3)
|
|
448
|
+
};
|
|
449
|
+
this.chartHover.emit(newPoint);
|
|
450
|
+
}
|
|
451
|
+
/* Logic to change the cursor icon when the "Click to Add Point" feature is active and viceversa. */
|
|
452
|
+
const option = ec.getOption();
|
|
453
|
+
const addPointIsActive = option?.toolbox?.[0]?.feature?.myAddPoint?.iconStatus;
|
|
454
|
+
if (addPointIsActive) {
|
|
455
|
+
this.zr?.setCursorStyle(ec.containPixel({ gridIndex: 0 }, pointInPixel) ? 'copy' : 'default');
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.2", ngImport: i0, type: KiwiChartDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
460
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.2", 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()" } }, usesOnChanges: true, ngImport: i0 });
|
|
461
|
+
}
|
|
462
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.2", ngImport: i0, type: KiwiChartDirective, decorators: [{
|
|
463
|
+
type: Directive,
|
|
464
|
+
args: [{
|
|
465
|
+
selector: 'div[kiwi-chart]',
|
|
466
|
+
standalone: true
|
|
467
|
+
}]
|
|
468
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { chart: [{
|
|
469
|
+
type: Input,
|
|
470
|
+
args: [{ required: true }]
|
|
471
|
+
}], width: [{
|
|
472
|
+
type: Input
|
|
473
|
+
}], height: [{
|
|
474
|
+
type: Input
|
|
475
|
+
}], chartInit: [{
|
|
476
|
+
type: Output
|
|
477
|
+
}], addPoint: [{
|
|
478
|
+
type: Output
|
|
479
|
+
}], chartHover: [{
|
|
480
|
+
type: Output
|
|
481
|
+
}], darkTheme: [{
|
|
482
|
+
type: Input
|
|
483
|
+
}], darkThemeBackground: [{
|
|
484
|
+
type: Input
|
|
485
|
+
}], onResize: [{
|
|
486
|
+
type: HostListener,
|
|
487
|
+
args: ['window:resize']
|
|
488
|
+
}] } });
|
|
489
|
+
|
|
490
|
+
// Angular General
|
|
491
|
+
class KiwiChartComponent {
|
|
492
|
+
/**
|
|
493
|
+
* The Chart Object rendered by the canvas. For all the available options refer
|
|
494
|
+
* to Chart interface in the models folder.
|
|
495
|
+
*
|
|
496
|
+
* @type {(Chart | null)}
|
|
497
|
+
* @memberof KiwiChartComponent
|
|
498
|
+
*/
|
|
499
|
+
chart = null;
|
|
500
|
+
/**
|
|
501
|
+
* Width and Height of the chart area. The dimensions refer to the father component
|
|
502
|
+
* into which the kiwi-chart is inserted. For example in an empty page the width/height
|
|
503
|
+
* of the chart can take the whole available space in the page.
|
|
504
|
+
*
|
|
505
|
+
* @type {string}
|
|
506
|
+
* @memberof KiwiChartComponent
|
|
507
|
+
*/
|
|
508
|
+
width = '100%';
|
|
509
|
+
height = '480px';
|
|
510
|
+
/**
|
|
511
|
+
* This property simply activates or not the dark theme of the chart
|
|
512
|
+
* defined by the Echarts library. In addition the background color can be custom
|
|
513
|
+
* so that the chart can match the background of the application in which it's used.
|
|
514
|
+
*
|
|
515
|
+
* @type {boolean}
|
|
516
|
+
* @memberof KiwiChartComponent
|
|
517
|
+
*/
|
|
518
|
+
darkTheme = false;
|
|
519
|
+
darkThemeBackground = null;
|
|
520
|
+
/**
|
|
521
|
+
* Output event used to emit to the father component the coordinates
|
|
522
|
+
* of the point clicked in the chart area. This functionality to be used must
|
|
523
|
+
* have the property "clickToAddPoint" in the Chart object set to true.
|
|
524
|
+
*
|
|
525
|
+
* @type {EventEmitter<BasePoint>}
|
|
526
|
+
* @memberof KiwiChartComponent
|
|
527
|
+
*/
|
|
528
|
+
addPoint = new EventEmitter();
|
|
529
|
+
/**
|
|
530
|
+
* When the cursor hovers the chart area it emits to the father component the
|
|
531
|
+
* x and y coordinates relative to the chart reference system.
|
|
532
|
+
*
|
|
533
|
+
* @type {EventEmitter<BasePoint>}
|
|
534
|
+
* @memberof KiwiChartComponent
|
|
535
|
+
*/
|
|
536
|
+
chartHover = new EventEmitter();
|
|
537
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.2", ngImport: i0, type: KiwiChartComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
538
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.2", 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: `
|
|
539
|
+
<div
|
|
540
|
+
kiwi-chart
|
|
541
|
+
[chart]="chart"
|
|
542
|
+
[width]="width"
|
|
543
|
+
[height]="height"
|
|
544
|
+
[darkTheme]="darkTheme"
|
|
545
|
+
[darkThemeBackground]="darkThemeBackground"
|
|
546
|
+
(addPoint)="addPoint.emit($event)"
|
|
547
|
+
(chartHover)="chartHover.emit($event)"
|
|
548
|
+
></div>
|
|
549
|
+
`, isInline: true, styles: [""], dependencies: [{ kind: "directive", type: KiwiChartDirective, selector: "div[kiwi-chart]", inputs: ["chart", "width", "height", "darkTheme", "darkThemeBackground"], outputs: ["chartInit", "addPoint", "chartHover"] }] });
|
|
550
|
+
}
|
|
551
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.2", ngImport: i0, type: KiwiChartComponent, decorators: [{
|
|
552
|
+
type: Component,
|
|
553
|
+
args: [{ selector: 'kiwi-chart', template: `
|
|
554
|
+
<div
|
|
555
|
+
kiwi-chart
|
|
556
|
+
[chart]="chart"
|
|
557
|
+
[width]="width"
|
|
558
|
+
[height]="height"
|
|
559
|
+
[darkTheme]="darkTheme"
|
|
560
|
+
[darkThemeBackground]="darkThemeBackground"
|
|
561
|
+
(addPoint)="addPoint.emit($event)"
|
|
562
|
+
(chartHover)="chartHover.emit($event)"
|
|
563
|
+
></div>
|
|
564
|
+
`, imports: [KiwiChartDirective] }]
|
|
565
|
+
}], propDecorators: { chart: [{
|
|
566
|
+
type: Input,
|
|
567
|
+
args: [{ required: true }]
|
|
568
|
+
}], width: [{
|
|
569
|
+
type: Input
|
|
570
|
+
}], height: [{
|
|
571
|
+
type: Input
|
|
572
|
+
}], darkTheme: [{
|
|
573
|
+
type: Input
|
|
574
|
+
}], darkThemeBackground: [{
|
|
575
|
+
type: Input
|
|
576
|
+
}], addPoint: [{
|
|
577
|
+
type: Output
|
|
578
|
+
}], chartHover: [{
|
|
579
|
+
type: Output
|
|
580
|
+
}] } });
|
|
581
|
+
|
|
582
|
+
/*
|
|
583
|
+
* Public API Surface of chart
|
|
584
|
+
*/
|
|
585
|
+
|
|
586
|
+
/**
|
|
587
|
+
* Generated bundle index. Do not edit.
|
|
588
|
+
*/
|
|
589
|
+
|
|
590
|
+
export { AxisType, KiwiChartComponent, PointSymbol, ShapeVariant, TraceStyle, TraceType };
|
|
591
|
+
//# sourceMappingURL=kiwibit-chart.mjs.map
|