@record-evolution/widget-image 1.1.15 → 1.1.17

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.
@@ -15,6 +15,9 @@ export class WidgetImage extends LitElement {
15
15
  @property({ type: Object })
16
16
  theme?: Theme
17
17
 
18
+ @property({ type: Object })
19
+ timeRange?: { start: number; end: number }
20
+
18
21
  @state() private themeBgColor?: string
19
22
  @state() private themeTitleColor?: string
20
23
  @state() private themeSubtitleColor?: string
@@ -34,7 +37,7 @@ export class WidgetImage extends LitElement {
34
37
  }
35
38
 
36
39
  update(changedProperties: Map<string, any>) {
37
- if (changedProperties.has('inputData')) {
40
+ if (changedProperties.has('inputData') || changedProperties.has('timeRange')) {
38
41
  this.updateGridLayout()
39
42
  }
40
43
 
@@ -69,20 +72,47 @@ export class WidgetImage extends LitElement {
69
72
  }
70
73
 
71
74
  /**
72
- * Update grid layout based on container size and number of elements
75
+ * Get images filtered by timeRange if available
73
76
  */
74
- updateGridLayout() {
75
- if (!this.wrapper) return
76
-
77
+ getFilteredImages() {
77
78
  const singleImageUrl = this.inputData?.useUpload
78
79
  ? typeof this.inputData?.image === 'string'
79
80
  ? this.inputData.image
80
81
  : ''
81
82
  : (this.inputData?.imageUrl ?? '')
82
83
 
83
- const images = this.inputData?.multiImage
84
+ let images = this.inputData?.multiImage
84
85
  ? (this.inputData?.data ?? [])
85
- : [{ imageUrl: singleImageUrl, title: this.inputData?.title ?? '' }]
86
+ : [{ imageUrl: singleImageUrl, label: this.inputData?.title ?? '' }]
87
+
88
+ // Filter by timeRange if provided and in multi-image mode
89
+ if (this.timeRange && this.inputData?.multiImage) {
90
+ const timeRangeStart = Number(this.timeRange.start)
91
+ const timeRangeEnd = Number(this.timeRange.end)
92
+
93
+ if (!isNaN(timeRangeStart) || !isNaN(timeRangeEnd)) {
94
+ images = images.filter((img) => {
95
+ const timestamp = img.timestamp
96
+ if (timestamp === undefined || timestamp === null) return true // Keep images without timestamps
97
+ const ts = Number(timestamp)
98
+ if (isNaN(ts)) return true // Keep if timestamp is not a valid number
99
+ if (!isNaN(timeRangeStart) && ts < timeRangeStart) return false
100
+ if (!isNaN(timeRangeEnd) && ts > timeRangeEnd) return false
101
+ return true
102
+ })
103
+ }
104
+ }
105
+
106
+ return images
107
+ }
108
+
109
+ /**
110
+ * Update grid layout based on container size and number of elements
111
+ */
112
+ updateGridLayout() {
113
+ if (!this.wrapper) return
114
+
115
+ const images = this.getFilteredImages()
86
116
 
87
117
  const numElements = images.length
88
118
  if (numElements === 0) return
@@ -273,18 +303,10 @@ export class WidgetImage extends LitElement {
273
303
  `
274
304
 
275
305
  render() {
276
- const singleImageUrl = this.inputData?.useUpload
277
- ? typeof this.inputData?.image === 'string'
278
- ? this.inputData.image
279
- : ''
280
- : (this.inputData?.imageUrl ?? '')
281
-
282
- const images = this.inputData?.multiImage
283
- ? (this.inputData?.data ?? [])
284
- : [{ imageUrl: singleImageUrl, title: this.inputData?.title ?? '' }]
306
+ const images = this.getFilteredImages()
285
307
 
286
308
  const hasMultipleItems = images.length > 1
287
- const showTitles = images.filter((img) => img.title).length > 0
309
+ const showTitles = images.filter((img) => img.label).length > 0
288
310
  const hasAnyImage = images.some((img) => img.imageUrl)
289
311
 
290
312
  return html`
@@ -328,11 +350,20 @@ export class WidgetImage extends LitElement {
328
350
  class="image-item"
329
351
  style="width: ${this.elementWidth}px; height: ${this.elementHeight}px;"
330
352
  >
331
- ${showTitles ? html`<h2 class="title">${img.title ?? ''}</h2>` : nothing}
353
+ ${showTitles
354
+ ? html`<h2
355
+ class="title"
356
+ style="${this.inputData?.labelFontSize
357
+ ? `font-size: ${this.inputData.labelFontSize}px;`
358
+ : ''}"
359
+ >
360
+ ${img.label ?? ''}
361
+ </h2>`
362
+ : nothing}
332
363
  <div class="img-container paging" ?active="${img.imageUrl}">
333
364
  <img
334
365
  src="${ifDefined(img.imageUrl)}"
335
- alt="${img.title || 'Image Widget'}"
366
+ alt="${img.label || 'Image Widget'}"
336
367
  style="object-fit: ${this.inputData?.stretchToFit ? 'fill' : 'contain'}"
337
368
  />
338
369
  </div>