11<script setup>
22import { ref , computed , nextTick } from " vue" ;
3- import { calcMarkerOffsetX , calcMarkerOffsetY , calcNutArrowPath , canShowValue , closestDecimal , makeDonut , palette , convertColorToHex , opacity , makeXls , createUid } from ' ../lib' ;
3+ import { calcMarkerOffsetX , calcMarkerOffsetY , calcNutArrowPath , canShowValue , closestDecimal , makeDonut , palette , convertColorToHex , opacity , makeXls , createUid , sumByAttribute } from ' ../lib' ;
44import pdf from " ../pdf" ;
55import img from " ../img" ;
66import mainConfig from " ../default_configs.json" ;
@@ -179,13 +179,8 @@ const yLabels = computed(() => {
179179 return steps;
180180});
181181
182- // lib
183- function sumValues (source ) {
184- return [... source].map (s => s .value ).reduce ((a , b ) => a + b, 0 );
185- }
186- // lib
187182function displayArcPercentage (arc , stepBreakdown ) {
188- return isNaN (arc .value / sumValues (stepBreakdown)) ? 0 : ((arc .value / sumValues (stepBreakdown)) * 100 ).toFixed (0 ) + " %" ;
183+ return isNaN (arc .value / sumByAttribute (stepBreakdown, ' value ' )) ? 0 : ((arc .value / sumByAttribute (stepBreakdown, " value " )) * 100 ).toFixed (0 ) + " %" ;
189184}
190185
191186function leave () {
@@ -641,13 +636,12 @@ defineExpose({
641636 : stroke= " donutEvolutionConfig.style.chart.color"
642637 stroke- width= " 1.5"
643638 / >
644- < rect
639+ < circle
645640 @click= " unfixDatapoint"
646641 @keypress .enter = " unfixDatapoint"
647- : x= " svg.absoluteWidth - padding.right - 20"
648- : y= " padding.top"
649- : width= " 20"
650- : height= " 20"
642+ : cx= " svg.absoluteWidth - padding.right - svg.width / 40"
643+ : cy= " padding.top + svg.height / 30"
644+ : r= " svg.height / 12"
651645 fill= " transparent"
652646 style= " cursor:pointer"
653647 tabindex= " 0"
@@ -669,16 +663,6 @@ defineExpose({
669663 : r= " svg.height / 7"
670664 : fill= " donutEvolutionConfig.style.chart.backgroundColor"
671665 / >
672- < text
673- text- anchor= " middle"
674- : x= " padding.left + svg.width / 2"
675- : y= " padding.top + (svg.height / 2) + 14 / 3"
676- : font- size= " 14"
677- : font- weight= " 'bold'"
678- : fill= " donutEvolutionConfig.style.chart.layout.dataLabels.color"
679- >
680- {{ labellizeValue (fixedDatapoint .subtotal ) }}
681- < / text>
682666 < path
683667 v- for = " (arc, k) in fixedDatapoint.donutFocus"
684668 : d= " arc.path"
@@ -705,6 +689,22 @@ defineExpose({
705689 : r= " svg.height / 3.8"
706690 : fill= " `url(#focus_${uid})`"
707691 / >
692+ < circle
693+ : cx= " padding.left + (svg.width / 2)"
694+ : cy= " padding.top + (svg.height / 2)"
695+ : r= " svg.height / 7.7"
696+ : fill= " donutEvolutionConfig.style.chart.backgroundColor"
697+ / >
698+ < text
699+ text- anchor= " middle"
700+ : x= " padding.left + svg.width / 2"
701+ : y= " padding.top + (svg.height / 2) + 14 / 3"
702+ : font- size= " 14"
703+ : font- weight= " 'bold'"
704+ : fill= " donutEvolutionConfig.style.chart.layout.dataLabels.color"
705+ >
706+ {{ labellizeValue (fixedDatapoint .subtotal ) }}
707+ < / text>
708708 < text
709709 v- if = " donutEvolutionConfig.style.chart.layout.grid.xAxis.dataLabels.values[fixedDatapoint.index]"
710710 : x= " padding.left + 6"
@@ -749,8 +749,11 @@ defineExpose({
749749 < / template>
750750 < template #td= " {td}" >
751751 < span v- if = " td.value === null" > - < / span>
752- < span v- else >
753- {{ ! isNaN (td .value ) ? donutEvolutionConfig .style .chart .layout .dataLabels .prefix : ' ' }}{{ ! isNaN (td .value ) && td .value !== null ? Number (td .value .toFixed (donutEvolutionConfig .table .td .roundingValue )).toLocaleString () : td }}{{ ! isNaN (td .value ) ? donutEvolutionConfig .style .chart .layout .dataLabels .suffix : ' ' }}
752+ < b v- else >
753+ {{ ! isNaN (td .value ) ? donutEvolutionConfig .style .chart .layout .dataLabels .prefix : ' ' }}{{ ! isNaN (td .value ) && td .value !== null ? Number (td .value .toFixed (donutEvolutionConfig .table .td .roundingValue )).toLocaleString () : td }}{{ ! isNaN (td .value ) ? donutEvolutionConfig .style .chart .layout .dataLabels .suffix : ' ' }}
754+ < / b>
755+ < span>
756+ {{ td .percentage && ! isNaN (td .percentage ) ? ` (${ Number (td .percentage .toFixed (donutEvolutionConfig .table .td .roundingPercentage )).toLocaleString ()} %)` : ' ' }}
754757 < / span>
755758 < / template>
756759 < / DataTable>
0 commit comments