Skip to content

Commit 393de77

Browse files
committed
Other - Minor refactoring
1 parent e1d7729 commit 393de77

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/components/vue-ui-vertical-bar.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createCsvContent,
66
createUid,
77
downloadCsv,
8+
dataLabel,
89
error,
910
functionReturnsString,
1011
isFunction,
@@ -345,7 +346,22 @@ function useTooltip(bar, seriesIndex) {
345346
346347
tooltipContent.value = `<div style="text-align:left">${html}</div>`;
347348
}
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)})`;
348363
364+
return `${label}${verticalBarConfig.value.style.chart.layout.bars.dataLabels.percentage.show ? ` ${percentage}` : ''}`;
349365
}
350366
351367
const __to__ = ref(null);
@@ -631,7 +647,7 @@ defineExpose({
631647
:fill="verticalBarConfig.style.chart.layout.bars.dataLabels.color"
632648
:font-weight="verticalBarConfig.style.chart.layout.bars.dataLabels.bold ? 'bold' : 'normal'"
633649
>
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) }}
635651
</text>
636652

637653
<!-- CHILDREN | LONELY PARENTS NAMES -->
@@ -668,8 +684,7 @@ defineExpose({
668684
:font-weight="verticalBarConfig.style.chart.layout.bars.dataLabels.bold ? 'bold' : 'normal'"
669685
text-anchor="start"
670686
>
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) }}
673688
</text>
674689

675690
<!-- TOOLTIP TRAPS -->

0 commit comments

Comments
 (0)