Skip to content

Commit 0fa70b0

Browse files
committed
Improvement - VueUiStackbar - Add formatter for y axis labels (#229)
1 parent 20e7e03 commit 0fa70b0

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

TestingArena/ArenaVueUiStackbar.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const monthValues = computed(() => {
8282
const model = ref([
8383
{ key: 'userOptions.position', def: 'right', type: 'select', options: ['left', 'right']},
8484
85-
{ key: 'orientation', def: 'vertical', type:'select', options: ['vertical', 'horizontal']},
85+
{ key: 'orientation', def: 'horizontal', type:'select', options: ['vertical', 'horizontal']},
8686
{ key: 'responsive', def: false, type: 'checkbox'},
8787
{ key: 'theme', def: '', type: 'select', options: ['', 'zen', 'hack', 'concrete']},
8888
{ key: 'useCssAnimation', def: true, type: 'checkbox'},
@@ -242,9 +242,9 @@ const config = computed(() => {
242242
...c.style.chart.bars,
243243
dataLabels: {
244244
...c.style.chart.bars.dataLabels,
245-
// formatter: ({value, config}) => {
246-
// return `f | ${value}`
247-
// }
245+
formatter: ({value, config}) => {
246+
return `f | ${value}`
247+
}
248248
}
249249
},
250250
grid: {
@@ -262,6 +262,13 @@ const config = computed(() => {
262262
}
263263
// values: ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG']
264264
}
265+
},
266+
y: {
267+
axisLabels: {
268+
formatter: ({ value }) => {
269+
return 'BOO' + value
270+
}
271+
}
265272
}
266273
}
267274
}

src/components/vue-ui-stackbar.vue

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,12 +1291,19 @@ defineExpose({
12911291
:fill="FINAL_CONFIG.style.chart.grid.y.axisLabels.color"
12921292
text-anchor="end"
12931293
>
1294-
{{ dataLabel({
1295-
p: FINAL_CONFIG.style.chart.bars.dataLabels.prefix,
1296-
v: yLabel.value,
1297-
s: FINAL_CONFIG.style.chart.bars.dataLabels.suffix,
1298-
r: FINAL_CONFIG.style.chart.grid.y.axisLabels.rounding,
1299-
}) }}
1294+
{{
1295+
applyDataLabel(
1296+
FINAL_CONFIG.style.chart.grid.y.axisLabels.formatter,
1297+
yLabel.value,
1298+
dataLabel({
1299+
p: FINAL_CONFIG.style.chart.bars.dataLabels.prefix,
1300+
v: yLabel.value,
1301+
s: FINAL_CONFIG.style.chart.bars.dataLabels.suffix,
1302+
r: FINAL_CONFIG.style.chart.grid.y.axisLabels.rounding,
1303+
}),
1304+
{ datapoint: yLabel }
1305+
)
1306+
}}
13001307
</text>
13011308
</template>
13021309
@@ -1322,12 +1329,19 @@ defineExpose({
13221329
:text-anchor="FINAL_CONFIG.style.chart.grid.x.timeLabels.rotation > 0 ? 'start' : FINAL_CONFIG.style.chart.grid.x.timeLabels.rotation < 0 ? 'end' : 'middle'"
13231330
:transform="`translate(${yLabel.horizontal_x}, ${drawingArea.bottom + FINAL_CONFIG.style.chart.grid.x.timeLabels.fontSize * 1.3 + FINAL_CONFIG.style.chart.grid.x.timeLabels.offsetY}), rotate(${FINAL_CONFIG.style.chart.grid.x.timeLabels.rotation})`"
13241331
>
1325-
{{ dataLabel({
1326-
p: FINAL_CONFIG.style.chart.bars.dataLabels.prefix,
1327-
v: yLabel.value,
1328-
s: FINAL_CONFIG.style.chart.bars.dataLabels.suffix,
1329-
r: FINAL_CONFIG.style.chart.grid.y.axisLabels.rounding,
1330-
}) }}
1332+
{{
1333+
applyDataLabel(
1334+
FINAL_CONFIG.style.chart.grid.y.axisLabels.formatter,
1335+
yLabel.value,
1336+
dataLabel({
1337+
p: FINAL_CONFIG.style.chart.bars.dataLabels.prefix,
1338+
v: yLabel.value,
1339+
s: FINAL_CONFIG.style.chart.bars.dataLabels.suffix,
1340+
r: FINAL_CONFIG.style.chart.grid.y.axisLabels.rounding,
1341+
}),
1342+
{ datapoint: yLabel }
1343+
)
1344+
}}
13311345
</text>
13321346
</template>
13331347

src/useConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ export function useConfig() {
389389
offsetX: 0,
390390
},
391391
axisLabels: {
392+
formatter: null,
392393
show: true,
393394
color: COLOR_BLACK,
394395
fontSize: FONT._14,

types/vue-data-ui.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6435,6 +6435,7 @@ declare module "vue-data-ui" {
64356435
offsetX?: number;
64366436
};
64376437
axisLabels?: {
6438+
formatter?: Formatter;
64386439
show?: boolean;
64396440
color?: string;
64406441
fontSize?: number;

0 commit comments

Comments
 (0)