Skip to content

Commit ac1abff

Browse files
committed
VueUiQuickChart added axis labels for line & bar charts
1 parent 5218a45 commit ac1abff

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-data-ui",
33
"private": false,
4-
"version": "2.1.14",
4+
"version": "2.1.15",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/App.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3331,7 +3331,9 @@ const quickDatasetBar = ref([
33313331
const quickConfig = ref({
33323332
title: 'Some title that can be kinda long',
33333333
xyPeriods: ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'],
3334-
xyPeriodLabelsRotation: -20
3334+
xyPeriodLabelsRotation: -20,
3335+
xAxisLabel: 'This is x axis',
3336+
yAxisLabel: 'This is y axis'
33353337
})
33363338
33373339
const cursorConfig = ref({

src/components/vue-ui-quick-chart.vue

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,53 @@ defineExpose({
10861086
/>
10871087
</g>
10881088
</template>
1089+
1090+
<template v-if="[detector.chartType.LINE, detector.chartType.BAR].includes(chartType)">
1091+
<g class="axis-labels">
1092+
<g v-if="quickConfig.xAxisLabel && chartType === detector.chartType.LINE">
1093+
<text
1094+
:font-size="quickConfig.axisLabelsFontSize"
1095+
:fill="quickConfig.color"
1096+
text-anchor="middle"
1097+
:x="line.drawingArea.left + (line.drawingArea.width / 2)"
1098+
:y="defaultSizes.line.height - (quickConfig.axisLabelsFontSize / 3)"
1099+
>
1100+
{{ quickConfig.xAxisLabel }}
1101+
</text>
1102+
</g>
1103+
<g v-if="quickConfig.xAxisLabel && chartType === detector.chartType.BAR">
1104+
<text
1105+
:font-size="quickConfig.axisLabelsFontSize"
1106+
:fill="quickConfig.color"
1107+
text-anchor="middle"
1108+
:x="bar.drawingArea.left + (bar.drawingArea.width / 2)"
1109+
:y="defaultSizes.bar.height - (quickConfig.axisLabelsFontSize / 3)"
1110+
>
1111+
{{ quickConfig.xAxisLabel }}
1112+
</text>
1113+
</g>
1114+
<g v-if="quickConfig.yAxisLabel && chartType === detector.chartType.LINE">
1115+
<text
1116+
:font-size="quickConfig.axisLabelsFontSize"
1117+
:fill="quickConfig.color"
1118+
:transform="`translate(${quickConfig.axisLabelsFontSize}, ${line.drawingArea.top + (line.drawingArea.height / 2)}) rotate(-90)`"
1119+
text-anchor="middle"
1120+
>
1121+
{{ quickConfig.yAxisLabel }}
1122+
</text>
1123+
</g>
1124+
<g v-if="quickConfig.yAxisLabel && chartType === detector.chartType.BAR">
1125+
<text
1126+
:font-size="quickConfig.axisLabelsFontSize"
1127+
:fill="quickConfig.color"
1128+
:transform="`translate(${quickConfig.axisLabelsFontSize}, ${bar.drawingArea.top + (bar.drawingArea.height / 2)}) rotate(-90)`"
1129+
text-anchor="middle"
1130+
>
1131+
{{ quickConfig.yAxisLabel }}
1132+
</text>
1133+
</g>
1134+
</g>
1135+
</template>
10891136
</svg>
10901137
<div
10911138
v-if="quickConfig.showLegend"

src/default_configs.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3657,6 +3657,7 @@
36573657
}
36583658
},
36593659
"vue_ui_quick_chart": {
3660+
"axisLabelsFontSize": 12,
36603661
"backgroundColor":"#FFFFFF",
36613662
"barGap": 12,
36623663
"barStrokeWidth": 1,
@@ -3696,6 +3697,7 @@
36963697
"valuePrefix": "",
36973698
"valueSuffix": "",
36983699
"width": 512,
3700+
"xAxisLabel": "",
36993701
"xyAxisStroke": "#CCCCCC",
37003702
"xyAxisStrokeWidth": 1,
37013703
"xyGridStroke": "#e1e5e8",
@@ -3704,16 +3706,17 @@
37043706
"xyHighlighterOpacity": 0.05,
37053707
"xyLabelsXFontSize": 8,
37063708
"xyLabelsYFontSize": 12,
3707-
"xyPaddingBottom": 24,
3709+
"xyPaddingBottom": 48,
37083710
"xyPaddingLeft": 48,
37093711
"xyPaddingRight": 12,
37103712
"xyPaddingTop": 24,
3711-
"xyPeriods": [],
37123713
"xyPeriodLabelsRotation": 0,
3714+
"xyPeriods": [],
37133715
"xyScaleSegments": 10,
37143716
"xyShowAxis": true,
37153717
"xyShowGrid": true,
3716-
"xyShowScale": true
3718+
"xyShowScale": true,
3719+
"yAxisLabel": ""
37173720
},
37183721
"vue_ui_cursor": {
37193722
"bubbleEffect": true,

types/vue-data-ui.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4673,6 +4673,7 @@ declare module 'vue-data-ui' {
46734673
}>
46744674

46754675
export type VueUiQuickChartConfig = {
4676+
axisLabelsFontSize?: number;
46764677
backgroundColor?: string;
46774678
barGap?: number;
46784679
barStrokeWidth?: number;
@@ -4712,6 +4713,7 @@ declare module 'vue-data-ui' {
47124713
valuePrefix?: string;
47134714
valueSuffix?: string;
47144715
width?: number | null;
4716+
xAxisLabel?: string;
47154717
xyAxisStroke?: string;
47164718
xyAxisStrokeWidth?: number;
47174719
xyGridStroke?: string;
@@ -4730,6 +4732,7 @@ declare module 'vue-data-ui' {
47304732
xyShowAxis?: boolean;
47314733
xyShowGrid?: boolean;
47324734
xyShowScale?: boolean;
4735+
yAxisLabel?: string;
47334736
};
47344737

47354738
export type VueUiQuickChartDatasetObjectItem = {

0 commit comments

Comments
 (0)