@antv/gpt-vis 0.5.4 → 0.5.6
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/dist/cjs/Area/index.d.ts +2 -3
- package/dist/cjs/Area/index.js +48 -5
- package/dist/cjs/Bar/index.d.ts +2 -2
- package/dist/cjs/Bar/index.js +38 -7
- package/dist/cjs/ChartCodeRender/VisChart.d.ts +7 -1
- package/dist/cjs/ChartCodeRender/VisChart.js +100 -12
- package/dist/cjs/ChartCodeRender/index.js +16 -2
- package/dist/cjs/ChartCodeRender/type.d.ts +104 -5
- package/dist/cjs/Column/index.d.ts +2 -3
- package/dist/cjs/Column/index.js +38 -7
- package/dist/cjs/ConfigProvider/hooks/useConfig.js +2 -1
- package/dist/cjs/DualAxes/index.d.ts +1 -1
- package/dist/cjs/DualAxes/index.js +20 -8
- package/dist/cjs/FishboneDiagram/index.d.ts +1 -0
- package/dist/cjs/FishboneDiagram/index.js +21 -7
- package/dist/cjs/Histogram/index.d.ts +4 -3
- package/dist/cjs/Histogram/index.js +32 -3
- package/dist/cjs/IndentedTree/index.d.ts +1 -0
- package/dist/cjs/IndentedTree/index.js +32 -20
- package/dist/cjs/Line/index.d.ts +2 -3
- package/dist/cjs/Line/index.js +36 -3
- package/dist/cjs/MindMap/index.d.ts +1 -0
- package/dist/cjs/MindMap/index.js +29 -21
- package/dist/cjs/Pie/index.d.ts +2 -2
- package/dist/cjs/Pie/index.js +22 -3
- package/dist/cjs/Radar/index.d.ts +5 -3
- package/dist/cjs/Radar/index.js +106 -37
- package/dist/cjs/Scatter/index.d.ts +2 -3
- package/dist/cjs/Scatter/index.js +46 -3
- package/dist/cjs/Treemap/index.d.ts +2 -3
- package/dist/cjs/Treemap/index.js +22 -3
- package/dist/cjs/WordCloud/index.d.ts +2 -3
- package/dist/cjs/WordCloud/index.js +34 -7
- package/dist/cjs/theme.d.ts +2 -0
- package/dist/cjs/theme.js +133 -0
- package/dist/cjs/types/chart.d.ts +11 -0
- package/dist/cjs/utils/palette.d.ts +2 -0
- package/dist/cjs/utils/palette.js +54 -0
- package/dist/cjs/utils/plot.d.ts +1 -0
- package/dist/cjs/utils/plot.js +15 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Area/index.d.ts +2 -3
- package/dist/esm/Area/index.js +80 -6
- package/dist/esm/Bar/index.d.ts +2 -2
- package/dist/esm/Bar/index.js +56 -9
- package/dist/esm/ChartCodeRender/VisChart.d.ts +7 -1
- package/dist/esm/ChartCodeRender/VisChart.js +144 -34
- package/dist/esm/ChartCodeRender/index.js +15 -1
- package/dist/esm/ChartCodeRender/type.d.ts +104 -5
- package/dist/esm/Column/index.d.ts +2 -3
- package/dist/esm/Column/index.js +56 -9
- package/dist/esm/ConfigProvider/hooks/useConfig.js +9 -1
- package/dist/esm/DualAxes/index.d.ts +1 -1
- package/dist/esm/DualAxes/index.js +35 -12
- package/dist/esm/FishboneDiagram/index.d.ts +1 -0
- package/dist/esm/FishboneDiagram/index.js +23 -7
- package/dist/esm/Histogram/index.d.ts +4 -3
- package/dist/esm/Histogram/index.js +55 -5
- package/dist/esm/IndentedTree/index.d.ts +1 -0
- package/dist/esm/IndentedTree/index.js +36 -29
- package/dist/esm/Line/index.d.ts +2 -3
- package/dist/esm/Line/index.js +63 -4
- package/dist/esm/MindMap/index.d.ts +1 -0
- package/dist/esm/MindMap/index.js +37 -30
- package/dist/esm/Pie/index.d.ts +2 -2
- package/dist/esm/Pie/index.js +37 -4
- package/dist/esm/Radar/index.d.ts +5 -3
- package/dist/esm/Radar/index.js +138 -42
- package/dist/esm/Scatter/index.d.ts +2 -3
- package/dist/esm/Scatter/index.js +65 -5
- package/dist/esm/Treemap/index.d.ts +2 -3
- package/dist/esm/Treemap/index.js +38 -4
- package/dist/esm/WordCloud/index.d.ts +2 -3
- package/dist/esm/WordCloud/index.js +51 -9
- package/dist/esm/theme.d.ts +2 -0
- package/dist/esm/theme.js +103 -0
- package/dist/esm/types/chart.d.ts +11 -0
- package/dist/esm/utils/palette.d.ts +2 -0
- package/dist/esm/utils/palette.js +2 -0
- package/dist/esm/utils/plot.d.ts +1 -0
- package/dist/esm/utils/plot.js +10 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +2 -1
package/dist/cjs/Area/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { AreaConfig } from '@ant-design/plots';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import type { BasePlotProps } from '../types';
|
|
2
|
+
import type { BasePlotProps, Style, Theme } from '../types';
|
|
4
3
|
type AreaDataItem = {
|
|
5
4
|
time: string | number;
|
|
6
5
|
value: number;
|
|
7
6
|
[key: string]: string | number;
|
|
8
7
|
};
|
|
9
|
-
export type AreaProps = BasePlotProps<AreaDataItem> &
|
|
8
|
+
export type AreaProps = BasePlotProps<AreaDataItem> & Theme & Style;
|
|
10
9
|
declare const Area: (props: AreaProps) => React.JSX.Element;
|
|
11
10
|
export default Area;
|
package/dist/cjs/Area/index.js
CHANGED
|
@@ -36,27 +36,70 @@ var import_plots = require("@ant-design/plots");
|
|
|
36
36
|
var import_lodash = require("lodash");
|
|
37
37
|
var import_react = __toESM(require("react"));
|
|
38
38
|
var import_hooks = require("../ConfigProvider/hooks");
|
|
39
|
+
var import_theme = require("../theme");
|
|
40
|
+
var getLinearGradientColor = (color) => `linear-gradient(-90deg, white 0%, ${color} 100%)`;
|
|
41
|
+
var DEFAULT_COLOR = "#3A95FF";
|
|
39
42
|
var defaultConfig = (props) => {
|
|
40
|
-
const { data, xField = "time", yField = "value" } = props;
|
|
43
|
+
const { data, xField = "time", yField = "value", style = {} } = props;
|
|
44
|
+
const { backgroundColor, palette, lineWidth = 2 } = style;
|
|
41
45
|
const hasGroupField = (0, import_lodash.get)(data, "[0].group") !== void 0;
|
|
42
46
|
const axisYTitle = (0, import_lodash.get)(props, "axis.y.title");
|
|
43
|
-
const
|
|
47
|
+
const fillColor = getLinearGradientColor((palette == null ? void 0 : palette[0]) || DEFAULT_COLOR);
|
|
48
|
+
const defaultStyle = hasGroupField ? { opacity: 0.6 } : { opacity: 0.6, fill: fillColor };
|
|
49
|
+
let paletteConfig = { color: void 0 };
|
|
50
|
+
let encode = {};
|
|
51
|
+
const hasPalette = !!(palette == null ? void 0 : palette[0]);
|
|
52
|
+
if (hasPalette) {
|
|
53
|
+
paletteConfig = {
|
|
54
|
+
color: {
|
|
55
|
+
range: palette
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (hasGroupField) {
|
|
60
|
+
encode = { x: xField, y: yField, color: "group" };
|
|
61
|
+
} else {
|
|
62
|
+
encode = { x: xField, y: yField, color: () => "all" };
|
|
63
|
+
}
|
|
44
64
|
return {
|
|
45
65
|
xField,
|
|
46
66
|
yField,
|
|
47
|
-
style:
|
|
67
|
+
style: defaultStyle,
|
|
48
68
|
colorField: hasGroupField ? "group" : void 0,
|
|
69
|
+
stack: hasGroupField,
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
encode,
|
|
72
|
+
legend: hasGroupField ? {} : false,
|
|
49
73
|
tooltip: (d) => {
|
|
50
74
|
const tooltipName = axisYTitle || d[xField];
|
|
51
75
|
return {
|
|
52
76
|
name: tooltipName,
|
|
53
77
|
value: d[yField]
|
|
54
78
|
};
|
|
55
|
-
}
|
|
79
|
+
},
|
|
80
|
+
scale: {
|
|
81
|
+
y: {
|
|
82
|
+
nice: true
|
|
83
|
+
},
|
|
84
|
+
...paletteConfig
|
|
85
|
+
},
|
|
86
|
+
line: {
|
|
87
|
+
encode,
|
|
88
|
+
style: {
|
|
89
|
+
lineWidth,
|
|
90
|
+
strokeOpacity: 0.6
|
|
91
|
+
},
|
|
92
|
+
...paletteConfig
|
|
93
|
+
},
|
|
94
|
+
...backgroundColor ? { viewStyle: { viewFill: backgroundColor } } : { viewStyle: void 0 }
|
|
56
95
|
};
|
|
57
96
|
};
|
|
58
97
|
var Area = (props) => {
|
|
59
|
-
const
|
|
98
|
+
const themeConfig = import_theme.THEME_MAP[props.theme ?? "default"];
|
|
99
|
+
const config = (0, import_hooks.usePlotConfig)("Area", defaultConfig, {
|
|
100
|
+
...props,
|
|
101
|
+
theme: themeConfig
|
|
102
|
+
});
|
|
60
103
|
return /* @__PURE__ */ import_react.default.createElement(import_plots.Area, { ...config });
|
|
61
104
|
};
|
|
62
105
|
var Area_default = Area;
|
package/dist/cjs/Bar/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { BarConfig } from '@ant-design/plots';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import type { BasePlotProps } from '../types';
|
|
3
|
+
import type { BasePlotProps, Style, Theme } from '../types';
|
|
4
4
|
type BarDataItem = {
|
|
5
5
|
category: string;
|
|
6
6
|
value: number;
|
|
7
7
|
[key: string]: string | number;
|
|
8
8
|
};
|
|
9
|
-
export type BarProps = BasePlotProps<BarDataItem> & Partial<BarConfig
|
|
9
|
+
export type BarProps = BasePlotProps<BarDataItem> & Partial<BarConfig> & Theme & Style;
|
|
10
10
|
declare const Bar: (props: BarProps) => React.JSX.Element;
|
|
11
11
|
export default Bar;
|
package/dist/cjs/Bar/index.js
CHANGED
|
@@ -36,14 +36,35 @@ var import_plots = require("@ant-design/plots");
|
|
|
36
36
|
var import_lodash = require("lodash");
|
|
37
37
|
var import_react = __toESM(require("react"));
|
|
38
38
|
var import_hooks = require("../ConfigProvider/hooks");
|
|
39
|
+
var import_theme = require("../theme");
|
|
39
40
|
var defaultConfig = (props) => {
|
|
40
|
-
const { data, xField = "category", yField = "value" } = props;
|
|
41
|
+
const { data, xField = "category", yField = "value", style = {}, theme = {} } = props;
|
|
42
|
+
const { backgroundColor, palette } = style;
|
|
41
43
|
const hasGroupField = (0, import_lodash.get)(data, "[0].group") !== void 0;
|
|
42
44
|
const axisYTitle = (0, import_lodash.get)(props, "axis.y.title");
|
|
45
|
+
const hasPalette = !!(palette == null ? void 0 : palette[0]);
|
|
46
|
+
let paletteConfig = { color: void 0 };
|
|
47
|
+
let radiusStyle = {
|
|
48
|
+
radiusTopLeft: 4,
|
|
49
|
+
radiusTopRight: 4
|
|
50
|
+
};
|
|
51
|
+
if ((theme == null ? void 0 : theme.type) === "academy") {
|
|
52
|
+
radiusStyle = {
|
|
53
|
+
radiusTopLeft: 0,
|
|
54
|
+
radiusTopRight: 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (hasPalette) {
|
|
58
|
+
paletteConfig = {
|
|
59
|
+
color: {
|
|
60
|
+
range: palette
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
43
64
|
return {
|
|
44
65
|
xField,
|
|
45
66
|
yField,
|
|
46
|
-
colorField: hasGroupField ? "group" :
|
|
67
|
+
colorField: hasGroupField ? "group" : xField,
|
|
47
68
|
tooltip: (d) => {
|
|
48
69
|
const tooltipName = axisYTitle || d[xField];
|
|
49
70
|
return {
|
|
@@ -52,14 +73,24 @@ var defaultConfig = (props) => {
|
|
|
52
73
|
};
|
|
53
74
|
},
|
|
54
75
|
style: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
...radiusStyle,
|
|
77
|
+
columnWidthRatio: 0.8
|
|
78
|
+
},
|
|
79
|
+
scale: {
|
|
80
|
+
y: {
|
|
81
|
+
nice: true
|
|
82
|
+
},
|
|
83
|
+
...paletteConfig
|
|
84
|
+
},
|
|
85
|
+
...backgroundColor ? { viewStyle: { viewFill: backgroundColor } } : { viewStyle: void 0 }
|
|
59
86
|
};
|
|
60
87
|
};
|
|
61
88
|
var Bar = (props) => {
|
|
62
|
-
const
|
|
89
|
+
const themeConfig = import_theme.THEME_MAP[props.theme ?? "default"];
|
|
90
|
+
const config = (0, import_hooks.usePlotConfig)("Bar", defaultConfig, {
|
|
91
|
+
...props,
|
|
92
|
+
theme: themeConfig
|
|
93
|
+
});
|
|
63
94
|
return /* @__PURE__ */ import_react.default.createElement(import_plots.Bar, { ...config });
|
|
64
95
|
};
|
|
65
96
|
var Bar_default = Bar;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { ChartComponents, ComponentErrorRender, ErrorRender } from './type';
|
|
2
|
+
import type { ChartComponents, ComponentErrorRender, ErrorRender, TextLabels } from './type';
|
|
3
3
|
type RenderVisChartProps = {
|
|
4
4
|
content: string;
|
|
5
5
|
components: ChartComponents;
|
|
@@ -8,6 +8,12 @@ type RenderVisChartProps = {
|
|
|
8
8
|
style?: React.CSSProperties;
|
|
9
9
|
componentErrorRender?: (errorInfo: ComponentErrorRender) => React.ReactElement;
|
|
10
10
|
errorRender?: (errorInfo: ErrorRender) => React.ReactElement;
|
|
11
|
+
showTabs?: boolean;
|
|
12
|
+
showCodeTab?: boolean;
|
|
13
|
+
showChartTab?: boolean;
|
|
14
|
+
defaultTab?: 'chart' | 'code';
|
|
15
|
+
textLabels?: TextLabels;
|
|
16
|
+
locale?: string;
|
|
11
17
|
};
|
|
12
18
|
export declare const RenderVisChart: React.FC<RenderVisChartProps>;
|
|
13
19
|
export {};
|
|
@@ -51,16 +51,77 @@ var G6List = [
|
|
|
51
51
|
"network-graph",
|
|
52
52
|
"indented-tree"
|
|
53
53
|
];
|
|
54
|
+
var DEFAULT_LABELS = {
|
|
55
|
+
"zh-CN": {
|
|
56
|
+
chartTab: "图表",
|
|
57
|
+
codeTab: "代码",
|
|
58
|
+
download: "下载",
|
|
59
|
+
copy: "复制",
|
|
60
|
+
copied: "完成",
|
|
61
|
+
renderError: "图表渲染失败",
|
|
62
|
+
parseError: "GPT-Vis parse content error!",
|
|
63
|
+
unsupportedChart: "Chart type not supported"
|
|
64
|
+
},
|
|
65
|
+
"en-US": {
|
|
66
|
+
chartTab: "Chart",
|
|
67
|
+
codeTab: "Code",
|
|
68
|
+
download: "Download",
|
|
69
|
+
copy: "Copy",
|
|
70
|
+
copied: "Copied",
|
|
71
|
+
renderError: "Chart render failed",
|
|
72
|
+
parseError: "Parse content error!",
|
|
73
|
+
unsupportedChart: "Chart type not supported"
|
|
74
|
+
},
|
|
75
|
+
"pt-BR": {
|
|
76
|
+
chartTab: "Gráfico",
|
|
77
|
+
codeTab: "Código",
|
|
78
|
+
download: "Baixar",
|
|
79
|
+
copy: "Copiar",
|
|
80
|
+
copied: "Copiado",
|
|
81
|
+
renderError: "Erro ao renderizar gráfico",
|
|
82
|
+
parseError: "Erro ao analisar conteúdo!",
|
|
83
|
+
unsupportedChart: "Tipo de gráfico não suportado"
|
|
84
|
+
}
|
|
85
|
+
};
|
|
54
86
|
var RenderVisChart = (0, import_react.memo)(
|
|
55
|
-
({
|
|
87
|
+
({
|
|
88
|
+
style,
|
|
89
|
+
content,
|
|
90
|
+
components,
|
|
91
|
+
debug = false,
|
|
92
|
+
loadingTimeout,
|
|
93
|
+
componentErrorRender,
|
|
94
|
+
errorRender,
|
|
95
|
+
showTabs = true,
|
|
96
|
+
showCodeTab = true,
|
|
97
|
+
showChartTab = true,
|
|
98
|
+
defaultTab = "chart",
|
|
99
|
+
textLabels = {},
|
|
100
|
+
locale = "zh-CN"
|
|
101
|
+
}) => {
|
|
56
102
|
const timeoutRef = (0, import_react.useRef)();
|
|
57
103
|
const copyTimeoutRef = (0, import_react.useRef)();
|
|
58
104
|
const [loading, setLoading] = (0, import_react.useState)(true);
|
|
59
|
-
const [activeTab, setActiveTab] = (0, import_react.useState)("chart");
|
|
60
105
|
const [hasRenderError, setHasRenderError] = (0, import_react.useState)(false);
|
|
61
106
|
const [copied, setCopied] = (0, import_react.useState)(false);
|
|
62
107
|
const chartRef = (0, import_react.useRef)(null);
|
|
63
108
|
const chartContainerRef = (0, import_react.useRef)(null);
|
|
109
|
+
const labels = {
|
|
110
|
+
...DEFAULT_LABELS[locale] || DEFAULT_LABELS["en-US"],
|
|
111
|
+
...textLabels
|
|
112
|
+
};
|
|
113
|
+
const getValidDefaultTab = () => {
|
|
114
|
+
if (defaultTab === "chart" && showChartTab)
|
|
115
|
+
return "chart";
|
|
116
|
+
if (defaultTab === "code" && showCodeTab)
|
|
117
|
+
return "code";
|
|
118
|
+
if (showChartTab)
|
|
119
|
+
return "chart";
|
|
120
|
+
if (showCodeTab)
|
|
121
|
+
return "code";
|
|
122
|
+
return "chart";
|
|
123
|
+
};
|
|
124
|
+
const [activeTab, setActiveTab] = (0, import_react.useState)(getValidDefaultTab());
|
|
64
125
|
let chartJson;
|
|
65
126
|
try {
|
|
66
127
|
chartJson = JSON.parse(content);
|
|
@@ -84,7 +145,7 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
84
145
|
content
|
|
85
146
|
});
|
|
86
147
|
}
|
|
87
|
-
return /* @__PURE__ */ import_react.default.createElement("div", null,
|
|
148
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, labels.parseError);
|
|
88
149
|
}
|
|
89
150
|
const { type, ...chartProps } = chartJson;
|
|
90
151
|
const ChartComponent = components[type];
|
|
@@ -92,20 +153,22 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
92
153
|
console.log("GPT-Vis withChartCode get chartJson parse from vis-chart code block", chartJson);
|
|
93
154
|
}
|
|
94
155
|
if (!ChartComponent) {
|
|
95
|
-
const message =
|
|
156
|
+
const message = `${labels.unsupportedChart}: "${type}"`;
|
|
96
157
|
if (errorRender) {
|
|
97
158
|
return errorRender({
|
|
98
159
|
error: new Error(message),
|
|
99
160
|
content
|
|
100
161
|
});
|
|
101
162
|
}
|
|
102
|
-
return /* @__PURE__ */ import_react.default.createElement("div", null,
|
|
163
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, message);
|
|
103
164
|
}
|
|
104
165
|
const FallbackComponent = (fallbackProps) => {
|
|
105
166
|
const { error } = fallbackProps;
|
|
106
167
|
if (!hasRenderError) {
|
|
107
168
|
setHasRenderError(true);
|
|
108
|
-
|
|
169
|
+
if (showCodeTab && showTabs) {
|
|
170
|
+
setActiveTab("code");
|
|
171
|
+
}
|
|
109
172
|
}
|
|
110
173
|
if (componentErrorRender) {
|
|
111
174
|
return componentErrorRender({
|
|
@@ -113,7 +176,7 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
113
176
|
content
|
|
114
177
|
});
|
|
115
178
|
}
|
|
116
|
-
return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_styles.ErrorMessage, null,
|
|
179
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(import_styles.ErrorMessage, null, labels.renderError));
|
|
117
180
|
};
|
|
118
181
|
const handleCopy = async () => {
|
|
119
182
|
try {
|
|
@@ -126,7 +189,7 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
126
189
|
setCopied(false);
|
|
127
190
|
}, 1e3);
|
|
128
191
|
} catch (error) {
|
|
129
|
-
console.error("
|
|
192
|
+
console.error("Copy failed:", error);
|
|
130
193
|
}
|
|
131
194
|
};
|
|
132
195
|
const handleDownload = async () => {
|
|
@@ -139,7 +202,7 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
139
202
|
});
|
|
140
203
|
}
|
|
141
204
|
} catch (error) {
|
|
142
|
-
console.error("
|
|
205
|
+
console.error("Download image failed:", error);
|
|
143
206
|
}
|
|
144
207
|
};
|
|
145
208
|
const isG6 = G6List.includes(type);
|
|
@@ -157,7 +220,30 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
157
220
|
chartRef.current.zoomTo(newZoom);
|
|
158
221
|
}
|
|
159
222
|
};
|
|
160
|
-
|
|
223
|
+
if (!showTabs) {
|
|
224
|
+
return /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", style }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
|
|
225
|
+
import_react_error_boundary.ErrorBoundary,
|
|
226
|
+
{
|
|
227
|
+
FallbackComponent,
|
|
228
|
+
onError: (error, errorInfo) => {
|
|
229
|
+
console.error("GPT-Vis Render error:", error);
|
|
230
|
+
if (debug) {
|
|
231
|
+
console.error("GPT-Vis Render error info:", errorInfo);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
236
|
+
ChartComponent,
|
|
237
|
+
{
|
|
238
|
+
...chartProps,
|
|
239
|
+
onReady: (chart) => {
|
|
240
|
+
chartRef.current = chart;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
)));
|
|
245
|
+
}
|
|
246
|
+
return /* @__PURE__ */ import_react.default.createElement(import_styles.TabContainer, { style }, /* @__PURE__ */ import_react.default.createElement(import_styles.TabHeader, null, /* @__PURE__ */ import_react.default.createElement(import_styles.TabLeftGroup, null, showChartTab && /* @__PURE__ */ import_react.default.createElement(import_styles.StyledTabButton, { active: activeTab === "chart", onClick: () => setActiveTab("chart") }, labels.chartTab), showCodeTab && /* @__PURE__ */ import_react.default.createElement(import_styles.StyledTabButton, { active: activeTab === "code", onClick: () => setActiveTab("code") }, labels.codeTab)), /* @__PURE__ */ import_react.default.createElement(import_styles.TabRightGroup, null, activeTab === "chart" ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, isG6 && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
|
|
161
247
|
import_styles.TextButton,
|
|
162
248
|
{
|
|
163
249
|
onClick: handleZoomIn,
|
|
@@ -171,7 +257,7 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
171
257
|
style: { width: "24px", height: "24px", padding: 0 }
|
|
172
258
|
},
|
|
173
259
|
/* @__PURE__ */ import_react.default.createElement(import_icon.ZoomOut, { size: 18 })
|
|
174
|
-
), /* @__PURE__ */ import_react.default.createElement(import_styles.Divider, null)), /* @__PURE__ */ import_react.default.createElement(import_styles.TextButton, { onClick: handleDownload }, /* @__PURE__ */ import_react.default.createElement(import_icon.DownLoad, { size: 16 }),
|
|
260
|
+
), /* @__PURE__ */ import_react.default.createElement(import_styles.Divider, null)), /* @__PURE__ */ import_react.default.createElement(import_styles.TextButton, { onClick: handleDownload }, /* @__PURE__ */ import_react.default.createElement(import_icon.DownLoad, { size: 16 }), labels.download)) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_styles.TextButton, { onClick: handleCopy }, copied ? /* @__PURE__ */ import_react.default.createElement(import_icon.Check, null) : /* @__PURE__ */ import_react.default.createElement(import_icon.Copy, null), copied ? labels.copied : labels.copy)))), /* @__PURE__ */ import_react.default.createElement(import_styles.TabContent, null, activeTab === "chart" ? /* @__PURE__ */ import_react.default.createElement(
|
|
175
261
|
import_react_error_boundary.ErrorBoundary,
|
|
176
262
|
{
|
|
177
263
|
FallbackComponent,
|
|
@@ -179,7 +265,9 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
179
265
|
console.error("GPT-Vis Render error:", error);
|
|
180
266
|
if (!hasRenderError) {
|
|
181
267
|
setHasRenderError(true);
|
|
182
|
-
|
|
268
|
+
if (showCodeTab) {
|
|
269
|
+
setActiveTab("code");
|
|
270
|
+
}
|
|
183
271
|
}
|
|
184
272
|
if (debug) {
|
|
185
273
|
console.error("GPT-Vis Render error info:", errorInfo);
|
|
@@ -55,7 +55,15 @@ var withCodeBlock = (options) => {
|
|
|
55
55
|
loadingTimeout = 5e3,
|
|
56
56
|
style,
|
|
57
57
|
errorRender,
|
|
58
|
-
componentErrorRender
|
|
58
|
+
componentErrorRender,
|
|
59
|
+
// New options for tab control
|
|
60
|
+
showTabs,
|
|
61
|
+
showCodeTab,
|
|
62
|
+
showChartTab,
|
|
63
|
+
defaultTab,
|
|
64
|
+
// New options for text customization
|
|
65
|
+
textLabels,
|
|
66
|
+
locale
|
|
59
67
|
} = options;
|
|
60
68
|
if (isVisChart) {
|
|
61
69
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
@@ -67,7 +75,13 @@ var withCodeBlock = (options) => {
|
|
|
67
75
|
debug,
|
|
68
76
|
loadingTimeout,
|
|
69
77
|
errorRender,
|
|
70
|
-
componentErrorRender
|
|
78
|
+
componentErrorRender,
|
|
79
|
+
showTabs,
|
|
80
|
+
showCodeTab,
|
|
81
|
+
showChartTab,
|
|
82
|
+
defaultTab,
|
|
83
|
+
textLabels,
|
|
84
|
+
locale
|
|
71
85
|
}
|
|
72
86
|
);
|
|
73
87
|
}
|
|
@@ -1,73 +1,172 @@
|
|
|
1
1
|
import type { FC } from 'react';
|
|
2
2
|
import type { Components, ExtraProps } from 'react-markdown';
|
|
3
3
|
/**
|
|
4
|
+
* Text labels type for internationalization
|
|
5
|
+
* 文本标签类型 - 用于国际化
|
|
6
|
+
*/
|
|
7
|
+
export type TextLabels = {
|
|
8
|
+
chartTab?: string;
|
|
9
|
+
codeTab?: string;
|
|
10
|
+
download?: string;
|
|
11
|
+
copy?: string;
|
|
12
|
+
copied?: string;
|
|
13
|
+
renderError?: string;
|
|
14
|
+
parseError?: string;
|
|
15
|
+
unsupportedChart?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Chart enhancement options - contains all new feature configurations
|
|
19
|
+
* 图表增强选项 - 包含所有新增的功能配置
|
|
20
|
+
*/
|
|
21
|
+
export type ChartEnhancementOptions = {
|
|
22
|
+
/**
|
|
23
|
+
* Controls whether tabs are displayed (default: true)
|
|
24
|
+
* 控制是否显示标签页 (默认: true)
|
|
25
|
+
*/
|
|
26
|
+
showTabs?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Controls whether code tab is shown (default: true)
|
|
29
|
+
* 控制是否显示代码标签页 (默认: true)
|
|
30
|
+
*/
|
|
31
|
+
showCodeTab?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Controls whether chart tab is shown (default: true)
|
|
34
|
+
* 控制是否显示图表标签页 (默认: true)
|
|
35
|
+
*/
|
|
36
|
+
showChartTab?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Default active tab (default: 'chart')
|
|
39
|
+
* 默认激活的标签页 (默认: 'chart')
|
|
40
|
+
*/
|
|
41
|
+
defaultTab?: 'chart' | 'code';
|
|
42
|
+
/**
|
|
43
|
+
* Custom text labels
|
|
44
|
+
* 自定义文本标签
|
|
45
|
+
*/
|
|
46
|
+
textLabels?: TextLabels;
|
|
47
|
+
/**
|
|
48
|
+
* Locale setting for default text labels (default: 'zh-CN')
|
|
49
|
+
* Supports: 'zh-CN' | 'en-US' | 'pt-BR'
|
|
50
|
+
* 语言区域设置,用于默认文本标签 (默认: 'zh-CN')
|
|
51
|
+
* 支持: 'zh-CN' | 'en-US' | 'pt-BR'
|
|
52
|
+
*/
|
|
53
|
+
locale?: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Error render function type
|
|
4
57
|
* 错误渲染函数类型
|
|
5
58
|
*/
|
|
6
59
|
export type ErrorRender = {
|
|
7
|
-
/** 错误对象 */
|
|
60
|
+
/** Error object | 错误对象 */
|
|
8
61
|
error?: Error;
|
|
9
|
-
/** 原始内容 */
|
|
62
|
+
/** Original content | 原始内容 */
|
|
10
63
|
content: string;
|
|
11
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Component error render type
|
|
67
|
+
* 组件错误渲染类型
|
|
68
|
+
*/
|
|
12
69
|
export type ComponentErrorRender = {
|
|
13
|
-
/** 错误对象 */
|
|
70
|
+
/** Error object | 错误对象 */
|
|
14
71
|
error?: Error;
|
|
15
|
-
/** 原始内容 */
|
|
72
|
+
/** Original content | 原始内容 */
|
|
16
73
|
content: string;
|
|
17
74
|
};
|
|
75
|
+
/**
|
|
76
|
+
* Options for withChartCode HOC
|
|
77
|
+
* withChartCode 高阶组件选项
|
|
78
|
+
*/
|
|
18
79
|
export type WithChartCodeOptions = {
|
|
19
80
|
/**
|
|
81
|
+
* Additional chart components to load
|
|
20
82
|
* 要额外加载的图表组件
|
|
21
83
|
*/
|
|
22
84
|
components: ChartComponents;
|
|
23
85
|
/**
|
|
86
|
+
* Custom renderers for other language code blocks
|
|
24
87
|
* 自定义其它语言代码块渲染器
|
|
25
88
|
*/
|
|
26
89
|
languageRenderers?: LanguageRenderers;
|
|
27
90
|
/**
|
|
91
|
+
* Default code renderer
|
|
28
92
|
* 默认的代码渲染器
|
|
29
93
|
*/
|
|
30
94
|
defaultRenderer?: CodeRenderer;
|
|
31
95
|
/**
|
|
96
|
+
* Enable debug logging
|
|
32
97
|
* 打开调试日志
|
|
33
98
|
*/
|
|
34
99
|
debug?: boolean;
|
|
35
100
|
/**
|
|
101
|
+
* Loading animation timeout, default 5s
|
|
36
102
|
* 设置loading动画的超时时间,默认为 5s
|
|
37
103
|
*/
|
|
38
104
|
loadingTimeout?: number;
|
|
39
105
|
/**
|
|
106
|
+
* Chart styles, configure container styles
|
|
40
107
|
* 图表样式,配置容器样式
|
|
41
108
|
*/
|
|
42
109
|
style?: React.CSSProperties;
|
|
43
110
|
/**
|
|
111
|
+
* Custom component error render function
|
|
44
112
|
* 自定义组件错误渲染函数
|
|
45
113
|
*/
|
|
46
114
|
componentErrorRender?: (errorInfo: ComponentErrorRender) => React.ReactElement;
|
|
47
115
|
/**
|
|
116
|
+
* Custom error render function
|
|
48
117
|
* 自定义错误渲染函数
|
|
49
118
|
*/
|
|
50
119
|
errorRender?: (errorInfo: ErrorRender) => React.ReactElement;
|
|
51
|
-
};
|
|
120
|
+
} & ChartEnhancementOptions;
|
|
121
|
+
/**
|
|
122
|
+
* RenderVisChart component props type
|
|
123
|
+
* RenderVisChart 组件属性类型
|
|
124
|
+
*/
|
|
125
|
+
export type RenderVisChartProps = {
|
|
126
|
+
/** Chart content string | 图表内容字符串 */
|
|
127
|
+
content: string;
|
|
128
|
+
/** Chart components dictionary | 图表组件字典 */
|
|
129
|
+
components: ChartComponents;
|
|
130
|
+
/** Enable debug mode | 启用调试模式 */
|
|
131
|
+
debug?: boolean;
|
|
132
|
+
/** Loading timeout in milliseconds | 加载超时时间(毫秒) */
|
|
133
|
+
loadingTimeout: number;
|
|
134
|
+
/** Container styles | 容器样式 */
|
|
135
|
+
style?: React.CSSProperties;
|
|
136
|
+
/** Custom component error renderer | 自定义组件错误渲染器 */
|
|
137
|
+
componentErrorRender?: (errorInfo: ComponentErrorRender) => React.ReactElement;
|
|
138
|
+
/** Custom error renderer | 自定义错误渲染器 */
|
|
139
|
+
errorRender?: (errorInfo: ErrorRender) => React.ReactElement;
|
|
140
|
+
} & ChartEnhancementOptions;
|
|
52
141
|
/**
|
|
142
|
+
* Chart render data interface, for future extension, this is just an example
|
|
53
143
|
* 图表渲染数据接口,后续拓展,这里只是写个示例
|
|
54
144
|
*/
|
|
55
145
|
export interface ChartJson {
|
|
146
|
+
/** Chart type | 图表类型 */
|
|
56
147
|
type: string;
|
|
148
|
+
/** Chart data | 图表数据 */
|
|
57
149
|
data: any;
|
|
58
150
|
}
|
|
59
151
|
/**
|
|
152
|
+
* Chart components dictionary
|
|
60
153
|
* 图表组件字典
|
|
61
154
|
*/
|
|
62
155
|
export interface ChartComponents {
|
|
63
156
|
[key: string]: FC<any>;
|
|
64
157
|
}
|
|
65
158
|
/**
|
|
159
|
+
* Code block renderer interface
|
|
66
160
|
* 代码块渲染器接口
|
|
67
161
|
*/
|
|
68
162
|
export type CodeBlockComponent = Components['code'];
|
|
163
|
+
/**
|
|
164
|
+
* Code renderer type
|
|
165
|
+
* 代码渲染器类型
|
|
166
|
+
*/
|
|
69
167
|
type CodeRenderer = FC<React.ClassAttributes<HTMLElement> & React.HTMLAttributes<HTMLElement> & ExtraProps>;
|
|
70
168
|
/**
|
|
169
|
+
* Custom renderers for other language code blocks
|
|
71
170
|
* 自定义其它语言代码块渲染器
|
|
72
171
|
*/
|
|
73
172
|
interface LanguageRenderers {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { ColumnConfig } from '@ant-design/plots';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import type { BasePlotProps } from '../types';
|
|
2
|
+
import type { BasePlotProps, Style, Theme } from '../types';
|
|
4
3
|
export type ColumnDataItem = {
|
|
5
4
|
category: string | number;
|
|
6
5
|
value: number;
|
|
7
6
|
[key: string]: string | number;
|
|
8
7
|
};
|
|
9
|
-
export type ColumnProps = BasePlotProps<ColumnDataItem> &
|
|
8
|
+
export type ColumnProps = BasePlotProps<ColumnDataItem> & Theme & Style;
|
|
10
9
|
declare const Column: (props: ColumnProps) => React.JSX.Element;
|
|
11
10
|
export default Column;
|
package/dist/cjs/Column/index.js
CHANGED
|
@@ -36,14 +36,35 @@ var import_plots = require("@ant-design/plots");
|
|
|
36
36
|
var import_lodash = require("lodash");
|
|
37
37
|
var import_react = __toESM(require("react"));
|
|
38
38
|
var import_hooks = require("../ConfigProvider/hooks");
|
|
39
|
+
var import_theme = require("../theme");
|
|
39
40
|
var defaultConfig = (props) => {
|
|
40
|
-
const { data, xField = "category", yField = "value" } = props;
|
|
41
|
+
const { data, xField = "category", yField = "value", style = {}, theme = {} } = props;
|
|
42
|
+
const { backgroundColor, palette } = style;
|
|
41
43
|
const hasGroupField = (0, import_lodash.get)(data, "[0].group") !== void 0;
|
|
44
|
+
const hasPalette = !!(palette == null ? void 0 : palette[0]);
|
|
42
45
|
const axisYTitle = (0, import_lodash.get)(props, "axis.y.title");
|
|
46
|
+
let paletteConfig = { color: void 0 };
|
|
47
|
+
let radiusStyle = {
|
|
48
|
+
radiusTopLeft: 4,
|
|
49
|
+
radiusTopRight: 4
|
|
50
|
+
};
|
|
51
|
+
if ((theme == null ? void 0 : theme.type) === "academy") {
|
|
52
|
+
radiusStyle = {
|
|
53
|
+
radiusTopLeft: 0,
|
|
54
|
+
radiusTopRight: 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
if (hasPalette) {
|
|
58
|
+
paletteConfig = {
|
|
59
|
+
color: {
|
|
60
|
+
range: palette
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
43
64
|
return {
|
|
44
65
|
xField,
|
|
45
66
|
yField,
|
|
46
|
-
colorField: hasGroupField ? "group" :
|
|
67
|
+
colorField: hasGroupField ? "group" : xField,
|
|
47
68
|
tooltip: (d) => {
|
|
48
69
|
const tooltipName = axisYTitle || d[xField];
|
|
49
70
|
return {
|
|
@@ -52,14 +73,24 @@ var defaultConfig = (props) => {
|
|
|
52
73
|
};
|
|
53
74
|
},
|
|
54
75
|
style: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
...radiusStyle,
|
|
77
|
+
columnWidthRatio: 0.8
|
|
78
|
+
},
|
|
79
|
+
scale: {
|
|
80
|
+
y: {
|
|
81
|
+
nice: true
|
|
82
|
+
},
|
|
83
|
+
...paletteConfig
|
|
84
|
+
},
|
|
85
|
+
...backgroundColor ? { viewStyle: { viewFill: backgroundColor } } : { viewStyle: void 0 }
|
|
59
86
|
};
|
|
60
87
|
};
|
|
61
88
|
var Column = (props) => {
|
|
62
|
-
const
|
|
89
|
+
const themeConfig = import_theme.THEME_MAP[props.theme ?? "default"];
|
|
90
|
+
const config = (0, import_hooks.usePlotConfig)("Column", defaultConfig, {
|
|
91
|
+
...props,
|
|
92
|
+
theme: themeConfig
|
|
93
|
+
});
|
|
63
94
|
return /* @__PURE__ */ import_react.default.createElement(import_plots.Column, { ...config });
|
|
64
95
|
};
|
|
65
96
|
var Column_default = Column;
|