Skip to content

Commit 1033058

Browse files
committed
Fix - VueUiWheel - Fix reactivity issues
1 parent 004beee commit 1033058

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/components/vue-ui-wheel.vue

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Title from "../atoms/Title.vue";
55
import UserOptions from "../atoms/UserOptions.vue";
66
import {
77
applyDataLabel,
8+
checkNaN,
89
createUid,
910
dataLabel,
1011
error,
@@ -94,10 +95,13 @@ function calcTickStart(angle, distance = 1) {
9495
9596
const activeValue = ref(FINAL_CONFIG.value.style.chart.animation.use ? 0 : (props.dataset.percentage || 0));
9697
97-
watch(() => props.dataset.percentage, () => {
98-
activeValue.value = ref(FINAL_CONFIG.value.style.chart.animation.use ? 0 : (props.dataset.percentage || 0));
99-
useAnimation()
100-
});
98+
watch(() => props.dataset, (v) => {
99+
if (FINAL_CONFIG.value.style.chart.animation.use) {
100+
useAnimation(v.percentage);
101+
} else {
102+
activeValue.value = v.percentage || 0
103+
}
104+
}, { deep: true });
101105
102106
const resizeObserver = ref(null);
103107
@@ -108,7 +112,7 @@ onMounted(() => {
108112
type: 'dataset'
109113
})
110114
}
111-
useAnimation();
115+
useAnimation(props.dataset.percentage || 0);
112116
113117
if (FINAL_CONFIG.value.responsive) {
114118
const handleResize = throttle(() => {
@@ -130,24 +134,22 @@ onBeforeUnmount(() => {
130134
if (resizeObserver.value) resizeObserver.value.disconnect();
131135
});
132136
133-
function useAnimation() {
134-
let acceleration = 0;
137+
function useAnimation(targetValue) {
135138
let speed = FINAL_CONFIG.value.style.chart.animation.speed;
136-
let incr = (0.005) * FINAL_CONFIG.value.style.chart.animation.acceleration;
139+
const chunk = Math.abs(targetValue - activeValue.value) / (speed * 120);
140+
137141
function animate() {
138-
activeValue.value += speed + acceleration;
139-
acceleration += incr;
140-
if(activeValue.value < (props.dataset.percentage || 0)) {
142+
if(activeValue.value < targetValue) {
143+
activeValue.value = Math.min(activeValue.value + chunk, targetValue);
144+
} else if (activeValue.value > targetValue) {
145+
activeValue.value = Math.max(activeValue.value - chunk, targetValue)
146+
}
147+
148+
if (activeValue.value !== targetValue) {
141149
requestAnimationFrame(animate)
142-
} else {
143-
activeValue.value = (props.dataset.percentage || 0)
144150
}
145151
}
146-
147-
if(FINAL_CONFIG.value.style.chart.animation.use) {
148-
activeValue.value = 0;
149-
animate()
150-
}
152+
animate()
151153
}
152154
153155
const ticks = computed(() => {
@@ -267,9 +269,9 @@ defineExpose({
267269
>
268270
{{ applyDataLabel(
269271
FINAL_CONFIG.style.chart.layout.percentage.formatter,
270-
activeValue,
272+
checkNaN(activeValue),
271273
dataLabel({
272-
v: activeValue,
274+
v: checkNaN(activeValue),
273275
s: '%',
274276
r: FINAL_CONFIG.style.chart.layout.percentage.rounding
275277
}))

0 commit comments

Comments
 (0)