Skip to content

Commit a384421

Browse files
committed
feat: add table chart
1 parent 3217546 commit a384421

File tree

7 files changed

+66
-5
lines changed

7 files changed

+66
-5
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@antv/g2": "^5.3.3",
13+
"@antv/s2": "^2.4.3",
1314
"@npkg/tinymce-plugins": "^0.0.7",
1415
"@tinymce/tinymce-vue": "^5.1.0",
1516
"dayjs": "^1.11.13",

frontend/src/i18n/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createI18n } from 'vue-i18n'
22
import en from './en.json'
33
import zhCN from './zh-CN.json'
4-
import elementEnLocale from 'element-plus/es/locale/lang/en'
5-
import elementZhLocale from 'element-plus/es/locale/lang/zh-cn'
4+
import elementEnLocale from 'element-plus-secondary/es/locale/lang/en'
5+
import elementZhLocale from 'element-plus-secondary/es/locale/lang/zh-cn'
66

77
const getDefaultLocale = () => {
88
/* const savedLang = localStorage.getItem('lang')

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class Bar extends BaseG2Chart {
66
super(id, "bar");
77
}
88

9-
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ name: string; value: string }>) {
9+
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ [key: string]: any }>) {
1010
super.init(axis, data);
1111
const x = this.axis.filter(item => item.type === "x");
1212
const y = this.axis.filter(item => item.type === "y");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class Column extends BaseG2Chart {
66
super(id, "column");
77
}
88

9-
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ name: string; value: string }>) {
9+
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ [key: string]: any }>) {
1010
super.init(axis, data);
1111

1212
const x = this.axis.filter(item => item.type === "x");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class Line extends BaseG2Chart {
66
super(id, "line");
77
}
88

9-
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ name: string; value: string }>) {
9+
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ [key: string]: any }>) {
1010
super.init(axis, data);
1111

1212
const x = this.axis.filter(item => item.type === "x");
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {BaseChart} from "@/views/chat/component/BaseChart.ts";
2+
import {TableSheet, type S2Options, type S2DataConfig, type S2MountContainer} from "@antv/s2";
3+
4+
export class Table extends BaseChart {
5+
6+
table?: TableSheet = undefined
7+
8+
container: S2MountContainer | null = null
9+
10+
constructor(id: string) {
11+
super(id, "table");
12+
this.container = document.getElementById(id);
13+
}
14+
15+
init(axis: Array<{ name: string; value: string; type: "x" | "y" }>, data: Array<{ [key: string]: any }>) {
16+
super.init(axis, data);
17+
18+
const s2DataConfig: S2DataConfig = {
19+
fields: {
20+
columns: this.axis?.map(a => a.value) ?? [],
21+
},
22+
meta: this.axis?.map(a => {
23+
return {
24+
field: a.value,
25+
name: a.name
26+
}
27+
}) ?? [],
28+
data: this.data,
29+
};
30+
31+
const s2Options: S2Options = {
32+
width: 600,
33+
height: 480,
34+
placeholder: {
35+
cell: '-',
36+
empty: {
37+
icon: 'Empty',
38+
description: 'No Data',
39+
},
40+
},
41+
};
42+
43+
if (this.container) {
44+
this.table = new TableSheet(this.container, s2DataConfig, s2Options);
45+
}
46+
47+
}
48+
49+
render() {
50+
this.table?.render()
51+
}
52+
53+
destroy() {
54+
this.table?.destroy()
55+
}
56+
57+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import {BaseChart} from "@/views/chat/component/BaseChart.ts";
22
import {Bar} from "@/views/chat/component/charts/Bar.ts";
33
import {Column} from "@/views/chat/component/charts/Column.ts";
44
import {Line} from "@/views/chat/component/charts/Line.ts";
5+
import {Table} from "@/views/chat/component/charts/Table.ts";
56

67
const CHART_TYPE_MAP: { [key: string]: any } = {
8+
"table": Table,
79
"column": Column,
810
"bar": Bar,
911
"line": Line,
12+
"pie": undefined
1013
}
1114

1215
const isParent = (type: any, parentType: any) => {

0 commit comments

Comments
 (0)