@@ -67,10 +67,13 @@ const { isPrinting, isImaging, generatePdf, generateImage } = usePrinter({
67
67
68
68
const activeValue = ref (FINAL_CONFIG .value .style .chart .animation .use ? 0 : checkNaN (props .dataset .percentage ));
69
69
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 });
74
77
75
78
onMounted (() => {
76
79
if (objectIsEmpty (props .dataset )) {
@@ -79,27 +82,25 @@ onMounted(() => {
79
82
type: ' dataset'
80
83
})
81
84
}
82
- useAnimation ()
85
+ useAnimation (props . dataset . percentage || 0 )
83
86
});
84
87
85
- function useAnimation () {
86
- let acceleration = 0 ;
88
+ function useAnimation (targetValue ) {
87
89
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
+
89
92
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)
96
101
}
97
102
}
98
-
99
- if (FINAL_CONFIG .value .style .chart .animation .use ) {
100
- activeValue .value = 0 ;
101
- animate ();
102
- }
103
+ animate ()
103
104
}
104
105
105
106
const isVertical = computed (() => {
0 commit comments