@eturnity/eturnity_reusable_components 8.16.9-qa-16-03-26.2 → 8.19.0
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 +1 -1
- package/src/components/barchart/BottomFields.vue +18 -102
- package/src/components/barchart/composables/useChartData.js +1 -1
- package/src/components/barchart/composables/useTooltip.js +0 -12
- package/src/components/barchart/index.vue +6 -27
- package/src/components/barchart/styles/bottomFields.js +1 -5
- package/src/components/barchart/styles/chart.js +0 -1
- package/src/components/inputs/inputNumber/index.vue +83 -81
- package/src/helpers/numberConverter.js +1 -1
- package/src/TestChart.vue +0 -234
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
<template>
|
2
2
|
<Container :is-chart-controls-shown-in-bottom="isChartControlsShownInBottom">
|
3
3
|
<LabelsColumn :width="yAxisWidth">
|
4
|
-
<LabelRow v-for="series in
|
4
|
+
<LabelRow v-for="series in props.series" :key="series.name">
|
5
5
|
{{ series.name }}
|
6
6
|
</LabelRow>
|
7
|
-
<TotalRow v-if="
|
7
|
+
<TotalRow v-if="props.series.length && fieldMode === 'percentage'">
|
8
8
|
{{ $gettext ? $gettext('Total (%)') : 'Total (%)' }}
|
9
9
|
</TotalRow>
|
10
|
-
<TotalRow v-if="
|
10
|
+
<TotalRow v-if="props.series.length">
|
11
11
|
{{ $gettext ? $gettext('Total (kWh)') : 'Total (kWh)' }}
|
12
12
|
</TotalRow>
|
13
13
|
</LabelsColumn>
|
@@ -18,9 +18,9 @@
|
|
18
18
|
>
|
19
19
|
<FieldsWrapper>
|
20
20
|
<!-- For stacked bar chart -->
|
21
|
-
<template v-if="
|
21
|
+
<template v-if="props.series.length">
|
22
22
|
<InputRow
|
23
|
-
v-for="series in
|
23
|
+
v-for="series in props.series"
|
24
24
|
:key="series.name"
|
25
25
|
:data-series-name="series.name"
|
26
26
|
>
|
@@ -32,14 +32,7 @@
|
|
32
32
|
>
|
33
33
|
<InputNumber
|
34
34
|
:allow-negative="false"
|
35
|
-
:error-message="null"
|
36
35
|
input-height="36px"
|
37
|
-
:is-border-error-only="true"
|
38
|
-
:is-error="
|
39
|
-
fieldMode === 'percentage'
|
40
|
-
? calculatePercentageTotal(item.label) !== 100
|
41
|
-
: false
|
42
|
-
"
|
43
36
|
:number-precision="0"
|
44
37
|
:min-decimals="0"
|
45
38
|
text-align="center"
|
@@ -68,7 +61,6 @@
|
|
68
61
|
:unit-name="fieldMode === 'percentage' ? '%' : ''"
|
69
62
|
:value="calculatePercentageTotal(item.label)"
|
70
63
|
/>
|
71
|
-
{{ $c.log(calculatePercentageTotal(item.label)) }}
|
72
64
|
</InputGroup>
|
73
65
|
</TotalInputRow>
|
74
66
|
|
@@ -80,19 +72,12 @@
|
|
80
72
|
:key="index"
|
81
73
|
>
|
82
74
|
<InputNumber
|
83
|
-
error-message="The entered values don’t add up to 100% so we will automatically scale the total kWh"
|
84
75
|
input-height="36px"
|
85
|
-
:is-border-error-only="true"
|
86
|
-
:is-error="
|
87
|
-
fieldMode === 'percentage'
|
88
|
-
? calculatePercentageTotal(item.label) !== 100
|
89
|
-
: false
|
90
|
-
"
|
91
76
|
:is-read-only="true"
|
92
77
|
:number-precision="2"
|
93
78
|
:min-decimals="0"
|
94
79
|
text-align="center"
|
95
|
-
:value="
|
80
|
+
:value="calculateTotal(item.label)"
|
96
81
|
/>
|
97
82
|
</InputGroup>
|
98
83
|
</TotalInputRow>
|
@@ -125,8 +110,7 @@
|
|
125
110
|
</template>
|
126
111
|
|
127
112
|
<script setup>
|
128
|
-
import { ref
|
129
|
-
import styled from 'vue3-styled-components'
|
113
|
+
import { ref } from 'vue'
|
130
114
|
import InputNumber from '../inputs/inputNumber'
|
131
115
|
|
132
116
|
import {
|
@@ -177,43 +161,6 @@
|
|
177
161
|
},
|
178
162
|
})
|
179
163
|
|
180
|
-
const seriesData = ref([])
|
181
|
-
|
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]
|
199
|
-
const newSeriesData = []
|
200
|
-
|
201
|
-
props.series.forEach((item, itemIndex) => {
|
202
|
-
const data = item.data.map((d, dIndex) => ({
|
203
|
-
label: d.label,
|
204
|
-
value: d.value,
|
205
|
-
originalValue: currentSeriesData[itemIndex].data[dIndex].originalValue,
|
206
|
-
}))
|
207
|
-
|
208
|
-
newSeriesData.push({
|
209
|
-
name: item.name,
|
210
|
-
data,
|
211
|
-
})
|
212
|
-
})
|
213
|
-
|
214
|
-
seriesData.value = [...newSeriesData]
|
215
|
-
})
|
216
|
-
|
217
164
|
const emit = defineEmits([
|
218
165
|
'sync-scroll',
|
219
166
|
'input-blur',
|
@@ -228,13 +175,11 @@
|
|
228
175
|
emit('input-focus', { seriesName, label })
|
229
176
|
}
|
230
177
|
|
231
|
-
const
|
232
|
-
|
178
|
+
const calculateTotal = (label) => {
|
179
|
+
return props.series.reduce((sum, series) => {
|
233
180
|
const value = series.data.find((d) => d.label === label)?.value || 0
|
234
181
|
return sum + value
|
235
182
|
}, 0)
|
236
|
-
|
237
|
-
return Math.round(total)
|
238
183
|
}
|
239
184
|
|
240
185
|
const syncScroll = (scrollLeft) => {
|
@@ -245,59 +190,30 @@
|
|
245
190
|
container.scrollLeft = scrollLeft
|
246
191
|
}
|
247
192
|
}
|
248
|
-
|
249
|
-
const calculateTotalOriginalValue = (label) => {
|
250
|
-
return seriesData.value.reduce((sum, series) => {
|
251
|
-
const value =
|
252
|
-
series.data.find((d) => d.label === label)?.originalValue || 0
|
253
|
-
return sum + value
|
254
|
-
}, 0)
|
255
|
-
}
|
256
|
-
|
257
|
-
const getDisplayValue = (data, label) => {
|
193
|
+
const getDisplayValue = (seriesData, label) => {
|
258
194
|
if (props.fieldMode === 'absolute') {
|
259
|
-
return
|
195
|
+
return seriesData.find((d) => d.label === label)?.value || ''
|
260
196
|
}
|
261
197
|
|
262
|
-
const value =
|
263
|
-
|
264
|
-
|
265
|
-
const value =
|
266
|
-
series.data.find((d) => d.label === label)?.originalValue || 0
|
267
|
-
return sum + value
|
268
|
-
}, 0)
|
269
|
-
|
270
|
-
return Math.round((value / total) * 100)
|
198
|
+
const value = seriesData.find((d) => d.label === label)?.value || 0
|
199
|
+
const total = calculateTotal(label)
|
200
|
+
return total ? Number(((value / total) * 100).toFixed(0)) : 0
|
271
201
|
}
|
272
202
|
|
273
203
|
const calculatePercentageTotal = (label) => {
|
274
|
-
|
275
|
-
const originalValue =
|
276
|
-
series.data.find((d) => d.label === label)?.originalValue || 0
|
277
|
-
return sum + originalValue
|
278
|
-
}, 0)
|
279
|
-
|
280
|
-
const totalPercentage = seriesData.value.reduce((sum, series) => {
|
204
|
+
return props.series.reduce((sum, series) => {
|
281
205
|
const value = series.data.find((d) => d.label === label)?.value || 0
|
282
|
-
const
|
283
|
-
|
284
|
-
: 0
|
206
|
+
const total = calculateTotal(label)
|
207
|
+
const percentage = total ? Number(((value / total) * 100).toFixed(0)) : 0
|
285
208
|
return sum + percentage
|
286
209
|
}, 0)
|
287
|
-
|
288
|
-
return Math.round(totalPercentage)
|
289
210
|
}
|
290
211
|
|
291
212
|
const handleInputBlur = (_value, seriesName, label) => {
|
292
213
|
let value = Number(_value)
|
293
214
|
|
294
215
|
if (props.fieldMode === 'percentage') {
|
295
|
-
const total =
|
296
|
-
const value =
|
297
|
-
series.data.find((d) => d.label === label)?.originalValue || 0
|
298
|
-
return sum + value
|
299
|
-
}, 0)
|
300
|
-
|
216
|
+
const total = calculateTotal(label)
|
301
217
|
value = (value / 100) * total
|
302
218
|
}
|
303
219
|
|
@@ -66,7 +66,7 @@ export function useChartData(props, paddedMaxValue) {
|
|
66
66
|
let accumulated = 0
|
67
67
|
return {
|
68
68
|
label: item.label,
|
69
|
-
segments: [...props.series].map((series, index) => {
|
69
|
+
segments: [...props.series].reverse().map((series, index) => {
|
70
70
|
const value =
|
71
71
|
series.data.find((d) => d.label === item.label)?.value || 0
|
72
72
|
accumulated += value
|
@@ -18,18 +18,6 @@ export function useTooltip(chartId, normalizedData) {
|
|
18
18
|
}
|
19
19
|
if (isObjectEqual(item, tooltipData.value)) return
|
20
20
|
|
21
|
-
const totalValue = item.segments.reduce((acc, segment) => {
|
22
|
-
return acc + segment.value
|
23
|
-
}, 0)
|
24
|
-
|
25
|
-
const segments = item.segments.map((segment) => {
|
26
|
-
let valuePercentage = (segment.value / totalValue) * 100
|
27
|
-
segment.valuePercentage = Math.round(valuePercentage)
|
28
|
-
|
29
|
-
return segment
|
30
|
-
})
|
31
|
-
item.segments = segments
|
32
|
-
|
33
21
|
tooltipData.value = { ...item }
|
34
22
|
|
35
23
|
const targetElement = series.length
|
@@ -30,7 +30,7 @@
|
|
30
30
|
)
|
31
31
|
"
|
32
32
|
>
|
33
|
-
<YAxisLabel>{{
|
33
|
+
<YAxisLabel>{{ label }}</YAxisLabel>
|
34
34
|
<YAxisLine :y-axis-width="yAxisWidth" />
|
35
35
|
</YAxisRow>
|
36
36
|
</YAxis>
|
@@ -128,11 +128,7 @@
|
|
128
128
|
:gradient-to="segment.gradientTo"
|
129
129
|
/>
|
130
130
|
<TooltipText>
|
131
|
-
{{
|
132
|
-
fieldMode === 'absolute' && showPercentageOnTooltip
|
133
|
-
? `${segment.valuePercentage}%`
|
134
|
-
: handleValueFormatter(segment.value)
|
135
|
-
}}
|
131
|
+
{{ handleValueFormatter(segment.value) }}
|
136
132
|
</TooltipText>
|
137
133
|
</TooltipRow>
|
138
134
|
</template>
|
@@ -175,13 +171,12 @@
|
|
175
171
|
</template>
|
176
172
|
|
177
173
|
<script setup>
|
178
|
-
import { useSlots, computed
|
174
|
+
import { useSlots, computed } from 'vue'
|
179
175
|
|
180
176
|
import ChartControls from './ChartControls'
|
181
177
|
import BottomFields from './BottomFields'
|
182
178
|
import SelectionBox from './SelectionBox'
|
183
179
|
import Spinner from '../spinner'
|
184
|
-
import { numberToString } from '../../helpers/numberConverter'
|
185
180
|
|
186
181
|
import {
|
187
182
|
useTooltip,
|
@@ -301,10 +296,6 @@
|
|
301
296
|
type: Boolean,
|
302
297
|
default: false,
|
303
298
|
},
|
304
|
-
showPercentageOnTooltip: {
|
305
|
-
type: Boolean,
|
306
|
-
default: false,
|
307
|
-
},
|
308
299
|
})
|
309
300
|
|
310
301
|
const generateChartId = () =>
|
@@ -387,20 +378,8 @@
|
|
387
378
|
}
|
388
379
|
|
389
380
|
const handleValueFormatter = (value) => {
|
390
|
-
|
391
|
-
value
|
392
|
-
|
393
|
-
minDecimals: 0,
|
394
|
-
})
|
395
|
-
|
396
|
-
return props.valueFormatter ? props.valueFormatter(value) : value
|
397
|
-
}
|
398
|
-
|
399
|
-
const getYAxisLabel = (label) => {
|
400
|
-
return numberToString({
|
401
|
-
value: label,
|
402
|
-
numberPrecision: 0,
|
403
|
-
minDecimals: 0,
|
404
|
-
})
|
381
|
+
return props.valueFormatter
|
382
|
+
? props.valueFormatter(Math.round(value))
|
383
|
+
: value
|
405
384
|
}
|
406
385
|
</script>
|
@@ -28,6 +28,7 @@ export const TotalRow = styled(LabelRow)``
|
|
28
28
|
|
29
29
|
export const FieldsContainer = styled.div`
|
30
30
|
flex: 1;
|
31
|
+
overflow-x: auto;
|
31
32
|
scrollbar-width: none;
|
32
33
|
|
33
34
|
&::-webkit-scrollbar {
|
@@ -62,9 +63,4 @@ export const InputGroup = styled('div', {
|
|
62
63
|
props.barWidth}px;
|
63
64
|
display: flex;
|
64
65
|
justify-content: center;
|
65
|
-
position: relative;
|
66
|
-
|
67
|
-
input[readonly] {
|
68
|
-
border: 1px solid ${(props) => props.theme.colors.grey4} !important;
|
69
|
-
}
|
70
66
|
`
|
@@ -50,7 +50,6 @@
|
|
50
50
|
:has-slot="hasSlot"
|
51
51
|
:has-unit="unitName && !!unitName.length"
|
52
52
|
:input-height="inputHeight"
|
53
|
-
:is-border-error-only="isBorderErrorOnly"
|
54
53
|
:is-disabled="disabled"
|
55
54
|
:is-error="isError"
|
56
55
|
:is-interactive="isInteractive"
|
@@ -58,12 +57,11 @@
|
|
58
57
|
:no-border="noBorder"
|
59
58
|
:placeholder="displayedPlaceholder"
|
60
59
|
:read-only="isReadOnly"
|
61
|
-
:readonly="isReadOnly"
|
62
60
|
:show-arrow-controls="showArrowControls"
|
63
61
|
:show-linear-unit-name="showLinearUnitName"
|
64
62
|
:slot-size="slotSize"
|
65
63
|
:text-align="textAlign"
|
66
|
-
:value="
|
64
|
+
:value="formatWithCurrency(value)"
|
67
65
|
@blur="onInputBlur($event)"
|
68
66
|
@focus="focusInput()"
|
69
67
|
@input="onInput($event)"
|
@@ -77,12 +75,12 @@
|
|
77
75
|
|
78
76
|
<UnitContainer
|
79
77
|
v-if="unitName && showLinearUnitName && !hasSlot"
|
80
|
-
:has-length="
|
78
|
+
:has-length="!!textInput.length"
|
81
79
|
:is-error="isError"
|
82
80
|
>{{ unitName }}</UnitContainer
|
83
81
|
>
|
84
82
|
<IconWrapper
|
85
|
-
v-if="isError && !showLinearUnitName
|
83
|
+
v-if="isError && !showLinearUnitName"
|
86
84
|
:margin-right="showSelect ? selectWidth : 0"
|
87
85
|
size="16px"
|
88
86
|
>
|
@@ -94,7 +92,7 @@
|
|
94
92
|
:disabled="isSelectDisabled"
|
95
93
|
:select-width="`${selectWidth}px`"
|
96
94
|
:show-border="false"
|
97
|
-
@input-change="
|
95
|
+
@input-change="$emit('select-change', $event)"
|
98
96
|
>
|
99
97
|
<template #selector>
|
100
98
|
<SelectText>{{ getSelectValue }}</SelectText>
|
@@ -136,9 +134,7 @@
|
|
136
134
|
</ArrowButton>
|
137
135
|
</ArrowControls>
|
138
136
|
</InputWrapper>
|
139
|
-
<ErrorMessage v-if="isError
|
140
|
-
errorMessage
|
141
|
-
}}</ErrorMessage>
|
137
|
+
<ErrorMessage v-if="isError">{{ errorMessage }}</ErrorMessage>
|
142
138
|
</Container>
|
143
139
|
</template>
|
144
140
|
|
@@ -209,7 +205,6 @@
|
|
209
205
|
colorMode: String,
|
210
206
|
showArrowControls: Boolean,
|
211
207
|
readOnly: Boolean,
|
212
|
-
isBorderErrorOnly: Boolean,
|
213
208
|
}
|
214
209
|
|
215
210
|
const Container = styled('div', inputProps)`
|
@@ -241,17 +236,16 @@
|
|
241
236
|
showLinearUnitName,
|
242
237
|
colorMode,
|
243
238
|
showArrowControls,
|
244
|
-
isBorderErrorOnly,
|
245
239
|
}) =>
|
246
240
|
showArrowControls
|
247
241
|
? '40px'
|
248
242
|
: colorMode === 'transparent'
|
249
243
|
? '0'
|
250
244
|
: slotSize
|
251
|
-
? isError && !showLinearUnitName
|
245
|
+
? isError && !showLinearUnitName
|
252
246
|
? 'calc(' + slotSize + ' + 24px)'
|
253
247
|
: 'calc(' + slotSize + ' + 10px)'
|
254
|
-
: isError && !showLinearUnitName
|
248
|
+
: isError && !showLinearUnitName
|
255
249
|
? '24px'
|
256
250
|
: '5px'};
|
257
251
|
border-radius: ${(props) =>
|
@@ -463,18 +457,8 @@
|
|
463
457
|
background-color: ${({ theme }) => theme.colors.grey4};
|
464
458
|
`
|
465
459
|
|
466
|
-
const EVENT_TYPES = {
|
467
|
-
INPUT_FOCUS: 'input-focus',
|
468
|
-
INPUT_CHANGE: 'input-change',
|
469
|
-
INPUT_BLUR: 'input-blur',
|
470
|
-
PRESS_ENTER: 'on-enter-click',
|
471
|
-
INPUT_DRAG: 'on-input-drag',
|
472
|
-
SELECT_CHANGE: 'select-change',
|
473
|
-
}
|
474
|
-
|
475
460
|
export default {
|
476
461
|
name: 'InputNumber',
|
477
|
-
emits: [...Object.values(EVENT_TYPES)],
|
478
462
|
components: {
|
479
463
|
Container,
|
480
464
|
InputContainer,
|
@@ -529,9 +513,10 @@
|
|
529
513
|
default: '40px',
|
530
514
|
},
|
531
515
|
value: {
|
532
|
-
type: [String, Number],
|
533
516
|
required: true,
|
534
517
|
default: null,
|
518
|
+
validator: (val) =>
|
519
|
+
typeof val === 'string' || typeof val === 'number' || val === null,
|
535
520
|
},
|
536
521
|
clearInput: {
|
537
522
|
type: Boolean,
|
@@ -714,17 +699,12 @@
|
|
714
699
|
type: Boolean,
|
715
700
|
default: false,
|
716
701
|
},
|
717
|
-
isBorderErrorOnly: {
|
718
|
-
type: Boolean,
|
719
|
-
default: false,
|
720
|
-
},
|
721
702
|
},
|
722
703
|
data() {
|
723
704
|
return {
|
705
|
+
textInput: '',
|
724
706
|
isFocused: false,
|
725
707
|
warningIcon: warningIcon,
|
726
|
-
inputValue: null,
|
727
|
-
enteredValue: null,
|
728
708
|
}
|
729
709
|
},
|
730
710
|
computed: {
|
@@ -747,14 +727,6 @@
|
|
747
727
|
|
748
728
|
return item ? item.label : '-'
|
749
729
|
},
|
750
|
-
formattedValue() {
|
751
|
-
return this.isFocused
|
752
|
-
? this.enteredValue
|
753
|
-
: this.formatWithCurrency(this.value)
|
754
|
-
},
|
755
|
-
hasLength() {
|
756
|
-
return this.formattedValue !== null && this.formattedValue.length > 0
|
757
|
-
},
|
758
730
|
},
|
759
731
|
watch: {
|
760
732
|
focus(value) {
|
@@ -765,19 +737,30 @@
|
|
765
737
|
clearInput: function (value) {
|
766
738
|
if (value) {
|
767
739
|
// If the value is typed, then we should clear the textInput on Continue
|
768
|
-
this.
|
769
|
-
this.enteredValue = ''
|
740
|
+
this.textInput = ''
|
770
741
|
}
|
771
742
|
},
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
}
|
780
|
-
}
|
743
|
+
},
|
744
|
+
created() {
|
745
|
+
if (this.value) {
|
746
|
+
this.textInput = numberToString({
|
747
|
+
value: this.value,
|
748
|
+
numberPrecision: this.numberPrecision,
|
749
|
+
minDecimals: this.minDecimals,
|
750
|
+
})
|
751
|
+
} else if (this.defaultNumber !== null) {
|
752
|
+
this.textInput = numberToString({
|
753
|
+
value: this.defaultNumber,
|
754
|
+
numberPrecision: this.numberPrecision,
|
755
|
+
minDecimals: this.minDecimals,
|
756
|
+
})
|
757
|
+
} else if (this.minNumber !== null) {
|
758
|
+
this.textInput = numberToString({
|
759
|
+
value: this.minNumber,
|
760
|
+
numberPrecision: this.numberPrecision,
|
761
|
+
minDecimals: this.minDecimals,
|
762
|
+
})
|
763
|
+
}
|
781
764
|
},
|
782
765
|
mounted() {
|
783
766
|
if (this.focus) {
|
@@ -816,28 +799,29 @@
|
|
816
799
|
}
|
817
800
|
},
|
818
801
|
onEnterPress() {
|
819
|
-
this.$emit(
|
802
|
+
this.$emit('on-enter-click')
|
820
803
|
this.$refs.inputField1.$el.blur()
|
821
804
|
},
|
822
|
-
onChangeHandler(
|
823
|
-
if (isNaN(
|
824
|
-
|
805
|
+
onChangeHandler(event) {
|
806
|
+
if (isNaN(event) || event === '') {
|
807
|
+
event = this.defaultNumber
|
825
808
|
? this.defaultNumber
|
826
809
|
: this.minNumber || this.minNumber === 0
|
827
810
|
? this.minNumber
|
828
|
-
:
|
811
|
+
: event
|
829
812
|
}
|
830
813
|
if (!this.allowNegative) {
|
831
|
-
|
814
|
+
event = Math.abs(event)
|
832
815
|
}
|
833
|
-
|
816
|
+
event = parseFloat(event)
|
834
817
|
// Need to return an integer rather than a string
|
835
|
-
|
818
|
+
this.$emit('input-change', event)
|
836
819
|
},
|
837
|
-
onEvaluateCode(
|
820
|
+
onEvaluateCode(event) {
|
838
821
|
// function to perform math on the code
|
839
822
|
// filter the string in case of any malicious content
|
840
|
-
|
823
|
+
const val = event.target.value
|
824
|
+
let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
|
841
825
|
filtered = filtered.split(/([-+*/()])/)
|
842
826
|
let formatted = filtered.map((item) => {
|
843
827
|
if (
|
@@ -895,32 +879,48 @@
|
|
895
879
|
return array
|
896
880
|
},
|
897
881
|
onInput(event) {
|
898
|
-
|
899
|
-
this.enteredValue = event.target.value
|
900
|
-
if (!this.isFocused || this.enteredValue === this.inputValue) {
|
882
|
+
if (!this.isFocused) {
|
901
883
|
return
|
902
884
|
}
|
885
|
+
if (event.target.value === '') {
|
886
|
+
this.$emit('on-input', '')
|
887
|
+
}
|
903
888
|
let evaluatedVal
|
904
889
|
try {
|
905
|
-
evaluatedVal = this.onEvaluateCode(
|
890
|
+
evaluatedVal = this.onEvaluateCode(event)
|
906
891
|
} finally {
|
907
|
-
this.
|
908
|
-
|
909
|
-
if (this.isFocused && typeof this.enteredValue !== 'number') {
|
910
|
-
this.$emit(EVENT_TYPES.INPUT_CHANGE, this.inputValue)
|
892
|
+
if (evaluatedVal && this.value != evaluatedVal) {
|
893
|
+
this.$emit('on-input', evaluatedVal)
|
911
894
|
}
|
912
895
|
}
|
913
896
|
this.textInput = evaluatedVal
|
914
897
|
},
|
915
898
|
onInputBlur(e) {
|
916
899
|
this.isFocused = false
|
917
|
-
|
918
|
-
|
900
|
+
let value = e.target.value
|
901
|
+
let evaluatedInput = this.onEvaluateCode(e)
|
902
|
+
this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
|
903
|
+
if ((evaluatedInput && value.length) || this.minNumber !== null) {
|
904
|
+
this.textInput = numberToString({
|
905
|
+
value:
|
906
|
+
evaluatedInput && value.length
|
907
|
+
? evaluatedInput
|
908
|
+
: this.defaultNumber
|
909
|
+
? this.defaultNumber
|
910
|
+
: this.minNumber,
|
911
|
+
numberPrecision: this.numberPrecision,
|
912
|
+
minDecimals: this.minDecimals,
|
913
|
+
})
|
919
914
|
}
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
915
|
+
let adjustedMinValue =
|
916
|
+
evaluatedInput && evaluatedInput.length
|
917
|
+
? evaluatedInput
|
918
|
+
: this.defaultNumber
|
919
|
+
? this.defaultNumber
|
920
|
+
: this.minNumber || this.minNumber === 0
|
921
|
+
? this.minNumber
|
922
|
+
: ''
|
923
|
+
this.$emit('input-blur', adjustedMinValue)
|
924
924
|
},
|
925
925
|
focusInput() {
|
926
926
|
if (this.disabled) {
|
@@ -930,7 +930,7 @@
|
|
930
930
|
this.$nextTick(() => {
|
931
931
|
this.$refs.inputField1.$el.select()
|
932
932
|
})
|
933
|
-
this.$emit(
|
933
|
+
this.$emit('input-focus')
|
934
934
|
},
|
935
935
|
blurInput() {
|
936
936
|
if (this.disabled) {
|
@@ -950,7 +950,7 @@
|
|
950
950
|
: this.minNumber || this.minNumber === 0
|
951
951
|
? this.minNumber
|
952
952
|
: ''
|
953
|
-
if (adjustedMinValue || adjustedMinValue === 0) {
|
953
|
+
if ((adjustedMinValue || adjustedMinValue === 0) && !this.isFocused) {
|
954
954
|
let input = this.numberToStringEnabled
|
955
955
|
? numberToString({
|
956
956
|
value: adjustedMinValue,
|
@@ -963,8 +963,6 @@
|
|
963
963
|
return input + ' ' + unit
|
964
964
|
} else if (!adjustedMinValue && adjustedMinValue !== 0) {
|
965
965
|
return ''
|
966
|
-
} else if (this.isFocused) {
|
967
|
-
return value
|
968
966
|
} else {
|
969
967
|
return this.numberToStringEnabled
|
970
968
|
? numberToString({
|
@@ -985,7 +983,14 @@
|
|
985
983
|
e.preventDefault()
|
986
984
|
let value = parseFloat(this.value || 0)
|
987
985
|
value += parseFloat(this.interactionStep) * parseInt(e.movementX)
|
988
|
-
this.$emit(
|
986
|
+
this.$emit('on-input-drag', value)
|
987
|
+
|
988
|
+
this.textInput = numberToString({
|
989
|
+
value: value && value.length ? value : this.minNumber,
|
990
|
+
numberPrecision: this.numberPrecision,
|
991
|
+
minDecimals: this.minDecimals,
|
992
|
+
})
|
993
|
+
//this.value=value
|
989
994
|
},
|
990
995
|
stopInteract(e) {
|
991
996
|
e.preventDefault()
|
@@ -993,9 +998,6 @@
|
|
993
998
|
window.removeEventListener('mouseup', this.stopInteract, false)
|
994
999
|
this.blurInput()
|
995
1000
|
},
|
996
|
-
handleSelectChange(value) {
|
997
|
-
this.$emit(EVENT_TYPES.SELECT_CHANGE, value)
|
998
|
-
},
|
999
1001
|
},
|
1000
1002
|
}
|
1001
1003
|
</script>
|
@@ -94,7 +94,7 @@ export const stringToNumber = ({
|
|
94
94
|
|
95
95
|
export const numberToString = ({ value, numberPrecision, minDecimals }) => {
|
96
96
|
const minimumRounding = minDecimals ? minDecimals : 0
|
97
|
-
value =
|
97
|
+
value = parseFloat(value)
|
98
98
|
return value.toLocaleString(langForLocaleString(), {
|
99
99
|
minimumFractionDigits: minimumRounding, // removing this for now. Why do we need this to be a minimum amount?
|
100
100
|
maximumFractionDigits:
|
package/src/TestChart.vue
DELETED
@@ -1,234 +0,0 @@
|
|
1
|
-
<template>
|
2
|
-
<div
|
3
|
-
style="
|
4
|
-
margin-top: 100px;
|
5
|
-
margin-left: 80px;
|
6
|
-
padding-bottom: 100px;
|
7
|
-
display: flex;
|
8
|
-
flex-direction: column;
|
9
|
-
"
|
10
|
-
>
|
11
|
-
<!-- Simple bar chart -->
|
12
|
-
<BarChart
|
13
|
-
:data="monthlyData"
|
14
|
-
width="700px"
|
15
|
-
height="400px"
|
16
|
-
:valueFormatter="valueFormatter"
|
17
|
-
:barWidth="60"
|
18
|
-
:isScrollable="false"
|
19
|
-
chartControlsPosition="bottom"
|
20
|
-
:isBottomFieldsShown="true"
|
21
|
-
:isSelectionEnabled="true"
|
22
|
-
:selectionSize="3"
|
23
|
-
@selection-change="handleSelectionChange"
|
24
|
-
>
|
25
|
-
</BarChart>
|
26
|
-
<br />
|
27
|
-
<br />
|
28
|
-
|
29
|
-
<!-- Stacked bar chart -->
|
30
|
-
<BarChart
|
31
|
-
yAxisTitle="Energy (kWh)"
|
32
|
-
:data="monthLabels"
|
33
|
-
:series="tariffZones"
|
34
|
-
width="700px"
|
35
|
-
height="400px"
|
36
|
-
:barWidth="60"
|
37
|
-
:valueFormatter="valueFormatter"
|
38
|
-
:legendsItemPerRow="4"
|
39
|
-
:splitButtonOptions="options"
|
40
|
-
:selectedSplitButton="selectedTimeFrame"
|
41
|
-
:showPercentageOnTooltip="true"
|
42
|
-
:isBottomFieldsShown="true"
|
43
|
-
:isLegendShown="true"
|
44
|
-
@select-split-button="handleSelectSplitButton"
|
45
|
-
@input-blur="handleInputBlur"
|
46
|
-
>
|
47
|
-
</BarChart>
|
48
|
-
|
49
|
-
<!-- Stacked bar chart -->
|
50
|
-
<BarChart
|
51
|
-
:data="monthLabels"
|
52
|
-
:series="tariffZones"
|
53
|
-
width="700px"
|
54
|
-
height="400px"
|
55
|
-
:barWidth="60"
|
56
|
-
:valueFormatter="valueFormatter"
|
57
|
-
:legendsItemPerRow="4"
|
58
|
-
:isBottomFieldsShown="true"
|
59
|
-
:isLegendShown="false"
|
60
|
-
fieldMode="percentage"
|
61
|
-
@select-split-button="handleSelectSplitButton"
|
62
|
-
@input-blur="handleInputBlur"
|
63
|
-
>
|
64
|
-
<!-- <template #tooltip="{ item, segment }">
|
65
|
-
<div style="display: flex; flex-direction: column">
|
66
|
-
{{ $c.log(item, segment) }}
|
67
|
-
<div>{{ item.label }}</div>
|
68
|
-
<div>{{ item.segments[0].value }} kWh</div>
|
69
|
-
</div>
|
70
|
-
</template> -->
|
71
|
-
</BarChart>
|
72
|
-
</div>
|
73
|
-
</template>
|
74
|
-
|
75
|
-
<script setup>
|
76
|
-
import { ref } from 'vue'
|
77
|
-
import BarChart from '@/components/barchart/index.vue'
|
78
|
-
|
79
|
-
const options = [
|
80
|
-
{ label: 'Day', value: 'day' },
|
81
|
-
{ label: 'Month', value: 'month' },
|
82
|
-
{ label: 'Year', value: 'year' },
|
83
|
-
]
|
84
|
-
|
85
|
-
const selectedTimeFrame = ref('day')
|
86
|
-
|
87
|
-
const handleSelectSplitButton = (value) => {
|
88
|
-
selectedTimeFrame.value = value
|
89
|
-
}
|
90
|
-
|
91
|
-
const monthlyData = [
|
92
|
-
{ label: 'Jan', value: 300 },
|
93
|
-
{ label: 'Feb', value: 600 },
|
94
|
-
{ label: 'Mar', value: 1000 },
|
95
|
-
{ label: 'Apr', value: 1200 },
|
96
|
-
{ label: 'May', value: 1400 },
|
97
|
-
{ label: 'Jun', value: 1810 },
|
98
|
-
{ label: 'Jul', value: 1400 },
|
99
|
-
{ label: 'Aug', value: 1200 },
|
100
|
-
{ label: 'Sep', value: 1000 },
|
101
|
-
// { label: 'Oct', value: 800 },
|
102
|
-
// { label: 'Nov', value: 600 },
|
103
|
-
// { label: 'Dec', value: 400 },
|
104
|
-
// { label: 'Jan', value: 300 },
|
105
|
-
// { label: 'Feb', value: 600 },
|
106
|
-
// { label: 'Mar', value: 1000 },
|
107
|
-
// { label: 'Apr', value: 1200 },
|
108
|
-
// { label: 'May', value: 1400 },
|
109
|
-
// { label: 'Jun', value: 1810 },
|
110
|
-
// { label: 'Jul', value: 1400 },
|
111
|
-
// { label: 'Aug', value: 1200 },
|
112
|
-
// { label: 'Sep', value: 1000 },
|
113
|
-
// { label: 'Oct', value: 800 },
|
114
|
-
// { label: 'Nov', value: 600 },
|
115
|
-
// { label: 'Dec', value: 400 },
|
116
|
-
|
117
|
-
// ... more months
|
118
|
-
]
|
119
|
-
|
120
|
-
const monthLabels = [
|
121
|
-
{ label: 'Jan' },
|
122
|
-
{ label: 'Feb' },
|
123
|
-
{ label: 'Mar' },
|
124
|
-
{ label: 'Apr' },
|
125
|
-
{ label: 'May' },
|
126
|
-
{ label: 'Jun' },
|
127
|
-
// ... more months
|
128
|
-
]
|
129
|
-
|
130
|
-
const tariffZones = ref([
|
131
|
-
{
|
132
|
-
name: 'Tariff Zone 1',
|
133
|
-
data: [
|
134
|
-
{ label: 'Jan', value: 200 },
|
135
|
-
{ label: 'Feb', value: 130 },
|
136
|
-
{ label: 'Mar', value: 220 },
|
137
|
-
{ label: 'Apr', value: 230 },
|
138
|
-
{ label: 'May', value: 200 },
|
139
|
-
{ label: 'Jun', value: 210 },
|
140
|
-
// ... more months
|
141
|
-
],
|
142
|
-
},
|
143
|
-
{
|
144
|
-
name: 'Tariff Zone 2',
|
145
|
-
data: [
|
146
|
-
{ label: 'Jan', value: 200 },
|
147
|
-
{ label: 'Feb', value: 100 },
|
148
|
-
{ label: 'Mar', value: 270 },
|
149
|
-
{ label: 'Apr', value: 180 },
|
150
|
-
{ label: 'May', value: 300 },
|
151
|
-
{ label: 'Jun', value: 250 },
|
152
|
-
// ... more months
|
153
|
-
],
|
154
|
-
},
|
155
|
-
{
|
156
|
-
name: 'Tariff Zone 3',
|
157
|
-
data: [
|
158
|
-
{ label: 'Jan', value: 200 },
|
159
|
-
{ label: 'Feb', value: 100 },
|
160
|
-
{ label: 'Mar', value: 210 },
|
161
|
-
{ label: 'Apr', value: 220 },
|
162
|
-
{ label: 'May', value: 300 },
|
163
|
-
{ label: 'Jun', value: 190 },
|
164
|
-
// ... more months
|
165
|
-
],
|
166
|
-
},
|
167
|
-
{
|
168
|
-
name: 'Tariff Zone 4',
|
169
|
-
data: [
|
170
|
-
{ label: 'Jan', value: 200 },
|
171
|
-
{ label: 'Feb', value: 100 },
|
172
|
-
{ label: 'Mar', value: 210 },
|
173
|
-
{ label: 'Apr', value: 220 },
|
174
|
-
{ label: 'May', value: 300 },
|
175
|
-
{ label: 'Jun', value: 190 },
|
176
|
-
// ... more months
|
177
|
-
],
|
178
|
-
},
|
179
|
-
{
|
180
|
-
name: 'Tariff Zone 5',
|
181
|
-
data: [
|
182
|
-
{ label: 'Jan', value: 200 },
|
183
|
-
{ label: 'Feb', value: 100 },
|
184
|
-
{ label: 'Mar', value: 210 },
|
185
|
-
{ label: 'Apr', value: 220 },
|
186
|
-
{ label: 'May', value: 300 },
|
187
|
-
{ label: 'Jun', value: 190 },
|
188
|
-
// ... more months
|
189
|
-
],
|
190
|
-
},
|
191
|
-
{
|
192
|
-
name: 'Tariff Zone 6',
|
193
|
-
data: [
|
194
|
-
{ label: 'Jan', value: 200 },
|
195
|
-
{ label: 'Feb', value: 100 },
|
196
|
-
{ label: 'Mar', value: 210 },
|
197
|
-
{ label: 'Apr', value: 220 },
|
198
|
-
{ label: 'May', value: 300 },
|
199
|
-
{ label: 'Jun', value: 190 },
|
200
|
-
// ... more months
|
201
|
-
],
|
202
|
-
},
|
203
|
-
// ... more tariff zones
|
204
|
-
])
|
205
|
-
|
206
|
-
const valueFormatter = (value) => {
|
207
|
-
return `${value} kWh`
|
208
|
-
}
|
209
|
-
|
210
|
-
const handleSelectionChange = (selectedBars) => {
|
211
|
-
console.log('selectedBars', selectedBars)
|
212
|
-
}
|
213
|
-
|
214
|
-
const handleInputBlur = (payload) => {
|
215
|
-
console.log({ payload })
|
216
|
-
const newVal = [...tariffZones.value].map((zone) => {
|
217
|
-
if (zone.name === payload.seriesName) {
|
218
|
-
zone.data = zone.data.map((item) => {
|
219
|
-
if (item.label === payload.label) {
|
220
|
-
item.value = payload.value
|
221
|
-
}
|
222
|
-
return item
|
223
|
-
})
|
224
|
-
}
|
225
|
-
return zone
|
226
|
-
})
|
227
|
-
|
228
|
-
console.log({ newVal })
|
229
|
-
|
230
|
-
tariffZones.value = newVal
|
231
|
-
}
|
232
|
-
</script>
|
233
|
-
|
234
|
-
<style lang="scss" scoped></style>
|