@record-evolution/widget-gauge 1.7.16 → 1.7.18
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 +4 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-gauge.js +57 -45
- package/dist/widget-gauge.js.map +1 -1
- package/package.json +1 -1
- package/src/default-data.json +1 -5
- package/src/widget-gauge.ts +22 -39
package/package.json
CHANGED
package/src/default-data.json
CHANGED
package/src/widget-gauge.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { html, css, LitElement, PropertyValueMap } from 'lit'
|
|
2
|
-
import { customElement, property, state } from 'lit/decorators.js'
|
|
1
|
+
import { html, css, LitElement, PropertyValueMap, PropertyValues } from 'lit'
|
|
2
|
+
import { customElement, property, query, state } from 'lit/decorators.js'
|
|
3
3
|
import { GaugeChartConfiguration, SectionBackgroundColors } from './definition-schema.js'
|
|
4
4
|
|
|
5
5
|
import * as echarts from 'echarts/core'
|
|
@@ -37,15 +37,17 @@ export class WidgetGauge extends LitElement {
|
|
|
37
37
|
@state() private themeTitleColor?: string
|
|
38
38
|
@state() private themeSubtitleColor?: string
|
|
39
39
|
|
|
40
|
+
@query('.gauge-container') private gaugeContainer?: HTMLDivElement
|
|
41
|
+
@query('.wrapper') private wrapper?: HTMLDivElement
|
|
42
|
+
|
|
40
43
|
private resizeObserver: ResizeObserver
|
|
41
44
|
|
|
42
45
|
boxes?: HTMLDivElement[]
|
|
43
|
-
origWidth: number =
|
|
44
|
-
origHeight: number =
|
|
46
|
+
origWidth: number = 600
|
|
47
|
+
origHeight: number = 350
|
|
45
48
|
template: EChartsOption
|
|
46
49
|
modifier: number = 1
|
|
47
50
|
version: string = 'versionplaceholder'
|
|
48
|
-
gaugeContainer: HTMLDivElement | null | undefined
|
|
49
51
|
|
|
50
52
|
constructor() {
|
|
51
53
|
super()
|
|
@@ -160,9 +162,6 @@ export class WidgetGauge extends LitElement {
|
|
|
160
162
|
if (changedProperties.has('inputData') && this.gaugeContainer) {
|
|
161
163
|
this.transformData()
|
|
162
164
|
this.setupCharts()
|
|
163
|
-
this.sizingSetup()
|
|
164
|
-
this.adjustSizes()
|
|
165
|
-
this.applyData()
|
|
166
165
|
}
|
|
167
166
|
|
|
168
167
|
if (changedProperties.has('theme')) {
|
|
@@ -170,20 +169,24 @@ export class WidgetGauge extends LitElement {
|
|
|
170
169
|
this.deleteCharts()
|
|
171
170
|
this.transformData()
|
|
172
171
|
this.setupCharts()
|
|
173
|
-
this.sizingSetup()
|
|
174
172
|
this.adjustSizes()
|
|
175
173
|
this.applyData()
|
|
176
174
|
}
|
|
177
175
|
super.update(changedProperties)
|
|
178
176
|
}
|
|
179
177
|
|
|
178
|
+
protected updated(changedProperties: PropertyValues): void {
|
|
179
|
+
if (changedProperties.has('inputData') && this.gaugeContainer) {
|
|
180
|
+
this.adjustSizes()
|
|
181
|
+
this.applyData()
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
180
185
|
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
181
|
-
this.resizeObserver.observe(this.
|
|
182
|
-
this.gaugeContainer = this.shadowRoot?.querySelector('.gauge-container')
|
|
186
|
+
if (this.wrapper) this.resizeObserver.observe(this.wrapper)
|
|
183
187
|
this.registerTheme(this.theme)
|
|
184
188
|
this.transformData()
|
|
185
189
|
this.setupCharts()
|
|
186
|
-
this.sizingSetup()
|
|
187
190
|
this.adjustSizes()
|
|
188
191
|
this.applyData()
|
|
189
192
|
}
|
|
@@ -197,23 +200,9 @@ export class WidgetGauge extends LitElement {
|
|
|
197
200
|
cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
|
|
198
201
|
|
|
199
202
|
if (!theme || !theme.theme_object || !theme.theme_name) return
|
|
200
|
-
|
|
201
203
|
echarts.registerTheme(theme.theme_name, theme.theme_object)
|
|
202
204
|
}
|
|
203
205
|
|
|
204
|
-
sizingSetup() {
|
|
205
|
-
if (this.origWidth !== 0 && this.origHeight !== 0) return
|
|
206
|
-
|
|
207
|
-
this.boxes =
|
|
208
|
-
Array.from(this?.shadowRoot?.querySelectorAll('.chart-wrapper') as NodeListOf<HTMLDivElement>) ??
|
|
209
|
-
[]
|
|
210
|
-
if (!this.boxes.length) return
|
|
211
|
-
this.origWidth = 600
|
|
212
|
-
// this.boxes?.map((b) => b.getBoundingClientRect().width).reduce((p, c) => (c > p ? c : p), 0) ?? 0
|
|
213
|
-
this.origHeight = 230
|
|
214
|
-
// this.boxes?.map((b) => b.getBoundingClientRect().height).reduce((p, c) => (c > p ? c : p), 0) ?? 0
|
|
215
|
-
}
|
|
216
|
-
|
|
217
206
|
adjustSizes() {
|
|
218
207
|
// if (!this.origHeight) return
|
|
219
208
|
if (!this.gaugeContainer) return
|
|
@@ -259,7 +248,7 @@ export class WidgetGauge extends LitElement {
|
|
|
259
248
|
// (userWidth * userHeight).toFixed(0),
|
|
260
249
|
// this.boxes
|
|
261
250
|
// )
|
|
262
|
-
this.boxes = Array.from(this?.
|
|
251
|
+
this.boxes = Array.from(this.gaugeContainer?.querySelectorAll('.chart') as NodeListOf<HTMLDivElement>)
|
|
263
252
|
|
|
264
253
|
this.boxes?.forEach((box) =>
|
|
265
254
|
box.setAttribute('style', `width:${modifier * chartW}px; height:${modifier * (chartH - 27)}px`)
|
|
@@ -280,8 +269,9 @@ export class WidgetGauge extends LitElement {
|
|
|
280
269
|
?.sort((a, b) => ((a.label ?? '') > (b.label ?? '') ? 1 : -1))
|
|
281
270
|
.forEach((ds) => {
|
|
282
271
|
// pivot data
|
|
283
|
-
const distincts =
|
|
284
|
-
|
|
272
|
+
const distincts = ds.multiChart
|
|
273
|
+
? ([...new Set(ds.data?.map((d: Data) => d.pivot))].sort() as string[])
|
|
274
|
+
: ['']
|
|
285
275
|
distincts.forEach((piv) => {
|
|
286
276
|
const prefix = piv ?? ''
|
|
287
277
|
const label = ds.label ?? ''
|
|
@@ -309,7 +299,6 @@ export class WidgetGauge extends LitElement {
|
|
|
309
299
|
})
|
|
310
300
|
|
|
311
301
|
this.dataSets.sort((a, b) => ((a.label as string) > (b.label as string) ? 1 : -1))
|
|
312
|
-
this.requestUpdate()
|
|
313
302
|
|
|
314
303
|
for (const ds of this.dataSets) {
|
|
315
304
|
// compute derivative values
|
|
@@ -319,7 +308,6 @@ export class WidgetGauge extends LitElement {
|
|
|
319
308
|
if (typeof ds.advanced?.averageLatest !== 'number' || isNaN(ds.advanced?.averageLatest))
|
|
320
309
|
ds.advanced.averageLatest = 1
|
|
321
310
|
const data = ds?.data?.slice(-ds.advanced?.averageLatest || -1) ?? []
|
|
322
|
-
console.log('multiChart', ds.multiChart)
|
|
323
311
|
if (!ds.multiChart) {
|
|
324
312
|
ds.needleValue = ds.value as number
|
|
325
313
|
} else {
|
|
@@ -355,10 +343,10 @@ export class WidgetGauge extends LitElement {
|
|
|
355
343
|
ga.data[0].name = ds.unit
|
|
356
344
|
// unit style
|
|
357
345
|
ga.title.fontSize = 20 * modifier
|
|
358
|
-
ga.title.color = ds.valueColor
|
|
346
|
+
ga.title.color = ds.valueColor || this.themeTitleColor
|
|
359
347
|
ga.title.opacity = 1
|
|
360
348
|
// value style
|
|
361
|
-
ga.detail.color = ds.valueColor
|
|
349
|
+
ga.detail.color = ds.valueColor || this.themeTitleColor
|
|
362
350
|
ga.detail.opacity = 1
|
|
363
351
|
ga.detail.fontSize = 40 * modifier
|
|
364
352
|
|
|
@@ -455,7 +443,7 @@ export class WidgetGauge extends LitElement {
|
|
|
455
443
|
newCanvas.setAttribute('class', 'chart')
|
|
456
444
|
newCanvas.setAttribute(
|
|
457
445
|
'style',
|
|
458
|
-
`min-width:
|
|
446
|
+
`min-width: ${this.origWidth}; min-height: ${this.origHeight}; width: ${this.origWidth}; height: ${this.origHeight};`
|
|
459
447
|
)
|
|
460
448
|
|
|
461
449
|
newWrapper!.appendChild(newTitle)
|
|
@@ -527,11 +515,6 @@ export class WidgetGauge extends LitElement {
|
|
|
527
515
|
white-space: nowrap;
|
|
528
516
|
}
|
|
529
517
|
|
|
530
|
-
.chart {
|
|
531
|
-
width: 600px; /* will be overriden by adjustSizes */
|
|
532
|
-
height: 230px;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
518
|
.no-data {
|
|
536
519
|
font-size: 20px;
|
|
537
520
|
display: flex;
|