@record-evolution/widget-gauge 1.7.2 → 1.7.3

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/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.2",
6
+ "version": "1.7.3",
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": {
@@ -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, SVGRenderer } from 'echarts/renderers'
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 themeBgColor?: string
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(this.adjustSizes.bind(this))
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)
@@ -174,6 +182,10 @@ export class WidgetGauge extends LitElement {
174
182
  this.resizeObserver.observe(this.shadowRoot?.querySelector('.wrapper') as HTMLDivElement)
175
183
  this.gaugeContainer = this.shadowRoot?.querySelector('.gauge-container')
176
184
  this.transformData()
185
+ this.setupCharts()
186
+ this.sizingSetup()
187
+ this.adjustSizes()
188
+ this.applyData()
177
189
  }
178
190
 
179
191
  registerTheme(theme?: Theme) {
@@ -181,6 +193,12 @@ export class WidgetGauge extends LitElement {
181
193
  if (!theme || !theme.theme_object || !theme.theme_name) return
182
194
 
183
195
  echarts.registerTheme(theme.theme_name, theme.theme_object)
196
+ const cssTextColor = getComputedStyle(this).getPropertyValue('--re-text-color').trim()
197
+ const cssBgColor = getComputedStyle(this).getPropertyValue('--re-background-color').trim()
198
+ this.themeBgColor = cssBgColor || this.theme?.theme_object?.backgroundColor
199
+ this.themeTitleColor = cssTextColor || this.theme?.theme_object?.title?.textStyle?.color
200
+ this.themeSubtitleColor =
201
+ cssTextColor || this.theme?.theme_object?.title?.subtextStyle?.color || this.themeTitleColor
184
202
  }
185
203
 
186
204
  sizingSetup() {
@@ -252,7 +270,6 @@ export class WidgetGauge extends LitElement {
252
270
  this.canvasList.forEach((canvasObj) => {
253
271
  canvasObj.echart?.resize()
254
272
  })
255
- this.applyData()
256
273
  }
257
274
 
258
275
  async transformData() {
@@ -280,9 +297,6 @@ export class WidgetGauge extends LitElement {
280
297
  this.dataSets.push(pds)
281
298
  })
282
299
  })
283
-
284
- this.setupCharts()
285
- this.adjustSizes()
286
300
  }
287
301
 
288
302
  applyData() {
@@ -331,8 +345,8 @@ export class WidgetGauge extends LitElement {
331
345
  ga.data[0].value = ds.needleValue
332
346
  ga.data[0].name = ds.unit
333
347
  ga.title.fontSize = 25 * modifier
334
- ga.title.color = ds.valueColor ?? this.themeColor
335
- ga.detail.color = ds.valueColor ?? this.themeColor
348
+ ga.title.color = ds.valueColor ?? this.themeTitleColor
349
+ ga.detail.color = ds.valueColor ?? this.themeTitleColor
336
350
  ga.detail.fontSize = 40 * modifier
337
351
  ga.detail.formatter = (val: number) =>
338
352
  isNaN(val) ? '-' : val.toFixed(Math.floor(ds.precision ?? 0))
@@ -423,18 +437,12 @@ export class WidgetGauge extends LitElement {
423
437
 
424
438
  const newChart = echarts.init(newCanvas, this.theme?.theme_name)
425
439
  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
440
  })
431
- this.sizingSetup()
432
441
  }
433
442
 
434
443
  static styles = css`
435
444
  :host {
436
445
  display: block;
437
- color: var(--re-text-color, #000);
438
446
  font-family: sans-serif;
439
447
  box-sizing: border-box;
440
448
  position: relative;
@@ -452,7 +460,6 @@ export class WidgetGauge extends LitElement {
452
460
  width: 100%;
453
461
  padding: 16px;
454
462
  box-sizing: border-box;
455
- color: var(--re-text-color, #000);
456
463
  gap: 12px;
457
464
  }
458
465
 
@@ -500,7 +507,6 @@ export class WidgetGauge extends LitElement {
500
507
 
501
508
  .no-data {
502
509
  font-size: 20px;
503
- color: var(--re-text-color, #000);
504
510
  display: flex;
505
511
  height: 100%;
506
512
  width: 100%;
@@ -512,10 +518,19 @@ export class WidgetGauge extends LitElement {
512
518
 
513
519
  render() {
514
520
  return html`
515
- <div class="wrapper" style="background-color: ${this.themeBgColor}; color: ${this.themeColor}">
521
+ <div
522
+ class="wrapper"
523
+ style="background-color: ${this.themeBgColor}; color: ${this.themeTitleColor}"
524
+ >
516
525
  <header class="paging" ?active=${this.inputData?.title || this.inputData?.subTitle}>
517
526
  <h3 class="paging" ?active=${this.inputData?.title}>${this.inputData?.title}</h3>
518
- <p class="paging" ?active=${this.inputData?.subTitle}>${this.inputData?.subTitle}</p>
527
+ <p
528
+ class="paging"
529
+ ?active=${this.inputData?.subTitle}
530
+ style="color: ${this.themeSubtitleColor}"
531
+ >
532
+ ${this.inputData?.subTitle}
533
+ </p>
519
534
  </header>
520
535
  <div class="paging no-data" ?active=${!this.dataSets.length}>No Data</div>
521
536
  <div class="gauge-container"></div>