11<script setup>
22import { ref , computed , nextTick } from " vue" ;
3- import { calcMarkerOffsetX , calcMarkerOffsetY , calcNutArrowPath , makeDonut , palette , convertColorToHex , opacity , createUid , createCsvContent , downloadCsv } from ' ../lib' ;
3+ import {
4+ calcMarkerOffsetX ,
5+ calcMarkerOffsetY ,
6+ calcNutArrowPath ,
7+ convertColorToHex ,
8+ createCsvContent ,
9+ createUid ,
10+ dataLabel ,
11+ downloadCsv ,
12+ makeDonut ,
13+ opacity ,
14+ palette ,
15+ } from ' ../lib' ;
416import pdf from " ../pdf" ;
517import img from " ../img" ;
618import mainConfig from " ../default_configs.json" ;
@@ -180,7 +192,7 @@ function useTooltip(arc, i, showTooltip = true) {
180192 html += ` <div data-cy="donut-tooltip-name" style="width:100%;text-align:center;border-bottom:1px solid #ccc;padding-bottom:6px;margin-bottom:3px;">${ arc .name } </div>` ;
181193 html += ` <div style="display:flex;flex-direction:row;gap:6px;align-items:center;"><svg viewBox="0 0 12 12" height="14" width="14"><circle data-cy="donut-tooltip-marker" cx="6" cy="6" r="6" stroke="none" fill="${ arc .color } "/></svg>` ;
182194 if (donutConfig .value .style .chart .tooltip .showValue ) {
183- html += ` <b data-cy="donut-tooltip-value">${ arc .value . toFixed ( donutConfig .value .style .chart .tooltip .roundingValue )} </b>` ;
195+ html += ` <b data-cy="donut-tooltip-value">${ dataLabel ({p : donutConfig . value . style . chart . layout . labels . dataLabels . prefix , v : arc .value , s : donutConfig . value . style . chart . layout . labels . dataLabels . suffix , r : donutConfig .value .style .chart .tooltip .roundingValue } )} </b>` ;
184196 }
185197 if (donutConfig .value .style .chart .tooltip .showPercentage ) {
186198 if (! donutConfig .value .style .chart .tooltip .showValue ) {
@@ -256,18 +268,18 @@ function generateCsv() {
256268
257269const dataTable = computed (() => {
258270 const head = [
259- ` <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>` ,
260- Number (total .value .toFixed (donutConfig .value .table .td .roundingValue )).toLocaleString (),
271+ ` <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>` , dataLabel ({p: donutConfig .value .style .chart .layout .labels .dataLabels .prefix , v: total .value , s: donutConfig .value .style .chart .layout .labels .dataLabels .suffix , r: donutConfig .value .table .td .roundingValue }),
261272 ' 100%'
262273 ];
263274
264275 const body = table .value .head .map ((h ,i ) => {
276+ const label = dataLabel ({p: donutConfig .value .style .chart .layout .labels .dataLabels .prefix , v: table .value .body [i], s: donutConfig .value .style .chart .layout .labels .dataLabels .suffix , r: donutConfig .value .table .td .roundingValue });
265277 return [
266278 {
267279 color: h .color ,
268280 name: h .name
269281 },
270- table . value . body [i]. toFixed ( donutConfig . value . table . td . roundingValue ) ,
282+ label ,
271283 isNaN (table .value .body [i] / total .value ) ? " -" : (table .value .body [i] / total .value * 100 ).toFixed (donutConfig .value .table .td .roundingPercentage ) + ' %'
272284 ]
273285 });
@@ -481,7 +493,7 @@ defineExpose({
481493 :font-size =" donutConfig.style.chart.layout.labels.hollow.total.value.fontSize"
482494 :style =" `font-weight:${donutConfig.style.chart.layout.labels.hollow.total.value.bold ? 'bold': ''}`"
483495 >
484- {{ donutConfig.style.chart.layout.labels.hollow.total.value.prefix }} {{ Number( total.toFixed(donutConfig.style.chart.layout.labels.hollow.total.value.rounding)).toLocaleString() }} {{ donutConfig.style.chart.layout.labels.hollow.total.value.suffix }}
496+ {{ dataLabel({p: donutConfig.style.chart.layout.labels.hollow.total.value.prefix, v: total, s: donutConfig.style.chart.layout.labels.hollow.total.value.suffix}) }}
485497 </text >
486498
487499 <text
@@ -533,7 +545,7 @@ defineExpose({
533545 :font-size =" donutConfig.style.chart.layout.labels.percentage.fontSize"
534546 :style =" `font-weight:${donutConfig.style.chart.layout.labels.percentage.bold ? 'bold': ''}`"
535547 >
536- {{ displayArcPercentage(arc, currentDonut) }}
548+ {{ displayArcPercentage(arc, currentDonut) }} {{ donutConfig.style.chart.layout.labels.value.show ? `(${dataLabel({p: donutConfig.style.chart.layout.labels.dataLabels.prefix, v: arc.value, s: donutConfig.style.chart.layout.labels.dataLabels.suffix, rounding: donutConfig.style.chart.layout.labels.value.rounding})})` : '' }}
537549 </text >
538550 <text
539551 :data-cy =" `donut-datalabel-name-${i}`"
@@ -567,7 +579,7 @@ defineExpose({
567579 >
568580 <template #item =" {legend , index } " >
569581 <div @click =" segregate(index)" :style =" `opacity:${segregated.includes(index) ? 0.5 : 1}`" >
570- {{ legend.name }} : {{ Number( legend.value.toFixed( donutConfig.style.chart.legend.roundingValue)).toLocaleString( ) }}
582+ {{ legend.name }} : {{ dataLabel({p: donutConfig.style.chart.layout.labels.dataLabels.prefix, v: legend.value, s: donutConfig.style.chart.layout.labels.dataLabels.suffix, r: donutConfig.style.chart.legend.roundingValue} ) }}
571583 <span v-if =" !segregated.includes(index)" >
572584 ({{ isNaN(legend.value / total) ? '-' : (legend.value / total * 100).toFixed(donutConfig.style.chart.legend.roundingPercentage)}}%)
573585 </span >
@@ -592,7 +604,7 @@ defineExpose({
592604 >
593605 <template #item =" {legend , index } " >
594606 <div @click =" segregate(index)" :style =" `opacity:${segregated.includes(index) ? 0.5 : 1}`" >
595- {{ legend.name }} : {{ Number( legend.value.toFixed( donutConfig.style.chart.legend.roundingValue)).toLocaleString( ) }}
607+ {{ legend.name }} : {{ dataLabel({p: donutConfig.style.chart.layout.labels.dataLabels.prefix, v: legend.value, s: donutConfig.style.chart.layout.labels.dataLabels.suffix, r: donutConfig.style.chart.legend.roundingValue} ) }}
596608 <span v-if =" !segregated.includes(index)" >
597609 ({{ isNaN(legend.value / total) ? '-' : (legend.value / total * 100).toFixed(donutConfig.style.chart.legend.roundingPercentage)}}%)
598610 </span >
0 commit comments