@record-evolution/widget-linechart 1.6.19 → 1.6.21

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.19",
6
+ "version": "1.6.21",
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": "5.6.0",
27
- "lit": "^3.3.0",
26
+ "echarts": "6.0.0",
27
+ "lit": "^3.3.1",
28
28
  "tinycolor2": "^1.6.0"
29
29
  },
30
30
  "devDependencies": {
@@ -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
- this.transformData()
183
- this.applyData()
184
- } else {
185
- console.log('skipping linechart draw')
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
@@ -386,21 +439,22 @@ export class WidgetLinechart extends LitElement {
386
439
  // option.yAxis.axisLine.lineStyle.width = 2 * modifier
387
440
  // option.yAxis.axisLabel.fontSize = 20 * modifier
388
441
  option.yAxis.scale = this.inputData?.axis?.yAxisScaling ?? false
442
+ option.yAxis.axisLabel.formatter = (value: number) => Math.round(value * 100) / 100
389
443
 
390
444
  const notMerge = option.series.length !== chart.series.length
391
445
  option.series = chart.series
392
446
  // console.log('Applying data to chart', label, option)
393
447
  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
448
 
398
- const tooFast = timeSinceLastUpdate < this.updateThresholdMs
399
- option.animation = !tooFast
400
- option.animationDuration = tooFast ? 0 : this.updateThresholdMs
449
+ // Calculate animation duration based on update frequency
450
+ const animationDuration = this.calculateAnimationDuration(chart, label)
451
+ option.animation = true
452
+ option.animationEasing = 'linear' // Use linear easing for predictable timing
453
+ option.animationDuration = animationDuration
454
+ option.animationDurationUpdate = animationDuration // Explicitly set update animation
401
455
  chart.echart?.on('finished', () => (chart.drawing = false))
402
456
  chart.drawing = true
403
- chart.echart?.setOption(option, { notMerge })
457
+ chart.echart?.setOption(option, { notMerge, lazyUpdate: true })
404
458
  // chart.echart?.resize()
405
459
  })
406
460
  }
@@ -422,7 +476,7 @@ export class WidgetLinechart extends LitElement {
422
476
  }
423
477
 
424
478
  if (!this.chartContainer) {
425
- console.warn('Chart container not found')
479
+ // console.warn('Chart container not found')
426
480
  return
427
481
  }
428
482
  const newContainer = document.createElement('div')
@@ -435,7 +489,10 @@ export class WidgetLinechart extends LitElement {
435
489
  echart: newChart,
436
490
  series: [] as SeriesOptionX[],
437
491
  element: newContainer,
438
- drawing: false
492
+ drawing: false,
493
+ lastUpdateTime: 0,
494
+ updateIntervals: [],
495
+ lastMaxTimestamp: 0
439
496
  }
440
497
  this.canvasList.set(label, chart)
441
498