@@ -67,10 +67,13 @@ const { isPrinting, isImaging, generatePdf, generateImage } = usePrinter({
6767
6868const 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
7578onMounted (() => {
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
105106const isVertical = computed (() => {
0 commit comments