@record-evolution/widget-linechart 1.6.19 → 1.6.20
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 +8 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-linechart.js +8235 -5555
- package/dist/widget-linechart.js.map +1 -1
- package/package.json +3 -3
- package/src/widget-linechart.ts +73 -17
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.20",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/widget-linechart.js",
|
|
9
9
|
"types": "dist/src/widget-linechart.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"release": "npm run build && npm run types && npm version patch --tag-version-prefix='' && git push && git push --tag && npm run build"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"echarts": "
|
|
27
|
-
"lit": "^3.3.
|
|
26
|
+
"echarts": "6.0.0",
|
|
27
|
+
"lit": "^3.3.1",
|
|
28
28
|
"tinycolor2": "^1.6.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
package/src/widget-linechart.ts
CHANGED
|
@@ -56,6 +56,9 @@ export class WidgetLinechart extends LitElement {
|
|
|
56
56
|
doomed?: boolean
|
|
57
57
|
element?: HTMLDivElement
|
|
58
58
|
drawing: boolean
|
|
59
|
+
lastUpdateTime?: number
|
|
60
|
+
updateIntervals?: number[]
|
|
61
|
+
lastMaxTimestamp?: number
|
|
59
62
|
}
|
|
60
63
|
> = new Map()
|
|
61
64
|
|
|
@@ -71,8 +74,8 @@ export class WidgetLinechart extends LitElement {
|
|
|
71
74
|
version: string = 'versionplaceholder'
|
|
72
75
|
chartContainer: HTMLDivElement | null | undefined
|
|
73
76
|
resizeObserver?: ResizeObserver
|
|
74
|
-
lastUpdateTime: number = 0
|
|
75
77
|
updateThresholdMs: number = 300
|
|
78
|
+
private maxIntervalSamples: number = 3
|
|
76
79
|
|
|
77
80
|
constructor() {
|
|
78
81
|
super()
|
|
@@ -177,13 +180,13 @@ export class WidgetLinechart extends LitElement {
|
|
|
177
180
|
|
|
178
181
|
update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
179
182
|
if (changedProperties.has('inputData') && this.chartContainer) {
|
|
180
|
-
const drawingStates = Array.from(this.canvasList).map(([key, chart]) => chart.drawing)
|
|
181
|
-
if (drawingStates.every((d) => !d)) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
} else {
|
|
185
|
-
|
|
186
|
-
}
|
|
183
|
+
// const drawingStates = Array.from(this.canvasList).map(([key, chart]) => chart.drawing)
|
|
184
|
+
// if (drawingStates.every((d) => !d)) {
|
|
185
|
+
this.transformData()
|
|
186
|
+
this.applyData()
|
|
187
|
+
// } else {
|
|
188
|
+
// console.log('skipping linechart draw')
|
|
189
|
+
// }
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
if (changedProperties.has('theme')) {
|
|
@@ -346,6 +349,56 @@ export class WidgetLinechart extends LitElement {
|
|
|
346
349
|
return 'category'
|
|
347
350
|
}
|
|
348
351
|
|
|
352
|
+
calculateAnimationDuration(chart: any, label: string): number {
|
|
353
|
+
const now = Date.now()
|
|
354
|
+
const isSingleSeries = chart.series.length === 1
|
|
355
|
+
// Only apply adaptive animation for single series charts
|
|
356
|
+
if (!isSingleSeries || !this.inputData?.axis?.timeseries) {
|
|
357
|
+
return this.updateThresholdMs
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Find the newest timestamp in the current chart data
|
|
361
|
+
let maxTimestamp = 0
|
|
362
|
+
if (this.xAxisType() === 'time') {
|
|
363
|
+
for (const series of chart.series) {
|
|
364
|
+
const seriesData = series.data as any[]
|
|
365
|
+
for (const point of seriesData || []) {
|
|
366
|
+
const timestamp = point.value?.[0] || 0
|
|
367
|
+
if (timestamp > maxTimestamp) {
|
|
368
|
+
maxTimestamp = timestamp
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
} else {
|
|
373
|
+
// For non-time series, use the current time as proxy
|
|
374
|
+
maxTimestamp = now
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Only track update if the data actually changed (new timestamp)
|
|
378
|
+
chart.lastMaxTimestamp = chart.lastMaxTimestamp ?? 0
|
|
379
|
+
const dataChanged = maxTimestamp > chart.lastMaxTimestamp
|
|
380
|
+
if (dataChanged) {
|
|
381
|
+
chart.updateIntervals ??= []
|
|
382
|
+
if (chart.lastUpdateTime > 0) {
|
|
383
|
+
const timeSinceLastUpdate = now - chart.lastUpdateTime
|
|
384
|
+
chart.updateIntervals.push(timeSinceLastUpdate)
|
|
385
|
+
if (chart.updateIntervals.length > this.maxIntervalSamples) {
|
|
386
|
+
chart.updateIntervals.shift()
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
chart.lastUpdateTime = now
|
|
390
|
+
chart.lastMaxTimestamp = maxTimestamp
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Calculate average update interval
|
|
394
|
+
const avgInterval =
|
|
395
|
+
chart.updateIntervals && chart.updateIntervals.length > 0
|
|
396
|
+
? chart.updateIntervals.reduce((a: number, b: number) => a + b, 0) /
|
|
397
|
+
chart.updateIntervals.length
|
|
398
|
+
: this.updateThresholdMs
|
|
399
|
+
return avgInterval
|
|
400
|
+
}
|
|
401
|
+
|
|
349
402
|
applyData() {
|
|
350
403
|
const modifier = 1
|
|
351
404
|
// Sort chartContainer children by drawOrder and label
|
|
@@ -391,16 +444,16 @@ export class WidgetLinechart extends LitElement {
|
|
|
391
444
|
option.series = chart.series
|
|
392
445
|
// console.log('Applying data to chart', label, option)
|
|
393
446
|
if (chart.series.length <= 1) option.legend.show = false
|
|
394
|
-
const now = Date.now()
|
|
395
|
-
const timeSinceLastUpdate = now - this.lastUpdateTime
|
|
396
|
-
this.lastUpdateTime = now
|
|
397
447
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
option.
|
|
448
|
+
// Calculate animation duration based on update frequency
|
|
449
|
+
const animationDuration = this.calculateAnimationDuration(chart, label)
|
|
450
|
+
option.animation = true
|
|
451
|
+
option.animationEasing = 'linear' // Use linear easing for predictable timing
|
|
452
|
+
option.animationDuration = animationDuration
|
|
453
|
+
option.animationDurationUpdate = animationDuration // Explicitly set update animation
|
|
401
454
|
chart.echart?.on('finished', () => (chart.drawing = false))
|
|
402
455
|
chart.drawing = true
|
|
403
|
-
chart.echart?.setOption(option, { notMerge })
|
|
456
|
+
chart.echart?.setOption(option, { notMerge, lazyUpdate: true })
|
|
404
457
|
// chart.echart?.resize()
|
|
405
458
|
})
|
|
406
459
|
}
|
|
@@ -422,7 +475,7 @@ export class WidgetLinechart extends LitElement {
|
|
|
422
475
|
}
|
|
423
476
|
|
|
424
477
|
if (!this.chartContainer) {
|
|
425
|
-
console.warn('Chart container not found')
|
|
478
|
+
// console.warn('Chart container not found')
|
|
426
479
|
return
|
|
427
480
|
}
|
|
428
481
|
const newContainer = document.createElement('div')
|
|
@@ -435,7 +488,10 @@ export class WidgetLinechart extends LitElement {
|
|
|
435
488
|
echart: newChart,
|
|
436
489
|
series: [] as SeriesOptionX[],
|
|
437
490
|
element: newContainer,
|
|
438
|
-
drawing: false
|
|
491
|
+
drawing: false,
|
|
492
|
+
lastUpdateTime: 0,
|
|
493
|
+
updateIntervals: [],
|
|
494
|
+
lastMaxTimestamp: 0
|
|
439
495
|
}
|
|
440
496
|
this.canvasList.set(label, chart)
|
|
441
497
|
|