Skip to content

Commit 83a3aea

Browse files
committed
Improvement - VueUiKpi - Add option to display value as analog numbers
1 parent 6c261b5 commit 83a3aea

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/components/vue-ui-kpi.vue

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ref, computed, onMounted, watch } from "vue";
33
import { useNestedProp } from "../useNestedProp";
44
import { applyDataLabel, dataLabel } from "../lib";
55
import { useConfig } from "../useConfig";
6+
import Digits from "./vue-ui-digits.vue";
67
78
const { vue_ui_kpi: DEFAULT_CONFIG } = useConfig();
89
@@ -35,9 +36,9 @@ const animateToValue = (targetValue) => {
3536
3637
function animate() {
3738
if (displayedValue.value < targetValue) {
38-
displayedValue.value = Math.min(displayedValue.value + chunk, targetValue);
39+
displayedValue.value = Number(Math.min(displayedValue.value + chunk, targetValue).toFixed(FINAL_CONFIG.value.valueRounding));
3940
} else if (displayedValue.value > targetValue) {
40-
displayedValue.value = Math.max(displayedValue.value - chunk, targetValue);
41+
displayedValue.value = Number(Math.max(displayedValue.value - chunk, targetValue).toFixed(FINAL_CONFIG.value.valueRounding));
4142
}
4243
4344
if (displayedValue.value !== targetValue) {
@@ -76,16 +77,32 @@ watch(() => props.dataset, (newValue) => {
7677
<slot name="comment-before" :comment="dataset"></slot>
7778
<div :class="`vue-ui-kpi-value ${FINAL_CONFIG.valueClass}`" :style="`font-family: ${FINAL_CONFIG.fontFamily}; font-size:${FINAL_CONFIG.valueFontSize}px; color:${FINAL_CONFIG.valueColor}; font-weight:${FINAL_CONFIG.valueBold ? 'bold': 'normal'}; ${FINAL_CONFIG.valueCss}`">
7879
<slot name="value" :comment="dataset"></slot>
79-
{{ applyDataLabel(
80-
FINAL_CONFIG.formatter,
81-
displayedValue,
82-
dataLabel({
83-
p: FINAL_CONFIG.prefix,
84-
v: displayedValue,
85-
s: FINAL_CONFIG.suffix,
86-
r: FINAL_CONFIG.valueRounding
87-
}))
88-
}}
80+
<template v-if="FINAL_CONFIG.analogDigits.show">
81+
<div :style="{ height: FINAL_CONFIG.analogDigits.height + 'px'}">
82+
<Digits
83+
:dataset="displayedValue"
84+
:config="{
85+
backgroundColor: FINAL_CONFIG.backgroundColor,
86+
digits: {
87+
color: FINAL_CONFIG.analogDigits.color,
88+
skeletonColor: FINAL_CONFIG.analogDigits.skeletonColor
89+
}
90+
}"
91+
/>
92+
</div>
93+
</template>
94+
<template v-else>
95+
{{ applyDataLabel(
96+
FINAL_CONFIG.formatter,
97+
displayedValue,
98+
dataLabel({
99+
p: FINAL_CONFIG.prefix,
100+
v: displayedValue,
101+
s: FINAL_CONFIG.suffix,
102+
r: FINAL_CONFIG.valueRounding
103+
}))
104+
}}
105+
</template>
89106
</div>
90107
<slot name="comment-after" :comment="dataset"></slot>
91108
</div>

0 commit comments

Comments
 (0)