@record-evolution/widget-gauge 1.7.22 → 1.7.23

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.22",
6
+ "version": "1.7.23",
7
7
  "type": "module",
8
8
  "main": "dist/widget-gauge.js",
9
9
  "types": "dist/src/widget-gauge.d.ts",
@@ -6,8 +6,7 @@
6
6
  "precision": 1,
7
7
  "value": 83,
8
8
  "sections": {
9
- "sectionLimits": [],
10
- "backgroundColors": []
9
+ "gaugeMinValue": 0
11
10
  },
12
11
  "advanced": {
13
12
  "averageLatest": 1
@@ -43,13 +43,16 @@ export type Data = {
43
43
  [k: string]: unknown;
44
44
  }[];
45
45
  /**
46
- * The limits of the gauge sections. Starting from the min value, ending with the max value.
46
+ * The minimum value of the gauge. If not specified 0 is used.
47
47
  */
48
- export type SectionLimits = number[];
48
+ export type GaugeMinimumValue = number;
49
+ export type UpperLimit = number;
49
50
  /**
50
- * Background color for each section. This Array is one shorter than the number of sections.
51
+ * The upper limits of the gauge sections and the color for each section.
51
52
  */
52
- export type SectionBackgroundColors = {
53
+ export type SectionUpperLimits = {
54
+ limit?: UpperLimit;
55
+ sectionColor?: SectionColor;
53
56
  [k: string]: unknown;
54
57
  }[];
55
58
  /**
@@ -83,8 +86,11 @@ export interface ValueColor {
83
86
  [k: string]: unknown;
84
87
  }
85
88
  export interface GaugeColorSections {
86
- sectionLimits?: SectionLimits;
87
- backgroundColors?: SectionBackgroundColors;
89
+ gaugeMinValue?: GaugeMinimumValue;
90
+ sectionLimits?: SectionUpperLimits;
91
+ [k: string]: unknown;
92
+ }
93
+ export interface SectionColor {
88
94
  [k: string]: unknown;
89
95
  }
90
96
  export interface AdvancedConfiguration {
@@ -101,27 +101,36 @@
101
101
  "type": "object",
102
102
  "order": 8,
103
103
  "properties": {
104
- "sectionLimits": {
105
- "title": "Section Limits",
106
- "description": "The limits of the gauge sections. Starting from the min value, ending with the max value.",
107
- "type": "array",
104
+ "gaugeMinValue": {
105
+ "title": "Gauge Minimum Value",
106
+ "description": "The minimum value of the gauge. If not specified 0 is used.",
107
+ "type": "number",
108
108
  "dataDrivenDisabled": true,
109
- "order": 4,
110
- "items": {
111
- "type": "number",
112
- "dataDrivenDisabled": true
113
- }
109
+ "order": 1
114
110
  },
115
- "backgroundColors": {
116
- "title": "Section background colors",
117
- "description": "Background color for each section. This Array is one shorter than the number of sections.",
111
+ "sectionLimits": {
112
+ "title": "Section Upper Limits",
113
+ "description": "The upper limits of the gauge sections and the color for each section.",
118
114
  "type": "array",
119
115
  "dataDrivenDisabled": true,
116
+ "order": 2,
120
117
  "items": {
121
- "type": "color",
122
- "dataDrivenDisabled": true
123
- },
124
- "order": 5
118
+ "type": "object",
119
+ "properties": {
120
+ "limit": {
121
+ "title": "Upper Limit",
122
+ "type": "number",
123
+ "dataDrivenDisabled": true,
124
+ "order": 1
125
+ },
126
+ "sectionColor": {
127
+ "title": "Section Color",
128
+ "type": "color",
129
+ "dataDrivenDisabled": true,
130
+ "order": 2
131
+ }
132
+ }
133
+ }
125
134
  }
126
135
  }
127
136
  },
@@ -1,6 +1,6 @@
1
1
  import { html, css, LitElement, PropertyValueMap, PropertyValues } from 'lit'
2
2
  import { customElement, property, query, state } from 'lit/decorators.js'
3
- import { GaugeChartConfiguration, SectionBackgroundColors } from './definition-schema.js'
3
+ import { GaugeChartConfiguration, SectionColor } from './definition-schema.js'
4
4
 
5
5
  import * as echarts from 'echarts/core'
6
6
  import { TooltipComponent } from 'echarts/components'
@@ -324,13 +324,13 @@ export class WidgetGauge extends LitElement {
324
324
  ds.needleValue = (values.reduce((p, c) => p + c, 0) / values.length) as number
325
325
  }
326
326
  ds.needleValue = isNaN(ds.needleValue as number)
327
- ? ds.sections?.sectionLimits?.[0]
327
+ ? (ds.sections?.gaugeMinValue ?? 0)
328
328
  : ds.needleValue
329
329
 
330
330
  // The full range of the gauge
331
331
  ds.range =
332
- (ds.sections?.sectionLimits?.[ds.sections?.sectionLimits?.length - 1] ?? 100) -
333
- (ds.sections?.sectionLimits?.[0] ?? 0)
332
+ (ds.sections?.sectionLimits?.[ds.sections?.sectionLimits?.length - 1].limit || 100) -
333
+ (ds.sections?.gaugeMinValue ?? 0)
334
334
  if (isNaN(ds.range as number)) ds.range = 100
335
335
  // ds.ranges = ds.sections?.sectionLimits?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
336
336
 
@@ -367,26 +367,23 @@ export class WidgetGauge extends LitElement {
367
367
 
368
368
  // Axis
369
369
  const sectionLimits = !ds.sections?.sectionLimits?.length
370
- ? [0, 40, 80, 100]
371
- : ds.sections?.sectionLimits
372
- ga2.min = sectionLimits?.length ? Math.min(...sectionLimits) : 0
370
+ ? [40, 80, 100]
371
+ : ds.sections?.sectionLimits.map((l) => l.limit).filter((l) => l !== undefined)
373
372
  ga2.max = sectionLimits?.length ? Math.max(...sectionLimits) : 100
374
- ga.min = ga2.min
373
+ ga.min = ga2.min = ds.sections?.gaugeMinValue ?? 0
375
374
  ga.max = ga2.max
376
375
 
377
- const tcolors: SectionBackgroundColors = this.theme?.theme_object?.color
378
- const bcolors: SectionBackgroundColors = !ds.sections?.backgroundColors?.length
376
+ const tcolors = this.theme?.theme_object?.color
377
+ const bcolors: SectionColor[] = !ds.sections?.sectionLimits?.length
379
378
  ? (tcolors?.slice(0, 3) ?? ['#bf444c', '#d88273', '#f6efa6'])
380
- : ds.sections?.backgroundColors
379
+ : ds.sections?.sectionLimits.map((l) => l.sectionColor).filter((c) => c !== undefined)
381
380
 
382
- const colors: SectionBackgroundColors = bcolors?.map(
383
- (b, i) => b || tcolors[i % (tcolors?.length ?? 0)]
384
- ) ??
381
+ const colors = bcolors?.map((b, i) => b || tcolors[i % (tcolors?.length ?? 0)]) ??
385
382
  tcolors?.slice(0, 3) ?? ['#bf444c', '#d88273', '#f6efa6']
386
383
 
387
384
  // percentages of the sections paired with the colors
388
385
  const colorSections = colors
389
- ?.map((b, i) => [((sectionLimits?.[i + 1] ?? ga.min) - ga.min) / (ds.range as number), b])
386
+ ?.map((b, i) => [(sectionLimits?.[i] - ga.min) / (ds.range as number), b])
390
387
  .filter(([s]) => !isNaN(s as number)) ?? [1 / 3, 1 / 3, 1 / 3]
391
388
 
392
389
  ga2.axisLine.lineStyle.width = 8 * modifier
@@ -403,7 +400,7 @@ export class WidgetGauge extends LitElement {
403
400
  let progressColor = colors?.[colors.length - 1]
404
401
  for (const [i, s] of sectionLimits?.entries() ?? []) {
405
402
  if (s > (ds.needleValue as number)) {
406
- progressColor = colors?.[i - 1] ?? colors?.[0]
403
+ progressColor = colors?.[i] ?? colors?.[0]
407
404
  break
408
405
  }
409
406
  }