@record-evolution/widget-gauge 1.5.28 → 1.5.30

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.5.28",
6
+ "version": "1.5.30",
7
7
  "type": "module",
8
8
  "main": "dist/widget-gauge.js",
9
9
  "types": "dist/src/widget-gauge.d.ts",
@@ -26,6 +26,14 @@ export type SectionBackgroundColors = {
26
26
  * Calculate the average over the given number of newest values. (If pivoted, then per each of the pivot dataseries.) If not specified then the latest value is shown without modification.
27
27
  */
28
28
  export type AverageLatestValues = number;
29
+ /**
30
+ * If you provide timestamp data, the delivered value is only shown in the gauge when the age of the data is not older than the given maximum Latency in seconds.
31
+ */
32
+ export type MaximumLatency = number;
33
+ /**
34
+ * This should be an ISO String date like 2023-11-04T22:47:52.351152+00:00. Will only be used to detect data age of data.
35
+ */
36
+ export type Timestamp = string;
29
37
  export type Value = number;
30
38
  /**
31
39
  * You can specify a column in the input data to autogenerate dataseries for each distinct entry in this column. E.g. if you have a table with columns [city, timestamp, temperature] and specify ''city'' as pivot column, then you will get a gauge for each city.
@@ -35,17 +43,19 @@ export type PivotColumn = string;
35
43
  * The data used to draw this data series.
36
44
  */
37
45
  export type Data = {
38
- value: Value;
46
+ tsp?: Timestamp;
47
+ value?: Value;
39
48
  pivot?: PivotColumn;
40
49
  [k: string]: unknown;
41
50
  }[];
42
51
  export type Gauges = {
43
- label: Label;
52
+ label?: Label;
44
53
  valueColor?: ValueColor;
45
54
  unit?: Unit;
46
55
  sections?: Sections;
47
56
  backgroundColors?: SectionBackgroundColors;
48
57
  averageLatest?: AverageLatestValues;
58
+ maxLatency?: MaximumLatency;
49
59
  data?: Data;
50
60
  [k: string]: unknown;
51
61
  }[];
@@ -67,25 +67,37 @@
67
67
  "type": "number",
68
68
  "order": 6
69
69
  },
70
+ "maxLatency": {
71
+ "title": "Maximum Latency",
72
+ "description": "If you provide timestamp data, the delivered value is only shown in the gauge when the age of the data is not older than the given maximum Latency in seconds.",
73
+ "type": "number",
74
+ "order": 7
75
+ },
70
76
  "data": {
71
77
  "title": "Data",
72
78
  "description": "The data used to draw this data series.",
73
79
  "type": "array",
74
- "order": 7,
80
+ "order": 8,
75
81
  "buffersize": 1000,
76
82
  "items": {
77
83
  "type": "object",
78
84
  "properties": {
85
+ "tsp": {
86
+ "title": "Timestamp",
87
+ "description": "This should be an ISO String date like 2023-11-04T22:47:52.351152+00:00. Will only be used to detect data age of data.",
88
+ "type": "string",
89
+ "order": 1
90
+ },
79
91
  "value": {
80
92
  "title": "Value",
81
93
  "type": "number",
82
- "order": 1,
94
+ "order": 2,
83
95
  "required": true
84
96
  },
85
97
  "pivot": {
86
98
  "title": "Pivot Column",
87
99
  "description": "You can specify a column in the input data to autogenerate dataseries for each distinct entry in this column. E.g. if you have a table with columns [city, timestamp, temperature] and specify ''city'' as pivot column, then you will get a gauge for each city.",
88
- "order": 2,
100
+ "order": 3,
89
101
  "type": "string"
90
102
  }
91
103
  }
@@ -216,22 +216,20 @@ export class WidgetGauge extends LitElement {
216
216
  this.inputData.dataseries?.forEach((ds) => {
217
217
  // pivot data
218
218
  const distincts = [...new Set(ds?.data?.map((d: Data) => d.pivot))]
219
- if (distincts.length > 1) {
220
- distincts.forEach((piv) => {
221
- const pds: any = {
222
- label: `${piv}-${ds.label ?? ''}`,
223
- unit: ds.unit,
224
- averageLatest: ds.averageLatest,
225
- valueColor: ds.valueColor,
226
- sections: ds.sections,
227
- backgroundColors: ds.backgroundColors,
228
- data: ds?.data?.filter((d) => d.pivot === piv)
229
- }
230
- this.dataSets.push(pds)
231
- })
232
- } else {
233
- this.dataSets.push(ds)
234
- }
219
+
220
+ distincts.forEach((piv) => {
221
+ const prefix = piv ? `${piv} - ` : ''
222
+ const pds: any = {
223
+ label: prefix + `${ds.label ?? ''}`,
224
+ unit: ds.unit,
225
+ averageLatest: ds.averageLatest,
226
+ valueColor: ds.valueColor,
227
+ sections: ds.sections,
228
+ backgroundColors: ds.backgroundColors,
229
+ data: distincts.length === 1 ? ds.data : ds?.data?.filter((d) => d.pivot === piv)
230
+ }
231
+ this.dataSets.push(pds)
232
+ })
235
233
  })
236
234
 
237
235
  // console.log('Gauge Datasets', this.dataSets)
@@ -240,7 +238,11 @@ export class WidgetGauge extends LitElement {
240
238
  applyData() {
241
239
  const modifier = this.modifier
242
240
  this.setupCharts()
243
- this.dataSets.sort((a, b) => (a.label < b.label ? 1 : -1))
241
+ this.dataSets.forEach((d) => {
242
+ d.label ??= ''
243
+ })
244
+
245
+ this.dataSets.sort((a, b) => ((a.label as string) > (b.label as string) ? 1 : -1))
244
246
  this.requestUpdate()
245
247
 
246
248
  for (const ds of this.dataSets) {
@@ -267,6 +269,13 @@ export class WidgetGauge extends LitElement {
267
269
  option.title.textStyle.fontSize = 22 * modifier
268
270
 
269
271
  // Needle
272
+ // Check age of data Latency
273
+ const tsp = Date.parse(ds.data?.[0].tsp ?? '')
274
+ if (isNaN(tsp)) {
275
+ const now = new Date().getTime()
276
+ if (now - tsp > (ds.maxLatency ?? Infinity) * 1000) ds.needleValue = undefined
277
+ }
278
+
270
279
  ga.data[0].value = ds.needleValue
271
280
  ga.data[0].name = ds.unit
272
281
  ga.title.fontSize = 20 * modifier
@@ -306,7 +315,7 @@ export class WidgetGauge extends LitElement {
306
315
  ga.progress.itemStyle.color = progressColor
307
316
  ga.progress.width = 80 * modifier
308
317
  // Apply
309
- this.canvasList[ds.label]?.setOption(option)
318
+ this.canvasList[ds.label ?? '']?.setOption(option)
310
319
  }
311
320
  }
312
321
 
@@ -318,12 +327,12 @@ export class WidgetGauge extends LitElement {
318
327
  }
319
328
 
320
329
  this.dataSets.forEach((ds) => {
321
- if (this.canvasList[ds.label]) return
330
+ if (this.canvasList[ds.label ?? '']) return
322
331
  const canvas = this.shadowRoot?.querySelector(`[name="${ds.label}"]`) as HTMLCanvasElement
323
332
  if (!canvas) return
324
333
  // @ts-ignore
325
- this.canvasList[ds.label] = echarts.init(canvas)
326
- this.canvasList[ds.label].setOption(JSON.parse(JSON.stringify(this.template)))
334
+ this.canvasList[ds.label ?? ''] = echarts.init(canvas)
335
+ this.canvasList[ds.label ?? ''].setOption(JSON.parse(JSON.stringify(this.template)))
327
336
  })
328
337
  }
329
338
 
@@ -410,7 +419,7 @@ export class WidgetGauge extends LitElement {
410
419
  (ds) => ds.label,
411
420
  (ds) => html`
412
421
  <div
413
- name="${ds.label}"
422
+ name="${ds.label ?? ''}"
414
423
  class="chart"
415
424
  style="min-width: 600px; min-height: 400px; width: 600px; height: 400px;"
416
425
  ></div>