@record-evolution/widget-gauge 1.7.7 → 1.7.8

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.7",
6
+ "version": "1.7.8",
7
7
  "type": "module",
8
8
  "main": "dist/widget-gauge.js",
9
9
  "types": "dist/src/widget-gauge.d.ts",
@@ -1,22 +1,5 @@
1
1
  {
2
2
  "dataseries": [
3
- {
4
- "label": "Demo Gauge Temperature",
5
- "unit": "°C",
6
- "precision": 1,
7
- "data": [
8
- {
9
- "value": 90
10
- }
11
- ],
12
- "sections": {
13
- "sectionLimits": [-20, 80, 90, 120],
14
- "backgroundColors": [null, null, null]
15
- },
16
- "advanced": {
17
- "averageLatest": 1
18
- }
19
- },
20
3
  {
21
4
  "label": "Demo Gauge Pascal",
22
5
  "unit": "Pa",
@@ -323,11 +323,12 @@ export class WidgetGauge extends LitElement {
323
323
 
324
324
  ds.needleValue = isNaN(average) ? ds.sections?.sectionLimits?.[0] : average
325
325
 
326
+ // The full range of the gauge
326
327
  ds.range =
327
328
  (ds.sections?.sectionLimits?.[ds.sections?.sectionLimits?.length - 1] ?? 100) -
328
329
  (ds.sections?.sectionLimits?.[0] ?? 0)
329
330
  if (isNaN(ds.range as number)) ds.range = 100
330
- ds.ranges = ds.sections?.sectionLimits?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
331
+ // ds.ranges = ds.sections?.sectionLimits?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
331
332
 
332
333
  const echart = this.canvasList.get(ds.label)?.echart
333
334
  const option = echart?.getOption() ?? window.structuredClone(this.template)
@@ -355,16 +356,24 @@ export class WidgetGauge extends LitElement {
355
356
  // ga.pointer.itemStyle.color = ds.valueColor
356
357
 
357
358
  // Axis
358
- ga2.min = ds.sections?.sectionLimits?.length ? Math.min(...ds.sections?.sectionLimits) : 0
359
- ga2.max = ds.sections?.sectionLimits?.length ? Math.max(...ds.sections?.sectionLimits) : 100
359
+ const sectionLimits = ds.sections?.sectionLimits ?? [0, 40, 80, 100]
360
+ ga2.min = sectionLimits?.length ? Math.min(...sectionLimits) : 0
361
+ ga2.max = sectionLimits?.length ? Math.max(...sectionLimits) : 100
360
362
  ga.min = ga2.min
361
363
  ga.max = ga2.max
362
- const colorSections = ds.sections?.backgroundColors
363
- ?.map((b, i) => [
364
- ((ds.sections?.sectionLimits?.[i + 1] ?? ga.min) - ga.min) / (ds.range as number),
365
- b
366
- ])
367
- .filter(([s]) => !isNaN(s as number))
364
+
365
+ const tcolors = this.theme?.theme_object?.color
366
+ const colors: string[] = ds.sections?.backgroundColors?.map(
367
+ (b, i) => b || tcolors[i % (tcolors?.length ?? 0)]
368
+ ) ??
369
+ tcolors?.slice(0, 3) ?? ['#bf444c', '#d88273', '#f6efa6']
370
+
371
+ // percentages of the sections paired with the colors
372
+ const colorSections = colors
373
+ ?.map((b, i) => [((sectionLimits?.[i + 1] ?? ga.min) - ga.min) / (ds.range as number), b])
374
+ .filter(([s]) => !isNaN(s as number)) ?? [1 / 3, 1 / 3, 1 / 3]
375
+
376
+ console.log('Color sections', colorSections, sectionLimits)
368
377
  ga2.axisLine.lineStyle.width = 8 * modifier
369
378
  ga2.axisLine.lineStyle.color = colorSections?.length
370
379
  ? colorSections
@@ -376,11 +385,10 @@ export class WidgetGauge extends LitElement {
376
385
  ga2.splitLine.distance = -16 * modifier
377
386
 
378
387
  // Progress
379
- let progressColor = ds.sections?.backgroundColors?.[ds.sections?.backgroundColors.length - 1]
380
- for (const [i, s] of ds.sections?.sectionLimits?.entries() ?? []) {
388
+ let progressColor = colors?.[colors.length - 1]
389
+ for (const [i, s] of sectionLimits?.entries() ?? []) {
381
390
  if (s > (ds.needleValue as number)) {
382
- progressColor =
383
- ds.sections?.backgroundColors?.[i - 1] ?? ds.sections?.backgroundColors?.[0]
391
+ progressColor = colors?.[i - 1] ?? colors?.[0]
384
392
  break
385
393
  }
386
394
  }