Skip to content

Commit 487474b

Browse files
committed
feat: chart style
1 parent 81751d3 commit 487474b

File tree

6 files changed

+54
-15
lines changed

6 files changed

+54
-15
lines changed

backend/template.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ template:
2020
- 如果根据提供的表结构不能生成符合问题与条件的SQL,回答:
2121
{{"success":false,"message":"无法生成SQL的原因"}}
2222
- 如果问题是图表展示相关且与生成SQL查询无关时,请参考上一次回答的SQL来生成SQL
23-
- 如果问题是图表展示相关,可参考的图表类型为表格(table)、条形图(bar)、折线图(line)或饼图(pie),返回的JSON:
24-
{{"success":true,"sql":"生成的SQL语句","chart-type":"选择的图表类型(table/bar/line/pie)"}}
23+
- 如果问题是图表展示相关,可参考的图表类型为表格(table)、柱状图(column)、条形图(bar)、折线图(line)或饼图(pie),返回的JSON:
24+
{{"success":true,"sql":"生成的SQL语句","chart-type":"选择的图表类型(table/column/bar/line/pie)"}}
2525
2626
### 请遵守以下输出要求:
2727
请逐步推理后给出答案
@@ -48,6 +48,9 @@ template:
4848
- 如果需要表格,则生成的 JSON 格式应为:
4949
{{"type":"table", "title": "标题", "columns": [{{"name":"中文字段名1", "value": "SQL 查询列 1(有别名用别名)"}}, {{"name": "中文字段名 2", "value": "SQL 查询列 2(有别名用别名)"}}]}}
5050
必须从 SQL 查询列中提取“columns”。
51+
- 如果需要柱状图,则生成的 JSON 格式应为:
52+
{{"type":"column", "title": "标题", "axis": {{"x": {{"name":"x轴的中文名称", "value": "SQL 查询 x 轴的列(有别名用别名)"}}, "y": {{"name":"y轴的中文名称","value": "SQL 查询 y 轴的列(有别名用别名)"}}}}
53+
必须从 SQL 查询列中提取“x”和“y”。
5154
- 如果需要条形图,则生成的 JSON 格式应为:
5255
{{"type":"bar", "title": "标题", "axis": {{"x": {{"name":"x轴的中文名称", "value": "SQL 查询 x 轴的列(有别名用别名)"}}, "y": {{"name":"y轴的中文名称","value": "SQL 查询 y 轴的列(有别名用别名)"}}}}
5356
必须从 SQL 查询列中提取“x”和“y”。

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dayjs": "^1.11.13",
1717
"element-plus-secondary": "^1.0.0",
1818
"lodash": "^4.17.21",
19+
"lodash-es": "^4.17.21",
1920
"snowflake-id": "^1.1.0",
2021
"tinymce": "^5.8.2",
2122
"vue": "^3.5.13",

frontend/src/views/chat/ChatAnswer.vue

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,18 @@ function onTypeChange(type: string) {
148148
</template>
149149
<template v-else-if="settings.type === 'chart'">
150150
<div>
151-
<div v-if="message.record.chart">
152-
<Component
153-
ref="chartRef"
154-
v-if="message.record.id"
155-
:id="message.record.id"
156-
:type="chartType"
157-
:columns="chartObject?.columns"
158-
:x="xAxis"
159-
:y="yAxis"
160-
:data="dataObject.data"/>
151+
<div v-if="message.record.chart" class="chart-base-container">
152+
<div>
153+
<Component
154+
ref="chartRef"
155+
v-if="message.record.id"
156+
:id="message.record.id"
157+
:type="chartType"
158+
:columns="chartObject?.columns"
159+
:x="xAxis"
160+
:y="yAxis"
161+
:data="dataObject.data"/>
162+
</div>
161163
</div>
162164
</div>
163165
<div v-if="message.record.error" style="color: red">
@@ -184,4 +186,9 @@ function onTypeChange(type: string) {
184186
.type-tabs {
185187
margin-right: 24px;
186188
}
189+
190+
.chart-base-container {
191+
padding: 20px;
192+
background: rgba(224,224,226,0.29);
193+
}
187194
</style>

frontend/src/views/chat/component/BaseG2Chart.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ export abstract class BaseG2Chart extends BaseChart {
1111
container: id,
1212
autoFit: true,
1313
})
14+
15+
this.chart.theme({
16+
view: {
17+
viewFill: '#FFFFFF',
18+
},
19+
})
1420
}
1521

1622
render() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ onUnmounted(() => {
7676
.chart-container {
7777
height: 100%;
7878
width: 100%;
79-
min-height: 200px;
80-
min-width: 200px;
79+
min-height: 360px;
80+
min-width: 360px;
8181
}
8282
</style>

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,36 @@
11
import {BaseChart} from "@/views/chat/component/BaseChart.ts";
22
import {TableSheet, type S2Options, type S2DataConfig, type S2MountContainer} from "@antv/s2";
3+
import {debounce} from "lodash-es";
34

45
export class Table extends BaseChart {
56

67
table?: TableSheet = undefined
78

89
container: S2MountContainer | null = null
910

11+
debounceRender: any
12+
13+
resizeObserver: ResizeObserver
14+
1015
constructor(id: string) {
1116
super(id, "table");
1217
this.container = document.getElementById(id);
18+
19+
this.debounceRender = debounce(async (width?: number, height?: number) => {
20+
if (this.table) {
21+
this.table.changeSheetSize(width, height);
22+
await this.table.render(false);
23+
}
24+
}, 200);
25+
26+
this.resizeObserver = new ResizeObserver(([entry] = []) => {
27+
const [size] = entry.borderBoxSize || [];
28+
this.debounceRender(size.inlineSize, size.blockSize);
29+
});
30+
31+
if (this.container?.parentElement) {
32+
this.resizeObserver.observe(this.container.parentElement);
33+
}
1334
}
1435

1536
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ [key: string]: any }>) {
@@ -30,7 +51,7 @@ export class Table extends BaseChart {
3051

3152
const s2Options: S2Options = {
3253
width: 600,
33-
height: 480,
54+
height: 360,
3455
placeholder: {
3556
cell: '-',
3657
empty: {
@@ -52,6 +73,7 @@ export class Table extends BaseChart {
5273

5374
destroy() {
5475
this.table?.destroy()
76+
this.resizeObserver?.disconnect()
5577
}
5678

5779
}

0 commit comments

Comments
 (0)