Skip to content

Commit e2e89a2

Browse files
committed
VueUiSparkgauge improvements
1 parent 7a750e3 commit e2e89a2

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-data-ui",
33
"private": false,
4-
"version": "2.0.33",
4+
"version": "2.0.34",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2727,7 +2727,7 @@ const nestedDonutsDataset = ref([
27272727
])
27282728
27292729
const sparkGaugeDataset = ref({
2730-
value: 10,
2730+
value: 0,
27312731
min: -10,
27322732
max: 10,
27332733
title: "Some KPI with a long name"

src/components/vue-ui-sparkgauge.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ const svg = computed(() => {
3636
}
3737
})
3838
39-
console.log(svg.value)
40-
4139
const bounds = computed(() => {
4240
const min = props.dataset.min ?? 0;
4341
const max = props.dataset.max ?? 0;
@@ -51,6 +49,16 @@ const bounds = computed(() => {
5149
5250
const currentScore = ref(sparkgaugeConfig.value.style.animation.show ? bounds.value.min : props.dataset.value);
5351
52+
const controlScore = computed(() => {
53+
if (currentScore.value > bounds.value.max) {
54+
return bounds.value.max;
55+
} else if (currentScore.value < bounds.value.min) {
56+
return bounds.value.min;
57+
} else {
58+
return currentScore.value;
59+
}
60+
})
61+
5462
const animationTick = computed(() => {
5563
return bounds.value.diff / sparkgaugeConfig.value.style.animation.speedMs;
5664
})
@@ -75,10 +83,11 @@ const nameLabel = computed(() => {
7583
})
7684
7785
const valueRatio = computed(() => {
86+
7887
if(currentScore.value >= 0) {
79-
return (currentScore.value - bounds.value.min) / bounds.value.diff
88+
return (controlScore.value - bounds.value.min) / bounds.value.diff
8089
} else {
81-
return (Math.abs(bounds.value.min) - Math.abs(currentScore.value)) / bounds.value.diff
90+
return (Math.abs(bounds.value.min) - Math.abs(controlScore.value)) / bounds.value.diff
8291
}
8392
})
8493

0 commit comments

Comments
 (0)