Skip to content

Commit d038ae8

Browse files
committed
feat: support data labels on charts
1 parent 245dab2 commit d038ae8

File tree

9 files changed

+78
-70
lines changed

9 files changed

+78
-70
lines changed

frontend/src/i18n/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@
728728
"line": "Line",
729729
"pie": "Pie"
730730
},
731+
"hide_label": "Hide Label",
732+
"show_label": "Show Label",
731733
"sort_asc": "Ascending",
732734
"sort_desc": "Descending",
733735
"sort_none": "No Sort",

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@
728728
"line": "선 차트",
729729
"pie": "원형 차트"
730730
},
731+
"hide_label": "라벨 숨기기",
732+
"show_label": "라벨 표시",
731733
"sort_asc": "오름차순",
732734
"sort_desc": "내림차순",
733735
"sort_none": "정렬 안 함",

frontend/src/i18n/zh-CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@
728728
"line": "折线图",
729729
"pie": "饼图"
730730
},
731+
"hide_label": "隐藏标签",
732+
"show_label": "显示标签",
731733
"sort_asc": "升序",
732734
"sort_desc": "降序",
733735
"sort_none": "不排序",
@@ -930,4 +932,4 @@
930932
"to_doc": "查看 API",
931933
"trigger_limit": "最多支持创建 {0} 个 API Key"
932934
}
933-
}
935+
}

frontend/src/views/chat/chat-block/ChartBlock.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,9 +396,8 @@ watch(
396396
</el-tooltip>
397397
</div>
398398

399-
<div class="chart-select-container">
399+
<div v-if="currentChartType !== 'table'" class="chart-select-container">
400400
<el-tooltip
401-
v-if="currentChartType !== 'table'"
402401
effect="dark"
403402
:offset="8"
404403
:content="showLabel ? t('chat.hide_label') : t('chat.show_label')"

frontend/src/views/chat/component/ChartComponent.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, nextTick, onMounted, onUnmounted } from 'vue'
2+
import { computed, nextTick, onMounted, onUnmounted, watch } from 'vue'
33
import { getChartInstance } from '@/views/chat/component/index.ts'
44
import type { BaseChart, ChartAxis, ChartData } from '@/views/chat/component/BaseChart.ts'
55
import { useEmitt } from '@/utils/useEmitt.ts'
@@ -63,6 +63,7 @@ const axis = computed(() => {
6363
6464
let chartInstance: BaseChart | undefined
6565
66+
function renderChart() {
6667
chartInstance = getChartInstance(params.type, chartId.value)
6768
if (chartInstance) {
6869
chartInstance.showLabel = params.showLabel

frontend/src/views/chat/component/charts/Bar.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,27 @@ export class Bar extends BaseG2Chart {
131131
},
132132
labels: this.showLabel
133133
? [
134-
{
135-
text: (data: any) => {
136-
const value = data[y[0].value]
137-
if (value === undefined || value === null) {
138-
return ''
139-
}
140-
return `${value}${_data.isPercent ? '%' : ''}`
134+
{
135+
text: (data: any) => {
136+
const value = data[y[0].value]
137+
if (value === undefined || value === null) {
138+
return ''
139+
}
140+
return `${value}${_data.isPercent ? '%' : ''}`
141+
},
142+
position: (data: any) => {
143+
if (data[y[0].value] < 0) {
144+
return 'left'
145+
}
146+
return 'right'
147+
},
148+
transform: [
149+
{ type: 'contrastReverse' },
150+
{ type: 'exceedAdjust' },
151+
{ type: 'overlapHide' },
152+
],
141153
},
142-
position: (data: any) => {
143-
if (data[y[0].value] < 0) {
144-
return 'left'
145-
}
146-
return 'right'
147-
},
148-
transform: [
149-
{ type: 'contrastReverse' },
150-
{ type: 'exceedAdjust' },
151-
{ type: 'overlapHide' },
152-
],
153-
},
154-
]
154+
]
155155
: [],
156156
} as G2Spec
157157

frontend/src/views/chat/component/charts/Column.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,27 +122,27 @@ export class Column extends BaseG2Chart {
122122
},
123123
labels: this.showLabel
124124
? [
125-
{
126-
text: (data: any) => {
127-
const value = data[y[0].value]
128-
if (value === undefined || value === null) {
129-
return ''
130-
}
131-
return `${value}${_data.isPercent ? '%' : ''}`
125+
{
126+
text: (data: any) => {
127+
const value = data[y[0].value]
128+
if (value === undefined || value === null) {
129+
return ''
130+
}
131+
return `${value}${_data.isPercent ? '%' : ''}`
132+
},
133+
position: (data: any) => {
134+
if (data[y[0].value] < 0) {
135+
return 'bottom'
136+
}
137+
return 'top'
138+
},
139+
transform: [
140+
{ type: 'contrastReverse' },
141+
{ type: 'exceedAdjust' },
142+
{ type: 'overlapHide' },
143+
],
132144
},
133-
position: (data: any) => {
134-
if (data[y[0].value] < 0) {
135-
return 'bottom'
136-
}
137-
return 'top'
138-
},
139-
transform: [
140-
{ type: 'contrastReverse' },
141-
{ type: 'exceedAdjust' },
142-
{ type: 'overlapHide' },
143-
],
144-
},
145-
]
145+
]
146146
: [],
147147
} as G2Spec
148148

frontend/src/views/chat/component/charts/Line.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,25 @@ export class Line extends BaseG2Chart {
8888
},
8989
labels: this.showLabel
9090
? [
91-
{
92-
text: (data: any) => {
93-
const value = data[y[0].value]
94-
if (value === undefined || value === null) {
95-
return ''
96-
}
97-
return `${value}${_data.isPercent ? '%' : ''}`
91+
{
92+
text: (data: any) => {
93+
const value = data[y[0].value]
94+
if (value === undefined || value === null) {
95+
return ''
96+
}
97+
return `${value}${_data.isPercent ? '%' : ''}`
98+
},
99+
style: {
100+
dx: -10,
101+
dy: -12,
102+
},
103+
transform: [
104+
{ type: 'contrastReverse' },
105+
{ type: 'exceedAdjust' },
106+
{ type: 'overlapHide' },
107+
],
98108
},
99-
style: {
100-
dx: -10,
101-
dy: -12,
102-
},
103-
transform: [
104-
{ type: 'contrastReverse' },
105-
{ type: 'exceedAdjust' },
106-
{ type: 'overlapHide' },
107-
],
108-
},
109-
]
109+
]
110110
: [],
111111
tooltip: (data: any) => {
112112
if (series.length > 0) {

frontend/src/views/chat/component/charts/Pie.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,16 @@ export class Pie extends BaseG2Chart {
4343
color: { position: 'bottom', layout: { justifyContent: 'center' } },
4444
},
4545
animate: { enter: { type: 'waveIn' } },
46-
labels: [
47-
{
48-
position: 'spider',
49-
text: (data: any) => {
50-
return `${data[series[0].value]}: ${data[y[0].value]}${_data.isPercent ? '%' : ''}`
51-
},
52-
},
53-
],
46+
labels: this.showLabel
47+
? [
48+
{
49+
position: 'spider',
50+
text: (data: any) => {
51+
return `${data[series[0].value]}: ${data[y[0].value]}${_data.isPercent ? '%' : ''}`
52+
},
53+
},
54+
]
55+
: [],
5456
tooltip: {
5557
title: (data: any) => data[series[0].value],
5658
items: [

0 commit comments

Comments
 (0)