Skip to content

Commit

Permalink
VueUiSparkgauge improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
graphieros committed Mar 20, 2024
1 parent 7a750e3 commit e2e89a2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vue-data-ui",
"private": false,
"version": "2.0.33",
"version": "2.0.34",
"type": "module",
"description": "A user-empowering data visualization Vue components library",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,7 @@ const nestedDonutsDataset = ref([
])
const sparkGaugeDataset = ref({
value: 10,
value: 0,
min: -10,
max: 10,
title: "Some KPI with a long name"
Expand Down
17 changes: 13 additions & 4 deletions src/components/vue-ui-sparkgauge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const svg = computed(() => {
}
})
console.log(svg.value)
const bounds = computed(() => {
const min = props.dataset.min ?? 0;
const max = props.dataset.max ?? 0;
Expand All @@ -51,6 +49,16 @@ const bounds = computed(() => {
const currentScore = ref(sparkgaugeConfig.value.style.animation.show ? bounds.value.min : props.dataset.value);
const controlScore = computed(() => {
if (currentScore.value > bounds.value.max) {
return bounds.value.max;
} else if (currentScore.value < bounds.value.min) {
return bounds.value.min;
} else {
return currentScore.value;
}
})
const animationTick = computed(() => {
return bounds.value.diff / sparkgaugeConfig.value.style.animation.speedMs;
})
Expand All @@ -75,10 +83,11 @@ const nameLabel = computed(() => {
})
const valueRatio = computed(() => {
if(currentScore.value >= 0) {
return (currentScore.value - bounds.value.min) / bounds.value.diff
return (controlScore.value - bounds.value.min) / bounds.value.diff
} else {
return (Math.abs(bounds.value.min) - Math.abs(currentScore.value)) / bounds.value.diff
return (Math.abs(bounds.value.min) - Math.abs(controlScore.value)) / bounds.value.diff
}
})
Expand Down

0 comments on commit e2e89a2

Please sign in to comment.