@record-evolution/widget-gauge 1.6.11 → 1.7.1

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.6.11",
6
+ "version": "1.7.1",
7
7
  "type": "module",
8
8
  "main": "dist/widget-gauge.js",
9
9
  "types": "dist/src/widget-gauge.d.ts",
@@ -16,9 +16,9 @@
16
16
  "start": "concurrently -k -r \"npm run watch\" \"wds\"",
17
17
  "build": "rollup -c rollup.config.js",
18
18
  "watch": "rollup -w -c rollup.config.js",
19
- "link": "npm link && cd ../RESWARM/frontend && npm link @record-evolution/widget-gauge",
19
+ "link": "npm run build && npm link && cd ../RESWARM/frontend && npm link @record-evolution/widget-gauge",
20
20
  "unlink": "npm unlink --global && cd ../RESWARM/frontend && npm unlink @record-evolution/widget-gauge && npm i @record-evolution/widget-gauge",
21
- "types": "cat src/definition-schema.json | json2ts > src/definition-schema.d.ts",
21
+ "types": "cat src/definition-schema.json | json2ts --style.tabWidth=4 > src/definition-schema.d.ts",
22
22
  "lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
23
23
  "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
24
24
  "release": "npm run build && npm run types && npm version patch --tag-version-prefix='' && git push && git push --tag"
@@ -29,10 +29,10 @@ export type SplitDataBy = string;
29
29
  * Provide a list of values. Only the latest value is shown in the gauge unless you configure "Advanced Settings" below or use split data.
30
30
  */
31
31
  export type Data = {
32
- tsp?: Timestamp;
33
- value?: Value;
34
- pivot?: SplitDataBy;
35
- [k: string]: unknown;
32
+ tsp?: Timestamp;
33
+ value?: Value;
34
+ pivot?: SplitDataBy;
35
+ [k: string]: unknown;
36
36
  }[];
37
37
  /**
38
38
  * The limits of the gauge sections. Starting from the min value, ending with the max value.
@@ -42,7 +42,7 @@ export type SectionLimits = number[];
42
42
  * Background color for each section. This Array is one shorter than the number of sections.
43
43
  */
44
44
  export type SectionBackgroundColors = {
45
- [k: string]: unknown;
45
+ [k: string]: unknown;
46
46
  }[];
47
47
  /**
48
48
  * Calculate the average over the given number of newest values. (If you use 'split by', then per each of the split dataseries.) If not specified then the latest value is shown without modification.
@@ -53,32 +53,32 @@ export type AverageLatestValues = number;
53
53
  */
54
54
  export type MaximumLatencyInSeconds = number;
55
55
  export type Gauges = {
56
- label?: Label;
57
- valueColor?: ValueColor;
58
- unit?: Unit;
59
- precision?: Precision;
60
- data?: Data;
61
- sections?: GaugeColorSections;
62
- advanced?: AdvancedConfiguration;
63
- [k: string]: unknown;
56
+ label?: Label;
57
+ valueColor?: ValueColor;
58
+ unit?: Unit;
59
+ precision?: Precision;
60
+ data?: Data;
61
+ sections?: GaugeColorSections;
62
+ advanced?: AdvancedConfiguration;
63
+ [k: string]: unknown;
64
64
  }[];
65
65
 
66
66
  export interface GaugeChartConfiguration {
67
- title?: Title;
68
- subTitle?: Subtitle;
69
- dataseries?: Gauges;
70
- [k: string]: unknown;
67
+ title?: Title;
68
+ subTitle?: Subtitle;
69
+ dataseries?: Gauges;
70
+ [k: string]: unknown;
71
71
  }
72
72
  export interface ValueColor {
73
- [k: string]: unknown;
73
+ [k: string]: unknown;
74
74
  }
75
75
  export interface GaugeColorSections {
76
- sectionLimits?: SectionLimits;
77
- backgroundColors?: SectionBackgroundColors;
78
- [k: string]: unknown;
76
+ sectionLimits?: SectionLimits;
77
+ backgroundColors?: SectionBackgroundColors;
78
+ [k: string]: unknown;
79
79
  }
80
80
  export interface AdvancedConfiguration {
81
- averageLatest?: AverageLatestValues;
82
- maxLatency?: MaximumLatencyInSeconds;
83
- [k: string]: unknown;
81
+ averageLatest?: AverageLatestValues;
82
+ maxLatency?: MaximumLatencyInSeconds;
83
+ [k: string]: unknown;
84
84
  }
@@ -6,6 +6,7 @@ import * as echarts from 'echarts/core'
6
6
  import { TooltipComponent } from 'echarts/components'
7
7
  import { GaugeChart, GaugeSeriesOption } from 'echarts/charts'
8
8
  import { CanvasRenderer, SVGRenderer } from 'echarts/renderers'
9
+ import { EChartsOption, SeriesOption } from 'echarts'
9
10
 
10
11
  echarts.use([TooltipComponent, GaugeChart, CanvasRenderer])
11
12
 
@@ -21,7 +22,7 @@ export class WidgetGauge extends LitElement {
21
22
  themeObject?: any
22
23
 
23
24
  @property({ type: String })
24
- themeName: string = 'light'
25
+ themeName?: string
25
26
 
26
27
  @state()
27
28
  private dataSets: Dataseries[] = []
@@ -30,17 +31,17 @@ export class WidgetGauge extends LitElement {
30
31
  private canvasList: any = {}
31
32
 
32
33
  @state()
33
- private themeBgColor: string = '#fff'
34
+ private themeBgColor?: string
34
35
 
35
36
  @state()
36
- private themeColor: string = '#000'
37
+ private themeColor?: string
37
38
 
38
39
  private resizeObserver: ResizeObserver
39
40
 
40
41
  boxes?: HTMLDivElement[]
41
42
  origWidth: number = 0
42
43
  origHeight: number = 0
43
- template: any
44
+ template: EChartsOption
44
45
  modifier: number = 1
45
46
  version: string = 'versionplaceholder'
46
47
  gaugeContainer: HTMLDivElement | null | undefined
@@ -96,12 +97,13 @@ export class WidgetGauge extends LitElement {
96
97
  data: [
97
98
  {
98
99
  value: 70,
99
- name: 'nASDf'
100
+ name: 'Value Name'
100
101
  }
101
102
  ]
102
- } as GaugeSeriesOption,
103
+ } as SeriesOption,
103
104
  {
104
105
  type: 'gauge',
106
+ name: 'Gauge B',
105
107
  startAngle: 180,
106
108
  endAngle: 0,
107
109
  min: 33,
@@ -131,7 +133,7 @@ export class WidgetGauge extends LitElement {
131
133
  text: 'Gauge B',
132
134
  offsetCenter: [0, '-35%'],
133
135
  fontSize: 20,
134
- show: false
136
+ show: true
135
137
  },
136
138
  axisLabel: {
137
139
  distance: -20,
@@ -139,7 +141,7 @@ export class WidgetGauge extends LitElement {
139
141
  rotate: 'tangential',
140
142
  fontSize: 12
141
143
  }
142
- } as GaugeSeriesOption
144
+ } as SeriesOption
143
145
  ]
144
146
  }
145
147
  }
@@ -157,10 +159,11 @@ export class WidgetGauge extends LitElement {
157
159
  }
158
160
 
159
161
  if (changedProperties.has('themeObject')) {
160
- this.registerTheme(this.themeObject)
162
+ this.registerTheme(this.themeName, this.themeObject)
161
163
  }
162
164
 
163
165
  if (changedProperties.has('themeName')) {
166
+ this.registerTheme(this.themeName, this.themeObject)
164
167
  this.deleteCharts()
165
168
  this.setupCharts()
166
169
  }
@@ -173,12 +176,10 @@ export class WidgetGauge extends LitElement {
173
176
  this.transformData()
174
177
  }
175
178
 
176
- registerTheme(themeObject: any) {
177
- if (!themeObject) return
178
- if (typeof themeObject === 'string') {
179
- return
180
- }
181
- echarts.registerTheme(this.themeName, this.themeObject)
179
+ registerTheme(themeName?: string, themeObject?: any) {
180
+ if (!themeObject || !themeName) return
181
+
182
+ echarts.registerTheme(themeName, this.themeObject)
182
183
  }
183
184
 
184
185
  sizingSetup() {
@@ -295,6 +296,7 @@ export class WidgetGauge extends LitElement {
295
296
  for (const ds of this.dataSets) {
296
297
  // compute derivative values
297
298
  // filter latest values and calculate average
299
+ ds.label ??= ''
298
300
  ds.advanced ??= {}
299
301
  if (typeof ds.advanced?.averageLatest !== 'number' || isNaN(ds.advanced?.averageLatest))
300
302
  ds.advanced.averageLatest = 1
@@ -312,12 +314,9 @@ export class WidgetGauge extends LitElement {
312
314
 
313
315
  // const option = this.canvasList[ds.label].getOption()
314
316
  const option = window.structuredClone(this.template)
315
- const ga = option.series[0],
316
- ga2 = option.series[1]
317
-
318
- // Title
319
- option.title.text = ds.label
320
- option.title.textStyle.fontSize = 25 * modifier
317
+ const seriesArr = option.series as GaugeSeriesOption[]
318
+ const ga: any = seriesArr?.[0],
319
+ ga2: any = seriesArr?.[1]
321
320
 
322
321
  // Needle
323
322
  // Check age of data Latency
@@ -371,10 +370,13 @@ export class WidgetGauge extends LitElement {
371
370
  ga.progress.itemStyle.color = progressColor
372
371
  ga.progress.width = 60 * modifier
373
372
  // Apply
374
- this.canvasList[ds.label ?? ''].title.style.fontSize = String(20 * modifier) + 'px'
375
- this.canvasList[ds.label ?? ''].title.style.maxWidth = String(300 * modifier) + 'px'
376
- this.canvasList[ds.label ?? ''].title.style.height = String(25 * modifier) + 'px'
377
- this.canvasList[ds.label ?? '']?.echart.setOption(option)
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 ?? ''
378
+
379
+ this.canvasList[ds.label]?.echart.setOption(option)
378
380
  }
379
381
  }
380
382
 
@@ -402,7 +404,6 @@ export class WidgetGauge extends LitElement {
402
404
  const newWrapper = document.createElement('div')
403
405
  newWrapper.setAttribute('class', 'chart-wrapper')
404
406
  const newTitle = document.createElement('h3')
405
- newTitle.textContent = ds.label ?? ''
406
407
  newTitle.style.fontSize = '20px'
407
408
  const newCanvas = document.createElement('div')
408
409
  newCanvas.setAttribute('name', ds.label ?? '')
@@ -420,9 +421,9 @@ export class WidgetGauge extends LitElement {
420
421
  this.canvasList[ds.label ?? ''] = { echart: newChart, title: newTitle, wrapper: newWrapper }
421
422
  // this.canvasList[ds.label ?? ''].setOption(structuredClone(this.template))
422
423
  //@ts-ignore
423
- this.themeBgColor = newChart._theme.backgroundColor ?? '#fff'
424
+ this.themeBgColor = newChart?._theme?.backgroundColor
424
425
  //@ts-ignore
425
- this.themeColor = newChart._theme.gauge?.title?.color ?? '#000'
426
+ this.themeColor = newChart?._theme?.gauge?.title?.color
426
427
  })
427
428
  this.sizingSetup()
428
429
  }