Skip to content

Commit 004beee

Browse files
committed
Fix - VueUiTiremarks - Fix reactivity issues
1 parent a20e8f7 commit 004beee

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/components/vue-ui-tiremarks.vue

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ const { isPrinting, isImaging, generatePdf, generateImage } = usePrinter({
6767
6868
const activeValue = ref(FINAL_CONFIG.value.style.chart.animation.use ? 0 : checkNaN(props.dataset.percentage));
6969
70-
watch(() => props.dataset.percentage, () => {
71-
activeValue.value = FINAL_CONFIG.value.style.chart.animation.use ? 0 : checkNaN(props.dataset.percentage);
72-
useAnimation()
73-
})
70+
watch(() => props.dataset, (v) => {
71+
if (FINAL_CONFIG.value.style.chart.animation.use) {
72+
useAnimation(v.percentage);
73+
} else {
74+
activeValue.value = v.percentage || 0
75+
}
76+
}, { deep: true });
7477
7578
onMounted(() => {
7679
if (objectIsEmpty(props.dataset)) {
@@ -79,27 +82,25 @@ onMounted(() => {
7982
type: 'dataset'
8083
})
8184
}
82-
useAnimation()
85+
useAnimation(props.dataset.percentage || 0)
8386
});
8487
85-
function useAnimation() {
86-
let acceleration = 0;
88+
function useAnimation(targetValue) {
8789
let speed = FINAL_CONFIG.value.style.chart.animation.speed;
88-
let incr = (0.005) * FINAL_CONFIG.value.style.chart.animation.acceleration;
90+
const chunk = Math.abs(targetValue - activeValue.value) / (speed * 120);
91+
8992
function animate() {
90-
activeValue.value += speed + acceleration;
91-
acceleration += incr;
92-
if (activeValue.value < props.dataset.percentage) {
93-
requestAnimationFrame(animate);
94-
} else {
95-
activeValue.value = checkNaN(props.dataset.percentage);
93+
if(activeValue.value < targetValue) {
94+
activeValue.value = Math.min(activeValue.value + chunk, targetValue);
95+
} else if (activeValue.value > targetValue) {
96+
activeValue.value = Math.max(activeValue.value - chunk, targetValue)
97+
}
98+
99+
if (activeValue.value !== targetValue) {
100+
requestAnimationFrame(animate)
96101
}
97102
}
98-
99-
if(FINAL_CONFIG.value.style.chart.animation.use) {
100-
activeValue.value = 0;
101-
animate();
102-
}
103+
animate()
103104
}
104105
105106
const isVertical = computed(() => {

0 commit comments

Comments
 (0)