|
5 | 5 | createCsvContent, |
6 | 6 | createUid, |
7 | 7 | downloadCsv, |
| 8 | + dataLabel, |
8 | 9 | error, |
9 | 10 | functionReturnsString, |
10 | 11 | isFunction, |
@@ -345,7 +346,22 @@ function useTooltip(bar, seriesIndex) { |
345 | 346 | |
346 | 347 | tooltipContent.value = `<div style="text-align:left">${html}</div>`; |
347 | 348 | } |
| 349 | +} |
| 350 | +
|
| 351 | +function makeDataLabel(value) { |
| 352 | + if (isNaN(value) || !verticalBarConfig.value.style.chart.layout.bars.dataLabels.value.show) { |
| 353 | + return ''; |
| 354 | + } |
| 355 | + const label = dataLabel({ |
| 356 | + p: verticalBarConfig.value.style.chart.layout.bars.dataLabels.value.prefix, |
| 357 | + v: value, |
| 358 | + s: verticalBarConfig.value.style.chart.layout.bars.dataLabels.value.suffix, |
| 359 | + r: verticalBarConfig.value.style.chart.layout.bars.dataLabels.value.roundingValue |
| 360 | + }); |
| 361 | +
|
| 362 | + const percentage = `(${calcProportionToTotal(value, true, verticalBarConfig.value.style.chart.layout.bars.dataLabels.percentage.roundingPercentage)})`; |
348 | 363 |
|
| 364 | + return `${label}${verticalBarConfig.value.style.chart.layout.bars.dataLabels.percentage.show ? ` ${percentage}` : ''}`; |
349 | 365 | } |
350 | 366 |
|
351 | 367 | const __to__ = ref(null); |
@@ -631,7 +647,7 @@ defineExpose({ |
631 | 647 | :fill="verticalBarConfig.style.chart.layout.bars.dataLabels.color" |
632 | 648 | :font-weight="verticalBarConfig.style.chart.layout.bars.dataLabels.bold ? 'bold' : 'normal'" |
633 | 649 | > |
634 | | - {{ verticalBarConfig.style.chart.layout.bars.dataLabels.value.prefix }} {{ isNaN(serie.value) || !verticalBarConfig.style.chart.layout.bars.dataLabels.value.show ? '' : serie.value.toFixed(verticalBarConfig.style.chart.layout.bars.dataLabels.value.roundingValue) }} {{ verticalBarConfig.style.chart.layout.bars.dataLabels.value.suffix }} {{ verticalBarConfig.style.chart.layout.bars.dataLabels.percentage.show ? `(${calcProportionToTotal(serie.value, true, verticalBarConfig.style.chart.layout.bars.dataLabels.percentage.roundingPercentage)})` : '' }} |
| 650 | + {{ makeDataLabel(serie.value) }} |
635 | 651 | </text> |
636 | 652 |
|
637 | 653 | <!-- CHILDREN | LONELY PARENTS NAMES --> |
@@ -668,8 +684,7 @@ defineExpose({ |
668 | 684 | :font-weight="verticalBarConfig.style.chart.layout.bars.dataLabels.bold ? 'bold' : 'normal'" |
669 | 685 | text-anchor="start" |
670 | 686 | > |
671 | | - |
672 | | - {{ verticalBarConfig.style.chart.layout.bars.dataLabels.value.prefix }} {{ verticalBarConfig.style.chart.layout.bars.dataLabels.value.show ? getParentData(serie, i).value : '' }} {{ verticalBarConfig.style.chart.layout.bars.dataLabels.percentage.show ? `(${getParentData(serie, i).percentageToTotal})` : '' }} {{ verticalBarConfig.style.chart.layout.bars.dataLabels.value.suffix }} |
| 687 | + {{ makeDataLabel(getParentData(serie, i).value) }} |
673 | 688 | </text> |
674 | 689 |
|
675 | 690 | <!-- TOOLTIP TRAPS --> |
|
0 commit comments