@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/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/widget-gauge.js +12 -13
- package/dist/widget-gauge.js.map +1 -1
- package/package.json +1 -1
- package/src/default-data.json +1 -2
- package/src/definition-schema.d.ts +12 -6
- package/src/definition-schema.json +25 -16
- package/src/widget-gauge.ts +13 -16
package/package.json
CHANGED
package/src/default-data.json
CHANGED
|
@@ -43,13 +43,16 @@ export type Data = {
|
|
|
43
43
|
[k: string]: unknown;
|
|
44
44
|
}[];
|
|
45
45
|
/**
|
|
46
|
-
* The
|
|
46
|
+
* The minimum value of the gauge. If not specified 0 is used.
|
|
47
47
|
*/
|
|
48
|
-
export type
|
|
48
|
+
export type GaugeMinimumValue = number;
|
|
49
|
+
export type UpperLimit = number;
|
|
49
50
|
/**
|
|
50
|
-
*
|
|
51
|
+
* The upper limits of the gauge sections and the color for each section.
|
|
51
52
|
*/
|
|
52
|
-
export type
|
|
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
|
-
|
|
87
|
-
|
|
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
|
-
"
|
|
105
|
-
"title": "
|
|
106
|
-
"description": "The
|
|
107
|
-
"type": "
|
|
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":
|
|
110
|
-
"items": {
|
|
111
|
-
"type": "number",
|
|
112
|
-
"dataDrivenDisabled": true
|
|
113
|
-
}
|
|
109
|
+
"order": 1
|
|
114
110
|
},
|
|
115
|
-
"
|
|
116
|
-
"title": "Section
|
|
117
|
-
"description": "
|
|
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": "
|
|
122
|
-
"
|
|
123
|
-
|
|
124
|
-
|
|
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
|
},
|
package/src/widget-gauge.ts
CHANGED
|
@@ -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,
|
|
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?.
|
|
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]
|
|
333
|
-
(ds.sections?.
|
|
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
|
-
? [
|
|
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
|
|
378
|
-
const bcolors:
|
|
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?.
|
|
379
|
+
: ds.sections?.sectionLimits.map((l) => l.sectionColor).filter((c) => c !== undefined)
|
|
381
380
|
|
|
382
|
-
const colors
|
|
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) => [(
|
|
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
|
|
403
|
+
progressColor = colors?.[i] ?? colors?.[0]
|
|
407
404
|
break
|
|
408
405
|
}
|
|
409
406
|
}
|