@record-evolution/widget-value 1.1.19 → 1.1.21

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-value",
4
4
  "license": "MIT",
5
5
  "author": "widget-value",
6
- "version": "1.1.19",
6
+ "version": "1.1.21",
7
7
  "engines": {
8
8
  "node": "18.18.2",
9
9
  "npm": ">=10.0.2"
@@ -4,28 +4,12 @@
4
4
  "label": "Temperature",
5
5
  "unit": "°C",
6
6
  "precision": 2,
7
- "styling": {},
8
- "advanced": {
9
- "averageLatest": 1
10
- },
11
- "data": [
12
- {
13
- "value": 90
14
- }
15
- ]
7
+ "value": 90
16
8
  },
17
9
  {
18
10
  "label": "Pressure",
19
11
  "unit": "Pa",
20
- "styling": {},
21
- "advanced": {
22
- "averageLatest": 1
23
- },
24
- "data": [
25
- {
26
- "value": 80
27
- }
28
- ]
12
+ "value": 80
29
13
  }
30
14
  ]
31
15
  }
@@ -1,6 +1,6 @@
1
- import { html, css, LitElement, PropertyValueMap } from 'lit'
1
+ import { html, css, LitElement, PropertyValueMap, PropertyValues } from 'lit'
2
2
  import { repeat } from 'lit/directives/repeat.js'
3
- import { customElement, property, state } from 'lit/decorators.js'
3
+ import { customElement, property, query, state } from 'lit/decorators.js'
4
4
  import { InputData } from './definition-schema.js'
5
5
 
6
6
  type Dataseries = Exclude<InputData['dataseries'], undefined>[number] & { needleValue?: number }
@@ -28,14 +28,19 @@ export class WidgetValue extends LitElement {
28
28
  @state() private themeTitleColor?: string
29
29
  @state() private themeSubtitleColor?: string
30
30
 
31
+ @query('.value-container')
32
+ valueContainer?: HTMLDivElement
33
+
34
+ @query('.sizing-container')
35
+ sizingContainer?: HTMLDivElement
36
+
31
37
  version: string = 'versionplaceholder'
32
38
 
33
39
  private resizeObserver: ResizeObserver
40
+ private lastLargerWidthTime?: number
41
+ private origWidth: number = 0
42
+ private origHeight: number = 0
34
43
 
35
- valueContainer?: HTMLDivElement
36
- boxes?: HTMLDivElement[]
37
- origWidth: number = 0
38
- origHeight: number = 0
39
44
  constructor() {
40
45
  super()
41
46
  this.resizeObserver = new ResizeObserver(this.applyData.bind(this))
@@ -50,18 +55,19 @@ export class WidgetValue extends LitElement {
50
55
  }
51
56
 
52
57
  protected firstUpdated(_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>) {
53
- this.valueContainer = this?.shadowRoot?.querySelector('.value-container') as HTMLDivElement
54
-
55
58
  this.registerTheme(this.theme)
56
- this.sizingSetup()
57
- this.transformData()
58
- this.applyData()
59
59
  }
60
60
 
61
- update(changedProperties: Map<string, any>) {
61
+ protected update(changedProperties: PropertyValues): void {
62
62
  if (changedProperties.has('inputData')) {
63
- this.sizingSetup()
64
63
  this.transformData()
64
+ }
65
+ super.update(changedProperties)
66
+ }
67
+
68
+ protected updated(changedProperties: Map<string, any>) {
69
+ if (changedProperties.has('inputData')) {
70
+ this.sizingSetup()
65
71
  this.applyData()
66
72
  }
67
73
 
@@ -69,7 +75,7 @@ export class WidgetValue extends LitElement {
69
75
  this.registerTheme(this.theme)
70
76
  }
71
77
 
72
- super.update(changedProperties)
78
+ super.updated(changedProperties)
73
79
  }
74
80
 
75
81
  registerTheme(theme?: Theme) {
@@ -83,20 +89,32 @@ export class WidgetValue extends LitElement {
83
89
 
84
90
  sizingSetup() {
85
91
  const boxes = Array.from(
86
- this?.shadowRoot?.querySelectorAll(
87
- '.sizing-container > .single-value'
88
- ) as NodeListOf<HTMLDivElement>
92
+ this.sizingContainer?.querySelectorAll('.single-value') as NodeListOf<HTMLDivElement>
89
93
  )
90
94
 
91
- this.origWidth =
92
- boxes?.map((b) => b.getBoundingClientRect().width).reduce((p, c) => (c > p ? c : p), 0) ?? 0
93
- this.origHeight =
94
- boxes?.map((b) => b.getBoundingClientRect().height).reduce((p, c) => (c > p ? c : p), 0) ?? 0
95
+ let width = 0
96
+ let height = 0
97
+ for (const box of boxes) {
98
+ const dims = box.getBoundingClientRect()
99
+ width = Math.max(dims.width, width)
100
+ height = Math.max(dims.height, height)
101
+ }
102
+
103
+ if (width < this.origWidth) {
104
+ if (!this.lastLargerWidthTime || Date.now() - this.lastLargerWidthTime > 5000) {
105
+ this.origWidth = width
106
+ }
107
+ } else {
108
+ this.origWidth = width
109
+ this.lastLargerWidthTime = Date.now()
110
+ }
111
+ this.origHeight = height
95
112
  }
96
113
 
97
114
  applyData() {
98
- const userWidth = this.valueContainer?.getBoundingClientRect().width
99
- const userHeight = this.valueContainer?.getBoundingClientRect().height
115
+ if (!this.valueContainer) return
116
+ const userWidth = this.valueContainer.getBoundingClientRect().width
117
+ const userHeight = this.valueContainer.getBoundingClientRect().height
100
118
  const count = this.dataSets.size
101
119
 
102
120
  const width = this.origWidth
@@ -110,7 +128,7 @@ export class WidgetValue extends LitElement {
110
128
  const uhgap = userHeight - 12 * (r - 1)
111
129
  const m = uwgap / width / c
112
130
  const size = m * m * width * height * count
113
- if (r * m * height <= uhgap) fits.push({ c, m, size, width, height, userWidth, userHeight })
131
+ if (r * m * height <= uhgap) fits.push({ r, c, m, size, width, height, userWidth, userHeight })
114
132
  }
115
133
 
116
134
  for (let r = 1; r <= count; r++) {
@@ -119,53 +137,47 @@ export class WidgetValue extends LitElement {
119
137
  const uhgap = userHeight - 12 * (r - 1)
120
138
  const m = uhgap / height / r
121
139
  const size = m * m * width * height * count
122
- if (c * m * width <= uwgap) fits.push({ r, m, size, width, height, userWidth, userHeight })
140
+ if (c * m * width <= uwgap) fits.push({ r, c, m, size, width, height, userWidth, userHeight })
123
141
  }
124
142
  const maxSize = fits.reduce((p, c) => (c.size < p ? p : c.size), 0)
125
143
  const fit = fits.find((f) => f.size === maxSize)
126
- const modifier = fit?.m ?? 1
144
+ if (!fit) return
145
+ const modifier = fit.m ?? 1
127
146
  // console.log('FITS', fits, 'modifier', modifier, 'cols',fit?.c, 'rows', fit?.r, 'new size', fit?.size.toFixed(0), 'total space', (userWidth* userHeight).toFixed(0))
128
-
129
147
  const boxes = Array.from(
130
- this?.shadowRoot?.querySelectorAll(
131
- '.value-container > .single-value'
132
- ) as NodeListOf<HTMLDivElement>
148
+ this.valueContainer?.querySelectorAll('.single-value') as NodeListOf<HTMLDivElement>
133
149
  )
150
+ this.valueContainer.style.gridTemplateColumns = `repeat(${fit.c}, 1fr)`
134
151
 
135
- boxes?.forEach((box) =>
152
+ for (const box of boxes) {
136
153
  box.setAttribute(
137
154
  'style',
138
155
  `width:${modifier * width}px; height:${modifier * height}px; padding:${modifier * 6}px`
139
156
  )
140
- )
141
157
 
142
- boxes?.forEach((n) => {
143
- const label: string | null = n.getAttribute('label')
158
+ const label: string | null = box.getAttribute('label')
144
159
  const ds: Dataseries | undefined = this.dataSets.get(label ?? '')
145
- const numberText = n.querySelector('.current-value') as HTMLDivElement
160
+
161
+ const numberText = box.querySelector('.current-value') as HTMLDivElement
146
162
  numberText.setAttribute(
147
163
  'style',
148
164
  `font-size: ${32 * modifier}px;
149
165
  color: ${ds?.styling?.valueColor || this.theme?.theme_object?.color?.[0] || this.themeTitleColor};`
150
166
  )
151
- })
152
167
 
153
- boxes?.forEach((n) => {
154
- const label: string | null = n.getAttribute('label')
155
- const ds: Dataseries | undefined = this.dataSets.get(label ?? '')
156
- const labelText = n.querySelector('.label') as HTMLDivElement
168
+ const labelText = box.querySelector('.label') as HTMLDivElement
157
169
  labelText.setAttribute(
158
170
  'style',
159
171
  `font-size: ${26 * modifier}px;
160
172
  color: ${ds?.styling?.labelColor || this.theme?.theme_object?.color?.[1] || this.themeSubtitleColor};`
161
173
  )
162
- const unitText = n.querySelector('.unit') as HTMLDivElement
174
+ const unitText = box.querySelector('.unit') as HTMLDivElement
163
175
  unitText.setAttribute(
164
176
  'style',
165
177
  `font-size: ${26 * modifier}px;
166
178
  color: ${ds?.styling?.valueColor || this.theme?.theme_object?.color?.[0] || this.themeTitleColor};`
167
179
  )
168
- })
180
+ }
169
181
 
170
182
  this.textActive = true
171
183
  }
@@ -180,8 +192,10 @@ export class WidgetValue extends LitElement {
180
192
  // ?.sort((a, b) => a.order - b.order)
181
193
  ?.forEach((ds) => {
182
194
  // pivot data
183
- const distincts = [...new Set(ds.data?.map((d: Data) => d.pivot))].sort() as string[]
184
- ds.needleValue = undefined
195
+ const distincts = ds.multiChart
196
+ ? ([...new Set(ds.data?.map((d: Data) => d.pivot))].sort() as string[])
197
+ : ['']
198
+
185
199
  distincts.forEach((piv) => {
186
200
  const prefix = piv ?? ''
187
201
  const label = ds.label ?? ''
@@ -221,10 +235,6 @@ export class WidgetValue extends LitElement {
221
235
  }
222
236
  }
223
237
  })
224
-
225
- this.requestUpdate()
226
- await this.updateComplete
227
- // console.log('Value Datasets', this.dataSets)
228
238
  }
229
239
 
230
240
  static styles = css`
@@ -267,10 +277,7 @@ export class WidgetValue extends LitElement {
267
277
  }
268
278
 
269
279
  .value-container {
270
- display: flex;
271
- flex-wrap: wrap;
272
- align-items: center;
273
- justify-content: center;
280
+ display: grid;
274
281
  line-height: 0.9;
275
282
  flex: 1;
276
283
  overflow: hidden;
@@ -284,7 +291,6 @@ export class WidgetValue extends LitElement {
284
291
  align-items: end;
285
292
  padding: 6px;
286
293
  box-sizing: border-box;
287
- /* border-left: 4px solid #ddd; */
288
294
  }
289
295
 
290
296
  .current-value {
@@ -302,13 +308,8 @@ export class WidgetValue extends LitElement {
302
308
 
303
309
  .sizing-container {
304
310
  position: absolute;
305
- left: 10000px;
306
- display: flex;
311
+ left: 100000px;
307
312
  line-height: 0.9;
308
- flex-wrap: wrap;
309
- align-items: center;
310
- justify-content: center;
311
- flex: 1;
312
313
  overflow: hidden;
313
314
  gap: 12px;
314
315
  }
@@ -377,7 +378,9 @@ export class WidgetValue extends LitElement {
377
378
  ?active=${this.textActive}
378
379
  style="color: ${this.themeTitleColor}"
379
380
  >
380
- ${isNaN(ds.needleValue ?? 0) || ds.needleValue === undefined
381
+ ${ds.needleValue === undefined ||
382
+ ds.needleValue === null ||
383
+ isNaN(ds.needleValue)
381
384
  ? ''
382
385
  : ds.needleValue.toFixed(Math.max(0, ds.precision ?? 0))}
383
386
  <span class="unit paging" ?active=${this.textActive}>${ds.unit}</span>