@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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "REWidget widget-gauge",
4
4
  "license": "MIT",
5
5
  "author": "widget-gauge",
6
- "version": "1.7.1",
6
+ "version": "1.7.2",
7
7
  "type": "module",
8
8
  "main": "dist/widget-gauge.js",
9
9
  "types": "dist/src/widget-gauge.d.ts",
@@ -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
- themeObject?: any
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: any = {}
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('themeObject')) {
162
- this.registerTheme(this.themeName, this.themeObject)
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.setupCharts()
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(themeName?: string, themeObject?: any) {
180
- if (!themeObject || !themeName) return
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(themeName, this.themeObject)
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
- for (const canvas in this.canvasList) {
252
- this.canvasList[canvas].echart.resize()
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[ds.label].getOption()
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[ds.label]?.title
374
- titleElement.style.fontSize = String(20 * modifier) + 'px'
375
- titleElement.style.maxWidth = String(300 * modifier) + 'px'
376
- titleElement.style.height = String(25 * modifier) + 'px'
377
- titleElement.textContent = ds.label ?? ''
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[ds.label]?.echart.setOption(option)
383
+ this.canvasList.get(ds.label)?.echart?.setOption(option)
380
384
  }
381
385
  }
382
-
383
386
  deleteCharts() {
384
- for (const label in this.canvasList) {
385
- this.canvasList[label].echart.dispose()
386
- this.canvasList[label].wrapper?.remove()
387
- delete this.canvasList[label]
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
- for (const label in this.canvasList) {
397
+ this.canvasList.forEach((canvasObj, label) => {
394
398
  const ex = this.dataSets.find((ds) => ds.label === label)
395
399
  if (!ex) {
396
- this.canvasList[label].echart.dispose()
397
- this.canvasList[label].wrapper?.remove()
398
- delete this.canvasList[label]
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[ds.label ?? '']) return
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.themeName)
421
- this.canvasList[ds.label ?? ''] = { echart: newChart, title: newTitle, wrapper: newWrapper }
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?._theme?.gauge?.title?.color
429
+ this.themeColor = newChart._theme?.title?.textStyle?.color
427
430
  })
428
431
  this.sizingSetup()
429
432
  }