@record-evolution/widget-linechart 1.6.12 → 1.6.14
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/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.14",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/widget-linechart.js",
|
|
9
9
|
"types": "dist/src/widget-linechart.d.ts",
|
package/src/widget-linechart.ts
CHANGED
|
@@ -37,6 +37,8 @@ type Theme = {
|
|
|
37
37
|
theme_name: string
|
|
38
38
|
theme_object: any
|
|
39
39
|
}
|
|
40
|
+
|
|
41
|
+
type SeriesOptionX = SeriesOption & { minDate?: number; maxDate?: number }
|
|
40
42
|
@customElement('widget-linechart-versionplaceholder')
|
|
41
43
|
export class WidgetLinechart extends LitElement {
|
|
42
44
|
@property({ type: Object })
|
|
@@ -48,7 +50,7 @@ export class WidgetLinechart extends LitElement {
|
|
|
48
50
|
@state()
|
|
49
51
|
private canvasList: Map<
|
|
50
52
|
string,
|
|
51
|
-
{ echart?: echarts.ECharts; series:
|
|
53
|
+
{ echart?: echarts.ECharts; series: SeriesOptionX[]; doomed?: boolean; element?: HTMLDivElement }
|
|
52
54
|
> = new Map()
|
|
53
55
|
|
|
54
56
|
@state() private themeBgColor?: string
|
|
@@ -248,19 +250,34 @@ export class WidgetLinechart extends LitElement {
|
|
|
248
250
|
: derivedBgColors[i]
|
|
249
251
|
: undefined
|
|
250
252
|
const data = distincts.length === 1 ? ds.data : ds.data?.filter((d) => d.pivot === piv)
|
|
251
|
-
|
|
252
|
-
? data?.map((d) => [new Date(d.x ?? ''), d.y, d.r])
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
253
|
+
let data2 = this.inputData?.axis?.timeseries
|
|
254
|
+
? (data?.map((d) => ({ name: d.x, value: [new Date(d.x ?? '').getTime(), d.y, d.r] })) ??
|
|
255
|
+
[])
|
|
256
|
+
: (data?.map((d) => ({ name: d.x, value: [d.x, d.y, d.r] })) ?? [])
|
|
257
|
+
|
|
258
|
+
let minDate: number = 0,
|
|
259
|
+
maxDate: number = 0,
|
|
260
|
+
extraData: (string | number | undefined)[][] = []
|
|
261
|
+
if (this.xAxisType() === 'time' && data2) {
|
|
262
|
+
const dates = data2.map((d: any) => d.value[0] as number)
|
|
263
|
+
minDate = Math.min(...dates)
|
|
264
|
+
maxDate = Math.max(...dates)
|
|
265
|
+
// extraData = (pds?.data as any[][])?.filter((d: any) => d[0] < minDate) ?? []
|
|
266
|
+
// data2.unshift(...extraData) // add old data to the beginning of the new data
|
|
267
|
+
// data2 = [...extraData, ...data2] // leave old data in for smooth shifting animation and delete after draw
|
|
268
|
+
}
|
|
269
|
+
const pds: SeriesOptionX = {
|
|
270
|
+
id: name,
|
|
257
271
|
name: name,
|
|
272
|
+
minDate,
|
|
273
|
+
maxDate,
|
|
258
274
|
type: ds.type ?? 'line',
|
|
259
275
|
lineStyle: {
|
|
260
276
|
color: lineColor,
|
|
261
277
|
width: ds.styling?.borderWidth ?? 2,
|
|
262
278
|
type: ds.styling?.borderDash ?? 'solid'
|
|
263
279
|
},
|
|
280
|
+
smooth: false,
|
|
264
281
|
itemStyle: {
|
|
265
282
|
color: fillColor,
|
|
266
283
|
borderColor: lineColor,
|
|
@@ -268,7 +285,7 @@ export class WidgetLinechart extends LitElement {
|
|
|
268
285
|
},
|
|
269
286
|
areaStyle: ds.styling?.fill ? { color: fillColor } : undefined,
|
|
270
287
|
symbol: ds.styling?.pointStyle ?? 'circle',
|
|
271
|
-
symbolSize: (
|
|
288
|
+
symbolSize: (d: any[]) => d[2] ?? 4,
|
|
272
289
|
showSymbol: ds.styling?.pointStyle === 'none' ? false : true,
|
|
273
290
|
data: data2 ?? []
|
|
274
291
|
}
|
|
@@ -318,6 +335,18 @@ export class WidgetLinechart extends LitElement {
|
|
|
318
335
|
|
|
319
336
|
// Axis
|
|
320
337
|
option.xAxis.name = this.inputData?.axis?.xAxisLabel ?? ''
|
|
338
|
+
if (this.xAxisType() === 'time') {
|
|
339
|
+
const axisMax = chart.series.map((s) => s.maxDate ?? 0).reduce((a, b) => Math.max(a, b), 0)
|
|
340
|
+
const axisMin = chart.series
|
|
341
|
+
.map((s) => s.minDate ?? Infinity)
|
|
342
|
+
.reduce((a, b) => Math.min(a, b), Infinity)
|
|
343
|
+
// console.log('Setting xAxis time range', label, new Date(axisMin), new Date(axisMax))
|
|
344
|
+
option.xAxis = {
|
|
345
|
+
...option.xAxis,
|
|
346
|
+
min: axisMin ?? new Date().getTime() - 1 * 24 * 60 * 60 * 1000, // 1 days ago,
|
|
347
|
+
max: axisMax ?? new Date().getTime() // today
|
|
348
|
+
}
|
|
349
|
+
}
|
|
321
350
|
option.dataZoom[0].show = this.inputData?.axis?.xAxisZoom ?? false
|
|
322
351
|
option.toolbox.show = this.inputData?.axis?.xAxisZoom ?? false
|
|
323
352
|
// option.xAxis.axisLine.lineStyle.width = 2 * modifier
|