@@ -5,6 +5,7 @@ import Title from "../atoms/Title.vue";
5
5
import UserOptions from " ../atoms/UserOptions.vue" ;
6
6
import {
7
7
applyDataLabel ,
8
+ checkNaN ,
8
9
createUid ,
9
10
dataLabel ,
10
11
error ,
@@ -94,10 +95,13 @@ function calcTickStart(angle, distance = 1) {
94
95
95
96
const activeValue = ref (FINAL_CONFIG .value .style .chart .animation .use ? 0 : (props .dataset .percentage || 0 ));
96
97
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 });
101
105
102
106
const resizeObserver = ref (null );
103
107
@@ -108,7 +112,7 @@ onMounted(() => {
108
112
type: ' dataset'
109
113
})
110
114
}
111
- useAnimation ();
115
+ useAnimation (props . dataset . percentage || 0 );
112
116
113
117
if (FINAL_CONFIG .value .responsive ) {
114
118
const handleResize = throttle (() => {
@@ -130,24 +134,22 @@ onBeforeUnmount(() => {
130
134
if (resizeObserver .value ) resizeObserver .value .disconnect ();
131
135
});
132
136
133
- function useAnimation () {
134
- let acceleration = 0 ;
137
+ function useAnimation (targetValue ) {
135
138
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
+
137
141
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) {
141
149
requestAnimationFrame (animate)
142
- } else {
143
- activeValue .value = (props .dataset .percentage || 0 )
144
150
}
145
151
}
146
-
147
- if (FINAL_CONFIG .value .style .chart .animation .use ) {
148
- activeValue .value = 0 ;
149
- animate ()
150
- }
152
+ animate ()
151
153
}
152
154
153
155
const ticks = computed (() => {
@@ -267,9 +269,9 @@ defineExpose({
267
269
>
268
270
{{ applyDataLabel(
269
271
FINAL_CONFIG.style.chart.layout.percentage.formatter,
270
- activeValue,
272
+ checkNaN( activeValue) ,
271
273
dataLabel({
272
- v: activeValue,
274
+ v: checkNaN( activeValue) ,
273
275
s: '%',
274
276
r: FINAL_CONFIG.style.chart.layout.percentage.rounding
275
277
}))
0 commit comments