@@ -134,7 +134,9 @@ const drawingArea = computed(() => {
134134 }
135135});
136136
137- const mutableDataset = computed (() => {
137+
138+
139+ function getMutableDataset () {
138140 return immutableDataset .value .map ((ds , i ) => {
139141 const startX = drawingArea .value .left + (((ds .start + Math .abs (scale .value .min )) / (scale .value .max + Math .abs (scale .value .min ))) * drawingArea .value .widthPlotReference );
140142 const endX = drawingArea .value .left + (((ds .end + Math .abs (scale .value .min )) / (scale .value .max + Math .abs (scale .value .min ))) * drawingArea .value .widthPlotReference );
@@ -144,11 +146,58 @@ const mutableDataset = computed(() => {
144146 startX,
145147 endX,
146148 centerX,
147- y: drawingArea .value .top + (i * dumbConfig .value .style .chart .rowHeight ) + (dumbConfig .value .style .chart .rowHeight / 2 )
149+ y: drawingArea .value .top + (i * dumbConfig .value .style .chart .rowHeight ) + (dumbConfig .value .style .chart .rowHeight / 2 ),
150+ endVal: ds .start
148151 }
149152 })
153+ }
154+
155+ const mutableDataset = ref ([])
156+
157+ const raf = ref (null );
158+ const grandTotalEnd = computed (() => {
159+ return immutableDataset .value .map (ds => ds .end ).reduce ((a , b ) => a + b, 0 );
150160});
151161
162+ onMounted (() => {
163+ mutableDataset .value = getMutableDataset ();
164+
165+ let totalEnd = mutableDataset .value .map (ds => ds .start ).reduce ((a , b ) => a + b, 0 );
166+
167+ function anim () {
168+ const diffs = immutableDataset .value .map (ds => {
169+ return ds .end - ds .start
170+ })
171+
172+ if (totalEnd >= grandTotalEnd .value ) {
173+ cancelAnimationFrame (raf .value );
174+ mutableDataset .value = getMutableDataset ();
175+ } else {
176+ mutableDataset .value = mutableDataset .value .map ((ds , i ) => {
177+ ds .endVal += diffs[i] * (dumbConfig .value .animationSpeed / 100 );
178+ const startX = drawingArea .value .left + (((ds .start + Math .abs (scale .value .min )) / (scale .value .max + Math .abs (scale .value .min ))) * drawingArea .value .widthPlotReference );
179+ const endX = drawingArea .value .left + (((ds .endVal + Math .abs (scale .value .min )) / (scale .value .max + Math .abs (scale .value .min ))) * drawingArea .value .widthPlotReference );
180+ const centerX = startX + ((endX - startX) / 2 )
181+ return {
182+ ... ds,
183+ startX,
184+ endX,
185+ centerX,
186+ y: drawingArea .value .top + (i * dumbConfig .value .style .chart .rowHeight ) + (dumbConfig .value .style .chart .rowHeight / 2 ),
187+ endVal: ds .endVal
188+ }
189+ })
190+ totalEnd = mutableDataset .value .map (ds => ds .endVal ).reduce ((a , b ) => a + b, 0 );
191+ raf .value = requestAnimationFrame (anim)
192+ }
193+ }
194+ if (dumbConfig .value .useAnimation ) {
195+ anim ()
196+ } else {
197+ mutableDataset .value = getMutableDataset ()
198+ }
199+ })
200+
152201const legendSet = computed (() => {
153202 return [
154203 { name: dumbConfig .value .style .chart .legend .labelStart , color: dumbConfig .value .style .chart .plots .gradient .show ? ` url(#start_grad_${ uid .value } )` : dumbConfig .style .chart .plots .startColordumbConfig .value .style .chart .plots .startColor },
@@ -316,7 +365,7 @@ defineExpose({
316365 </script >
317366
318367<template >
319- <div ref =" dumbbellChart" :class =" `vue-ui-dumbbell ${isFullscreen ? 'vue-data-ui-wrapper-fullscreen' : ''} ${dumbConfig.useCssAnimation ? '' : 'vue-ui-dna'} `" :style =" `font-family:${dumbConfig.style.fontFamily};width:100%; text-align:center;${!dumbConfig.style.chart.title.text ? 'padding-top:36px' : ''};background:${dumbConfig.style.chart.backgroundColor}`" :id =" `dumbbell_${uid}`" >
368+ <div ref =" dumbbellChart" :class =" `vue-ui-dumbbell ${isFullscreen ? 'vue-data-ui-wrapper-fullscreen' : ''}`" :style =" `font-family:${dumbConfig.style.fontFamily};width:100%; text-align:center;${!dumbConfig.style.chart.title.text ? 'padding-top:36px' : ''};background:${dumbConfig.style.chart.backgroundColor}`" :id =" `dumbbell_${uid}`" >
320369
321370 <div v-if =" dumbConfig.style.chart.title.text" :style =" `width:100%;background:${dumbConfig.style.chart.backgroundColor};padding-bottom:24px`" >
322371 <Title
@@ -505,7 +554,7 @@ defineExpose({
505554 :fill =" dumbConfig.style.chart.plots.gradient.show ? `url(#start_grad_${uid})` : dumbConfig.style.chart.plots.startColor"
506555 :stroke =" dumbConfig.style.chart.plots.stroke"
507556 :stroke-width =" dumbConfig.style.chart.plots.strokeWidth"
508- :class = " { 'animated' : dumbConfig.useCssAnimation } "
557+
509558 />
510559 <!-- END -->
511560 <circle
@@ -515,7 +564,7 @@ defineExpose({
515564 :fill =" dumbConfig.style.chart.plots.gradient.show ? `url(#end_grad_${uid})` : dumbConfig.style.chart.plots.endColor"
516565 :stroke =" dumbConfig.style.chart.plots.stroke"
517566 :stroke-width =" dumbConfig.style.chart.plots.strokeWidth"
518- :class = " { 'animated' : dumbConfig.useCssAnimation } "
567+
519568 />
520569
521570 <!-- START LABELS -->
@@ -527,7 +576,7 @@ defineExpose({
527576 :fill =" dumbConfig.style.chart.labels.startLabels.useStartColor ? dumbConfig.style.chart.plots.startColor : dumbConfig.style.chart.labels.startLabels.color"
528577 :font-size =" dumbConfig.style.chart.labels.startLabels.fontSize"
529578 text-anchor =" middle"
530- :class = " { 'animated' : dumbConfig.useCssAnimation } "
579+
531580 >
532581 {{ dataLabel({
533582 p: dumbConfig.style.chart.labels.prefix,
@@ -546,7 +595,7 @@ defineExpose({
546595 :fill =" dumbConfig.style.chart.labels.endLabels.useEndColor ? dumbConfig.style.chart.plots.endColor : dumbConfig.style.chart.labels.endLabels.color"
547596 :font-size =" dumbConfig.style.chart.labels.endLabels.fontSize"
548597 text-anchor =" middle"
549- :class = " { 'animated' : dumbConfig.useCssAnimation } "
598+
550599 >
551600 {{ dataLabel({
552601 p: dumbConfig.style.chart.labels.prefix,
@@ -620,23 +669,4 @@ defineExpose({
620669 user-select : none ;
621670 position : relative ;
622671}
623-
624- .animated {
625- animation : dumbbell 0.5s ease-in-out ;
626- transform-origin : center ;
627- }
628- @keyframes dumbbell {
629- 0% {
630- transform : scale (0.9 ,0.9 );
631- opacity : 0 ;
632- }
633- 80% {
634- transform : scale (1.02 ,1.02 );
635- opacity : 1 ;
636- }
637- to {
638- transform : scale (1 ,1 );
639- opacity : 1 ;
640- }
641- }
642672 </style >
0 commit comments