@record-evolution/widget-gauge 1.6.9 → 1.6.11
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 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-gauge.js +34905 -524
- package/dist/widget-gauge.js.map +1 -1
- package/package.json +19 -25
- package/src/default-data.json +3 -3
- package/src/definition-schema.d.ts +8 -3
- package/src/definition-schema.json +9 -2
- package/src/widget-gauge.ts +149 -79
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.
|
|
6
|
+
"version": "1.6.11",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/widget-gauge.js",
|
|
9
9
|
"types": "dist/src/widget-gauge.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"analyze": "cem analyze --litelement",
|
|
16
|
-
"start": "
|
|
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
19
|
"link": "npm link && cd ../RESWARM/frontend && npm link @record-evolution/widget-gauge",
|
|
@@ -21,35 +21,29 @@
|
|
|
21
21
|
"types": "cat src/definition-schema.json | json2ts > 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
|
-
"release": "npm version patch --tag-version-prefix='' && git push && git push --tag"
|
|
24
|
+
"release": "npm run build && npm run types && npm version patch --tag-version-prefix='' && git push && git push --tag"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"echarts": "
|
|
28
|
-
"lit": "^3.
|
|
27
|
+
"echarts": "5.6.0",
|
|
28
|
+
"lit": "^3.3.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@custom-elements-manifest/analyzer": "^0.10.
|
|
31
|
+
"@custom-elements-manifest/analyzer": "^0.10.4",
|
|
32
32
|
"@rollup/plugin-babel": "^6.0.4",
|
|
33
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
34
|
-
"@rollup/plugin-node-resolve": "^
|
|
35
|
-
"@rollup/plugin-replace": "^6.0.
|
|
36
|
-
"@rollup/plugin-typescript": "^12.1.
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
38
|
-
"@typescript-eslint/parser": "^8.
|
|
33
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
34
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
35
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
36
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^8.34.0",
|
|
38
|
+
"@typescript-eslint/parser": "^8.34.0",
|
|
39
39
|
"@web/dev-server": "^0.4.6",
|
|
40
|
-
"concurrently": "^9.
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"lint-staged": "^15.2.10",
|
|
48
|
-
"prettier": "^3.3.3",
|
|
49
|
-
"rimraf": "^6.0.1",
|
|
50
|
-
"rollup": "^4.24.0",
|
|
51
|
-
"tslib": "^2.7.0",
|
|
52
|
-
"typescript": "5.3.2"
|
|
40
|
+
"concurrently": "^9.1.2",
|
|
41
|
+
"eslint": "^9.29.0",
|
|
42
|
+
"eslint-config-prettier": "^10.1.5",
|
|
43
|
+
"json-schema-to-typescript": "^15.0.4",
|
|
44
|
+
"prettier": "^3.5.3",
|
|
45
|
+
"rollup": "^4.43.0",
|
|
46
|
+
"typescript": "5.8.3"
|
|
53
47
|
},
|
|
54
48
|
"repository": {
|
|
55
49
|
"type": "git",
|
package/src/default-data.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
2
|
+
"title": "Demo Gauge",
|
|
3
|
+
"subTitle": "A simple gauge demo",
|
|
3
4
|
"dataseries": [
|
|
4
5
|
{
|
|
5
6
|
"label": "Demo Gauge Temperature",
|
|
6
7
|
"unit": "°C",
|
|
7
|
-
"
|
|
8
|
+
"precision": 1,
|
|
8
9
|
"data": [
|
|
9
10
|
{
|
|
10
11
|
"value": 90
|
|
@@ -21,7 +22,6 @@
|
|
|
21
22
|
{
|
|
22
23
|
"label": "Demo Gauge Pascal",
|
|
23
24
|
"unit": "Pa",
|
|
24
|
-
"valueColor": "green",
|
|
25
25
|
"data": [
|
|
26
26
|
{
|
|
27
27
|
"value": 79
|
|
@@ -12,6 +12,10 @@ export type Label = string;
|
|
|
12
12
|
* The unit of the values. e.g. °C or km/h
|
|
13
13
|
*/
|
|
14
14
|
export type Unit = string;
|
|
15
|
+
/**
|
|
16
|
+
* The number of decimal places to show in the value. If not specified, precision is 0.
|
|
17
|
+
*/
|
|
18
|
+
export type Precision = number;
|
|
15
19
|
/**
|
|
16
20
|
* This should be an ISO String date like 2023-11-04T22:47:52.351152+00:00. Will only be used to detect data age of data.
|
|
17
21
|
*/
|
|
@@ -22,7 +26,7 @@ export type Value = number;
|
|
|
22
26
|
*/
|
|
23
27
|
export type SplitDataBy = string;
|
|
24
28
|
/**
|
|
25
|
-
*
|
|
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.
|
|
26
30
|
*/
|
|
27
31
|
export type Data = {
|
|
28
32
|
tsp?: Timestamp;
|
|
@@ -47,11 +51,12 @@ export type AverageLatestValues = number;
|
|
|
47
51
|
/**
|
|
48
52
|
* If you provide timestamp data, the delivered value is only shown in the gauge when the age of the data is not older than the given maximum Latency in seconds.
|
|
49
53
|
*/
|
|
50
|
-
export type
|
|
54
|
+
export type MaximumLatencyInSeconds = number;
|
|
51
55
|
export type Gauges = {
|
|
52
56
|
label?: Label;
|
|
53
57
|
valueColor?: ValueColor;
|
|
54
58
|
unit?: Unit;
|
|
59
|
+
precision?: Precision;
|
|
55
60
|
data?: Data;
|
|
56
61
|
sections?: GaugeColorSections;
|
|
57
62
|
advanced?: AdvancedConfiguration;
|
|
@@ -74,6 +79,6 @@ export interface GaugeColorSections {
|
|
|
74
79
|
}
|
|
75
80
|
export interface AdvancedConfiguration {
|
|
76
81
|
averageLatest?: AverageLatestValues;
|
|
77
|
-
maxLatency?:
|
|
82
|
+
maxLatency?: MaximumLatencyInSeconds;
|
|
78
83
|
[k: string]: unknown;
|
|
79
84
|
}
|
|
@@ -35,9 +35,16 @@
|
|
|
35
35
|
"title": "Unit",
|
|
36
36
|
"description": "The unit of the values. e.g. °C or km/h",
|
|
37
37
|
"type": "string",
|
|
38
|
-
"dataDrivenDisabled":
|
|
38
|
+
"dataDrivenDisabled": false,
|
|
39
39
|
"order": 3
|
|
40
40
|
},
|
|
41
|
+
"precision": {
|
|
42
|
+
"title": "Precision",
|
|
43
|
+
"description": "The number of decimal places to show in the value. If not specified, precision is 0.",
|
|
44
|
+
"type": "number",
|
|
45
|
+
"dataDrivenDisabled": false,
|
|
46
|
+
"order": 4
|
|
47
|
+
},
|
|
41
48
|
"data": {
|
|
42
49
|
"title": "Data",
|
|
43
50
|
"description": "Provide a list of values. Only the latest value is shown in the gauge unless you configure \"Advanced Settings\" below or use split data.",
|
|
@@ -111,7 +118,7 @@
|
|
|
111
118
|
"order": 6
|
|
112
119
|
},
|
|
113
120
|
"maxLatency": {
|
|
114
|
-
"title": "Maximum Latency",
|
|
121
|
+
"title": "Maximum Latency in seconds",
|
|
115
122
|
"description": "If you provide timestamp data, the delivered value is only shown in the gauge when the age of the data is not older than the given maximum Latency in seconds.",
|
|
116
123
|
"type": "number",
|
|
117
124
|
"dataDrivenDisabled": true,
|
package/src/widget-gauge.ts
CHANGED
|
@@ -1,25 +1,42 @@
|
|
|
1
1
|
import { html, css, LitElement, PropertyValueMap } from 'lit'
|
|
2
|
-
import { property, state } from 'lit/decorators.js'
|
|
3
|
-
// import * as echarts from 'echarts'
|
|
4
|
-
import type { EChartsOption, GaugeSeriesOption } from 'echarts'
|
|
2
|
+
import { customElement, property, state } from 'lit/decorators.js'
|
|
5
3
|
import { GaugeChartConfiguration } from './definition-schema.js'
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
import * as echarts from 'echarts/core'
|
|
6
|
+
import { TooltipComponent } from 'echarts/components'
|
|
7
|
+
import { GaugeChart, GaugeSeriesOption } from 'echarts/charts'
|
|
8
|
+
import { CanvasRenderer, SVGRenderer } from 'echarts/renderers'
|
|
9
|
+
|
|
10
|
+
echarts.use([TooltipComponent, GaugeChart, CanvasRenderer])
|
|
8
11
|
|
|
9
12
|
type Dataseries = Exclude<GaugeChartConfiguration['dataseries'], undefined>[number]
|
|
10
13
|
type Data = Exclude<Dataseries['data'], undefined>[number]
|
|
11
14
|
|
|
15
|
+
@customElement('widget-gauge-versionplaceholder')
|
|
12
16
|
export class WidgetGauge extends LitElement {
|
|
13
17
|
@property({ type: Object })
|
|
14
18
|
inputData?: GaugeChartConfiguration
|
|
15
19
|
|
|
20
|
+
@property({ type: Object })
|
|
21
|
+
themeObject?: any
|
|
22
|
+
|
|
23
|
+
@property({ type: String })
|
|
24
|
+
themeName: string = 'light'
|
|
25
|
+
|
|
16
26
|
@state()
|
|
17
27
|
private dataSets: Dataseries[] = []
|
|
18
28
|
|
|
19
29
|
@state()
|
|
20
30
|
private canvasList: any = {}
|
|
21
31
|
|
|
32
|
+
@state()
|
|
33
|
+
private themeBgColor: string = '#fff'
|
|
34
|
+
|
|
35
|
+
@state()
|
|
36
|
+
private themeColor: string = '#000'
|
|
37
|
+
|
|
22
38
|
private resizeObserver: ResizeObserver
|
|
39
|
+
|
|
23
40
|
boxes?: HTMLDivElement[]
|
|
24
41
|
origWidth: number = 0
|
|
25
42
|
origHeight: number = 0
|
|
@@ -27,6 +44,7 @@ export class WidgetGauge extends LitElement {
|
|
|
27
44
|
modifier: number = 1
|
|
28
45
|
version: string = 'versionplaceholder'
|
|
29
46
|
gaugeContainer: HTMLDivElement | null | undefined
|
|
47
|
+
|
|
30
48
|
constructor() {
|
|
31
49
|
super()
|
|
32
50
|
this.resizeObserver = new ResizeObserver(this.adjustSizes.bind(this))
|
|
@@ -46,7 +64,7 @@ export class WidgetGauge extends LitElement {
|
|
|
46
64
|
endAngle: 0,
|
|
47
65
|
min: 33,
|
|
48
66
|
max: 99,
|
|
49
|
-
radius: '
|
|
67
|
+
radius: '140%',
|
|
50
68
|
center: ['50%', '90%'],
|
|
51
69
|
progress: {
|
|
52
70
|
show: true,
|
|
@@ -70,12 +88,15 @@ export class WidgetGauge extends LitElement {
|
|
|
70
88
|
color: 'inherit'
|
|
71
89
|
},
|
|
72
90
|
title: {
|
|
91
|
+
text: 'Gauge A',
|
|
73
92
|
offsetCenter: [0, '-35%'],
|
|
74
|
-
fontSize: 20
|
|
93
|
+
fontSize: 20,
|
|
94
|
+
show: true
|
|
75
95
|
},
|
|
76
96
|
data: [
|
|
77
97
|
{
|
|
78
|
-
value: 70
|
|
98
|
+
value: 70,
|
|
99
|
+
name: 'nASDf'
|
|
79
100
|
}
|
|
80
101
|
]
|
|
81
102
|
} as GaugeSeriesOption,
|
|
@@ -85,7 +106,7 @@ export class WidgetGauge extends LitElement {
|
|
|
85
106
|
endAngle: 0,
|
|
86
107
|
min: 33,
|
|
87
108
|
max: 99,
|
|
88
|
-
radius: '
|
|
109
|
+
radius: '145%',
|
|
89
110
|
center: ['50%', '90%'],
|
|
90
111
|
axisLine: {
|
|
91
112
|
lineStyle: {
|
|
@@ -106,6 +127,12 @@ export class WidgetGauge extends LitElement {
|
|
|
106
127
|
color: 'auto'
|
|
107
128
|
}
|
|
108
129
|
},
|
|
130
|
+
title: {
|
|
131
|
+
text: 'Gauge B',
|
|
132
|
+
offsetCenter: [0, '-35%'],
|
|
133
|
+
fontSize: 20,
|
|
134
|
+
show: false
|
|
135
|
+
},
|
|
109
136
|
axisLabel: {
|
|
110
137
|
distance: -20,
|
|
111
138
|
color: '#666',
|
|
@@ -124,29 +151,42 @@ export class WidgetGauge extends LitElement {
|
|
|
124
151
|
}
|
|
125
152
|
}
|
|
126
153
|
|
|
127
|
-
update(changedProperties: Map<
|
|
128
|
-
changedProperties.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
this.adjustSizes()
|
|
132
|
-
}
|
|
133
|
-
})
|
|
154
|
+
update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
155
|
+
if (changedProperties.has('inputData') && this.gaugeContainer) {
|
|
156
|
+
this.transformData()
|
|
157
|
+
}
|
|
134
158
|
|
|
159
|
+
if (changedProperties.has('themeObject')) {
|
|
160
|
+
this.registerTheme(this.themeObject)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (changedProperties.has('themeName')) {
|
|
164
|
+
this.deleteCharts()
|
|
165
|
+
this.setupCharts()
|
|
166
|
+
}
|
|
135
167
|
super.update(changedProperties)
|
|
136
168
|
}
|
|
137
169
|
|
|
138
170
|
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
139
171
|
this.resizeObserver.observe(this.shadowRoot?.querySelector('.wrapper') as HTMLDivElement)
|
|
140
172
|
this.gaugeContainer = this.shadowRoot?.querySelector('.gauge-container')
|
|
141
|
-
this.sizingSetup()
|
|
142
173
|
this.transformData()
|
|
143
|
-
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
registerTheme(themeObject: any) {
|
|
177
|
+
if (!themeObject) return
|
|
178
|
+
if (typeof themeObject === 'string') {
|
|
179
|
+
return
|
|
180
|
+
}
|
|
181
|
+
echarts.registerTheme(this.themeName, this.themeObject)
|
|
144
182
|
}
|
|
145
183
|
|
|
146
184
|
sizingSetup() {
|
|
147
185
|
if (this.origWidth !== 0 && this.origHeight !== 0) return
|
|
148
186
|
|
|
149
|
-
this.boxes =
|
|
187
|
+
this.boxes =
|
|
188
|
+
Array.from(this?.shadowRoot?.querySelectorAll('.chart-wrapper') as NodeListOf<HTMLDivElement>) ??
|
|
189
|
+
[]
|
|
150
190
|
if (!this.boxes.length) return
|
|
151
191
|
this.origWidth =
|
|
152
192
|
this.boxes?.map((b) => b.getBoundingClientRect().width).reduce((p, c) => (c > p ? c : p), 0) ?? 0
|
|
@@ -161,26 +201,26 @@ export class WidgetGauge extends LitElement {
|
|
|
161
201
|
const userHeight = this.gaugeContainer.getBoundingClientRect().height
|
|
162
202
|
const count = this.dataSets.length
|
|
163
203
|
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
if (!userHeight || !userWidth || !
|
|
204
|
+
const chartW = this.origWidth
|
|
205
|
+
const chartH = this.origHeight
|
|
206
|
+
if (!userHeight || !userWidth || !chartW || !chartH) return
|
|
167
207
|
const fits = []
|
|
168
208
|
for (let c = 1; c <= count; c++) {
|
|
169
209
|
const r = Math.ceil(count / c)
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
const m =
|
|
173
|
-
const size = m * m *
|
|
174
|
-
if (r * m *
|
|
210
|
+
const netWidth = userWidth - 24 * (c - 1) // subtract the gaps between the charts
|
|
211
|
+
const netHeight = userHeight - 24 * (r - 1)
|
|
212
|
+
const m = netWidth / chartW / c // modifying factor to make it fit
|
|
213
|
+
const size = m * m * chartW * chartH * count // screen space used by charts overall
|
|
214
|
+
if (r * m * chartH <= netHeight) fits.push({ c, r, m, size, uwgap: netWidth, uhgap: netHeight })
|
|
175
215
|
}
|
|
176
216
|
|
|
177
217
|
for (let r = 1; r <= count; r++) {
|
|
178
218
|
const c = Math.ceil(count / r)
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
const m =
|
|
182
|
-
const size = m * m *
|
|
183
|
-
if (c * m *
|
|
219
|
+
const netWidth = userWidth - 24 * (c - 1)
|
|
220
|
+
const netHeight = userHeight - 24 * (r - 1)
|
|
221
|
+
const m = netHeight / chartH / r
|
|
222
|
+
const size = m * m * chartW * chartH * count
|
|
223
|
+
if (c * m * chartW <= netWidth) fits.push({ c, r, m, size, uwgap: netWidth, uhgap: netHeight })
|
|
184
224
|
}
|
|
185
225
|
|
|
186
226
|
const maxSize = fits.reduce((p, c) => (c.size < p ? p : c.size), 0)
|
|
@@ -202,39 +242,45 @@ export class WidgetGauge extends LitElement {
|
|
|
202
242
|
this.boxes = Array.from(this?.shadowRoot?.querySelectorAll('.chart') as NodeListOf<HTMLDivElement>)
|
|
203
243
|
|
|
204
244
|
this.boxes?.forEach((box) =>
|
|
205
|
-
box.setAttribute('style', `width:${modifier *
|
|
245
|
+
box.setAttribute('style', `width:${modifier * chartW}px; height:${modifier * (chartH - 25)}px`)
|
|
206
246
|
)
|
|
207
247
|
|
|
208
248
|
this.modifier = modifier
|
|
209
249
|
|
|
210
250
|
for (const canvas in this.canvasList) {
|
|
211
|
-
this.canvasList[canvas].resize()
|
|
251
|
+
this.canvasList[canvas].echart.resize()
|
|
212
252
|
}
|
|
213
253
|
this.applyData()
|
|
214
254
|
}
|
|
215
255
|
|
|
216
256
|
async transformData() {
|
|
217
|
-
|
|
257
|
+
// console.log('Transforming data', this.inputData?.dataseries)
|
|
218
258
|
this.dataSets = []
|
|
219
|
-
this
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
259
|
+
if (!this?.inputData) return
|
|
260
|
+
this.inputData.dataseries
|
|
261
|
+
?.sort((a, b) => ((a.label ?? '') > (b.label ?? '') ? 1 : -1))
|
|
262
|
+
.forEach((ds) => {
|
|
263
|
+
// pivot data
|
|
264
|
+
const distincts = [...new Set(ds?.data?.map((d: Data) => d.pivot))]
|
|
265
|
+
|
|
266
|
+
distincts.forEach((piv) => {
|
|
267
|
+
const prefix = piv ?? ''
|
|
268
|
+
const label = ds.label ?? ''
|
|
269
|
+
const pds: any = {
|
|
270
|
+
label: prefix + (!!prefix && !!label ? ' - ' : '') + label,
|
|
271
|
+
unit: ds.unit,
|
|
272
|
+
precision: ds.precision,
|
|
273
|
+
advanced: ds.advanced,
|
|
274
|
+
valueColor: ds.valueColor,
|
|
275
|
+
sections: ds.sections,
|
|
276
|
+
data: distincts.length === 1 ? ds.data : ds?.data?.filter((d) => d.pivot === piv)
|
|
277
|
+
}
|
|
278
|
+
this.dataSets.push(pds)
|
|
279
|
+
})
|
|
234
280
|
})
|
|
235
|
-
})
|
|
236
281
|
|
|
237
282
|
this.setupCharts()
|
|
283
|
+
this.adjustSizes()
|
|
238
284
|
}
|
|
239
285
|
|
|
240
286
|
applyData() {
|
|
@@ -265,13 +311,13 @@ export class WidgetGauge extends LitElement {
|
|
|
265
311
|
ds.ranges = ds.sections?.sectionLimits?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
|
|
266
312
|
|
|
267
313
|
// const option = this.canvasList[ds.label].getOption()
|
|
268
|
-
const option = structuredClone(this.template)
|
|
314
|
+
const option = window.structuredClone(this.template)
|
|
269
315
|
const ga = option.series[0],
|
|
270
316
|
ga2 = option.series[1]
|
|
271
317
|
|
|
272
318
|
// Title
|
|
273
319
|
option.title.text = ds.label
|
|
274
|
-
option.title.textStyle.fontSize =
|
|
320
|
+
option.title.textStyle.fontSize = 25 * modifier
|
|
275
321
|
|
|
276
322
|
// Needle
|
|
277
323
|
// Check age of data Latency
|
|
@@ -283,11 +329,12 @@ export class WidgetGauge extends LitElement {
|
|
|
283
329
|
|
|
284
330
|
ga.data[0].value = ds.needleValue
|
|
285
331
|
ga.data[0].name = ds.unit
|
|
286
|
-
ga.title.fontSize =
|
|
287
|
-
ga.title.color = ds.valueColor ??
|
|
288
|
-
ga.detail.color = ds.valueColor ??
|
|
289
|
-
ga.detail.fontSize =
|
|
290
|
-
ga.detail.formatter = (val: number) =>
|
|
332
|
+
ga.title.fontSize = 25 * modifier
|
|
333
|
+
ga.title.color = ds.valueColor ?? this.themeColor
|
|
334
|
+
ga.detail.color = ds.valueColor ?? this.themeColor
|
|
335
|
+
ga.detail.fontSize = 40 * modifier
|
|
336
|
+
ga.detail.formatter = (val: number) =>
|
|
337
|
+
isNaN(val) ? '-' : val.toFixed(Math.floor(ds.precision ?? 0))
|
|
291
338
|
// ga.anchor.itemStyle.color = ds.valueColor
|
|
292
339
|
// ga.pointer.itemStyle.color = ds.valueColor
|
|
293
340
|
|
|
@@ -313,21 +360,29 @@ export class WidgetGauge extends LitElement {
|
|
|
313
360
|
ga2.splitLine.distance = -16 * modifier
|
|
314
361
|
|
|
315
362
|
// Progress
|
|
316
|
-
let progressColor =
|
|
317
|
-
ds.sections?.backgroundColors?.[ds.sections?.backgroundColors.length - 1] ?? 'green'
|
|
363
|
+
let progressColor = ds.sections?.backgroundColors?.[ds.sections?.backgroundColors.length - 1]
|
|
318
364
|
for (const [i, s] of ds.sections?.sectionLimits?.entries() ?? []) {
|
|
319
365
|
if (s > (ds.needleValue as number)) {
|
|
320
366
|
progressColor =
|
|
321
|
-
ds.sections?.backgroundColors?.[i - 1] ??
|
|
322
|
-
ds.sections?.backgroundColors?.[0] ??
|
|
323
|
-
'green'
|
|
367
|
+
ds.sections?.backgroundColors?.[i - 1] ?? ds.sections?.backgroundColors?.[0]
|
|
324
368
|
break
|
|
325
369
|
}
|
|
326
370
|
}
|
|
327
371
|
ga.progress.itemStyle.color = progressColor
|
|
328
|
-
ga.progress.width =
|
|
372
|
+
ga.progress.width = 60 * modifier
|
|
329
373
|
// Apply
|
|
330
|
-
this.canvasList[ds.label ?? '']
|
|
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)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
deleteCharts() {
|
|
382
|
+
for (const label in this.canvasList) {
|
|
383
|
+
this.canvasList[label].echart.dispose()
|
|
384
|
+
this.canvasList[label].wrapper?.remove()
|
|
385
|
+
delete this.canvasList[label]
|
|
331
386
|
}
|
|
332
387
|
}
|
|
333
388
|
|
|
@@ -336,26 +391,38 @@ export class WidgetGauge extends LitElement {
|
|
|
336
391
|
for (const label in this.canvasList) {
|
|
337
392
|
const ex = this.dataSets.find((ds) => ds.label === label)
|
|
338
393
|
if (!ex) {
|
|
394
|
+
this.canvasList[label].echart.dispose()
|
|
395
|
+
this.canvasList[label].wrapper?.remove()
|
|
339
396
|
delete this.canvasList[label]
|
|
340
|
-
const containerDiv = this.gaugeContainer?.querySelector(`[name="${label}"]`)
|
|
341
|
-
containerDiv?.remove()
|
|
342
397
|
}
|
|
343
398
|
}
|
|
344
399
|
|
|
345
400
|
this.dataSets.forEach((ds) => {
|
|
346
401
|
if (this.canvasList[ds.label ?? '']) return
|
|
402
|
+
const newWrapper = document.createElement('div')
|
|
403
|
+
newWrapper.setAttribute('class', 'chart-wrapper')
|
|
404
|
+
const newTitle = document.createElement('h3')
|
|
405
|
+
newTitle.textContent = ds.label ?? ''
|
|
406
|
+
newTitle.style.fontSize = '20px'
|
|
347
407
|
const newCanvas = document.createElement('div')
|
|
348
408
|
newCanvas.setAttribute('name', ds.label ?? '')
|
|
349
409
|
newCanvas.setAttribute('class', 'chart')
|
|
350
410
|
newCanvas.setAttribute(
|
|
351
411
|
'style',
|
|
352
|
-
`min-width: 600px; min-height:
|
|
412
|
+
`min-width: 600px; min-height: 250px; width: 600px; height: 250px;`
|
|
353
413
|
)
|
|
354
414
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
this.
|
|
358
|
-
|
|
415
|
+
newWrapper!.appendChild(newTitle)
|
|
416
|
+
newWrapper!.appendChild(newCanvas)
|
|
417
|
+
this.gaugeContainer!.appendChild(newWrapper)
|
|
418
|
+
|
|
419
|
+
const newChart = echarts.init(newCanvas, this.themeName)
|
|
420
|
+
this.canvasList[ds.label ?? ''] = { echart: newChart, title: newTitle, wrapper: newWrapper }
|
|
421
|
+
// this.canvasList[ds.label ?? ''].setOption(structuredClone(this.template))
|
|
422
|
+
//@ts-ignore
|
|
423
|
+
this.themeBgColor = newChart._theme.backgroundColor ?? '#fff'
|
|
424
|
+
//@ts-ignore
|
|
425
|
+
this.themeColor = newChart._theme.gauge?.title?.color ?? '#000'
|
|
359
426
|
})
|
|
360
427
|
this.sizingSetup()
|
|
361
428
|
}
|
|
@@ -381,6 +448,14 @@ export class WidgetGauge extends LitElement {
|
|
|
381
448
|
width: 100%;
|
|
382
449
|
padding: 16px;
|
|
383
450
|
box-sizing: border-box;
|
|
451
|
+
color: var(--re-text-color, #000);
|
|
452
|
+
gap: 12px;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
.chart-wrapper {
|
|
456
|
+
display: flex;
|
|
457
|
+
flex-direction: column;
|
|
458
|
+
align-items: center;
|
|
384
459
|
}
|
|
385
460
|
.gauge-container {
|
|
386
461
|
display: flex;
|
|
@@ -390,13 +465,12 @@ export class WidgetGauge extends LitElement {
|
|
|
390
465
|
flex-wrap: wrap;
|
|
391
466
|
overflow: hidden;
|
|
392
467
|
position: relative;
|
|
393
|
-
gap:
|
|
468
|
+
gap: 24px;
|
|
394
469
|
}
|
|
395
470
|
|
|
396
471
|
header {
|
|
397
472
|
display: flex;
|
|
398
473
|
flex-direction: column;
|
|
399
|
-
margin: 0 0 16px 0;
|
|
400
474
|
}
|
|
401
475
|
h3 {
|
|
402
476
|
margin: 0;
|
|
@@ -404,7 +478,6 @@ export class WidgetGauge extends LitElement {
|
|
|
404
478
|
overflow: hidden;
|
|
405
479
|
text-overflow: ellipsis;
|
|
406
480
|
white-space: nowrap;
|
|
407
|
-
color: var(--re-text-color, #000) !important;
|
|
408
481
|
}
|
|
409
482
|
p {
|
|
410
483
|
margin: 10px 0 0 0;
|
|
@@ -414,12 +487,11 @@ export class WidgetGauge extends LitElement {
|
|
|
414
487
|
overflow: hidden;
|
|
415
488
|
text-overflow: ellipsis;
|
|
416
489
|
white-space: nowrap;
|
|
417
|
-
color: var(--re-text-color, #000) !important;
|
|
418
490
|
}
|
|
419
491
|
|
|
420
492
|
.chart {
|
|
421
493
|
width: 600px; /* will be overriden by adjustSizes */
|
|
422
|
-
height:
|
|
494
|
+
height: 230px;
|
|
423
495
|
}
|
|
424
496
|
|
|
425
497
|
.no-data {
|
|
@@ -436,7 +508,7 @@ export class WidgetGauge extends LitElement {
|
|
|
436
508
|
|
|
437
509
|
render() {
|
|
438
510
|
return html`
|
|
439
|
-
<div class="wrapper">
|
|
511
|
+
<div class="wrapper" style="background-color: ${this.themeBgColor}; color: ${this.themeColor}">
|
|
440
512
|
<header class="paging" ?active=${this.inputData?.title || this.inputData?.subTitle}>
|
|
441
513
|
<h3 class="paging" ?active=${this.inputData?.title}>${this.inputData?.title}</h3>
|
|
442
514
|
<p class="paging" ?active=${this.inputData?.subTitle}>${this.inputData?.subTitle}</p>
|
|
@@ -447,5 +519,3 @@ export class WidgetGauge extends LitElement {
|
|
|
447
519
|
`
|
|
448
520
|
}
|
|
449
521
|
}
|
|
450
|
-
|
|
451
|
-
window.customElements.define('widget-gauge-versionplaceholder', WidgetGauge)
|