@record-evolution/widget-gauge 1.7.23 → 1.7.25
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 +46 -31
- package/dist/widget-gauge.js.map +1 -1
- package/package.json +1 -1
- package/src/definition-schema.d.ts +8 -8
- package/src/definition-schema.json +5 -5
- package/src/widget-gauge.ts +59 -33
package/package.json
CHANGED
|
@@ -43,15 +43,15 @@ export type Data = {
|
|
|
43
43
|
[k: string]: unknown;
|
|
44
44
|
}[];
|
|
45
45
|
/**
|
|
46
|
-
* The
|
|
46
|
+
* The start value of the gauge. If not specified 0 is used.
|
|
47
47
|
*/
|
|
48
|
-
export type
|
|
49
|
-
export type
|
|
48
|
+
export type GaugeStartValue = number;
|
|
49
|
+
export type RightLimit = number;
|
|
50
50
|
/**
|
|
51
|
-
* The
|
|
51
|
+
* The right limits of the gauge sections and the color for that section.
|
|
52
52
|
*/
|
|
53
|
-
export type
|
|
54
|
-
limit?:
|
|
53
|
+
export type SectionRightLimits = {
|
|
54
|
+
limit?: RightLimit;
|
|
55
55
|
sectionColor?: SectionColor;
|
|
56
56
|
[k: string]: unknown;
|
|
57
57
|
}[];
|
|
@@ -86,8 +86,8 @@ export interface ValueColor {
|
|
|
86
86
|
[k: string]: unknown;
|
|
87
87
|
}
|
|
88
88
|
export interface GaugeColorSections {
|
|
89
|
-
gaugeMinValue?:
|
|
90
|
-
sectionLimits?:
|
|
89
|
+
gaugeMinValue?: GaugeStartValue;
|
|
90
|
+
sectionLimits?: SectionRightLimits;
|
|
91
91
|
[k: string]: unknown;
|
|
92
92
|
}
|
|
93
93
|
export interface SectionColor {
|
|
@@ -102,15 +102,15 @@
|
|
|
102
102
|
"order": 8,
|
|
103
103
|
"properties": {
|
|
104
104
|
"gaugeMinValue": {
|
|
105
|
-
"title": "Gauge
|
|
106
|
-
"description": "The
|
|
105
|
+
"title": "Gauge Start Value",
|
|
106
|
+
"description": "The start value of the gauge. If not specified 0 is used.",
|
|
107
107
|
"type": "number",
|
|
108
108
|
"dataDrivenDisabled": true,
|
|
109
109
|
"order": 1
|
|
110
110
|
},
|
|
111
111
|
"sectionLimits": {
|
|
112
|
-
"title": "Section
|
|
113
|
-
"description": "The
|
|
112
|
+
"title": "Section Right Limits",
|
|
113
|
+
"description": "The right limits of the gauge sections and the color for that section.",
|
|
114
114
|
"type": "array",
|
|
115
115
|
"dataDrivenDisabled": true,
|
|
116
116
|
"order": 2,
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"type": "object",
|
|
119
119
|
"properties": {
|
|
120
120
|
"limit": {
|
|
121
|
-
"title": "
|
|
121
|
+
"title": "Right Limit",
|
|
122
122
|
"type": "number",
|
|
123
123
|
"dataDrivenDisabled": true,
|
|
124
124
|
"order": 1
|
package/src/widget-gauge.ts
CHANGED
|
@@ -327,13 +327,6 @@ export class WidgetGauge extends LitElement {
|
|
|
327
327
|
? (ds.sections?.gaugeMinValue ?? 0)
|
|
328
328
|
: ds.needleValue
|
|
329
329
|
|
|
330
|
-
// The full range of the gauge
|
|
331
|
-
ds.range =
|
|
332
|
-
(ds.sections?.sectionLimits?.[ds.sections?.sectionLimits?.length - 1].limit || 100) -
|
|
333
|
-
(ds.sections?.gaugeMinValue ?? 0)
|
|
334
|
-
if (isNaN(ds.range as number)) ds.range = 100
|
|
335
|
-
// ds.ranges = ds.sections?.sectionLimits?.map((v, i, a) => v - (a?.[i - 1] ?? 0)).slice(1) ?? []
|
|
336
|
-
|
|
337
330
|
const echart = this.canvasList.get(ds.label)?.echart
|
|
338
331
|
const option = echart?.getOption() ?? window.structuredClone(this.template)
|
|
339
332
|
const seriesArr = option.series as GaugeSeriesOption[]
|
|
@@ -362,34 +355,64 @@ export class WidgetGauge extends LitElement {
|
|
|
362
355
|
|
|
363
356
|
ga.detail.formatter = (val: number) =>
|
|
364
357
|
isNaN(val) ? '-' : val.toFixed(Math.floor(ds.precision ?? 0))
|
|
365
|
-
// ga.anchor.itemStyle.color = ds.valueColor
|
|
366
|
-
// ga.pointer.itemStyle.color = ds.valueColor
|
|
367
|
-
|
|
368
358
|
// Axis
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
359
|
+
const defaultColors = ['#bf444c', '#d88273', '#f6efa6']
|
|
360
|
+
const themeColors = this.theme?.theme_object?.color ?? defaultColors
|
|
361
|
+
const gaugeMin = ds.sections?.gaugeMinValue ?? 0
|
|
362
|
+
|
|
363
|
+
// Filter out entries with null/undefined/empty limits, keeping limits and colors in sync
|
|
364
|
+
const validSections = (ds.sections?.sectionLimits ?? [])
|
|
365
|
+
.map((l, i) => {
|
|
366
|
+
const limit = l?.limit as string | number | null | undefined
|
|
367
|
+
return {
|
|
368
|
+
limit: limit === '' || limit == null ? undefined : Number(limit),
|
|
369
|
+
color: l?.sectionColor || themeColors[i % themeColors.length]
|
|
370
|
+
}
|
|
371
|
+
})
|
|
372
|
+
.filter(
|
|
373
|
+
(s): s is { limit: number; color: SectionColor } => s.limit != null && !isNaN(s.limit)
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
// Determine ascending/descending based on gaugeMin vs first limit
|
|
377
|
+
const isAscending = !validSections.length || gaugeMin <= validSections[0].limit
|
|
378
|
+
|
|
379
|
+
// Filter to keep only sections that maintain monotonic order
|
|
380
|
+
const sections = validSections.filter((s, i, arr) => {
|
|
381
|
+
if (i === 0) return true
|
|
382
|
+
return isAscending ? s.limit > arr[i - 1].limit : s.limit < arr[i - 1].limit
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
const sectionLimits = sections.length ? sections.map((s) => s.limit) : [40, 80, 100]
|
|
386
|
+
const colors: SectionColor[] = sections.length
|
|
387
|
+
? sections.map((s) => s.color)
|
|
388
|
+
: themeColors.slice(0, 3)
|
|
389
|
+
|
|
390
|
+
const gaugeMax = sectionLimits?.[sectionLimits.length - 1] ?? 100
|
|
391
|
+
ds.range = Math.abs(gaugeMax - gaugeMin)
|
|
388
392
|
|
|
393
|
+
ga.min = ga2.min = gaugeMin
|
|
394
|
+
ga.max = ga2.max = gaugeMax
|
|
395
|
+
|
|
396
|
+
// percentages of the sections paired with the colors (must be strictly ascending for ECharts)
|
|
397
|
+
const colorSections = sectionLimits
|
|
398
|
+
.map((limit, i) => {
|
|
399
|
+
const pct = Math.abs(limit - gaugeMin) / (ds.range as number)
|
|
400
|
+
const color = colors[i]
|
|
401
|
+
return [pct, color] as [number, SectionColor]
|
|
402
|
+
})
|
|
403
|
+
.filter(([s]) => !isNaN(s) && s >= 0)
|
|
404
|
+
|
|
405
|
+
console.log(
|
|
406
|
+
'Gauge sections',
|
|
407
|
+
ds.label,
|
|
408
|
+
gaugeMin,
|
|
409
|
+
gaugeMax,
|
|
410
|
+
sections,
|
|
411
|
+
sectionLimits,
|
|
412
|
+
colorSections
|
|
413
|
+
)
|
|
389
414
|
ga2.axisLine.lineStyle.width = 8 * modifier
|
|
390
|
-
ga2.axisLine.lineStyle.color = colorSections
|
|
391
|
-
? colorSections
|
|
392
|
-
: ga2.axisLine.lineStyle.color
|
|
415
|
+
if (colorSections.length) ga2.axisLine.lineStyle.color = colorSections
|
|
393
416
|
ga2.axisLabel.fontSize = 24 * modifier
|
|
394
417
|
// ga2.axisLabel.color = ds.valueColor
|
|
395
418
|
ga2.axisLabel.distance = -24 * modifier
|
|
@@ -399,7 +422,10 @@ export class WidgetGauge extends LitElement {
|
|
|
399
422
|
// Progress
|
|
400
423
|
let progressColor = colors?.[colors.length - 1]
|
|
401
424
|
for (const [i, s] of sectionLimits?.entries() ?? []) {
|
|
402
|
-
|
|
425
|
+
const inSection = isAscending
|
|
426
|
+
? s > (ds.needleValue as number)
|
|
427
|
+
: s < (ds.needleValue as number)
|
|
428
|
+
if (inSection) {
|
|
403
429
|
progressColor = colors?.[i] ?? colors?.[0]
|
|
404
430
|
break
|
|
405
431
|
}
|