@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/line/index.ts
DELETED
|
@@ -1,159 +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
|
-
* LineDataItem is the type for each data item in the line chart.
|
|
7
|
-
*/
|
|
8
|
-
export type LineDataItem = {
|
|
9
|
-
time: string | number;
|
|
10
|
-
value: number;
|
|
11
|
-
group?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* LineConfig defines the configuration for rendering the line chart.
|
|
16
|
-
*/
|
|
17
|
-
export interface LineConfig {
|
|
18
|
-
type?: 'line';
|
|
19
|
-
data: LineDataItem[];
|
|
20
|
-
title?: string;
|
|
21
|
-
axisXTitle?: string;
|
|
22
|
-
axisYTitle?: string;
|
|
23
|
-
theme?: 'default' | 'academy' | 'dark';
|
|
24
|
-
style?: {
|
|
25
|
-
backgroundColor?: string;
|
|
26
|
-
palette?: string[];
|
|
27
|
-
lineWidth?: number;
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* LineInstance represents a line chart instance with render and destroy methods.
|
|
33
|
-
*/
|
|
34
|
-
export interface LineInstance {
|
|
35
|
-
render: (config: LineConfig) => void;
|
|
36
|
-
destroy: () => void;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Line chart component using G2 5.0.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* const line = Line({
|
|
45
|
-
* container: '#container',
|
|
46
|
-
* width: 600,
|
|
47
|
-
* height: 400,
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* line.render({
|
|
51
|
-
* type: 'line',
|
|
52
|
-
* data: [
|
|
53
|
-
* { time: '2015 年', value: 1700 },
|
|
54
|
-
* { time: '2016 年', value: 1500 },
|
|
55
|
-
* { time: '2017 年', value: 1200 },
|
|
56
|
-
* ],
|
|
57
|
-
* title: '出生人口变化',
|
|
58
|
-
* axisXTitle: '年份',
|
|
59
|
-
* axisYTitle: '出生人口(万人)',
|
|
60
|
-
* });
|
|
61
|
-
*
|
|
62
|
-
* line.destroy();
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export const Line = (options: VisualizationOptions): LineInstance => {
|
|
66
|
-
const { container, width, height, theme: chartTheme = 'default' } = options;
|
|
67
|
-
let chart: Chart | null = null;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Render the line chart with the given configuration.
|
|
71
|
-
*/
|
|
72
|
-
const render = (config: LineConfig): void => {
|
|
73
|
-
const { data = [], theme = chartTheme, title, axisXTitle, axisYTitle, style = {} } = config;
|
|
74
|
-
|
|
75
|
-
// Clean up previous chart if exists
|
|
76
|
-
if (chart) {
|
|
77
|
-
chart.destroy();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const { lineWidth = 2 } = style;
|
|
81
|
-
const hasGroupField = data.length > 0 && data[0]?.group !== undefined;
|
|
82
|
-
const colors = style.palette || getThemeColors(theme);
|
|
83
|
-
const backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
84
|
-
|
|
85
|
-
// Create chart
|
|
86
|
-
chart = new Chart({
|
|
87
|
-
container,
|
|
88
|
-
width,
|
|
89
|
-
height,
|
|
90
|
-
autoFit: true,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
// Configure chart encode based on whether there's a group field
|
|
94
|
-
let encode: any = {};
|
|
95
|
-
const scaleConfig: any = { y: { nice: true } };
|
|
96
|
-
|
|
97
|
-
if (hasGroupField) {
|
|
98
|
-
encode = { x: 'time', y: 'value', color: 'group' };
|
|
99
|
-
scaleConfig.color = { range: colors };
|
|
100
|
-
} else {
|
|
101
|
-
encode = { x: 'time', y: 'value' };
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Configure chart options
|
|
105
|
-
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
106
|
-
// This is consistent with how G2 5.0 is used elsewhere in the codebase
|
|
107
|
-
const chartOptions: any = {
|
|
108
|
-
type: 'view',
|
|
109
|
-
data,
|
|
110
|
-
title: title ?? '',
|
|
111
|
-
encode,
|
|
112
|
-
children: [
|
|
113
|
-
{
|
|
114
|
-
type: 'line',
|
|
115
|
-
style: {
|
|
116
|
-
lineWidth,
|
|
117
|
-
...(!hasGroupField && style.palette ? { stroke: colors[0] } : {}),
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
],
|
|
121
|
-
scale: scaleConfig,
|
|
122
|
-
axis: {
|
|
123
|
-
x: { title: axisXTitle || false },
|
|
124
|
-
y: { title: axisYTitle || false },
|
|
125
|
-
},
|
|
126
|
-
legend: hasGroupField ? { color: { position: 'top' } } : false,
|
|
127
|
-
tooltip: {
|
|
128
|
-
items: [
|
|
129
|
-
(d: any) => ({
|
|
130
|
-
name: axisYTitle || d.time,
|
|
131
|
-
value: d.value,
|
|
132
|
-
}),
|
|
133
|
-
],
|
|
134
|
-
},
|
|
135
|
-
viewStyle: {
|
|
136
|
-
viewFill: backgroundColor,
|
|
137
|
-
},
|
|
138
|
-
theme: getThemeObject(theme),
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
chart.options(chartOptions);
|
|
142
|
-
chart.render();
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Destroy the chart instance and clean up resources.
|
|
147
|
-
*/
|
|
148
|
-
const destroy = (): void => {
|
|
149
|
-
if (chart) {
|
|
150
|
-
chart.destroy();
|
|
151
|
-
chart = null;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
render,
|
|
157
|
-
destroy,
|
|
158
|
-
};
|
|
159
|
-
};
|
package/src/vis/liquid/README.md
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
# Liquid
|
|
2
|
-
|
|
3
|
-
A liquid fill chart component for displaying progress, completion rates, or percentage values with a dynamic wave effect, built with G2 5.0.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Liquid } from '@antv/gpt-vis/ai';
|
|
9
|
-
|
|
10
|
-
const liquid = Liquid({
|
|
11
|
-
container: '#container',
|
|
12
|
-
width: 600,
|
|
13
|
-
height: 400,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
liquid.render({
|
|
17
|
-
percent: 0.75,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
liquid.destroy();
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Configuration
|
|
24
|
-
|
|
25
|
-
### Constructor Options (LiquidOptions)
|
|
26
|
-
|
|
27
|
-
| Property | Type | Default | Description |
|
|
28
|
-
| --------- | --------------------- | ------- | ----------------------------- |
|
|
29
|
-
| container | string \| HTMLElement | - | Container element or selector |
|
|
30
|
-
| width | number | 640 | Chart width in pixels |
|
|
31
|
-
| height | number | 480 | Chart height in pixels |
|
|
32
|
-
|
|
33
|
-
### Render Config (LiquidConfig)
|
|
34
|
-
|
|
35
|
-
| Property | Type | Default | Description |
|
|
36
|
-
| -------- | ------ | --------- | ------------------------------------------------ |
|
|
37
|
-
| percent | number | - | Fill percentage (0-1), e.g., 0.75 for 75% |
|
|
38
|
-
| shape | string | 'circle' | Chart shape: 'circle', 'rect', 'pin', 'triangle' |
|
|
39
|
-
| theme | string | 'default' | Color theme: 'default', 'academy', 'dark' |
|
|
40
|
-
| title | string | - | Chart title |
|
|
41
|
-
| style | object | - | Chart style configuration |
|
|
42
|
-
|
|
43
|
-
### Style Options
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
style?: {
|
|
47
|
-
backgroundColor?: string; // Background color
|
|
48
|
-
palette?: string[]; // Color palette (uses first color for liquid fill)
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Examples
|
|
53
|
-
|
|
54
|
-
### Basic Example
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
const liquid = Liquid({
|
|
58
|
-
container: '#container',
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
liquid.render({
|
|
62
|
-
percent: 0.75,
|
|
63
|
-
});
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### With Title
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
liquid.render({
|
|
70
|
-
percent: 0.6,
|
|
71
|
-
title: 'Task Completion',
|
|
72
|
-
});
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Different Shapes
|
|
76
|
-
|
|
77
|
-
```ts
|
|
78
|
-
// Circle (default)
|
|
79
|
-
liquid.render({
|
|
80
|
-
percent: 0.75,
|
|
81
|
-
shape: 'circle',
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Rectangle
|
|
85
|
-
liquid.render({
|
|
86
|
-
percent: 0.6,
|
|
87
|
-
shape: 'rect',
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Pin (water drop)
|
|
91
|
-
liquid.render({
|
|
92
|
-
percent: 0.85,
|
|
93
|
-
shape: 'pin',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
// Triangle
|
|
97
|
-
liquid.render({
|
|
98
|
-
percent: 0.92,
|
|
99
|
-
shape: 'triangle',
|
|
100
|
-
});
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### With Themes
|
|
104
|
-
|
|
105
|
-
```ts
|
|
106
|
-
// Academy theme
|
|
107
|
-
liquid.render({
|
|
108
|
-
percent: 0.75,
|
|
109
|
-
theme: 'academy',
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Dark theme
|
|
113
|
-
liquid.render({
|
|
114
|
-
percent: 0.6,
|
|
115
|
-
theme: 'dark',
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### With Custom Styles
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
liquid.render({
|
|
123
|
-
percent: 0.92,
|
|
124
|
-
title: 'KPI Achievement',
|
|
125
|
-
shape: 'triangle',
|
|
126
|
-
style: {
|
|
127
|
-
palette: ['#00BFFF'],
|
|
128
|
-
backgroundColor: '#F0F0F0',
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## Methods
|
|
134
|
-
|
|
135
|
-
- `render(config: LiquidConfig): void` - Render or update the chart with new configuration
|
|
136
|
-
- `destroy(): void` - Destroy the chart instance and clean up resources
|
|
137
|
-
|
|
138
|
-
## Use Cases
|
|
139
|
-
|
|
140
|
-
- Display task completion rates
|
|
141
|
-
- Show resource usage percentages
|
|
142
|
-
- Visualize KPI achievement levels
|
|
143
|
-
- Present single metric progress indicators
|
|
144
|
-
|
|
145
|
-
## Notes
|
|
146
|
-
|
|
147
|
-
- The `percent` value should be between 0 and 1 (e.g., 0.75 = 75%)
|
|
148
|
-
- Font size is automatically calculated based on chart dimensions
|
|
149
|
-
- The wave animation is disabled for consistent rendering
|
|
150
|
-
- Custom palette colors only use the first color in the array
|
package/src/vis/liquid/index.ts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { Chart } from '@antv/g2';
|
|
2
|
-
import type { VisualizationOptions } from '../../types';
|
|
3
|
-
import { getBackgroundColor, getThemeColors, getThemeObject } from '../../util/theme';
|
|
4
|
-
|
|
5
|
-
// Default dimensions used for font size calculation when not explicitly provided
|
|
6
|
-
const DEFAULT_WIDTH = 640;
|
|
7
|
-
const DEFAULT_HEIGHT = 480;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* LiquidConfig defines the configuration for rendering the liquid chart.
|
|
11
|
-
*/
|
|
12
|
-
export interface LiquidConfig {
|
|
13
|
-
type?: 'liquid';
|
|
14
|
-
percent: number;
|
|
15
|
-
shape?: 'rect' | 'circle' | 'pin' | 'triangle';
|
|
16
|
-
theme?: 'default' | 'academy' | 'dark';
|
|
17
|
-
title?: string;
|
|
18
|
-
style?: {
|
|
19
|
-
backgroundColor?: string;
|
|
20
|
-
palette?: string[];
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* LiquidInstance represents a liquid chart instance with render and destroy methods.
|
|
26
|
-
*/
|
|
27
|
-
export interface LiquidInstance {
|
|
28
|
-
render: (config: LiquidConfig) => void;
|
|
29
|
-
destroy: () => void;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Liquid chart component using G2 5.0.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const liquid = Liquid({
|
|
38
|
-
* container: '#container',
|
|
39
|
-
* width: 600,
|
|
40
|
-
* height: 400,
|
|
41
|
-
* });
|
|
42
|
-
*
|
|
43
|
-
* liquid.render({
|
|
44
|
-
* type: 'liquid',
|
|
45
|
-
* percent: 0.75,
|
|
46
|
-
* shape: 'circle',
|
|
47
|
-
* theme: 'academy'
|
|
48
|
-
* });
|
|
49
|
-
*
|
|
50
|
-
* liquid.destroy();
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export const Liquid = (options: VisualizationOptions): LiquidInstance => {
|
|
54
|
-
const { container, width, height, theme: chartTheme = 'default' } = options;
|
|
55
|
-
let chart: Chart | null = null;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Render the liquid chart with the given configuration.
|
|
59
|
-
*/
|
|
60
|
-
const render = (config: LiquidConfig): void => {
|
|
61
|
-
const { percent, shape = 'circle', theme = chartTheme, title, style = {} } = config;
|
|
62
|
-
|
|
63
|
-
// Clean up previous chart if exists
|
|
64
|
-
if (chart) {
|
|
65
|
-
chart.destroy();
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Get colors from style.palette or theme defaults
|
|
69
|
-
const colors = style.palette || getThemeColors(theme);
|
|
70
|
-
const backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
71
|
-
|
|
72
|
-
// Calculate dynamic font size based on chart dimensions
|
|
73
|
-
// Use default dimensions for font size calculation when not provided
|
|
74
|
-
const inferFontSize = Math.min(width ?? DEFAULT_WIDTH, height ?? DEFAULT_HEIGHT) / 10;
|
|
75
|
-
const fontSize = Math.min(Math.max(inferFontSize, 24), 64);
|
|
76
|
-
|
|
77
|
-
// Create chart
|
|
78
|
-
chart = new Chart({
|
|
79
|
-
container,
|
|
80
|
-
width,
|
|
81
|
-
height,
|
|
82
|
-
autoFit: true,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// Configure chart options
|
|
86
|
-
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
87
|
-
// This is consistent with how G2 5.0 is used elsewhere in the codebase
|
|
88
|
-
const chartOptions: any = {
|
|
89
|
-
type: 'liquid',
|
|
90
|
-
data: percent,
|
|
91
|
-
title: title ?? '',
|
|
92
|
-
style: {
|
|
93
|
-
shape,
|
|
94
|
-
contentFontSize: fontSize,
|
|
95
|
-
contentFill: '#000',
|
|
96
|
-
contentStroke: '#fff',
|
|
97
|
-
contentLineWidth: 2,
|
|
98
|
-
outlineBorder: 4,
|
|
99
|
-
outlineDistance: 4,
|
|
100
|
-
waveLength: 128,
|
|
101
|
-
contentPointerEvents: 'none',
|
|
102
|
-
// Use palette color if provided
|
|
103
|
-
...(colors[0] ? { fill: colors[0], outlineStroke: colors[0] } : {}),
|
|
104
|
-
},
|
|
105
|
-
viewStyle: {
|
|
106
|
-
viewFill: backgroundColor,
|
|
107
|
-
},
|
|
108
|
-
theme: getThemeObject(theme),
|
|
109
|
-
tooltip: false,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
chart.options(chartOptions);
|
|
113
|
-
chart.render();
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Destroy the chart instance and clean up resources.
|
|
118
|
-
*/
|
|
119
|
-
const destroy = (): void => {
|
|
120
|
-
if (chart) {
|
|
121
|
-
chart.destroy();
|
|
122
|
-
chart = null;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
render,
|
|
128
|
-
destroy,
|
|
129
|
-
};
|
|
130
|
-
};
|
package/src/vis/pie/README.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# Pie
|
|
2
|
-
|
|
3
|
-
A pie chart component for displaying categorical data as slices of a circle, built with G2 5.0.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
import { Pie } from '@antv/gpt-vis/ai';
|
|
9
|
-
|
|
10
|
-
const pie = Pie({
|
|
11
|
-
container: '#container',
|
|
12
|
-
width: 600,
|
|
13
|
-
height: 400,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
pie.render({
|
|
17
|
-
data: [
|
|
18
|
-
{ category: '分类一', value: 27 },
|
|
19
|
-
{ category: '分类二', value: 25 },
|
|
20
|
-
{ category: '分类三', value: 18 },
|
|
21
|
-
{ category: '分类四', value: 15 },
|
|
22
|
-
{ category: '分类五', value: 10 },
|
|
23
|
-
{ category: '其他', value: 5 },
|
|
24
|
-
],
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
pie.destroy();
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## Configuration
|
|
31
|
-
|
|
32
|
-
### Constructor Options (PieOptions)
|
|
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 (PieConfig)
|
|
41
|
-
|
|
42
|
-
| Property | Type | Default | Description |
|
|
43
|
-
| ----------- | -------------------------------- | --------- | ---------------------------------- |
|
|
44
|
-
| data | PieDataItem[] | - | Chart data array |
|
|
45
|
-
| innerRadius | number | 0 | Inner radius for donut chart (0-1) |
|
|
46
|
-
| theme | 'default' \| 'academy' \| 'dark' | 'default' | Color theme |
|
|
47
|
-
| title | string | - | Chart title |
|
|
48
|
-
| style | object | - | Chart style configuration |
|
|
49
|
-
|
|
50
|
-
### PieDataItem
|
|
51
|
-
|
|
52
|
-
```ts
|
|
53
|
-
type PieDataItem = {
|
|
54
|
-
category: string;
|
|
55
|
-
value: number;
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### Style Options
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
style?: {
|
|
63
|
-
backgroundColor?: string; // Background color
|
|
64
|
-
palette?: string[]; // Color palette
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Examples
|
|
69
|
-
|
|
70
|
-
### Donut Chart
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
pie.render({
|
|
74
|
-
data: [...],
|
|
75
|
-
innerRadius: 0.6,
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### With Title
|
|
80
|
-
|
|
81
|
-
```ts
|
|
82
|
-
pie.render({
|
|
83
|
-
data: [...],
|
|
84
|
-
title: '餐饮业营收额占比',
|
|
85
|
-
});
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Themes
|
|
89
|
-
|
|
90
|
-
```ts
|
|
91
|
-
// Academy theme
|
|
92
|
-
pie.render({
|
|
93
|
-
data: [...],
|
|
94
|
-
theme: 'academy',
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// Dark theme
|
|
98
|
-
pie.render({
|
|
99
|
-
data: [...],
|
|
100
|
-
theme: 'dark',
|
|
101
|
-
});
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Custom Styles
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
// Custom colors
|
|
108
|
-
pie.render({
|
|
109
|
-
data: [...],
|
|
110
|
-
style: {
|
|
111
|
-
palette: ['#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA07A'],
|
|
112
|
-
},
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// Custom background
|
|
116
|
-
pie.render({
|
|
117
|
-
data: [...],
|
|
118
|
-
style: {
|
|
119
|
-
backgroundColor: '#f5f5f5',
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## Methods
|
|
125
|
-
|
|
126
|
-
- `render(config: PieConfig): void` - Render or update the chart
|
|
127
|
-
- `destroy(): void` - Destroy the chart instance and clean up resources
|