@record-evolution/widget-linechart 1.6.14 → 1.6.16
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.16",
|
|
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
|
@@ -38,7 +38,7 @@ type Theme = {
|
|
|
38
38
|
theme_object: any
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
type SeriesOptionX = SeriesOption & { minDate?: number; maxDate?: number }
|
|
41
|
+
type SeriesOptionX = SeriesOption & { minDate?: number; maxDate?: number; drawOrder: number }
|
|
42
42
|
@customElement('widget-linechart-versionplaceholder')
|
|
43
43
|
export class WidgetLinechart extends LitElement {
|
|
44
44
|
@property({ type: Object })
|
|
@@ -65,6 +65,8 @@ export class WidgetLinechart extends LitElement {
|
|
|
65
65
|
version: string = 'versionplaceholder'
|
|
66
66
|
chartContainer: HTMLDivElement | null | undefined
|
|
67
67
|
resizeObserver?: ResizeObserver
|
|
68
|
+
lastUpdateTime: number = 0
|
|
69
|
+
updateThresholdMs: number = 300
|
|
68
70
|
|
|
69
71
|
constructor() {
|
|
70
72
|
super()
|
|
@@ -184,9 +186,9 @@ export class WidgetLinechart extends LitElement {
|
|
|
184
186
|
|
|
185
187
|
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
186
188
|
this.chartContainer = this.shadowRoot?.querySelector('.chart-container')
|
|
189
|
+
this.registerTheme(this.theme)
|
|
187
190
|
this.transformData()
|
|
188
191
|
this.applyData()
|
|
189
|
-
this.registerTheme(this.theme)
|
|
190
192
|
// Add ResizeObserver for chart container
|
|
191
193
|
if (this.chartContainer) {
|
|
192
194
|
this.resizeObserver = new ResizeObserver(() => {
|
|
@@ -287,7 +289,8 @@ export class WidgetLinechart extends LitElement {
|
|
|
287
289
|
symbol: ds.styling?.pointStyle ?? 'circle',
|
|
288
290
|
symbolSize: (d: any[]) => d[2] ?? 4,
|
|
289
291
|
showSymbol: ds.styling?.pointStyle === 'none' ? false : true,
|
|
290
|
-
data: data2 ?? []
|
|
292
|
+
data: data2 ?? [],
|
|
293
|
+
drawOrder: ds.advanced?.drawOrder ?? 0
|
|
291
294
|
}
|
|
292
295
|
let chartName = ds.advanced?.chartName ?? ''
|
|
293
296
|
chartName = chartName.replace('#split#', prefix)
|
|
@@ -307,6 +310,17 @@ export class WidgetLinechart extends LitElement {
|
|
|
307
310
|
})
|
|
308
311
|
|
|
309
312
|
doomedCharts.forEach((label) => this.canvasList.delete(label))
|
|
313
|
+
this.canvasList = new Map(
|
|
314
|
+
[...this.canvasList.entries()].sort(([labelA, va], [labelB, vb]) => {
|
|
315
|
+
const orderA = va.series?.[0].drawOrder ?? 0
|
|
316
|
+
const orderB = vb.series?.[0].drawOrder ?? 0
|
|
317
|
+
if (orderA !== orderB) {
|
|
318
|
+
return orderA - orderB
|
|
319
|
+
}
|
|
320
|
+
console.log('Sorting by label', labelA, labelB, labelA.localeCompare(labelB))
|
|
321
|
+
return labelA.localeCompare(labelB)
|
|
322
|
+
})
|
|
323
|
+
)
|
|
310
324
|
}
|
|
311
325
|
|
|
312
326
|
xAxisType(): 'value' | 'log' | 'category' | 'time' | undefined {
|
|
@@ -324,7 +338,11 @@ export class WidgetLinechart extends LitElement {
|
|
|
324
338
|
|
|
325
339
|
applyData() {
|
|
326
340
|
const modifier = 1
|
|
327
|
-
|
|
341
|
+
// Sort chartContainer children by drawOrder and label
|
|
342
|
+
if (!this.chartContainer) return
|
|
343
|
+
for (const canvas of this.canvasList.values()) {
|
|
344
|
+
if (canvas.element) this.chartContainer.appendChild(canvas.element)
|
|
345
|
+
}
|
|
328
346
|
this.canvasList.forEach((chart, label) => {
|
|
329
347
|
chart.series.sort((a, b) => ((a.name as string) > (b.name as string) ? 1 : -1))
|
|
330
348
|
|
|
@@ -363,6 +381,14 @@ export class WidgetLinechart extends LitElement {
|
|
|
363
381
|
option.series = chart.series
|
|
364
382
|
// console.log('Applying data to chart', label, option)
|
|
365
383
|
if (chart.series.length <= 1) option.legend.show = false
|
|
384
|
+
// const now = Date.now()
|
|
385
|
+
// const timeSinceLastUpdate = now - this.lastUpdateTime
|
|
386
|
+
// this.lastUpdateTime = now
|
|
387
|
+
|
|
388
|
+
// const tooFast = timeSinceLastUpdate < this.updateThresholdMs
|
|
389
|
+
// console.warn('too fast')
|
|
390
|
+
// option.animation = !tooFast
|
|
391
|
+
// option.animationDuration = tooFast ? 0 : this.updateThresholdMs
|
|
366
392
|
chart.echart?.setOption(option, { notMerge })
|
|
367
393
|
// chart.echart?.resize()
|
|
368
394
|
})
|
|
@@ -392,9 +418,10 @@ export class WidgetLinechart extends LitElement {
|
|
|
392
418
|
newContainer.setAttribute('name', label)
|
|
393
419
|
newContainer.setAttribute('class', 'sizer')
|
|
394
420
|
this.chartContainer.appendChild(newContainer)
|
|
421
|
+
console.log('Setting up chart for label:', label)
|
|
395
422
|
|
|
396
423
|
const newChart = echarts.init(newContainer, this.theme?.theme_name)
|
|
397
|
-
const chart = { echart: newChart, series: [] as
|
|
424
|
+
const chart = { echart: newChart, series: [] as SeriesOptionX[], element: newContainer }
|
|
398
425
|
this.canvasList.set(label, chart)
|
|
399
426
|
|
|
400
427
|
return chart
|