@record-evolution/widget-linechart 1.6.3 → 1.6.5
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/dist/src/widget-linechart.d.ts +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-linechart.js +45 -27
- package/dist/widget-linechart.js.map +1 -1
- package/package.json +2 -2
- package/src/default-data.json +1 -1
- package/src/definition-schema.d.ts +6 -6
- package/src/definition-schema.json +15 -15
- package/src/widget-linechart.ts +40 -28
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Webcomponent widget-linechart following open-wc recommendations",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "widget-linechart",
|
|
6
|
-
"version": "1.6.
|
|
6
|
+
"version": "1.6.5",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/widget-linechart.js",
|
|
9
9
|
"types": "dist/src/widget-linechart.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"analyze": "cem analyze --litelement",
|
|
16
16
|
"start": "concurrently -k -r \"npm run watch\" \"wds\"",
|
|
17
|
-
"link": "
|
|
17
|
+
"link": "npm run build && npm link && cd ../RESWARM/frontend && npm link @record-evolution/widget-linechart",
|
|
18
18
|
"unlink": "npm unlink --global && cd ../RESWARM/frontend && npm unlink @record-evolution/widget-linechart && npm i @record-evolution/widget-linechart",
|
|
19
19
|
"build": "rollup -c rollup.config.js",
|
|
20
20
|
"watch": "rollup -w -c rollup.config.js",
|
package/src/default-data.json
CHANGED
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
export type Title = string;
|
|
9
9
|
export type Subtitle = string;
|
|
10
|
+
export type XAxisLabel = string;
|
|
11
|
+
export type YAxisLabel = string;
|
|
10
12
|
/**
|
|
11
13
|
* This will apply a proper time series x-Axis. Check if your x-values are timestamps.
|
|
12
14
|
*/
|
|
13
15
|
export type TimeseriesChart = boolean;
|
|
14
|
-
export type XAxisLabel = string;
|
|
15
16
|
/**
|
|
16
17
|
* If checked, a zoom tool will be shown on the x-axis to zoom into the chart.
|
|
17
18
|
*/
|
|
18
19
|
export type XAxisZoomTool = boolean;
|
|
19
|
-
export type YAxisLabel = string;
|
|
20
20
|
/**
|
|
21
21
|
* If checked, the Y-Axis will be scaled to the data range. If not checked, the Y-Axis will always start at 0.
|
|
22
22
|
*/
|
|
@@ -52,9 +52,9 @@ export type ChartName = string;
|
|
|
52
52
|
* If timeseries is checked in the settings, then this should be an ISO String date like 2023-11-04T22:47:52.351152+00:00. But this works with many other formats as well.
|
|
53
53
|
*/
|
|
54
54
|
export type XValue = string;
|
|
55
|
-
export type YValue =
|
|
55
|
+
export type YValue = string;
|
|
56
56
|
/**
|
|
57
|
-
*
|
|
57
|
+
* Controls the symbol size for line and scatter charts.
|
|
58
58
|
*/
|
|
59
59
|
export type BubbleSize = number;
|
|
60
60
|
/**
|
|
@@ -90,10 +90,10 @@ export interface InputData {
|
|
|
90
90
|
[k: string]: unknown;
|
|
91
91
|
}
|
|
92
92
|
export interface AxisSettings {
|
|
93
|
-
timeseries?: TimeseriesChart;
|
|
94
93
|
xAxisLabel?: XAxisLabel;
|
|
95
|
-
xAxisZoom?: XAxisZoomTool;
|
|
96
94
|
yAxisLabel?: YAxisLabel;
|
|
95
|
+
timeseries?: TimeseriesChart;
|
|
96
|
+
xAxisZoom?: XAxisZoomTool;
|
|
97
97
|
yAxisScaling?: YAxisScaling;
|
|
98
98
|
columnLayout?: VerticalLayout;
|
|
99
99
|
[k: string]: unknown;
|
|
@@ -17,30 +17,30 @@
|
|
|
17
17
|
"type": "object",
|
|
18
18
|
"order": 3,
|
|
19
19
|
"properties": {
|
|
20
|
-
"timeseries": {
|
|
21
|
-
"title": "Timeseries Chart",
|
|
22
|
-
"description": "This will apply a proper time series x-Axis. Check if your x-values are timestamps.",
|
|
23
|
-
"type": "boolean",
|
|
24
|
-
"dataDrivenDisabled": true,
|
|
25
|
-
"order": 3
|
|
26
|
-
},
|
|
27
20
|
"xAxisLabel": {
|
|
28
21
|
"title": "X-Axis Label",
|
|
29
22
|
"type": "string",
|
|
30
23
|
"dataDrivenDisabled": false,
|
|
24
|
+
"order": 3
|
|
25
|
+
},
|
|
26
|
+
"yAxisLabel": {
|
|
27
|
+
"title": "Y-Axis Label",
|
|
28
|
+
"type": "string",
|
|
29
|
+
"dataDrivenDisabled": false,
|
|
31
30
|
"order": 4
|
|
32
31
|
},
|
|
32
|
+
"timeseries": {
|
|
33
|
+
"title": "Timeseries Chart",
|
|
34
|
+
"description": "This will apply a proper time series x-Axis. Check if your x-values are timestamps.",
|
|
35
|
+
"type": "boolean",
|
|
36
|
+
"dataDrivenDisabled": true,
|
|
37
|
+
"order": 5
|
|
38
|
+
},
|
|
33
39
|
"xAxisZoom": {
|
|
34
40
|
"title": "X-Axis Zoom Tool",
|
|
35
41
|
"type": "boolean",
|
|
36
42
|
"description": "If checked, a zoom tool will be shown on the x-axis to zoom into the chart.",
|
|
37
43
|
"dataDrivenDisabled": true,
|
|
38
|
-
"order": 5
|
|
39
|
-
},
|
|
40
|
-
"yAxisLabel": {
|
|
41
|
-
"title": "Y-Axis Label",
|
|
42
|
-
"type": "string",
|
|
43
|
-
"dataDrivenDisabled": false,
|
|
44
44
|
"order": 6
|
|
45
45
|
},
|
|
46
46
|
"yAxisScaling": {
|
|
@@ -179,13 +179,13 @@
|
|
|
179
179
|
},
|
|
180
180
|
"y": {
|
|
181
181
|
"title": "Y-Value",
|
|
182
|
-
"type": "
|
|
182
|
+
"type": "string",
|
|
183
183
|
"order": 2,
|
|
184
184
|
"required": true
|
|
185
185
|
},
|
|
186
186
|
"r": {
|
|
187
187
|
"title": "Bubble Size",
|
|
188
|
-
"description": "
|
|
188
|
+
"description": "Controls the symbol size for line and scatter charts.",
|
|
189
189
|
"order": 3,
|
|
190
190
|
"type": "number"
|
|
191
191
|
},
|
package/src/widget-linechart.ts
CHANGED
|
@@ -71,7 +71,7 @@ export class WidgetLinechart extends LitElement {
|
|
|
71
71
|
this.template = {
|
|
72
72
|
title: {
|
|
73
73
|
text: 'Temperature Change in the Coming Week',
|
|
74
|
-
left:
|
|
74
|
+
left: 20,
|
|
75
75
|
textStyle: {
|
|
76
76
|
fontSize: 14
|
|
77
77
|
}
|
|
@@ -81,7 +81,15 @@ export class WidgetLinechart extends LitElement {
|
|
|
81
81
|
},
|
|
82
82
|
legend: {
|
|
83
83
|
right: '10%',
|
|
84
|
-
top:
|
|
84
|
+
top: 0
|
|
85
|
+
},
|
|
86
|
+
grid: {
|
|
87
|
+
backgroundColor: 'rgba(0, 255, 0, 0.1)',
|
|
88
|
+
top: 30,
|
|
89
|
+
bottom: 20,
|
|
90
|
+
left: 20,
|
|
91
|
+
right: 10,
|
|
92
|
+
containLabel: true // ensures labels are not cut off
|
|
85
93
|
},
|
|
86
94
|
toolbox: {
|
|
87
95
|
show: true,
|
|
@@ -106,7 +114,7 @@ export class WidgetLinechart extends LitElement {
|
|
|
106
114
|
xAxis: {
|
|
107
115
|
type: 'value', // value, time, log, category
|
|
108
116
|
name: 'Time',
|
|
109
|
-
nameGap:
|
|
117
|
+
nameGap: 27,
|
|
110
118
|
nameLocation: 'middle',
|
|
111
119
|
axisLine: {
|
|
112
120
|
lineStyle: {
|
|
@@ -121,7 +129,7 @@ export class WidgetLinechart extends LitElement {
|
|
|
121
129
|
type: 'value',
|
|
122
130
|
nameLocation: 'middle',
|
|
123
131
|
name: 'Temperature (°C)',
|
|
124
|
-
nameGap:
|
|
132
|
+
nameGap: 30,
|
|
125
133
|
axisLabel: {
|
|
126
134
|
fontSize: 14
|
|
127
135
|
},
|
|
@@ -238,52 +246,47 @@ export class WidgetLinechart extends LitElement {
|
|
|
238
246
|
: undefined
|
|
239
247
|
const data = distincts.length === 1 ? ds.data : ds.data?.filter((d) => d.pivot === piv)
|
|
240
248
|
const data2 = this.inputData?.axis?.timeseries
|
|
241
|
-
? data?.map((d) =>
|
|
242
|
-
|
|
243
|
-
)
|
|
244
|
-
: data?.map((d) => (d?.r !== undefined ? [d.x, d.y, d.r] : [d.x, d.y]))
|
|
249
|
+
? data?.map((d) => [new Date(d.x ?? ''), d.y, d.r])
|
|
250
|
+
: data?.map((d) => [d.x, d.y, d.r])
|
|
245
251
|
|
|
252
|
+
// preparing the echarts series option for later application
|
|
246
253
|
const pds: SeriesOption = {
|
|
247
254
|
name: name,
|
|
248
255
|
type: ds.type ?? 'line',
|
|
249
256
|
lineStyle: {
|
|
250
257
|
color: lineColor,
|
|
251
258
|
width: ds.styling?.borderWidth ?? 2,
|
|
252
|
-
// @ts-ignore
|
|
253
259
|
type: ds.styling?.borderDash ?? 'solid'
|
|
254
260
|
},
|
|
255
261
|
itemStyle: {
|
|
256
262
|
color: fillColor,
|
|
257
263
|
borderColor: lineColor,
|
|
258
|
-
borderWidth: ds.styling?.borderWidth ?? 2
|
|
259
|
-
// @ts-ignore
|
|
260
|
-
type: ds.styling?.borderDash ?? 'solid'
|
|
264
|
+
borderWidth: ds.styling?.borderWidth ?? 2
|
|
261
265
|
},
|
|
262
|
-
areaStyle:
|
|
266
|
+
areaStyle: ds.styling?.fill ? { color: fillColor } : undefined,
|
|
263
267
|
symbol: ds.styling?.pointStyle ?? 'circle',
|
|
264
268
|
symbolSize: (data) => data[2] ?? 4,
|
|
265
269
|
showSymbol: ds.styling?.pointStyle === 'none' ? false : true,
|
|
266
270
|
data: data2 ?? []
|
|
267
271
|
}
|
|
268
|
-
// if (ds.type === 'scatter') (pds as ScatterSeriesOption).symbolSize = (data) => data[2]
|
|
269
|
-
|
|
270
272
|
let chartName = ds.advanced?.chartName ?? ''
|
|
271
|
-
|
|
272
|
-
chartName = prefix + '-' + chartName
|
|
273
|
-
}
|
|
273
|
+
chartName = chartName.replace('#split#', prefix)
|
|
274
274
|
|
|
275
275
|
const chart = this.setupChart(chartName)
|
|
276
276
|
chart?.series.push(pds)
|
|
277
277
|
})
|
|
278
278
|
})
|
|
279
279
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
280
|
+
const doomedCharts: string[] = []
|
|
281
|
+
// remove all doomed charts
|
|
282
|
+
this.canvasList.forEach((chart, label) => {
|
|
283
|
+
if (!chart.doomed) return
|
|
284
|
+
chart.echart?.dispose()
|
|
285
|
+
chart.element?.remove()
|
|
286
|
+
doomedCharts.push(label)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
doomedCharts.forEach((label) => this.canvasList.delete(label))
|
|
287
290
|
}
|
|
288
291
|
|
|
289
292
|
xAxisType(): 'value' | 'log' | 'category' | 'time' | undefined {
|
|
@@ -293,6 +296,12 @@ export class WidgetLinechart extends LitElement {
|
|
|
293
296
|
return 'category'
|
|
294
297
|
}
|
|
295
298
|
|
|
299
|
+
yAxisType(): 'value' | 'log' | 'category' | undefined {
|
|
300
|
+
const onePoint = this.inputData?.dataseries?.[0]?.data?.[0]
|
|
301
|
+
if (!isNaN(Number(onePoint?.y))) return 'value'
|
|
302
|
+
return 'category'
|
|
303
|
+
}
|
|
304
|
+
|
|
296
305
|
applyData() {
|
|
297
306
|
const modifier = 1
|
|
298
307
|
|
|
@@ -312,6 +321,7 @@ export class WidgetLinechart extends LitElement {
|
|
|
312
321
|
// option.xAxis.axisLine.lineStyle.width = 2 * modifier
|
|
313
322
|
// option.xAxis.axisLabel.fontSize = 20 * modifier
|
|
314
323
|
option.xAxis.type = this.xAxisType()
|
|
324
|
+
option.yAxis.type = this.yAxisType()
|
|
315
325
|
|
|
316
326
|
option.yAxis.name = this.inputData?.axis?.yAxisLabel ?? ''
|
|
317
327
|
// option.yAxis.axisLine.lineStyle.width = 2 * modifier
|
|
@@ -319,10 +329,12 @@ export class WidgetLinechart extends LitElement {
|
|
|
319
329
|
option.yAxis.scale = this.inputData?.axis?.yAxisScaling ?? false
|
|
320
330
|
|
|
321
331
|
option.series = chart.series
|
|
322
|
-
|
|
332
|
+
// console.log('Applying data to chart', label, option)
|
|
323
333
|
if (chart.series.length <= 1) option.legend.show = false
|
|
324
|
-
|
|
325
|
-
chart.
|
|
334
|
+
const oldOption: any = chart.echart?.getOption() ?? {}
|
|
335
|
+
const notMerge = oldOption.series?.length !== chart.series.length
|
|
336
|
+
chart.echart?.setOption(option, { notMerge })
|
|
337
|
+
chart.echart?.resize()
|
|
326
338
|
})
|
|
327
339
|
}
|
|
328
340
|
|