@record-evolution/widget-gauge 1.7.1 → 1.7.2
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-gauge.d.ts +7 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-gauge.js +42 -41
- package/dist/widget-gauge.js.map +1 -1
- package/package.json +1 -1
- package/src/widget-gauge.ts +45 -42
package/package.json
CHANGED
package/src/widget-gauge.ts
CHANGED
|
@@ -12,23 +12,26 @@ echarts.use([TooltipComponent, GaugeChart, CanvasRenderer])
|
|
|
12
12
|
|
|
13
13
|
type Dataseries = Exclude<GaugeChartConfiguration['dataseries'], undefined>[number]
|
|
14
14
|
type Data = Exclude<Dataseries['data'], undefined>[number]
|
|
15
|
-
|
|
15
|
+
type Theme = {
|
|
16
|
+
theme_name: string
|
|
17
|
+
theme_object: any
|
|
18
|
+
}
|
|
16
19
|
@customElement('widget-gauge-versionplaceholder')
|
|
17
20
|
export class WidgetGauge extends LitElement {
|
|
18
21
|
@property({ type: Object })
|
|
19
22
|
inputData?: GaugeChartConfiguration
|
|
20
23
|
|
|
21
24
|
@property({ type: Object })
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@property({ type: String })
|
|
25
|
-
themeName?: string
|
|
25
|
+
theme?: Theme
|
|
26
26
|
|
|
27
27
|
@state()
|
|
28
28
|
private dataSets: Dataseries[] = []
|
|
29
29
|
|
|
30
30
|
@state()
|
|
31
|
-
private canvasList:
|
|
31
|
+
private canvasList: Map<
|
|
32
|
+
string,
|
|
33
|
+
{ echart?: echarts.ECharts; title?: HTMLHeadingElement; wrapper?: HTMLDivElement }
|
|
34
|
+
> = new Map()
|
|
32
35
|
|
|
33
36
|
@state()
|
|
34
37
|
private themeBgColor?: string
|
|
@@ -158,14 +161,11 @@ export class WidgetGauge extends LitElement {
|
|
|
158
161
|
this.transformData()
|
|
159
162
|
}
|
|
160
163
|
|
|
161
|
-
if (changedProperties.has('
|
|
162
|
-
this.registerTheme(this.
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (changedProperties.has('themeName')) {
|
|
166
|
-
this.registerTheme(this.themeName, this.themeObject)
|
|
164
|
+
if (changedProperties.has('theme')) {
|
|
165
|
+
this.registerTheme(this.theme)
|
|
167
166
|
this.deleteCharts()
|
|
168
|
-
this.
|
|
167
|
+
this.transformData()
|
|
168
|
+
this.applyData()
|
|
169
169
|
}
|
|
170
170
|
super.update(changedProperties)
|
|
171
171
|
}
|
|
@@ -176,10 +176,11 @@ export class WidgetGauge extends LitElement {
|
|
|
176
176
|
this.transformData()
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
registerTheme(
|
|
180
|
-
|
|
179
|
+
registerTheme(theme?: Theme) {
|
|
180
|
+
console.log('Registering theme', theme)
|
|
181
|
+
if (!theme || !theme.theme_object || !theme.theme_name) return
|
|
181
182
|
|
|
182
|
-
echarts.registerTheme(
|
|
183
|
+
echarts.registerTheme(theme.theme_name, theme.theme_object)
|
|
183
184
|
}
|
|
184
185
|
|
|
185
186
|
sizingSetup() {
|
|
@@ -248,9 +249,9 @@ export class WidgetGauge extends LitElement {
|
|
|
248
249
|
|
|
249
250
|
this.modifier = modifier
|
|
250
251
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
252
|
+
this.canvasList.forEach((canvasObj) => {
|
|
253
|
+
canvasObj.echart?.resize()
|
|
254
|
+
})
|
|
254
255
|
this.applyData()
|
|
255
256
|
}
|
|
256
257
|
|
|
@@ -285,6 +286,7 @@ export class WidgetGauge extends LitElement {
|
|
|
285
286
|
}
|
|
286
287
|
|
|
287
288
|
applyData() {
|
|
289
|
+
if (!this.gaugeContainer) return
|
|
288
290
|
const modifier = this.modifier
|
|
289
291
|
this.dataSets.forEach((d) => {
|
|
290
292
|
d.label ??= ''
|
|
@@ -312,7 +314,7 @@ export class WidgetGauge extends LitElement {
|
|
|
312
314
|
if (isNaN(ds.range as number)) ds.range = 100
|
|
313
315
|
ds.ranges = ds.sections?.sectionLimits?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
|
|
314
316
|
|
|
315
|
-
// const option = this.canvasList
|
|
317
|
+
// const option = this.canvasList.get(ds.label)?.echart.getOption()
|
|
316
318
|
const option = window.structuredClone(this.template)
|
|
317
319
|
const seriesArr = option.series as GaugeSeriesOption[]
|
|
318
320
|
const ga: any = seriesArr?.[0],
|
|
@@ -370,37 +372,39 @@ export class WidgetGauge extends LitElement {
|
|
|
370
372
|
ga.progress.itemStyle.color = progressColor
|
|
371
373
|
ga.progress.width = 60 * modifier
|
|
372
374
|
// Apply
|
|
373
|
-
const titleElement = this.canvasList
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
375
|
+
const titleElement = this.canvasList.get(ds.label)?.title
|
|
376
|
+
if (titleElement) {
|
|
377
|
+
titleElement.style.fontSize = String(20 * modifier) + 'px'
|
|
378
|
+
titleElement.style.maxWidth = String(300 * modifier) + 'px'
|
|
379
|
+
titleElement.style.height = String(25 * modifier) + 'px'
|
|
380
|
+
titleElement.textContent = ds.label ?? ''
|
|
381
|
+
}
|
|
378
382
|
|
|
379
|
-
this.canvasList
|
|
383
|
+
this.canvasList.get(ds.label)?.echart?.setOption(option)
|
|
380
384
|
}
|
|
381
385
|
}
|
|
382
|
-
|
|
383
386
|
deleteCharts() {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
387
|
+
this.canvasList.forEach((canvasObj, label) => {
|
|
388
|
+
canvasObj.echart?.dispose()
|
|
389
|
+
canvasObj.wrapper?.remove()
|
|
390
|
+
})
|
|
391
|
+
this.canvasList.clear()
|
|
389
392
|
}
|
|
390
393
|
|
|
391
394
|
setupCharts() {
|
|
395
|
+
if (!this.gaugeContainer) return
|
|
392
396
|
// remove the gauge canvases of non provided data series
|
|
393
|
-
|
|
397
|
+
this.canvasList.forEach((canvasObj, label) => {
|
|
394
398
|
const ex = this.dataSets.find((ds) => ds.label === label)
|
|
395
399
|
if (!ex) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
400
|
+
canvasObj.echart?.dispose()
|
|
401
|
+
canvasObj.wrapper?.remove()
|
|
402
|
+
this.canvasList.delete(label)
|
|
399
403
|
}
|
|
400
|
-
}
|
|
404
|
+
})
|
|
401
405
|
|
|
402
406
|
this.dataSets.forEach((ds) => {
|
|
403
|
-
if (this.canvasList
|
|
407
|
+
if (this.canvasList.has(ds.label ?? '')) return
|
|
404
408
|
const newWrapper = document.createElement('div')
|
|
405
409
|
newWrapper.setAttribute('class', 'chart-wrapper')
|
|
406
410
|
const newTitle = document.createElement('h3')
|
|
@@ -417,13 +421,12 @@ export class WidgetGauge extends LitElement {
|
|
|
417
421
|
newWrapper!.appendChild(newCanvas)
|
|
418
422
|
this.gaugeContainer!.appendChild(newWrapper)
|
|
419
423
|
|
|
420
|
-
const newChart = echarts.init(newCanvas, this.
|
|
421
|
-
this.canvasList
|
|
422
|
-
// this.canvasList[ds.label ?? ''].setOption(structuredClone(this.template))
|
|
424
|
+
const newChart = echarts.init(newCanvas, this.theme?.theme_name)
|
|
425
|
+
this.canvasList.set(ds.label ?? '', { echart: newChart, title: newTitle, wrapper: newWrapper })
|
|
423
426
|
//@ts-ignore
|
|
424
427
|
this.themeBgColor = newChart?._theme?.backgroundColor
|
|
425
428
|
//@ts-ignore
|
|
426
|
-
this.themeColor = newChart
|
|
429
|
+
this.themeColor = newChart._theme?.title?.textStyle?.color
|
|
427
430
|
})
|
|
428
431
|
this.sizingSetup()
|
|
429
432
|
}
|