Skip to content

Commit abee80a

Browse files
committed
Improvement - VueUiStackbar - Add formatters
1 parent d4690c9 commit abee80a

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed

TestingArena/ArenaVueUiStackBar.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ const config = computed(() => {
142142
...c.style,
143143
chart: {
144144
...c.style.chart,
145+
bars: {
146+
...c.style.chart.bars,
147+
dataLabels: {
148+
...c.style.chart.bars.dataLabels,
149+
formatter: ({value, config}) => {
150+
// console.log(config)
151+
return `f | ${value}`
152+
}
153+
}
154+
},
145155
grid: {
146156
...c.style.chart.grid,
147157
x: {

src/components/vue-ui-stackbar.vue

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
<script setup>
22
import { ref, computed, onMounted } from "vue";
33
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";
526
import { useNestedProp } from "../useNestedProp";
627
import { throttle } from "../canvas-lib";
728
import { useResponsive } from "../useResponsive";
@@ -290,21 +311,31 @@ const totalLabels = computed(() => {
290311
});
291312
292313
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+
)
300326
}
301327
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+
)
308339
}
309340
310341
function selectDatapoint(index) {
@@ -726,7 +757,7 @@ defineExpose({
726757
:font-weight="FINAL_CONFIG.style.chart.bars.dataLabels.bold ? 'bold' : 'normal'"
727758
text-anchor="middle"
728759
>
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) }}
730761
</text>
731762
</g>
732763
@@ -741,7 +772,7 @@ defineExpose({
741772
:font-weight="FINAL_CONFIG.style.chart.bars.totalValues.bold ? 'bold' : 'normal'"
742773
:fill="FINAL_CONFIG.style.chart.bars.totalValues.color"
743774
>
744-
{{ barDataLabel(total.value) }}
775+
{{ barDataLabel(total.value, total, i) }}
745776
</text>
746777
</g>
747778
</template>

src/useConfig.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ export function useConfig() {
253253
bold: false,
254254
rounding: 0,
255255
prefix: '',
256-
suffix: ''
256+
suffix: '',
257+
formatter: null
257258
}
258259
},
259260
grid: {

types/vue-data-ui.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ declare module 'vue-data-ui' {
249249
valueCss?: string;
250250
valueFontSize?: number;
251251
valueRounding?: number;
252-
formatter?: null;
252+
formatter?: Formatter;
253253
}
254254

255255
export const VueUiKpi: DefineComponent<{
@@ -5394,6 +5394,7 @@ declare module 'vue-data-ui' {
53945394
rounding?: number;
53955395
prefix?: string;
53965396
suffix?: string;
5397+
formatter?: Formatter;
53975398
};
53985399
};
53995400
grid?: {

0 commit comments

Comments
 (0)