@record-evolution/widget-gauge 1.6.11 → 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/README.md +3 -1
- package/dist/src/widget-gauge.d.ts +11 -6
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-gauge.js +49 -52
- package/dist/widget-gauge.js.map +1 -1
- package/package.json +3 -3
- package/src/definition-schema.d.ts +24 -24
- package/src/widget-gauge.ts +61 -57
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
|
+
"version": "1.7.2",
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
title?: Title;
|
|
68
|
+
subTitle?: Subtitle;
|
|
69
|
+
dataseries?: Gauges;
|
|
70
|
+
[k: string]: unknown;
|
|
71
71
|
}
|
|
72
72
|
export interface ValueColor {
|
|
73
|
-
|
|
73
|
+
[k: string]: unknown;
|
|
74
74
|
}
|
|
75
75
|
export interface GaugeColorSections {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
sectionLimits?: SectionLimits;
|
|
77
|
+
backgroundColors?: SectionBackgroundColors;
|
|
78
|
+
[k: string]: unknown;
|
|
79
79
|
}
|
|
80
80
|
export interface AdvancedConfiguration {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
averageLatest?: AverageLatestValues;
|
|
82
|
+
maxLatency?: MaximumLatencyInSeconds;
|
|
83
|
+
[k: string]: unknown;
|
|
84
84
|
}
|
package/src/widget-gauge.ts
CHANGED
|
@@ -6,41 +6,45 @@ 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
|
|
|
12
13
|
type Dataseries = Exclude<GaugeChartConfiguration['dataseries'], undefined>[number]
|
|
13
14
|
type Data = Exclude<Dataseries['data'], undefined>[number]
|
|
14
|
-
|
|
15
|
+
type Theme = {
|
|
16
|
+
theme_name: string
|
|
17
|
+
theme_object: any
|
|
18
|
+
}
|
|
15
19
|
@customElement('widget-gauge-versionplaceholder')
|
|
16
20
|
export class WidgetGauge extends LitElement {
|
|
17
21
|
@property({ type: Object })
|
|
18
22
|
inputData?: GaugeChartConfiguration
|
|
19
23
|
|
|
20
24
|
@property({ type: Object })
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@property({ type: String })
|
|
24
|
-
themeName: string = 'light'
|
|
25
|
+
theme?: Theme
|
|
25
26
|
|
|
26
27
|
@state()
|
|
27
28
|
private dataSets: Dataseries[] = []
|
|
28
29
|
|
|
29
30
|
@state()
|
|
30
|
-
private canvasList:
|
|
31
|
+
private canvasList: Map<
|
|
32
|
+
string,
|
|
33
|
+
{ echart?: echarts.ECharts; title?: HTMLHeadingElement; wrapper?: HTMLDivElement }
|
|
34
|
+
> = new Map()
|
|
31
35
|
|
|
32
36
|
@state()
|
|
33
|
-
private themeBgColor
|
|
37
|
+
private themeBgColor?: string
|
|
34
38
|
|
|
35
39
|
@state()
|
|
36
|
-
private themeColor
|
|
40
|
+
private themeColor?: string
|
|
37
41
|
|
|
38
42
|
private resizeObserver: ResizeObserver
|
|
39
43
|
|
|
40
44
|
boxes?: HTMLDivElement[]
|
|
41
45
|
origWidth: number = 0
|
|
42
46
|
origHeight: number = 0
|
|
43
|
-
template:
|
|
47
|
+
template: EChartsOption
|
|
44
48
|
modifier: number = 1
|
|
45
49
|
version: string = 'versionplaceholder'
|
|
46
50
|
gaugeContainer: HTMLDivElement | null | undefined
|
|
@@ -96,12 +100,13 @@ export class WidgetGauge extends LitElement {
|
|
|
96
100
|
data: [
|
|
97
101
|
{
|
|
98
102
|
value: 70,
|
|
99
|
-
name: '
|
|
103
|
+
name: 'Value Name'
|
|
100
104
|
}
|
|
101
105
|
]
|
|
102
|
-
} as
|
|
106
|
+
} as SeriesOption,
|
|
103
107
|
{
|
|
104
108
|
type: 'gauge',
|
|
109
|
+
name: 'Gauge B',
|
|
105
110
|
startAngle: 180,
|
|
106
111
|
endAngle: 0,
|
|
107
112
|
min: 33,
|
|
@@ -131,7 +136,7 @@ export class WidgetGauge extends LitElement {
|
|
|
131
136
|
text: 'Gauge B',
|
|
132
137
|
offsetCenter: [0, '-35%'],
|
|
133
138
|
fontSize: 20,
|
|
134
|
-
show:
|
|
139
|
+
show: true
|
|
135
140
|
},
|
|
136
141
|
axisLabel: {
|
|
137
142
|
distance: -20,
|
|
@@ -139,7 +144,7 @@ export class WidgetGauge extends LitElement {
|
|
|
139
144
|
rotate: 'tangential',
|
|
140
145
|
fontSize: 12
|
|
141
146
|
}
|
|
142
|
-
} as
|
|
147
|
+
} as SeriesOption
|
|
143
148
|
]
|
|
144
149
|
}
|
|
145
150
|
}
|
|
@@ -156,13 +161,11 @@ export class WidgetGauge extends LitElement {
|
|
|
156
161
|
this.transformData()
|
|
157
162
|
}
|
|
158
163
|
|
|
159
|
-
if (changedProperties.has('
|
|
160
|
-
this.registerTheme(this.
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (changedProperties.has('themeName')) {
|
|
164
|
+
if (changedProperties.has('theme')) {
|
|
165
|
+
this.registerTheme(this.theme)
|
|
164
166
|
this.deleteCharts()
|
|
165
|
-
this.
|
|
167
|
+
this.transformData()
|
|
168
|
+
this.applyData()
|
|
166
169
|
}
|
|
167
170
|
super.update(changedProperties)
|
|
168
171
|
}
|
|
@@ -173,12 +176,11 @@ export class WidgetGauge extends LitElement {
|
|
|
173
176
|
this.transformData()
|
|
174
177
|
}
|
|
175
178
|
|
|
176
|
-
registerTheme(
|
|
177
|
-
|
|
178
|
-
if (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
echarts.registerTheme(this.themeName, this.themeObject)
|
|
179
|
+
registerTheme(theme?: Theme) {
|
|
180
|
+
console.log('Registering theme', theme)
|
|
181
|
+
if (!theme || !theme.theme_object || !theme.theme_name) return
|
|
182
|
+
|
|
183
|
+
echarts.registerTheme(theme.theme_name, theme.theme_object)
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
sizingSetup() {
|
|
@@ -247,9 +249,9 @@ export class WidgetGauge extends LitElement {
|
|
|
247
249
|
|
|
248
250
|
this.modifier = modifier
|
|
249
251
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
252
|
+
this.canvasList.forEach((canvasObj) => {
|
|
253
|
+
canvasObj.echart?.resize()
|
|
254
|
+
})
|
|
253
255
|
this.applyData()
|
|
254
256
|
}
|
|
255
257
|
|
|
@@ -284,6 +286,7 @@ export class WidgetGauge extends LitElement {
|
|
|
284
286
|
}
|
|
285
287
|
|
|
286
288
|
applyData() {
|
|
289
|
+
if (!this.gaugeContainer) return
|
|
287
290
|
const modifier = this.modifier
|
|
288
291
|
this.dataSets.forEach((d) => {
|
|
289
292
|
d.label ??= ''
|
|
@@ -295,6 +298,7 @@ export class WidgetGauge extends LitElement {
|
|
|
295
298
|
for (const ds of this.dataSets) {
|
|
296
299
|
// compute derivative values
|
|
297
300
|
// filter latest values and calculate average
|
|
301
|
+
ds.label ??= ''
|
|
298
302
|
ds.advanced ??= {}
|
|
299
303
|
if (typeof ds.advanced?.averageLatest !== 'number' || isNaN(ds.advanced?.averageLatest))
|
|
300
304
|
ds.advanced.averageLatest = 1
|
|
@@ -310,14 +314,11 @@ export class WidgetGauge extends LitElement {
|
|
|
310
314
|
if (isNaN(ds.range as number)) ds.range = 100
|
|
311
315
|
ds.ranges = ds.sections?.sectionLimits?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
|
|
312
316
|
|
|
313
|
-
// const option = this.canvasList
|
|
317
|
+
// const option = this.canvasList.get(ds.label)?.echart.getOption()
|
|
314
318
|
const option = window.structuredClone(this.template)
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
// Title
|
|
319
|
-
option.title.text = ds.label
|
|
320
|
-
option.title.textStyle.fontSize = 25 * modifier
|
|
319
|
+
const seriesArr = option.series as GaugeSeriesOption[]
|
|
320
|
+
const ga: any = seriesArr?.[0],
|
|
321
|
+
ga2: any = seriesArr?.[1]
|
|
321
322
|
|
|
322
323
|
// Needle
|
|
323
324
|
// Check age of data Latency
|
|
@@ -371,38 +372,42 @@ export class WidgetGauge extends LitElement {
|
|
|
371
372
|
ga.progress.itemStyle.color = progressColor
|
|
372
373
|
ga.progress.width = 60 * modifier
|
|
373
374
|
// Apply
|
|
374
|
-
this.canvasList
|
|
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
|
+
}
|
|
382
|
+
|
|
383
|
+
this.canvasList.get(ds.label)?.echart?.setOption(option)
|
|
378
384
|
}
|
|
379
385
|
}
|
|
380
|
-
|
|
381
386
|
deleteCharts() {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
+
this.canvasList.forEach((canvasObj, label) => {
|
|
388
|
+
canvasObj.echart?.dispose()
|
|
389
|
+
canvasObj.wrapper?.remove()
|
|
390
|
+
})
|
|
391
|
+
this.canvasList.clear()
|
|
387
392
|
}
|
|
388
393
|
|
|
389
394
|
setupCharts() {
|
|
395
|
+
if (!this.gaugeContainer) return
|
|
390
396
|
// remove the gauge canvases of non provided data series
|
|
391
|
-
|
|
397
|
+
this.canvasList.forEach((canvasObj, label) => {
|
|
392
398
|
const ex = this.dataSets.find((ds) => ds.label === label)
|
|
393
399
|
if (!ex) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
400
|
+
canvasObj.echart?.dispose()
|
|
401
|
+
canvasObj.wrapper?.remove()
|
|
402
|
+
this.canvasList.delete(label)
|
|
397
403
|
}
|
|
398
|
-
}
|
|
404
|
+
})
|
|
399
405
|
|
|
400
406
|
this.dataSets.forEach((ds) => {
|
|
401
|
-
if (this.canvasList
|
|
407
|
+
if (this.canvasList.has(ds.label ?? '')) return
|
|
402
408
|
const newWrapper = document.createElement('div')
|
|
403
409
|
newWrapper.setAttribute('class', 'chart-wrapper')
|
|
404
410
|
const newTitle = document.createElement('h3')
|
|
405
|
-
newTitle.textContent = ds.label ?? ''
|
|
406
411
|
newTitle.style.fontSize = '20px'
|
|
407
412
|
const newCanvas = document.createElement('div')
|
|
408
413
|
newCanvas.setAttribute('name', ds.label ?? '')
|
|
@@ -416,13 +421,12 @@ export class WidgetGauge extends LitElement {
|
|
|
416
421
|
newWrapper!.appendChild(newCanvas)
|
|
417
422
|
this.gaugeContainer!.appendChild(newWrapper)
|
|
418
423
|
|
|
419
|
-
const newChart = echarts.init(newCanvas, this.
|
|
420
|
-
this.canvasList
|
|
421
|
-
// 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 })
|
|
422
426
|
//@ts-ignore
|
|
423
|
-
this.themeBgColor = newChart
|
|
427
|
+
this.themeBgColor = newChart?._theme?.backgroundColor
|
|
424
428
|
//@ts-ignore
|
|
425
|
-
this.themeColor = newChart._theme
|
|
429
|
+
this.themeColor = newChart._theme?.title?.textStyle?.color
|
|
426
430
|
})
|
|
427
431
|
this.sizingSetup()
|
|
428
432
|
}
|