@record-evolution/widget-gauge 1.5.21 → 1.5.22

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.
@@ -1,394 +1,410 @@
1
- import { html, css, LitElement, PropertyValueMap } from 'lit';
1
+ import { html, css, LitElement, PropertyValueMap } from 'lit'
2
2
  import { repeat } from 'lit/directives/repeat.js'
3
- import { property, state } from 'lit/decorators.js';
3
+ import { property, state } from 'lit/decorators.js'
4
4
  // import * as echarts from "echarts";
5
- import { InputData, Data, Dataseries } from './types.js';
6
- import type { EChartsOption, GaugeSeriesOption } from 'echarts';
5
+ import type { EChartsOption, GaugeSeriesOption } from 'echarts'
6
+ import { GaugeChartConfiguration } from './definition-schema.js'
7
7
 
8
8
  // echarts.use([GaugeChart, CanvasRenderer]);
9
9
 
10
- export class WidgetGauge extends LitElement {
10
+ type Dataseries = Exclude<GaugeChartConfiguration['dataseries'], undefined>[number]
11
+ type Data = Exclude<Dataseries['data'], undefined>[number]
11
12
 
12
- @property({ type: Object })
13
- inputData?: InputData = undefined
14
-
15
- @state()
16
- private dataSets: Dataseries[] = []
17
-
18
- @state()
19
- private canvasList: any = {}
20
-
21
- resizeObserver: ResizeObserver
22
- boxes?: HTMLDivElement[]
23
- origWidth: number = 0
24
- origHeight: number = 0
25
- template: EChartsOption
26
- modifier: number = 1
27
- version: string = 'versionplaceholder'
28
- constructor() {
29
- super()
30
- this.resizeObserver = new ResizeObserver(this.adjustSizes.bind(this))
31
-
32
- this.template = {
33
- title: {
34
- text: 'Gauge',
35
- left: 'center',
36
- textStyle: {
37
- fontSize: 10
13
+ export class WidgetGauge extends LitElement {
14
+ @property({ type: Object })
15
+ inputData?: GaugeChartConfiguration
16
+
17
+ @state()
18
+ private dataSets: Dataseries[] = []
19
+
20
+ @state()
21
+ private canvasList: any = {}
22
+
23
+ resizeObserver: ResizeObserver
24
+ boxes?: HTMLDivElement[]
25
+ origWidth: number = 0
26
+ origHeight: number = 0
27
+ template: EChartsOption
28
+ modifier: number = 1
29
+ version: string = 'versionplaceholder'
30
+ constructor() {
31
+ super()
32
+ this.resizeObserver = new ResizeObserver(this.adjustSizes.bind(this))
33
+
34
+ this.template = {
35
+ title: {
36
+ text: 'Gauge',
37
+ left: 'center',
38
+ textStyle: {
39
+ fontSize: 10
40
+ }
41
+ },
42
+ series: [
43
+ {
44
+ type: 'gauge',
45
+ startAngle: 180,
46
+ endAngle: 0,
47
+ min: 33,
48
+ max: 99,
49
+ radius: '120%',
50
+ center: ['50%', '90%'],
51
+ progress: {
52
+ show: true,
53
+ clip: true,
54
+ width: 50,
55
+ roundCap: false,
56
+ itemStyle: {
57
+ color: 'auto'
58
+ }
59
+ },
60
+ axisLine: { show: false },
61
+ axisTick: { show: false },
62
+ splitLine: { show: false },
63
+ axisLabel: { show: false },
64
+ anchor: { show: false },
65
+ pointer: { show: false },
66
+ detail: {
67
+ valueAnimation: false,
68
+ fontSize: 25,
69
+ offsetCenter: [0, '-7%'],
70
+ color: 'inherit',
71
+ formatter: (val) => (isNaN(val) ? '-' : val.toFixed())
72
+ },
73
+ title: {
74
+ offsetCenter: [0, '-35%'],
75
+ fontSize: 20
76
+ },
77
+ data: [
78
+ {
79
+ value: 70
80
+ }
81
+ ]
82
+ } as GaugeSeriesOption,
83
+ {
84
+ type: 'gauge',
85
+ startAngle: 180,
86
+ endAngle: 0,
87
+ min: 33,
88
+ max: 99,
89
+ radius: '125%',
90
+ center: ['50%', '90%'],
91
+ axisLine: {
92
+ lineStyle: {
93
+ width: 20,
94
+ color: [
95
+ [0.2, '#67e0e3'],
96
+ [0.8, '#37a2da'],
97
+ [1, '#fd666d']
98
+ ]
99
+ }
100
+ },
101
+ axisTick: { show: false },
102
+ splitLine: {
103
+ length: 15,
104
+ distance: -25,
105
+ lineStyle: {
106
+ width: 2,
107
+ color: 'auto'
108
+ }
109
+ },
110
+ axisLabel: {
111
+ distance: -20,
112
+ color: '#999',
113
+ rotate: 'tangential',
114
+ fontSize: 12
115
+ }
116
+ } as GaugeSeriesOption
117
+ ]
38
118
  }
39
- },
40
- series: [
41
- {
42
- type: 'gauge',
43
- startAngle: 180,
44
- endAngle: 0,
45
- min: 33,
46
- max: 99,
47
- radius: '120%',
48
- center: ['50%', '90%'],
49
- progress: {
50
- show: true,
51
- clip: true,
52
- width: 50,
53
- roundCap: false,
54
- itemStyle: {
55
- color: 'auto'
56
- }
57
- },
58
- axisLine: { show: false },
59
- axisTick: { show: false },
60
- splitLine: { show: false },
61
- axisLabel: { show: false },
62
- anchor: { show: false },
63
- pointer: { show: false },
64
- detail: {
65
- valueAnimation: false,
66
- fontSize: 25,
67
- offsetCenter: [0, '-7%'],
68
- color: 'inherit',
69
- formatter: (val) => isNaN(val) ? '-' : val.toFixed()
70
- },
71
- title: {
72
- offsetCenter: [0, '-35%'],
73
- fontSize: 20
74
- },
75
- data: [
76
- {
77
- value: 70,
78
- }
79
- ]
80
- } as GaugeSeriesOption,
81
- {
82
- type: 'gauge',
83
- startAngle: 180,
84
- endAngle: 0,
85
- min: 33,
86
- max: 99,
87
- radius: '125%',
88
- center: ['50%', '90%'],
89
- axisLine: {
90
- lineStyle: {
91
- width: 20,
92
- color: [
93
- [0.2, '#67e0e3'],
94
- [0.8, '#37a2da'],
95
- [1, '#fd666d']
96
- ]
97
- }
98
- },
99
- axisTick: { show: false },
100
- splitLine: {
101
- length: 15,
102
- distance: -25,
103
- lineStyle: {
104
- width: 2,
105
- color: 'auto',
119
+ }
120
+
121
+ update(changedProperties: Map<string, any>) {
122
+ changedProperties.forEach((oldValue, propName) => {
123
+ if (propName === 'inputData') {
124
+ this.transformData()
125
+ this.applyData()
106
126
  }
107
- },
108
- axisLabel: {
109
- distance: -20,
110
- color: '#999',
111
- rotate: 'tangential',
112
- fontSize: 12,
113
- },
114
- } as GaugeSeriesOption,
115
- ]
116
- };
117
-
118
- }
119
-
120
- update(changedProperties: Map<string, any>) {
121
- changedProperties.forEach((oldValue, propName) => {
122
- if (propName === 'inputData') {
127
+ })
128
+
129
+ super.update(changedProperties)
130
+ }
131
+
132
+ protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
133
+ this.resizeObserver.observe(this.shadowRoot?.querySelector('.wrapper') as HTMLDivElement)
134
+
135
+ this.sizingSetup()
123
136
  this.transformData()
137
+ this.adjustSizes()
124
138
  this.applyData()
125
- }
126
- })
127
-
128
- super.update(changedProperties)
129
- }
130
-
131
- protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
132
- this.resizeObserver.observe(this.shadowRoot?.querySelector('.wrapper') as HTMLDivElement)
133
-
134
- this.sizingSetup()
135
- this.transformData()
136
- this.adjustSizes()
137
- this.applyData()
138
-
139
- }
140
-
141
- sizingSetup() {
142
- if (this.origWidth !== 0 && this.origHeight !== 0) return
143
-
144
- this.boxes = Array.from(this?.shadowRoot?.querySelectorAll('.chart') as NodeListOf<HTMLDivElement>)
145
- if (!this.boxes.length) return
146
- this.origWidth = this.boxes?.map(b => b.getBoundingClientRect().width).reduce((p, c) => c > p ? c : p, 0) ?? 0
147
- this.origHeight = this.boxes?.map(b => b.getBoundingClientRect().height).reduce((p, c) => c > p ? c : p, 0) ?? 0
148
-
149
- if (this.origWidth > 0) this.origWidth += 16
150
- if (this.origHeight > 0) this.origHeight += 16
151
- // console.log('OrigWidth', this.origWidth, this.origHeight)
152
-
153
- }
154
-
155
- adjustSizes() {
156
- // if (!this.origHeight) return
157
- const container = this.shadowRoot?.querySelector('.gauge-container') as HTMLDivElement
158
- if (!container) return
159
- const userWidth = container.getBoundingClientRect().width
160
- const userHeight = container.getBoundingClientRect().height
161
- const count = this.dataSets.length
162
-
163
- const width = this.origWidth
164
- const height = this.origHeight
165
- if (!userHeight || !userWidth || !width || !height) return
166
- const fits = []
167
- for (let c = 1; c <= count; c++) {
168
- const r = Math.ceil(count / c)
169
- const uwgap = (userWidth - 12 * (c - 1))
170
- const uhgap = (userHeight - 12 * (r - 1))
171
- const m = uwgap / width / c
172
- const size = m * m * width * height * count
173
- if (r * m * height < uhgap) fits.push({ c, m, size, width, height, userWidth, userHeight })
174
139
  }
175
140
 
176
- for (let r = 1; r <= count; r++) {
177
- const c = Math.ceil(count / r)
178
- const uwgap = (userWidth - 12 * (c - 1))
179
- const uhgap = (userHeight - 12 * (r - 1))
180
- const m = uhgap / height / r
181
- const size = m * m * width * height * count
182
- if (c * m * width < uwgap) fits.push({ r, m, size, width, height, userWidth, userHeight })
141
+ sizingSetup() {
142
+ if (this.origWidth !== 0 && this.origHeight !== 0) return
143
+
144
+ this.boxes = Array.from(this?.shadowRoot?.querySelectorAll('.chart') as NodeListOf<HTMLDivElement>)
145
+ if (!this.boxes.length) return
146
+ this.origWidth =
147
+ this.boxes?.map((b) => b.getBoundingClientRect().width).reduce((p, c) => (c > p ? c : p), 0) ?? 0
148
+ this.origHeight =
149
+ this.boxes?.map((b) => b.getBoundingClientRect().height).reduce((p, c) => (c > p ? c : p), 0) ?? 0
150
+
151
+ if (this.origWidth > 0) this.origWidth += 16
152
+ if (this.origHeight > 0) this.origHeight += 16
153
+ // console.log('OrigWidth', this.origWidth, this.origHeight)
183
154
  }
184
155
 
185
- const maxSize = fits.reduce((p, c) => c.size < p ? p : c.size, 0)
186
- const fit = fits.find(f => f.size === maxSize)
187
- const modifier = (fit?.m ?? 0)
156
+ adjustSizes() {
157
+ // if (!this.origHeight) return
158
+ const container = this.shadowRoot?.querySelector('.gauge-container') as HTMLDivElement
159
+ if (!container) return
160
+ const userWidth = container.getBoundingClientRect().width
161
+ const userHeight = container.getBoundingClientRect().height
162
+ const count = this.dataSets.length
163
+
164
+ const width = this.origWidth
165
+ const height = this.origHeight
166
+ if (!userHeight || !userWidth || !width || !height) return
167
+ const fits = []
168
+ for (let c = 1; c <= count; c++) {
169
+ const r = Math.ceil(count / c)
170
+ const uwgap = userWidth - 12 * (c - 1)
171
+ const uhgap = userHeight - 12 * (r - 1)
172
+ const m = uwgap / width / c
173
+ const size = m * m * width * height * count
174
+ if (r * m * height < uhgap) fits.push({ c, m, size, width, height, userWidth, userHeight })
175
+ }
188
176
 
189
- // console.log('FITS count', count, userWidth, userHeight, 'modifier', modifier, 'cols',fit?.c, 'rows', fit?.r, 'new size', fit?.size.toFixed(0), 'total space', (userWidth* userHeight).toFixed(0))
177
+ for (let r = 1; r <= count; r++) {
178
+ const c = Math.ceil(count / r)
179
+ const uwgap = userWidth - 12 * (c - 1)
180
+ const uhgap = userHeight - 12 * (r - 1)
181
+ const m = uhgap / height / r
182
+ const size = m * m * width * height * count
183
+ if (c * m * width < uwgap) fits.push({ r, m, size, width, height, userWidth, userHeight })
184
+ }
190
185
 
191
- this.boxes?.forEach(box => box.setAttribute("style", `width:${modifier * width}px; height:${modifier * height}px`))
186
+ const maxSize = fits.reduce((p, c) => (c.size < p ? p : c.size), 0)
187
+ const fit = fits.find((f) => f.size === maxSize)
188
+ const modifier = fit?.m ?? 0
192
189
 
193
- this.modifier = modifier
190
+ // console.log('FITS count', count, userWidth, userHeight, 'modifier', modifier, 'cols',fit?.c, 'rows', fit?.r, 'new size', fit?.size.toFixed(0), 'total space', (userWidth* userHeight).toFixed(0))
194
191
 
195
- for (const canvas in this.canvasList) {
196
- this.canvasList[canvas].resize()
197
- }
198
- this.applyData()
199
- }
200
-
201
- async transformData() {
202
- if (!this?.inputData) return
203
- this.dataSets = []
204
- this.inputData.dataseries?.forEach(ds => {
205
- // pivot data
206
- const distincts = [...new Set(ds.data.map((d: Data) => d.pivot))]
207
- if (distincts.length > 1) {
208
- distincts.forEach((piv) => {
209
- const pds: any = {
210
- label: `${ds.label} ${piv}`,
211
- unit: ds.unit,
212
- averageLatest: ds.averageLatest,
213
- valueColor: ds.valueColor,
214
- sections: ds.sections,
215
- backgroundColors: ds.backgroundColors,
216
- data: ds.data.filter(d => d.pivot === piv)
217
- }
218
- this.dataSets.push(pds)
219
- })
220
- } else {
221
- this.dataSets.push(ds)
222
- }
223
- })
224
-
225
- // console.log('Gauge Datasets', this.dataSets)
226
-
227
- }
228
-
229
- applyData() {
230
- const modifier = this.modifier
231
- this.setupCharts()
232
- for (const ds of this.dataSets) {
233
-
234
- // compute derivative values
235
- // filter latest values and calculate average
236
- if (typeof ds.averageLatest !== 'number' || !isNaN(ds.averageLatest)) ds.averageLatest = 1
237
- ds.data = ds.data.splice(-ds.averageLatest || -1)
238
- ds.needleValue = ds.data.map(d => d.value).reduce((p, c) => p + c, 0) / ds.data.length ?? ds.sections?.[0]
239
-
240
- ds.range = ds.sections?.[ds.sections?.length - 1] - ds.sections?.[0] ?? 100
241
- if (isNaN(ds.range)) ds.range = 100
242
- ds.ranges = ds.sections?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
243
-
244
- // const option = this.canvasList[ds.label].getOption()
245
- const option = JSON.parse(JSON.stringify(this.template))
246
- const ga = option.series[0],
247
- ga2 = option.series[1]
248
-
249
- // Title
250
- option.title.text = ds.label
251
- option.title.textStyle.fontSize = 22 * modifier
252
-
253
- // Needle
254
- ga.data[0].value = ds.needleValue
255
- ga.data[0].name = ds.unit
256
- ga.title.fontSize = 20 * modifier
257
- ga.title.color = ds.valueColor ?? 'black'
258
- ga.detail.color = ds.valueColor ?? 'black'
259
- ga.detail.fontSize = 40 * modifier
260
- ga.detail.formatter = (val: number) => isNaN(val) ? '-' : val.toFixed(0)
261
- // ga.anchor.itemStyle.color = ds.valueColor
262
- // ga.pointer.itemStyle.color = ds.valueColor
263
-
264
- // Axis
265
- ga2.min = ds.sections?.length ? Math.min(...ds.sections) : 0
266
- ga2.max = ds.sections?.length ? Math.max(...ds.sections) : 100
267
- ga.min = ga2.min
268
- ga.max = ga2.max
269
- // @ts-ignore
270
- const colorSections = ds.backgroundColors?.map((b: string, i) => [(ds.sections?.[i + 1] - ga.min) / ds.range, b]).filter(([s]) => !isNaN(s))
271
- ga2.axisLine.lineStyle.width = 8 * modifier
272
- ga2.axisLine.lineStyle.color = colorSections?.length ? colorSections : ga2.axisLine.lineStyle.color
273
- ga2.axisLabel.fontSize = 20 * modifier
274
- // ga2.axisLabel.color = ds.valueColor
275
- ga2.axisLabel.distance = -24 * modifier
276
- ga2.splitLine.length = 16 * modifier
277
- ga2.splitLine.distance = -16 * modifier
278
-
279
- // Progress
280
- let progressColor: string = ds.backgroundColors?.[ds.backgroundColors.length - 1] ?? 'green'
281
- for (const [i, s] of ds.sections?.entries() ?? []) {
282
- if (s > ds.needleValue) {
283
- progressColor = ds.backgroundColors[i - 1] ?? ds.backgroundColors[0]
284
- break
192
+ this.boxes?.forEach((box) =>
193
+ box.setAttribute('style', `width:${modifier * width}px; height:${modifier * height}px`)
194
+ )
195
+
196
+ this.modifier = modifier
197
+
198
+ for (const canvas in this.canvasList) {
199
+ this.canvasList[canvas].resize()
285
200
  }
286
- }
287
- ga.progress.itemStyle.color = progressColor
288
- ga.progress.width = 80 * modifier
289
- // Apply
290
- this.canvasList[ds.label]?.setOption(option)
201
+ this.applyData()
291
202
  }
292
203
 
293
- }
294
-
295
- setupCharts() {
204
+ async transformData() {
205
+ if (!this?.inputData) return
206
+ this.dataSets = []
207
+ this.inputData.dataseries?.forEach((ds) => {
208
+ // pivot data
209
+ const distincts = [...new Set(ds?.data?.map((d: Data) => d.pivot))]
210
+ if (distincts.length > 1) {
211
+ distincts.forEach((piv) => {
212
+ const pds: any = {
213
+ label: `${ds.label} ${piv}`,
214
+ unit: ds.unit,
215
+ averageLatest: ds.averageLatest,
216
+ valueColor: ds.valueColor,
217
+ sections: ds.sections,
218
+ backgroundColors: ds.backgroundColors,
219
+ data: ds?.data?.filter((d) => d.pivot === piv)
220
+ }
221
+ this.dataSets.push(pds)
222
+ })
223
+ } else {
224
+ this.dataSets.push(ds)
225
+ }
226
+ })
296
227
 
297
- // remove the gauge canvases of non provided data series
298
- for (const label in this.canvasList) {
299
- const ex = this.dataSets.find(ds => ds.label === label)
300
- if (!ex) delete this.canvasList[label]
228
+ // console.log('Gauge Datasets', this.dataSets)
301
229
  }
302
230
 
303
- this.dataSets.forEach(ds => {
304
- if (this.canvasList[ds.label]) return
305
- const canvas = this.shadowRoot?.querySelector(`[name="${ds.label}"]`) as HTMLCanvasElement;
306
- if (!canvas) return
307
- // @ts-ignore
308
- this.canvasList[ds.label] = echarts.init(canvas);
309
- this.canvasList[ds.label].setOption(JSON.parse(JSON.stringify(this.template)))
310
-
311
- })
312
-
313
- }
314
-
315
- static styles = css`
316
- :host {
317
- display: block;
318
- color: var(--re-text-color, #000);
319
- font-family: sans-serif;
320
- box-sizing: border-box;
321
- position: relative;
322
- margin: auto;
231
+ applyData() {
232
+ const modifier = this.modifier
233
+ this.setupCharts()
234
+ for (const ds of this.dataSets) {
235
+ // compute derivative values
236
+ // filter latest values and calculate average
237
+ if (typeof ds.averageLatest !== 'number' || !isNaN(ds.averageLatest)) ds.averageLatest = 1
238
+ ds.data = ds?.data?.splice(-ds.averageLatest || -1)
239
+ const values = (ds?.data?.map((d) => d.value)?.filter((p) => p !== undefined) ?? []) as number[]
240
+ const average = values.reduce((p, c) => p + c, 0) / values.length
241
+
242
+ ds.needleValue = isNaN(average) ? ds.sections?.[0] : average
243
+
244
+ ds.range = (ds.sections?.[ds.sections?.length - 1] ?? 100) - (ds.sections?.[0] ?? 0)
245
+ if (isNaN(ds.range as number)) ds.range = 100
246
+ ds.ranges = ds.sections?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
247
+
248
+ // const option = this.canvasList[ds.label].getOption()
249
+ const option = JSON.parse(JSON.stringify(this.template))
250
+ const ga = option.series[0],
251
+ ga2 = option.series[1]
252
+
253
+ // Title
254
+ option.title.text = ds.label
255
+ option.title.textStyle.fontSize = 22 * modifier
256
+
257
+ // Needle
258
+ ga.data[0].value = ds.needleValue
259
+ ga.data[0].name = ds.unit
260
+ ga.title.fontSize = 20 * modifier
261
+ ga.title.color = ds.valueColor ?? 'black'
262
+ ga.detail.color = ds.valueColor ?? 'black'
263
+ ga.detail.fontSize = 40 * modifier
264
+ ga.detail.formatter = (val: number) => (isNaN(val) ? '-' : val.toFixed(0))
265
+ // ga.anchor.itemStyle.color = ds.valueColor
266
+ // ga.pointer.itemStyle.color = ds.valueColor
267
+
268
+ // Axis
269
+ ga2.min = ds.sections?.length ? Math.min(...ds.sections) : 0
270
+ ga2.max = ds.sections?.length ? Math.max(...ds.sections) : 100
271
+ ga.min = ga2.min
272
+ ga.max = ga2.max
273
+ const colorSections = ds.backgroundColors
274
+ ?.map((b, i) => [((ds.sections?.[i + 1] ?? ga.min) - ga.min) / (ds.range as number), b])
275
+ .filter(([s]) => !isNaN(s as number))
276
+ ga2.axisLine.lineStyle.width = 8 * modifier
277
+ ga2.axisLine.lineStyle.color = colorSections?.length
278
+ ? colorSections
279
+ : ga2.axisLine.lineStyle.color
280
+ ga2.axisLabel.fontSize = 20 * modifier
281
+ // ga2.axisLabel.color = ds.valueColor
282
+ ga2.axisLabel.distance = -24 * modifier
283
+ ga2.splitLine.length = 16 * modifier
284
+ ga2.splitLine.distance = -16 * modifier
285
+
286
+ // Progress
287
+ let progressColor = ds.backgroundColors?.[ds.backgroundColors.length - 1] ?? 'green'
288
+ for (const [i, s] of ds.sections?.entries() ?? []) {
289
+ if (s > (ds.needleValue as number)) {
290
+ progressColor = ds.backgroundColors?.[i - 1] ?? ds.backgroundColors?.[0] ?? 'green'
291
+ break
292
+ }
293
+ }
294
+ ga.progress.itemStyle.color = progressColor
295
+ ga.progress.width = 80 * modifier
296
+ // Apply
297
+ this.canvasList[ds.label]?.setOption(option)
298
+ }
323
299
  }
324
300
 
325
- .paging:not([active]) { display: none !important; }
301
+ setupCharts() {
302
+ // remove the gauge canvases of non provided data series
303
+ for (const label in this.canvasList) {
304
+ const ex = this.dataSets.find((ds) => ds.label === label)
305
+ if (!ex) delete this.canvasList[label]
306
+ }
326
307
 
327
- .wrapper {
328
- display: flex;
329
- flex-direction: column;
330
- height: 100%;
331
- width: 100%;
332
- padding: 16px;
333
- box-sizing: border-box;
334
- }
335
- .gauge-container {
336
- display: flex;
337
- flex: 1;
338
- justify-content: center;
339
- align-items: center;
340
- flex-wrap: wrap;
341
- overflow: hidden;
342
- position: relative;
343
- gap: 12px;
308
+ this.dataSets.forEach((ds) => {
309
+ if (this.canvasList[ds.label]) return
310
+ const canvas = this.shadowRoot?.querySelector(`[name="${ds.label}"]`) as HTMLCanvasElement
311
+ if (!canvas) return
312
+ // @ts-ignore
313
+ this.canvasList[ds.label] = echarts.init(canvas)
314
+ this.canvasList[ds.label].setOption(JSON.parse(JSON.stringify(this.template)))
315
+ })
344
316
  }
345
317
 
346
- header {
347
- display: flex;
348
- flex-direction: column;
349
- margin: 0 0 16px 0;
350
- }
351
- h3 {
352
- margin: 0;
353
- max-width: 300px;
354
- overflow: hidden;
355
- text-overflow: ellipsis;
356
- white-space: nowrap;
357
- color: var(--re-text-color, #000) !important;
358
- }
359
- p {
360
- margin: 10px 0 0 0;
361
- max-width: 300px;
362
- font-size: 14px;
363
- line-height: 17px;
364
- overflow: hidden;
365
- text-overflow: ellipsis;
366
- white-space: nowrap;
367
- color: var(--re-text-color, #000) !important;
368
- }
318
+ static styles = css`
319
+ :host {
320
+ display: block;
321
+ color: var(--re-text-color, #000);
322
+ font-family: sans-serif;
323
+ box-sizing: border-box;
324
+ position: relative;
325
+ margin: auto;
326
+ }
369
327
 
370
- .chart {
371
- width: 600px; /* will be overriden by adjustSizes */
372
- height: 300px;
373
- }
328
+ .paging:not([active]) {
329
+ display: none !important;
330
+ }
331
+
332
+ .wrapper {
333
+ display: flex;
334
+ flex-direction: column;
335
+ height: 100%;
336
+ width: 100%;
337
+ padding: 16px;
338
+ box-sizing: border-box;
339
+ }
340
+ .gauge-container {
341
+ display: flex;
342
+ flex: 1;
343
+ justify-content: center;
344
+ align-items: center;
345
+ flex-wrap: wrap;
346
+ overflow: hidden;
347
+ position: relative;
348
+ gap: 12px;
349
+ }
374
350
 
375
- `;
376
-
377
- render() {
378
- return html`
379
- <div class="wrapper">
380
- <header>
381
- <h3 class="paging" ?active=${this.inputData?.settings?.title}>${this.inputData?.settings?.title}</h3>
382
- <p class="paging" ?active=${this.inputData?.settings?.subTitle}>${this.inputData?.settings?.subTitle}</p>
383
- </header>
384
- <div class="gauge-container">
385
- ${repeat(this.dataSets, ds => ds.label, ds => html`
386
- <div name="${ds.label}" class="chart" style="min-width: 600px; min-height: 300px; width: 600px; height: 300px;"></div>
387
- `)}
388
- </div>
389
- </div>
390
- `;
391
- }
351
+ header {
352
+ display: flex;
353
+ flex-direction: column;
354
+ margin: 0 0 16px 0;
355
+ }
356
+ h3 {
357
+ margin: 0;
358
+ max-width: 300px;
359
+ overflow: hidden;
360
+ text-overflow: ellipsis;
361
+ white-space: nowrap;
362
+ color: var(--re-text-color, #000) !important;
363
+ }
364
+ p {
365
+ margin: 10px 0 0 0;
366
+ max-width: 300px;
367
+ font-size: 14px;
368
+ line-height: 17px;
369
+ overflow: hidden;
370
+ text-overflow: ellipsis;
371
+ white-space: nowrap;
372
+ color: var(--re-text-color, #000) !important;
373
+ }
374
+
375
+ .chart {
376
+ width: 600px; /* will be overriden by adjustSizes */
377
+ height: 300px;
378
+ }
379
+ `
380
+
381
+ render() {
382
+ return html`
383
+ <div class="wrapper">
384
+ <header>
385
+ <h3 class="paging" ?active=${this.inputData?.settings?.title}>
386
+ ${this.inputData?.settings?.title}
387
+ </h3>
388
+ <p class="paging" ?active=${this.inputData?.settings?.subTitle}>
389
+ ${this.inputData?.settings?.subTitle}
390
+ </p>
391
+ </header>
392
+ <div class="gauge-container">
393
+ ${repeat(
394
+ this.dataSets,
395
+ (ds) => ds.label,
396
+ (ds) => html`
397
+ <div
398
+ name="${ds.label}"
399
+ class="chart"
400
+ style="min-width: 600px; min-height: 300px; width: 600px; height: 300px;"
401
+ ></div>
402
+ `
403
+ )}
404
+ </div>
405
+ </div>
406
+ `
407
+ }
392
408
  }
393
409
 
394
- window.customElements.define('widget-gauge-versionplaceholder', WidgetGauge);
410
+ window.customElements.define('widget-gauge-versionplaceholder', WidgetGauge)