1
1
<script setup>
2
2
import { ref , computed , onMounted } from " vue" ;
3
3
import { useConfig } from " ../useConfig" ;
4
- import { convertCustomPalette , createUid , palette , themePalettes , sumSeries , convertColorToHex , XMLNS , calculateNiceScale , dataLabel , adaptColorToBackground , isFunction , opacity , lightenHexColor , functionReturnsString , objectIsEmpty , getMissingDatasetAttributes , error , createCsvContent , downloadCsv } from " ../lib" ;
4
+ import {
5
+ adaptColorToBackground ,
6
+ applyDataLabel ,
7
+ calculateNiceScale ,
8
+ convertColorToHex ,
9
+ convertCustomPalette ,
10
+ createCsvContent ,
11
+ createUid ,
12
+ dataLabel ,
13
+ downloadCsv ,
14
+ error ,
15
+ functionReturnsString ,
16
+ getMissingDatasetAttributes ,
17
+ isFunction ,
18
+ lightenHexColor ,
19
+ objectIsEmpty ,
20
+ opacity ,
21
+ palette ,
22
+ sumSeries ,
23
+ themePalettes ,
24
+ XMLNS ,
25
+ } from " ../lib" ;
5
26
import { useNestedProp } from " ../useNestedProp" ;
6
27
import { throttle } from " ../canvas-lib" ;
7
28
import { useResponsive } from " ../useResponsive" ;
@@ -290,21 +311,31 @@ const totalLabels = computed(() => {
290
311
});
291
312
292
313
293
- function barDataLabel (val ) {
294
- return dataLabel ({
295
- p: FINAL_CONFIG .value .style .chart .bars .dataLabels .prefix ,
296
- v: val,
297
- s: FINAL_CONFIG .value .style .chart .bars .dataLabels .suffix ,
298
- r: FINAL_CONFIG .value .style .chart .bars .dataLabels .rounding ,
299
- });
314
+ function barDataLabel (val , datapoint , index , dpIndex ) {
315
+ return applyDataLabel (
316
+ FINAL_CONFIG .value .style .chart .bars .dataLabels .formatter ,
317
+ val,
318
+ dataLabel ({
319
+ p: FINAL_CONFIG .value .style .chart .bars .dataLabels .prefix ,
320
+ v: val,
321
+ s: FINAL_CONFIG .value .style .chart .bars .dataLabels .suffix ,
322
+ r: FINAL_CONFIG .value .style .chart .bars .dataLabels .rounding ,
323
+ }),
324
+ { datapoint, seriesIndex: index, datapointIndex: dpIndex }
325
+ )
300
326
}
301
327
302
- function barDataLabelPercentage (val ) {
303
- return dataLabel ({
304
- v: val,
305
- s: ' %' ,
306
- r: FINAL_CONFIG .value .style .chart .bars .dataLabels .rounding ,
307
- });
328
+ function barDataLabelPercentage (val , datapoint , index , dpIndex ) {
329
+ return applyDataLabel (
330
+ FINAL_CONFIG .value .style .chart .bars .dataLabels .formatter ,
331
+ val,
332
+ dataLabel ({
333
+ v: val,
334
+ s: ' %' ,
335
+ r: FINAL_CONFIG .value .style .chart .bars .dataLabels .rounding ,
336
+ }),
337
+ { datapoint, seriesIndex: index, datapointIndex: dpIndex }
338
+ )
308
339
}
309
340
310
341
function selectDatapoint (index ) {
@@ -726,7 +757,7 @@ defineExpose({
726
757
: font- weight= " FINAL_CONFIG.style.chart.bars.dataLabels.bold ? 'bold' : 'normal'"
727
758
text- anchor= " middle"
728
759
>
729
- {{ FINAL_CONFIG .style .chart .bars .showDistributedPercentage && FINAL_CONFIG .style .chart .bars .distributed ? barDataLabelPercentage (dp .proportions [j] * 100 ) : barDataLabel (dp .series [j]) }}
760
+ {{ FINAL_CONFIG .style .chart .bars .showDistributedPercentage && FINAL_CONFIG .style .chart .bars .distributed ? barDataLabelPercentage (dp .proportions [j] * 100 , dp, i, j ) : barDataLabel (dp .series [j], dp, i, j ) }}
730
761
< / text>
731
762
< / g>
732
763
@@ -741,7 +772,7 @@ defineExpose({
741
772
: font- weight= " FINAL_CONFIG.style.chart.bars.totalValues.bold ? 'bold' : 'normal'"
742
773
: fill= " FINAL_CONFIG.style.chart.bars.totalValues.color"
743
774
>
744
- {{ barDataLabel (total .value ) }}
775
+ {{ barDataLabel (total .value , total, i ) }}
745
776
< / text>
746
777
< / g>
747
778
< / template>
0 commit comments