@antv/gpt-vis 1.0.0-beta.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +223 -47
- package/README.zh-CN.md +227 -51
- package/dist/cjs/gpt-vis/index.d.ts +8 -1
- package/dist/cjs/gpt-vis/index.js +43 -20
- package/dist/cjs/index.d.ts +15 -2
- package/dist/cjs/index.js +22 -2
- package/dist/cjs/syntax/parser.d.ts +17 -2
- package/dist/cjs/syntax/parser.js +151 -38
- package/dist/cjs/util/container.d.ts +5 -0
- package/dist/cjs/util/container.js +43 -0
- package/dist/cjs/util/theme.d.ts +5 -0
- package/dist/cjs/util/theme.js +9 -2
- package/dist/cjs/vis/area/index.js +2 -1
- package/dist/cjs/vis/bar/index.js +5 -4
- package/dist/cjs/vis/boxplot/index.js +7 -2
- package/dist/cjs/vis/column/index.js +5 -4
- package/dist/cjs/vis/dual-axes/index.js +3 -3
- package/dist/cjs/vis/fishbone-diagram/index.d.ts +35 -0
- package/dist/cjs/vis/fishbone-diagram/index.js +191 -0
- package/dist/cjs/vis/flow-diagram/index.d.ts +27 -0
- package/dist/cjs/vis/flow-diagram/index.js +287 -0
- package/dist/cjs/vis/funnel/index.js +2 -1
- package/dist/cjs/vis/histogram/index.js +3 -7
- package/dist/cjs/vis/indented-tree/index.d.ts +40 -0
- package/dist/cjs/vis/indented-tree/index.js +385 -0
- package/dist/cjs/vis/line/index.js +2 -1
- package/dist/cjs/vis/liquid/index.js +2 -1
- package/dist/cjs/vis/mindmap/index.d.ts +32 -0
- package/dist/cjs/vis/mindmap/index.js +222 -0
- package/dist/cjs/vis/network-graph/index.d.ts +59 -0
- package/dist/cjs/vis/network-graph/index.js +175 -0
- package/dist/cjs/vis/organization-chart/index.d.ts +64 -0
- package/dist/cjs/vis/organization-chart/index.js +200 -0
- package/dist/cjs/vis/pie/index.js +3 -3
- package/dist/cjs/vis/radar/index.d.ts +1 -0
- package/dist/cjs/vis/radar/index.js +10 -9
- package/dist/cjs/vis/sankey/index.js +2 -1
- package/dist/cjs/vis/scatter/index.d.ts +2 -0
- package/dist/cjs/vis/scatter/index.js +9 -4
- package/dist/cjs/vis/summary/index.js +17 -3
- package/dist/cjs/vis/table/index.d.ts +1 -0
- package/dist/cjs/vis/table/index.js +37 -1
- package/dist/cjs/vis/treemap/index.js +2 -1
- package/dist/cjs/vis/venn/index.d.ts +2 -1
- package/dist/cjs/vis/venn/index.js +18 -3
- package/dist/cjs/vis/violin/index.js +2 -1
- package/dist/cjs/vis/waterfall/index.d.ts +6 -9
- package/dist/cjs/vis/waterfall/index.js +29 -6
- package/dist/cjs/vis/word-cloud/index.js +2 -1
- package/dist/cjs/vis-wrapper/icons.js +2 -2
- package/dist/cjs/vis-wrapper/index.d.ts +1 -0
- package/dist/cjs/vis-wrapper/index.js +27 -16
- package/dist/cjs/vis-wrapper/styles.d.ts +1 -1
- package/dist/cjs/vis-wrapper/styles.js +8 -1
- package/dist/esm/gpt-vis/index.d.ts +8 -1
- package/dist/esm/gpt-vis/index.js +47 -26
- package/dist/esm/index.d.ts +15 -2
- package/dist/esm/index.js +7 -1
- package/dist/esm/syntax/parser.d.ts +17 -2
- package/dist/esm/syntax/parser.js +248 -90
- package/dist/esm/util/container.d.ts +5 -0
- package/dist/esm/util/container.js +20 -0
- package/dist/esm/util/theme.d.ts +5 -0
- package/dist/esm/util/theme.js +9 -0
- package/dist/esm/vis/area/index.js +3 -2
- package/dist/esm/vis/bar/index.js +7 -6
- package/dist/esm/vis/boxplot/index.js +17 -4
- package/dist/esm/vis/column/index.js +7 -6
- package/dist/esm/vis/dual-axes/index.js +13 -5
- package/dist/esm/vis/fishbone-diagram/index.d.ts +35 -0
- package/dist/esm/vis/fishbone-diagram/index.js +219 -0
- package/dist/esm/vis/flow-diagram/index.d.ts +27 -0
- package/dist/esm/vis/flow-diagram/index.js +349 -0
- package/dist/esm/vis/funnel/index.js +3 -2
- package/dist/esm/vis/histogram/index.js +6 -7
- package/dist/esm/vis/indented-tree/index.d.ts +40 -0
- package/dist/esm/vis/indented-tree/index.js +569 -0
- package/dist/esm/vis/line/index.js +3 -2
- package/dist/esm/vis/liquid/index.js +3 -2
- package/dist/esm/vis/mindmap/index.d.ts +32 -0
- package/dist/esm/vis/mindmap/index.js +316 -0
- package/dist/esm/vis/network-graph/index.d.ts +59 -0
- package/dist/esm/vis/network-graph/index.js +242 -0
- package/dist/esm/vis/organization-chart/index.d.ts +64 -0
- package/dist/esm/vis/organization-chart/index.js +271 -0
- package/dist/esm/vis/pie/index.js +4 -8
- package/dist/esm/vis/radar/index.d.ts +1 -0
- package/dist/esm/vis/radar/index.js +20 -4
- package/dist/esm/vis/sankey/index.js +3 -2
- package/dist/esm/vis/scatter/index.d.ts +2 -0
- package/dist/esm/vis/scatter/index.js +15 -4
- package/dist/esm/vis/summary/index.js +25 -4
- package/dist/esm/vis/table/index.d.ts +1 -0
- package/dist/esm/vis/table/index.js +9 -2
- package/dist/esm/vis/treemap/index.js +3 -2
- package/dist/esm/vis/venn/index.d.ts +2 -1
- package/dist/esm/vis/venn/index.js +29 -4
- package/dist/esm/vis/violin/index.js +3 -2
- package/dist/esm/vis/waterfall/index.d.ts +6 -9
- package/dist/esm/vis/waterfall/index.js +33 -13
- package/dist/esm/vis/word-cloud/index.js +3 -2
- package/dist/esm/vis-wrapper/icons.js +2 -2
- package/dist/esm/vis-wrapper/index.d.ts +1 -0
- package/dist/esm/vis-wrapper/index.js +15 -10
- package/dist/esm/vis-wrapper/styles.d.ts +1 -1
- package/dist/esm/vis-wrapper/styles.js +1 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +17 -21
- package/src/gpt-vis/index.ts +0 -283
- package/src/index.ts +0 -44
- package/src/readme.md +0 -37
- package/src/syntax/index.ts +0 -2
- package/src/syntax/parser.ts +0 -411
- package/src/types/index.ts +0 -29
- package/src/util/theme.ts +0 -167
- package/src/vis/area/README.md +0 -143
- package/src/vis/area/index.ts +0 -212
- package/src/vis/bar/README.md +0 -158
- package/src/vis/bar/index.ts +0 -186
- package/src/vis/boxplot/README.md +0 -168
- package/src/vis/boxplot/index.ts +0 -162
- package/src/vis/column/README.md +0 -158
- package/src/vis/column/index.ts +0 -185
- package/src/vis/dual-axes/README.md +0 -191
- package/src/vis/dual-axes/index.ts +0 -218
- package/src/vis/funnel/README.md +0 -143
- package/src/vis/funnel/index.ts +0 -238
- package/src/vis/histogram/README.md +0 -130
- package/src/vis/histogram/index.ts +0 -153
- package/src/vis/line/README.md +0 -138
- package/src/vis/line/index.ts +0 -159
- package/src/vis/liquid/README.md +0 -150
- package/src/vis/liquid/index.ts +0 -130
- package/src/vis/pie/README.md +0 -127
- package/src/vis/pie/index.ts +0 -163
- package/src/vis/radar/README.md +0 -184
- package/src/vis/radar/index.ts +0 -214
- package/src/vis/sankey/README.md +0 -144
- package/src/vis/sankey/index.ts +0 -144
- package/src/vis/scatter/README.md +0 -145
- package/src/vis/scatter/index.ts +0 -147
- package/src/vis/summary/README.md +0 -272
- package/src/vis/summary/index.ts +0 -91
- package/src/vis/table/README.md +0 -174
- package/src/vis/table/index.ts +0 -241
- package/src/vis/treemap/README.md +0 -199
- package/src/vis/treemap/index.ts +0 -167
- package/src/vis/venn/README.md +0 -153
- package/src/vis/venn/index.ts +0 -149
- package/src/vis/violin/README.md +0 -168
- package/src/vis/violin/index.ts +0 -216
- package/src/vis/waterfall/README.md +0 -178
- package/src/vis/waterfall/index.ts +0 -258
- package/src/vis/word-cloud/README.md +0 -137
- package/src/vis/word-cloud/index.ts +0 -137
- package/src/vis-wrapper/README.md +0 -159
- package/src/vis-wrapper/icons.ts +0 -35
- package/src/vis-wrapper/index.ts +0 -276
- package/src/vis-wrapper/styles.ts +0 -195
package/src/vis/area/README.md
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
# Area
|
|
2
|
-
|
|
3
|
-
An area chart component for visualizing trends and total changes over time, built with G2 5.0.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Area } from '@antv/gpt-vis/ai';
|
|
9
|
-
|
|
10
|
-
const area = Area({
|
|
11
|
-
container: '#container',
|
|
12
|
-
width: 600,
|
|
13
|
-
height: 400,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
area.render({
|
|
17
|
-
data: [
|
|
18
|
-
{ time: '1 月', value: 23.895 },
|
|
19
|
-
{ time: '2 月', value: 23.695 },
|
|
20
|
-
{ time: '3 月', value: 23.655 },
|
|
21
|
-
],
|
|
22
|
-
title: '1月到3月股票价格的变化',
|
|
23
|
-
axisXTitle: '月份',
|
|
24
|
-
axisYTitle: '价格',
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
area.destroy();
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Configuration
|
|
31
|
-
|
|
32
|
-
### Constructor Options (AreaOptions)
|
|
33
|
-
|
|
34
|
-
| Property | Type | Default | Description |
|
|
35
|
-
| --------- | --------------------- | ------- | ----------------------------- |
|
|
36
|
-
| container | string \| HTMLElement | - | Container element or selector |
|
|
37
|
-
| width | number | 640 | Chart width in pixels |
|
|
38
|
-
| height | number | 480 | Chart height in pixels |
|
|
39
|
-
|
|
40
|
-
### Render Config (AreaConfig)
|
|
41
|
-
|
|
42
|
-
| Property | Type | Default | Description |
|
|
43
|
-
| ---------- | ------- | --------- | -------------------------------------- |
|
|
44
|
-
| data | Array | - | Chart data array |
|
|
45
|
-
| type | string | 'area' | Chart type identifier |
|
|
46
|
-
| stack | boolean | false | Enable stacking (requires group field) |
|
|
47
|
-
| title | string | - | Chart title |
|
|
48
|
-
| axisXTitle | string | - | X-axis title |
|
|
49
|
-
| axisYTitle | string | - | Y-axis title |
|
|
50
|
-
| theme | string | 'default' | Color theme |
|
|
51
|
-
| style | object | - | Chart style configuration |
|
|
52
|
-
|
|
53
|
-
### Data Structure
|
|
54
|
-
|
|
55
|
-
```ts
|
|
56
|
-
type AreaDataItem = {
|
|
57
|
-
time: string | number; // Time or category value
|
|
58
|
-
value: number; // Numeric value
|
|
59
|
-
group?: string; // Optional group name for multi-area or stacked charts
|
|
60
|
-
};
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Style Options
|
|
64
|
-
|
|
65
|
-
| Property | Type | Default | Description |
|
|
66
|
-
| --------------- | -------- | ------- | ------------------------------------------- |
|
|
67
|
-
| backgroundColor | string | - | Background color of the chart |
|
|
68
|
-
| palette | string[] | - | Array of colors for the chart color palette |
|
|
69
|
-
| lineWidth | number | 2 | Width of the area border line in pixels |
|
|
70
|
-
|
|
71
|
-
## Examples
|
|
72
|
-
|
|
73
|
-
### Basic Area Chart
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
area.render({
|
|
77
|
-
data: [
|
|
78
|
-
{ time: 2015, value: 7200.0 },
|
|
79
|
-
{ time: 2016, value: 3660.0 },
|
|
80
|
-
{ time: 2017, value: 4100.0 },
|
|
81
|
-
],
|
|
82
|
-
axisXTitle: 'year',
|
|
83
|
-
axisYTitle: 'value',
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Stacked Area Chart
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
area.render({
|
|
91
|
-
data: [
|
|
92
|
-
{ time: '2019年', value: 150, group: '北京' },
|
|
93
|
-
{ time: '2020年', value: 160, group: '北京' },
|
|
94
|
-
{ time: '2021年', value: 145, group: '北京' },
|
|
95
|
-
{ time: '2019年', value: 100, group: '广州' },
|
|
96
|
-
{ time: '2020年', value: 110, group: '广州' },
|
|
97
|
-
{ time: '2021年', value: 105, group: '广州' },
|
|
98
|
-
{ time: '2019年', value: 90, group: '上海' },
|
|
99
|
-
{ time: '2020年', value: 85, group: '上海' },
|
|
100
|
-
{ time: '2021年', value: 80, group: '上海' },
|
|
101
|
-
],
|
|
102
|
-
stack: true,
|
|
103
|
-
title: '城市空气污染指数变化',
|
|
104
|
-
axisXTitle: '年份',
|
|
105
|
-
axisYTitle: '空气污染指数',
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### With Theme
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
area.render({
|
|
113
|
-
data: [
|
|
114
|
-
{ time: '1 月', value: 23.895 },
|
|
115
|
-
{ time: '2 月', value: 23.695 },
|
|
116
|
-
{ time: '3 月', value: 23.655 },
|
|
117
|
-
],
|
|
118
|
-
theme: 'dark',
|
|
119
|
-
title: '股票价格变化',
|
|
120
|
-
});
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### With Custom Styles
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
area.render({
|
|
127
|
-
data: [
|
|
128
|
-
{ time: '1 月', value: 23.895 },
|
|
129
|
-
{ time: '2 月', value: 23.695 },
|
|
130
|
-
{ time: '3 月', value: 23.655 },
|
|
131
|
-
],
|
|
132
|
-
style: {
|
|
133
|
-
palette: ['#FF6B6B', '#4ECDC4', '#45B7D1'],
|
|
134
|
-
lineWidth: 3,
|
|
135
|
-
backgroundColor: '#F5F5F5',
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Methods
|
|
141
|
-
|
|
142
|
-
- `render(config: AreaConfig): void` - Render or update the chart
|
|
143
|
-
- `destroy(): void` - Destroy the chart instance and clean up resources
|
package/src/vis/area/index.ts
DELETED
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { Chart } from '@antv/g2';
|
|
2
|
-
import type { VisualizationOptions } from '../../types';
|
|
3
|
-
import { getBackgroundColor, getThemeColors, getThemeObject } from '../../util/theme';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* AreaDataItem is the type for each data item in the area chart.
|
|
7
|
-
*/
|
|
8
|
-
export type AreaDataItem = {
|
|
9
|
-
time: string | number;
|
|
10
|
-
value: number;
|
|
11
|
-
group?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* AreaConfig defines the configuration for rendering the area chart.
|
|
16
|
-
*/
|
|
17
|
-
export interface AreaConfig {
|
|
18
|
-
type?: 'area';
|
|
19
|
-
data: AreaDataItem[];
|
|
20
|
-
stack?: boolean;
|
|
21
|
-
title?: string;
|
|
22
|
-
axisXTitle?: string;
|
|
23
|
-
axisYTitle?: string;
|
|
24
|
-
theme?: 'default' | 'academy' | 'dark';
|
|
25
|
-
style?: {
|
|
26
|
-
backgroundColor?: string;
|
|
27
|
-
palette?: string[];
|
|
28
|
-
lineWidth?: number;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* AreaInstance represents an area chart instance with render and destroy methods.
|
|
34
|
-
*/
|
|
35
|
-
export interface AreaInstance {
|
|
36
|
-
render: (config: AreaConfig) => void;
|
|
37
|
-
destroy: () => void;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const getLinearGradientColor = (color: string) =>
|
|
41
|
-
`linear-gradient(-90deg, white 0%, ${color} 100%)`;
|
|
42
|
-
const DEFAULT_COLOR = '#3A95FF';
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Area chart component using G2 5.0.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* const area = Area({
|
|
50
|
-
* container: '#container',
|
|
51
|
-
* width: 600,
|
|
52
|
-
* height: 400,
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* area.render({
|
|
56
|
-
* type: 'area',
|
|
57
|
-
* data: [
|
|
58
|
-
* { time: '1 月', value: 23.895 },
|
|
59
|
-
* { time: '2 月', value: 23.695 },
|
|
60
|
-
* { time: '3 月', value: 23.655 },
|
|
61
|
-
* ],
|
|
62
|
-
* title: '1月到3月股票价格的变化',
|
|
63
|
-
* axisXTitle: '月份',
|
|
64
|
-
* axisYTitle: '价格',
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* area.destroy();
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export const Area = (options: VisualizationOptions): AreaInstance => {
|
|
71
|
-
const { container, width, height, theme: chartTheme = 'default' } = options;
|
|
72
|
-
let chart: Chart | null = null;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Render the area chart with the given configuration.
|
|
76
|
-
*/
|
|
77
|
-
const render = (config: AreaConfig): void => {
|
|
78
|
-
const {
|
|
79
|
-
data = [],
|
|
80
|
-
theme = chartTheme,
|
|
81
|
-
title,
|
|
82
|
-
axisXTitle,
|
|
83
|
-
axisYTitle,
|
|
84
|
-
stack = false,
|
|
85
|
-
style = {},
|
|
86
|
-
} = config;
|
|
87
|
-
|
|
88
|
-
// Clean up previous chart if exists
|
|
89
|
-
if (chart) {
|
|
90
|
-
chart.destroy();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const { lineWidth = 2 } = style;
|
|
94
|
-
const hasGroupField = data.length > 0 && data[0]?.group !== undefined;
|
|
95
|
-
const colors = style.palette || getThemeColors(theme);
|
|
96
|
-
const backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
97
|
-
const fillColor = getLinearGradientColor(colors[0] || DEFAULT_COLOR);
|
|
98
|
-
|
|
99
|
-
// Create chart
|
|
100
|
-
chart = new Chart({
|
|
101
|
-
container,
|
|
102
|
-
width,
|
|
103
|
-
height,
|
|
104
|
-
autoFit: true,
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Configure chart encode and transform based on stack and group
|
|
108
|
-
let encode: any = {};
|
|
109
|
-
let transform: any = [];
|
|
110
|
-
const scaleConfig: any = { y: { nice: true } };
|
|
111
|
-
let children: any = [];
|
|
112
|
-
|
|
113
|
-
if (hasGroupField && stack) {
|
|
114
|
-
// Stacked area chart
|
|
115
|
-
encode = { x: 'time', y: 'value', color: 'group' };
|
|
116
|
-
transform = [{ type: 'stackY' }];
|
|
117
|
-
scaleConfig.color = { range: colors };
|
|
118
|
-
children = [
|
|
119
|
-
{
|
|
120
|
-
type: 'area',
|
|
121
|
-
style: { fillOpacity: 0.6 },
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
type: 'line',
|
|
125
|
-
style: { lineWidth, strokeOpacity: 0.6 },
|
|
126
|
-
},
|
|
127
|
-
];
|
|
128
|
-
} else if (hasGroupField) {
|
|
129
|
-
// Multi-line area chart (not stacked)
|
|
130
|
-
encode = { x: 'time', y: 'value', color: 'group' };
|
|
131
|
-
scaleConfig.color = { range: colors };
|
|
132
|
-
children = [
|
|
133
|
-
{
|
|
134
|
-
type: 'area',
|
|
135
|
-
style: { fillOpacity: 0.6 },
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
type: 'line',
|
|
139
|
-
style: { lineWidth, strokeOpacity: 0.6 },
|
|
140
|
-
},
|
|
141
|
-
];
|
|
142
|
-
} else {
|
|
143
|
-
// Single area chart
|
|
144
|
-
encode = { x: 'time', y: 'value' };
|
|
145
|
-
children = [
|
|
146
|
-
{
|
|
147
|
-
type: 'area',
|
|
148
|
-
style: {
|
|
149
|
-
fillOpacity: 0.6,
|
|
150
|
-
fill: fillColor,
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
type: 'line',
|
|
155
|
-
style: {
|
|
156
|
-
lineWidth,
|
|
157
|
-
strokeOpacity: 0.6,
|
|
158
|
-
...(style.palette ? { stroke: colors[0] } : {}),
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// Configure chart options
|
|
165
|
-
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
166
|
-
// This is consistent with how G2 5.0 is used elsewhere in the codebase
|
|
167
|
-
const chartOptions: any = {
|
|
168
|
-
type: 'view',
|
|
169
|
-
data,
|
|
170
|
-
title: title ?? '',
|
|
171
|
-
encode,
|
|
172
|
-
transform,
|
|
173
|
-
children,
|
|
174
|
-
scale: scaleConfig,
|
|
175
|
-
axis: {
|
|
176
|
-
x: { title: axisXTitle || false },
|
|
177
|
-
y: { title: axisYTitle || false },
|
|
178
|
-
},
|
|
179
|
-
legend: hasGroupField ? { color: { position: 'top' } } : false,
|
|
180
|
-
tooltip: {
|
|
181
|
-
items: [
|
|
182
|
-
(d: any) => ({
|
|
183
|
-
name: axisYTitle || d.time,
|
|
184
|
-
value: d.value,
|
|
185
|
-
}),
|
|
186
|
-
],
|
|
187
|
-
},
|
|
188
|
-
viewStyle: {
|
|
189
|
-
viewFill: backgroundColor,
|
|
190
|
-
},
|
|
191
|
-
theme: getThemeObject(theme),
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
chart.options(chartOptions);
|
|
195
|
-
chart.render();
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Destroy the chart instance and clean up resources.
|
|
200
|
-
*/
|
|
201
|
-
const destroy = (): void => {
|
|
202
|
-
if (chart) {
|
|
203
|
-
chart.destroy();
|
|
204
|
-
chart = null;
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
render,
|
|
210
|
-
destroy,
|
|
211
|
-
};
|
|
212
|
-
};
|
package/src/vis/bar/README.md
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
# Bar
|
|
2
|
-
|
|
3
|
-
A horizontal bar chart component for comparing categorical data, built with G2 5.0.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Bar } from '@antv/gpt-vis/ai';
|
|
9
|
-
|
|
10
|
-
const bar = Bar({
|
|
11
|
-
container: '#container',
|
|
12
|
-
width: 600,
|
|
13
|
-
height: 400,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
bar.render({
|
|
17
|
-
data: [
|
|
18
|
-
{ category: '2015 年', value: 80 },
|
|
19
|
-
{ category: '2016 年', value: 140 },
|
|
20
|
-
{ category: '2017 年', value: 220 },
|
|
21
|
-
],
|
|
22
|
-
title: '海底捞公司外卖收入',
|
|
23
|
-
axisXTitle: '年份',
|
|
24
|
-
axisYTitle: '金额 (百万元)',
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
bar.destroy();
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Configuration
|
|
31
|
-
|
|
32
|
-
### Constructor Options (BarOptions)
|
|
33
|
-
|
|
34
|
-
| Property | Type | Default | Description |
|
|
35
|
-
| --------- | --------------------- | ------- | ----------------------------- |
|
|
36
|
-
| container | string \| HTMLElement | - | Container element or selector |
|
|
37
|
-
| width | number | 640 | Chart width in pixels |
|
|
38
|
-
| height | number | 480 | Chart height in pixels |
|
|
39
|
-
|
|
40
|
-
### Render Config (BarConfig)
|
|
41
|
-
|
|
42
|
-
| Property | Type | Default | Description |
|
|
43
|
-
| ---------- | ------- | --------- | -------------------------------------- |
|
|
44
|
-
| data | Array | - | Chart data array |
|
|
45
|
-
| type | string | 'bar' | Chart type identifier |
|
|
46
|
-
| group | boolean | false | Enable grouping (requires group field) |
|
|
47
|
-
| stack | boolean | false | Enable stacking (requires group field) |
|
|
48
|
-
| title | string | - | Chart title |
|
|
49
|
-
| axisXTitle | string | - | X-axis title |
|
|
50
|
-
| axisYTitle | string | - | Y-axis title |
|
|
51
|
-
| theme | string | 'default' | Color theme |
|
|
52
|
-
| style | object | - | Chart style configuration |
|
|
53
|
-
|
|
54
|
-
### Data Structure
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
type BarDataItem = {
|
|
58
|
-
category: string; // Category name
|
|
59
|
-
value: number; // Numeric value
|
|
60
|
-
group?: string; // Optional group name for grouped or stacked charts
|
|
61
|
-
};
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Style Options
|
|
65
|
-
|
|
66
|
-
| Property | Type | Default | Description |
|
|
67
|
-
| --------------- | -------- | ------- | ------------------------------------------- |
|
|
68
|
-
| backgroundColor | string | - | Background color of the chart |
|
|
69
|
-
| palette | string[] | - | Array of colors for the chart color palette |
|
|
70
|
-
|
|
71
|
-
## Examples
|
|
72
|
-
|
|
73
|
-
### Basic Bar Chart
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
bar.render({
|
|
77
|
-
data: [
|
|
78
|
-
{ category: '第一产业', value: 7200.0 },
|
|
79
|
-
{ category: '第二产业', value: 36600.0 },
|
|
80
|
-
{ category: '第三产业', value: 41000.0 },
|
|
81
|
-
],
|
|
82
|
-
axisXTitle: 'name',
|
|
83
|
-
axisYTitle: 'industrial',
|
|
84
|
-
});
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Grouped Bar Chart
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
bar.render({
|
|
91
|
-
data: [
|
|
92
|
-
{ category: '北京', value: 825.6, group: '油车' },
|
|
93
|
-
{ category: '北京', value: 60.2, group: '新能源汽车' },
|
|
94
|
-
{ category: '上海', value: 450, group: '油车' },
|
|
95
|
-
{ category: '上海', value: 95, group: '新能源汽车' },
|
|
96
|
-
{ category: '深圳', value: 506, group: '油车' },
|
|
97
|
-
{ category: '深圳', value: 76.7, group: '新能源汽车' },
|
|
98
|
-
],
|
|
99
|
-
group: true,
|
|
100
|
-
title: '油车与新能源汽车售卖量',
|
|
101
|
-
axisXTitle: '城市',
|
|
102
|
-
axisYTitle: '售卖量 (万辆)',
|
|
103
|
-
});
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### Stacked Bar Chart
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
bar.render({
|
|
110
|
-
data: [
|
|
111
|
-
{ category: '北京', value: 825.6, group: '油车' },
|
|
112
|
-
{ category: '北京', value: 60.2, group: '新能源汽车' },
|
|
113
|
-
{ category: '上海', value: 450, group: '油车' },
|
|
114
|
-
{ category: '上海', value: 95, group: '新能源汽车' },
|
|
115
|
-
{ category: '深圳', value: 506, group: '油车' },
|
|
116
|
-
{ category: '深圳', value: 76.7, group: '新能源汽车' },
|
|
117
|
-
],
|
|
118
|
-
stack: true,
|
|
119
|
-
title: '油车与新能源汽车售卖量',
|
|
120
|
-
axisXTitle: '城市',
|
|
121
|
-
axisYTitle: '售卖量 (万辆)',
|
|
122
|
-
});
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### With Theme
|
|
126
|
-
|
|
127
|
-
```ts
|
|
128
|
-
bar.render({
|
|
129
|
-
data: [
|
|
130
|
-
{ category: '2015 年', value: 80 },
|
|
131
|
-
{ category: '2016 年', value: 140 },
|
|
132
|
-
{ category: '2017 年', value: 220 },
|
|
133
|
-
],
|
|
134
|
-
theme: 'academy',
|
|
135
|
-
title: '海底捞公司外卖收入',
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### With Custom Styles
|
|
140
|
-
|
|
141
|
-
```ts
|
|
142
|
-
bar.render({
|
|
143
|
-
data: [
|
|
144
|
-
{ category: '2015 年', value: 80 },
|
|
145
|
-
{ category: '2016 年', value: 140 },
|
|
146
|
-
{ category: '2017 年', value: 220 },
|
|
147
|
-
],
|
|
148
|
-
style: {
|
|
149
|
-
palette: ['#FF6B6B', '#4ECDC4', '#45B7D1'],
|
|
150
|
-
backgroundColor: '#F5F5F5',
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## Methods
|
|
156
|
-
|
|
157
|
-
- `render(config: BarConfig): void` - Render or update the chart
|
|
158
|
-
- `destroy(): void` - Destroy the chart instance and clean up resources
|
package/src/vis/bar/index.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { Chart } from '@antv/g2';
|
|
2
|
-
import type { VisualizationOptions } from '../../types';
|
|
3
|
-
import { getBackgroundColor, getThemeColors, getThemeObject } from '../../util/theme';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* BarDataItem is the type for each data item in the bar chart.
|
|
7
|
-
*/
|
|
8
|
-
export type BarDataItem = {
|
|
9
|
-
category: string;
|
|
10
|
-
value: number;
|
|
11
|
-
group?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* BarConfig defines the configuration for rendering the bar chart.
|
|
16
|
-
*/
|
|
17
|
-
export interface BarConfig {
|
|
18
|
-
type?: 'bar';
|
|
19
|
-
data: BarDataItem[];
|
|
20
|
-
group?: boolean;
|
|
21
|
-
stack?: boolean;
|
|
22
|
-
title?: string;
|
|
23
|
-
axisXTitle?: string;
|
|
24
|
-
axisYTitle?: string;
|
|
25
|
-
theme?: 'default' | 'academy' | 'dark';
|
|
26
|
-
style?: {
|
|
27
|
-
backgroundColor?: string;
|
|
28
|
-
palette?: string[];
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* BarInstance represents a bar chart instance with render and destroy methods.
|
|
34
|
-
*/
|
|
35
|
-
export interface BarInstance {
|
|
36
|
-
render: (config: BarConfig) => void;
|
|
37
|
-
destroy: () => void;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Bar chart component using G2 5.0.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```ts
|
|
45
|
-
* const bar = Bar({
|
|
46
|
-
* container: '#container',
|
|
47
|
-
* width: 600,
|
|
48
|
-
* height: 400,
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* bar.render({
|
|
52
|
-
* type: 'bar',
|
|
53
|
-
* data: [
|
|
54
|
-
* { category: '2015 年', value: 80 },
|
|
55
|
-
* { category: '2016 年', value: 140 },
|
|
56
|
-
* { category: '2017 年', value: 220 },
|
|
57
|
-
* ],
|
|
58
|
-
* title: '海底捞公司外卖收入',
|
|
59
|
-
* axisXTitle: '年份',
|
|
60
|
-
* axisYTitle: '金额 (百万元)',
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* bar.destroy();
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
export const Bar = (options: VisualizationOptions): BarInstance => {
|
|
67
|
-
const { container, width, height, theme: chartTheme = 'default' } = options;
|
|
68
|
-
let chart: Chart | null = null;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Render the bar chart with the given configuration.
|
|
72
|
-
*/
|
|
73
|
-
const render = (config: BarConfig): void => {
|
|
74
|
-
const {
|
|
75
|
-
data = [],
|
|
76
|
-
theme = chartTheme,
|
|
77
|
-
title,
|
|
78
|
-
axisXTitle,
|
|
79
|
-
axisYTitle,
|
|
80
|
-
group = false,
|
|
81
|
-
stack = false,
|
|
82
|
-
style = {},
|
|
83
|
-
} = config;
|
|
84
|
-
|
|
85
|
-
// Clean up previous chart if exists
|
|
86
|
-
if (chart) {
|
|
87
|
-
chart.destroy();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const hasGroupField = data.length > 0 && data[0]?.group !== undefined;
|
|
91
|
-
const colors = style.palette || getThemeColors(theme);
|
|
92
|
-
const backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
93
|
-
|
|
94
|
-
// Create chart
|
|
95
|
-
chart = new Chart({
|
|
96
|
-
container,
|
|
97
|
-
width,
|
|
98
|
-
height,
|
|
99
|
-
autoFit: true,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// Configure chart encode and transform based on group/stack
|
|
103
|
-
let encode: any = {};
|
|
104
|
-
let transform: any = [];
|
|
105
|
-
let radiusStyle: any = {};
|
|
106
|
-
|
|
107
|
-
// Set radius style for default theme
|
|
108
|
-
if (theme === 'default') {
|
|
109
|
-
radiusStyle = { radiusTopLeft: 4, radiusTopRight: 4 };
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Configure transforms based on group/stack flags
|
|
113
|
-
if (hasGroupField && group) {
|
|
114
|
-
transform = [{ type: 'dodgeX' }];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (hasGroupField && stack) {
|
|
118
|
-
transform = [{ type: 'stackY' }];
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Configure encode based on whether data has group field
|
|
122
|
-
if (hasGroupField) {
|
|
123
|
-
encode = { x: 'category', y: 'value', color: 'group' };
|
|
124
|
-
} else {
|
|
125
|
-
encode = { x: 'category', y: 'value', color: 'category' };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Configure scale
|
|
129
|
-
const scaleConfig: any = {
|
|
130
|
-
y: { nice: true },
|
|
131
|
-
...(style.palette?.length ? { color: { range: colors } } : {}),
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// Configure chart options
|
|
135
|
-
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
136
|
-
// This is consistent with how G2 5.0 is used elsewhere in the codebase
|
|
137
|
-
const chartOptions: any = {
|
|
138
|
-
type: 'interval',
|
|
139
|
-
data,
|
|
140
|
-
title: title ?? '',
|
|
141
|
-
encode,
|
|
142
|
-
transform,
|
|
143
|
-
coordinate: { transform: [{ type: 'transpose' }] },
|
|
144
|
-
scale: scaleConfig,
|
|
145
|
-
axis: {
|
|
146
|
-
x: { title: axisXTitle || false },
|
|
147
|
-
y: { title: axisYTitle || false },
|
|
148
|
-
},
|
|
149
|
-
legend: hasGroupField ? { color: { position: 'top' } } : false,
|
|
150
|
-
tooltip: {
|
|
151
|
-
items: [
|
|
152
|
-
(d: any) => ({
|
|
153
|
-
name: axisYTitle || d.category,
|
|
154
|
-
value: d.value,
|
|
155
|
-
}),
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
style: {
|
|
159
|
-
...radiusStyle,
|
|
160
|
-
columnWidthRatio: 0.8,
|
|
161
|
-
},
|
|
162
|
-
viewStyle: {
|
|
163
|
-
viewFill: backgroundColor,
|
|
164
|
-
},
|
|
165
|
-
theme: getThemeObject(theme),
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
chart.options(chartOptions);
|
|
169
|
-
chart.render();
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Destroy the chart instance and clean up resources.
|
|
174
|
-
*/
|
|
175
|
-
const destroy = (): void => {
|
|
176
|
-
if (chart) {
|
|
177
|
-
chart.destroy();
|
|
178
|
-
chart = null;
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
return {
|
|
183
|
-
render,
|
|
184
|
-
destroy,
|
|
185
|
-
};
|
|
186
|
-
};
|