@record-evolution/widget-gauge 1.7.2 → 1.7.4
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 +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-gauge.js +43 -22
- package/dist/widget-gauge.js.map +1 -1
- package/package.json +1 -3
- package/src/widget-gauge.ts +40 -24
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.7.
|
|
6
|
+
"version": "1.7.4",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/widget-gauge.js",
|
|
9
9
|
"types": "dist/src/widget-gauge.d.ts",
|
|
@@ -19,8 +19,6 @@
|
|
|
19
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
21
|
"types": "cat src/definition-schema.json | json2ts --style.tabWidth=4 > src/definition-schema.d.ts",
|
|
22
|
-
"lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
|
|
23
|
-
"format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
|
|
24
22
|
"release": "npm run build && npm run types && npm version patch --tag-version-prefix='' && git push && git push --tag"
|
|
25
23
|
},
|
|
26
24
|
"dependencies": {
|
package/src/widget-gauge.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { GaugeChartConfiguration } from './definition-schema.js'
|
|
|
5
5
|
import * as echarts from 'echarts/core'
|
|
6
6
|
import { TooltipComponent } from 'echarts/components'
|
|
7
7
|
import { GaugeChart, GaugeSeriesOption } from 'echarts/charts'
|
|
8
|
-
import { CanvasRenderer
|
|
8
|
+
import { CanvasRenderer } from 'echarts/renderers'
|
|
9
9
|
import { EChartsOption, SeriesOption } from 'echarts'
|
|
10
10
|
|
|
11
11
|
echarts.use([TooltipComponent, GaugeChart, CanvasRenderer])
|
|
@@ -33,11 +33,9 @@ export class WidgetGauge extends LitElement {
|
|
|
33
33
|
{ echart?: echarts.ECharts; title?: HTMLHeadingElement; wrapper?: HTMLDivElement }
|
|
34
34
|
> = new Map()
|
|
35
35
|
|
|
36
|
-
@state()
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
@state()
|
|
40
|
-
private themeColor?: string
|
|
36
|
+
@state() private themeBgColor?: string
|
|
37
|
+
@state() private themeTitleColor?: string
|
|
38
|
+
@state() private themeSubtitleColor?: string
|
|
41
39
|
|
|
42
40
|
private resizeObserver: ResizeObserver
|
|
43
41
|
|
|
@@ -51,7 +49,10 @@ export class WidgetGauge extends LitElement {
|
|
|
51
49
|
|
|
52
50
|
constructor() {
|
|
53
51
|
super()
|
|
54
|
-
this.resizeObserver = new ResizeObserver(
|
|
52
|
+
this.resizeObserver = new ResizeObserver(() => {
|
|
53
|
+
this.adjustSizes()
|
|
54
|
+
this.applyData()
|
|
55
|
+
})
|
|
55
56
|
|
|
56
57
|
this.template = {
|
|
57
58
|
title: {
|
|
@@ -159,12 +160,19 @@ export class WidgetGauge extends LitElement {
|
|
|
159
160
|
update(changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
160
161
|
if (changedProperties.has('inputData') && this.gaugeContainer) {
|
|
161
162
|
this.transformData()
|
|
163
|
+
this.setupCharts()
|
|
164
|
+
this.sizingSetup()
|
|
165
|
+
this.adjustSizes()
|
|
166
|
+
this.applyData()
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
if (changedProperties.has('theme')) {
|
|
165
170
|
this.registerTheme(this.theme)
|
|
166
171
|
this.deleteCharts()
|
|
167
172
|
this.transformData()
|
|
173
|
+
this.setupCharts()
|
|
174
|
+
this.sizingSetup()
|
|
175
|
+
this.adjustSizes()
|
|
168
176
|
this.applyData()
|
|
169
177
|
}
|
|
170
178
|
super.update(changedProperties)
|
|
@@ -173,11 +181,22 @@ export class WidgetGauge extends LitElement {
|
|
|
173
181
|
protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>): void {
|
|
174
182
|
this.resizeObserver.observe(this.shadowRoot?.querySelector('.wrapper') as HTMLDivElement)
|
|
175
183
|
this.gaugeContainer = this.shadowRoot?.querySelector('.gauge-container')
|
|
184
|
+
this.registerTheme(this.theme)
|
|
176
185
|
this.transformData()
|
|
186
|
+
this.setupCharts()
|
|
187
|
+
this.sizingSetup()
|
|
188
|
+
this.adjustSizes()
|
|
189
|
+
this.applyData()
|
|
177
190
|
}
|
|
178
191
|
|
|
179
192
|
registerTheme(theme?: Theme) {
|
|
180
|
-
|
|
193
|
+
const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
|
|
194
|
+
const cssBgColor = getComputedStyle(this).getPropertyValue('--re-background-color').trim()
|
|
195
|
+
this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
|
|
196
|
+
this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
|
|
197
|
+
this.themeSubtitleColor =
|
|
198
|
+
cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
|
|
199
|
+
|
|
181
200
|
if (!theme || !theme.theme_object || !theme.theme_name) return
|
|
182
201
|
|
|
183
202
|
echarts.registerTheme(theme.theme_name, theme.theme_object)
|
|
@@ -252,7 +271,6 @@ export class WidgetGauge extends LitElement {
|
|
|
252
271
|
this.canvasList.forEach((canvasObj) => {
|
|
253
272
|
canvasObj.echart?.resize()
|
|
254
273
|
})
|
|
255
|
-
this.applyData()
|
|
256
274
|
}
|
|
257
275
|
|
|
258
276
|
async transformData() {
|
|
@@ -280,9 +298,6 @@ export class WidgetGauge extends LitElement {
|
|
|
280
298
|
this.dataSets.push(pds)
|
|
281
299
|
})
|
|
282
300
|
})
|
|
283
|
-
|
|
284
|
-
this.setupCharts()
|
|
285
|
-
this.adjustSizes()
|
|
286
301
|
}
|
|
287
302
|
|
|
288
303
|
applyData() {
|
|
@@ -331,8 +346,8 @@ export class WidgetGauge extends LitElement {
|
|
|
331
346
|
ga.data[0].value = ds.needleValue
|
|
332
347
|
ga.data[0].name = ds.unit
|
|
333
348
|
ga.title.fontSize = 25 * modifier
|
|
334
|
-
ga.title.color = ds.valueColor ?? this.
|
|
335
|
-
ga.detail.color = ds.valueColor ?? this.
|
|
349
|
+
ga.title.color = ds.valueColor ?? this.themeTitleColor
|
|
350
|
+
ga.detail.color = ds.valueColor ?? this.themeTitleColor
|
|
336
351
|
ga.detail.fontSize = 40 * modifier
|
|
337
352
|
ga.detail.formatter = (val: number) =>
|
|
338
353
|
isNaN(val) ? '-' : val.toFixed(Math.floor(ds.precision ?? 0))
|
|
@@ -423,18 +438,12 @@ export class WidgetGauge extends LitElement {
|
|
|
423
438
|
|
|
424
439
|
const newChart = echarts.init(newCanvas, this.theme?.theme_name)
|
|
425
440
|
this.canvasList.set(ds.label ?? '', { echart: newChart, title: newTitle, wrapper: newWrapper })
|
|
426
|
-
//@ts-ignore
|
|
427
|
-
this.themeBgColor = newChart?._theme?.backgroundColor
|
|
428
|
-
//@ts-ignore
|
|
429
|
-
this.themeColor = newChart._theme?.title?.textStyle?.color
|
|
430
441
|
})
|
|
431
|
-
this.sizingSetup()
|
|
432
442
|
}
|
|
433
443
|
|
|
434
444
|
static styles = css`
|
|
435
445
|
:host {
|
|
436
446
|
display: block;
|
|
437
|
-
color: var(--re-text-color, #000);
|
|
438
447
|
font-family: sans-serif;
|
|
439
448
|
box-sizing: border-box;
|
|
440
449
|
position: relative;
|
|
@@ -452,7 +461,6 @@ export class WidgetGauge extends LitElement {
|
|
|
452
461
|
width: 100%;
|
|
453
462
|
padding: 16px;
|
|
454
463
|
box-sizing: border-box;
|
|
455
|
-
color: var(--re-text-color, #000);
|
|
456
464
|
gap: 12px;
|
|
457
465
|
}
|
|
458
466
|
|
|
@@ -500,7 +508,6 @@ export class WidgetGauge extends LitElement {
|
|
|
500
508
|
|
|
501
509
|
.no-data {
|
|
502
510
|
font-size: 20px;
|
|
503
|
-
color: var(--re-text-color, #000);
|
|
504
511
|
display: flex;
|
|
505
512
|
height: 100%;
|
|
506
513
|
width: 100%;
|
|
@@ -512,10 +519,19 @@ export class WidgetGauge extends LitElement {
|
|
|
512
519
|
|
|
513
520
|
render() {
|
|
514
521
|
return html`
|
|
515
|
-
<div
|
|
522
|
+
<div
|
|
523
|
+
class="wrapper"
|
|
524
|
+
style="background-color: ${this.themeBgColor}; color: ${this.themeTitleColor}"
|
|
525
|
+
>
|
|
516
526
|
<header class="paging" ?active=${this.inputData?.title || this.inputData?.subTitle}>
|
|
517
527
|
<h3 class="paging" ?active=${this.inputData?.title}>${this.inputData?.title}</h3>
|
|
518
|
-
<p
|
|
528
|
+
<p
|
|
529
|
+
class="paging"
|
|
530
|
+
?active=${this.inputData?.subTitle}
|
|
531
|
+
style="color: ${this.themeSubtitleColor}"
|
|
532
|
+
>
|
|
533
|
+
${this.inputData?.subTitle}
|
|
534
|
+
</p>
|
|
519
535
|
</header>
|
|
520
536
|
<div class="paging no-data" ?active=${!this.dataSets.length}>No Data</div>
|
|
521
537
|
<div class="gauge-container"></div>
|