@eturnity/eturnity_reusable_components 8.16.9-qa-16-03-26.2 → 8.16.9-qa-16-03-26.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eturnity/eturnity_reusable_components",
3
- "version": "8.16.9-qa-16-03-26.2",
3
+ "version": "8.16.9-qa-16-03-26.4",
4
4
  "files": [
5
5
  "dist",
6
6
  "src"
@@ -5,10 +5,10 @@
5
5
  {{ series.name }}
6
6
  </LabelRow>
7
7
  <TotalRow v-if="seriesData.length && fieldMode === 'percentage'">
8
- {{ $gettext ? $gettext('Total (%)') : 'Total (%)' }}
8
+ {{ $gettext ? `${$gettext('Total')} (%)` : 'Total (%)' }}
9
9
  </TotalRow>
10
10
  <TotalRow v-if="seriesData.length">
11
- {{ $gettext ? $gettext('Total (kWh)') : 'Total (kWh)' }}
11
+ {{ $gettext ? `${$gettext('Total')} (kWh)` : 'Total (kWh)' }}
12
12
  </TotalRow>
13
13
  </LabelsColumn>
14
14
 
@@ -32,6 +32,7 @@
32
32
  >
33
33
  <InputNumber
34
34
  :allow-negative="false"
35
+ :disabled="isInputsDisabled"
35
36
  :error-message="null"
36
37
  input-height="36px"
37
38
  :is-border-error-only="true"
@@ -40,12 +41,14 @@
40
41
  ? calculatePercentageTotal(item.label) !== 100
41
42
  : false
42
43
  "
43
- :number-precision="0"
44
+ :number-precision="fieldMode === 'percentage' ? 2 : 0"
44
45
  :min-decimals="0"
45
46
  text-align="center"
46
47
  :unit-name="fieldMode === 'percentage' ? '%' : ''"
47
48
  :value="getDisplayValue(series.data, item.label)"
48
- @input-blur="handleInputBlur($event, series.name, item.label)"
49
+ @input-blur="
50
+ handleInputBlur($event, series.name, item.label, series.data)
51
+ "
49
52
  @input-focus="handleInputFocus(series.name, item.label)"
50
53
  />
51
54
  </InputGroup>
@@ -60,15 +63,15 @@
60
63
  >
61
64
  <InputNumber
62
65
  :allow-negative="false"
66
+ :disabled="isInputsDisabled"
63
67
  input-height="36px"
64
68
  :is-read-only="true"
65
- :number-precision="0"
69
+ :number-precision="fieldMode === 'percentage' ? 2 : 0"
66
70
  :min-decimals="0"
67
71
  text-align="center"
68
72
  :unit-name="fieldMode === 'percentage' ? '%' : ''"
69
73
  :value="calculatePercentageTotal(item.label)"
70
74
  />
71
- {{ $c.log(calculatePercentageTotal(item.label)) }}
72
75
  </InputGroup>
73
76
  </TotalInputRow>
74
77
 
@@ -108,12 +111,14 @@
108
111
  :key="index"
109
112
  >
110
113
  <InputNumber
114
+ :allow-negative="false"
115
+ :disabled="isInputsDisabled"
111
116
  input-height="36px"
112
117
  :min-decimals="0"
113
118
  :number-precision="2"
114
119
  text-align="center"
115
120
  :value="item.value"
116
- @input-blur="handleInputBlur($event, null, item.label)"
121
+ @input-blur="handleInputBlur($event, null, item.label, null)"
117
122
  @input-focus="handleInputFocus(null, item.label)"
118
123
  />
119
124
  </InputGroup>
@@ -125,7 +130,7 @@
125
130
  </template>
126
131
 
127
132
  <script setup>
128
- import { ref, watch, onMounted } from 'vue'
133
+ import { ref, watch, watchEffect, onMounted } from 'vue'
129
134
  import styled from 'vue3-styled-components'
130
135
  import InputNumber from '../inputs/inputNumber'
131
136
 
@@ -175,34 +180,52 @@
175
180
  default: 'absolute',
176
181
  validator: (value) => ['absolute', 'percentage'].includes(value),
177
182
  },
183
+ isInputsDisabled: {
184
+ type: Boolean,
185
+ default: false,
186
+ },
178
187
  })
179
188
 
180
189
  const seriesData = ref([])
181
190
 
182
- onMounted(() => {
183
- seriesData.value = props.series.map((item) => {
184
- const data = item.data.map((d) => ({
185
- label: d.label,
186
- value: d.value,
187
- originalValue: d.value,
188
- }))
189
-
190
- return {
191
- name: item.name,
192
- data,
193
- }
194
- })
195
- })
196
-
197
- watch(props.series, () => {
198
- const currentSeriesData = [...seriesData.value]
191
+ // onMounted(() => {
192
+ // seriesData.value = props.series.map((item) => {
193
+ // const data = item.data.map((d) => ({
194
+ // label: d.label,
195
+ // value: d.value,
196
+ // originalValue: d.value,
197
+ // }))
198
+
199
+ // return {
200
+ // name: item.name,
201
+ // data,
202
+ // }
203
+ // })
204
+ // })
205
+
206
+ watchEffect(() => {
207
+ let isNewSetOfSeries = false
208
+ const seriesDataCopy = [...seriesData.value]
209
+ if (
210
+ !seriesDataCopy.length ||
211
+ !props.series.length ||
212
+ seriesDataCopy.length !== props.series.length ||
213
+ !seriesDataCopy.some((item) => {
214
+ return props.series.map((s) => s.name).includes(item.name)
215
+ })
216
+ ) {
217
+ isNewSetOfSeries = true
218
+ }
219
+ const currentSeriesData = !isNewSetOfSeries ? seriesDataCopy : []
199
220
  const newSeriesData = []
200
221
 
201
222
  props.series.forEach((item, itemIndex) => {
202
223
  const data = item.data.map((d, dIndex) => ({
203
224
  label: d.label,
204
225
  value: d.value,
205
- originalValue: currentSeriesData[itemIndex].data[dIndex].originalValue,
226
+ originalValue: currentSeriesData.length
227
+ ? currentSeriesData[itemIndex].data[dIndex].originalValue
228
+ : d.value,
206
229
  }))
207
230
 
208
231
  newSeriesData.push({
@@ -254,7 +277,7 @@
254
277
  }, 0)
255
278
  }
256
279
 
257
- const getDisplayValue = (data, label) => {
280
+ const getDisplayValue = (data, label, shouldRound = true) => {
258
281
  if (props.fieldMode === 'absolute') {
259
282
  return data.find((d) => d.label === label)?.value || ''
260
283
  }
@@ -267,7 +290,7 @@
267
290
  return sum + value
268
291
  }, 0)
269
292
 
270
- return Math.round((value / total) * 100)
293
+ return shouldRound ? (value / total) * 100 : (value / total) * 100
271
294
  }
272
295
 
273
296
  const calculatePercentageTotal = (label) => {
@@ -288,7 +311,7 @@
288
311
  return Math.round(totalPercentage)
289
312
  }
290
313
 
291
- const handleInputBlur = (_value, seriesName, label) => {
314
+ const handleInputBlur = (_value, seriesName, label, currentSeriesData) => {
292
315
  let value = Number(_value)
293
316
 
294
317
  if (props.fieldMode === 'percentage') {
@@ -301,7 +324,18 @@
301
324
  value = (value / 100) * total
302
325
  }
303
326
 
304
- const payload = seriesName ? { seriesName, label, value } : { label, value }
327
+ const payload = seriesName
328
+ ? {
329
+ seriesName,
330
+ label,
331
+ value,
332
+ inputValue: _value,
333
+ percentage: Number(
334
+ getDisplayValue(currentSeriesData, label, false).toFixed(2)
335
+ ),
336
+ totalSeriesValue: calculateTotalOriginalValue(label),
337
+ }
338
+ : { label, value }
305
339
  emit('input-blur', payload)
306
340
  focusedInput.value = null
307
341
 
@@ -331,6 +365,11 @@
331
365
  emit('sync-scroll', event.target.scrollLeft)
332
366
  }
333
367
 
368
+ const toFixedNoRounding = (number, decimals) => {
369
+ const factor = Math.pow(10, decimals)
370
+ return Math.floor(number * factor) / factor
371
+ }
372
+
334
373
  defineExpose({
335
374
  syncScroll,
336
375
  })
@@ -84,7 +84,7 @@ export function useAxisCalculations(props, maxValue) {
84
84
  })
85
85
 
86
86
  const yAxisWidth = computed(() => {
87
- return !!props.yAxisTitle || props.isBottomFieldsShown ? '70px' : '60px'
87
+ return !!props.yAxisTitle || props.isBottomFieldsShown ? '80px' : '60px'
88
88
  })
89
89
 
90
90
  const isChartControlsShown = (position) => {
@@ -16,7 +16,9 @@ export function useTooltip(chartId, normalizedData) {
16
16
  if (!showTooltipContent.value) {
17
17
  showTooltipContent.value = true
18
18
  }
19
- if (isObjectEqual(item, tooltipData.value)) return
19
+ if (isObjectEqual(item, tooltipData.value)) {
20
+ return
21
+ }
20
22
 
21
23
  const totalValue = item.segments.reduce((acc, segment) => {
22
24
  return acc + segment.value
@@ -53,16 +55,27 @@ export function useTooltip(chartId, normalizedData) {
53
55
 
54
56
  isInputFocused.value = true
55
57
  const barData = normalizedData.value.find((item) => item.label === label)
56
-
57
58
  if (!barData) return
59
+
60
+ const totalValue = barData.segments.reduce((acc, segment) => {
61
+ return acc + segment.value
62
+ }, 0)
63
+ const segments = barData.segments.map((segment) => {
64
+ let valuePercentage = (segment.value / totalValue) * 100
65
+ segment.valuePercentage = Math.round(valuePercentage)
66
+
67
+ return segment
68
+ })
69
+ barData.segments = segments
58
70
  focusedBarData.value = barData
71
+
59
72
  const barElement = document.querySelector(
60
73
  `.barchart-${chartId} .bar-group:nth-child(${
61
74
  normalizedData.value.indexOf(barData) + 1
62
75
  })`
63
76
  )
64
-
65
77
  if (!barElement) return
78
+
66
79
  // Get the last bar segment, samee as hover behavior
67
80
  const targetElement = barElement.querySelector('.bar-segment:last-child')
68
81
  const rect = targetElement.getBoundingClientRect()
@@ -163,6 +163,7 @@
163
163
  :data="data"
164
164
  :field-mode="fieldMode"
165
165
  :is-chart-controls-shown-in-bottom="isChartControlsShown('bottom')"
166
+ :is-inputs-disabled="isLoading"
166
167
  :is-scrollable="isScrollable"
167
168
  :series="series"
168
169
  :y-axis-width="yAxisWidth"
@@ -387,13 +388,22 @@
387
388
  }
388
389
 
389
390
  const handleValueFormatter = (value) => {
390
- value = numberToString({
391
- value,
392
- numberPrecision: 0,
393
- minDecimals: 0,
394
- })
391
+ let formattedValue = value
392
+ if (value < 1000) {
393
+ formattedValue = numberToString({
394
+ value: formattedValue,
395
+ numberPrecision: 0,
396
+ minDecimals: 0,
397
+ })
398
+ } else if (value < 1000000) {
399
+ formattedValue = Number((value / 1000).toFixed(2))
400
+ } else {
401
+ formattedValue = Number((value / 1000000).toFixed(2))
402
+ }
395
403
 
396
- return props.valueFormatter ? props.valueFormatter(value) : value
404
+ return props.valueFormatter
405
+ ? props.valueFormatter(formattedValue)
406
+ : formattedValue
397
407
  }
398
408
 
399
409
  const getYAxisLabel = (label) => {