@antv/gpt-vis 0.5.14 → 0.6.1
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/Bar/index.js +1 -1
- package/dist/cjs/ChartCodeRender/VisChart.js +34 -31
- package/dist/cjs/ChartCodeRender/styles.js +1 -1
- package/dist/cjs/Column/index.js +1 -1
- package/dist/cjs/Spreadsheet/index.d.ts +28 -0
- package/dist/cjs/Spreadsheet/index.js +113 -0
- package/dist/cjs/export.d.ts +3 -1
- package/dist/cjs/export.js +3 -0
- package/dist/cjs/types/chart.d.ts +1 -0
- package/dist/cjs/types/chart.js +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Bar/index.js +1 -1
- package/dist/esm/ChartCodeRender/VisChart.js +54 -49
- package/dist/esm/ChartCodeRender/styles.js +1 -1
- package/dist/esm/Column/index.js +1 -1
- package/dist/esm/Spreadsheet/index.d.ts +28 -0
- package/dist/esm/Spreadsheet/index.js +129 -0
- package/dist/esm/export.d.ts +3 -1
- package/dist/esm/export.js +2 -1
- package/dist/esm/types/chart.d.ts +1 -0
- package/dist/esm/types/chart.js +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/376.async.js +1 -0
- package/dist/umd/index.min.css +1 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +4 -2
- package/dist/umd/436.async.js +0 -1
package/dist/cjs/Bar/index.js
CHANGED
|
@@ -66,7 +66,7 @@ var defaultConfig = (props) => {
|
|
|
66
66
|
yField,
|
|
67
67
|
colorField: hasGroupField ? "group" : xField,
|
|
68
68
|
tooltip: (d) => {
|
|
69
|
-
const tooltipName = axisYTitle || d[xField];
|
|
69
|
+
const tooltipName = hasGroupField ? d["group"] : axisYTitle || d[xField];
|
|
70
70
|
return {
|
|
71
71
|
name: tooltipName,
|
|
72
72
|
value: d[yField]
|
|
@@ -127,11 +127,38 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
127
127
|
return "chart";
|
|
128
128
|
};
|
|
129
129
|
const [activeTab, setActiveTab] = (0, import_react.useState)(getValidDefaultTab());
|
|
130
|
-
let chartJson;
|
|
130
|
+
let chartJson = null;
|
|
131
|
+
let parseError = null;
|
|
132
|
+
let type;
|
|
131
133
|
try {
|
|
132
134
|
chartJson = JSON.parse(content);
|
|
135
|
+
type = chartJson == null ? void 0 : chartJson.type;
|
|
133
136
|
} catch (e) {
|
|
134
|
-
|
|
137
|
+
parseError = e;
|
|
138
|
+
}
|
|
139
|
+
const isG6 = type ? G6List.includes(type) : false;
|
|
140
|
+
const handleResize = (0, import_react.useMemo)(() => {
|
|
141
|
+
const debouncedFn = (0, import_lodash.debounce)(() => {
|
|
142
|
+
var _a, _b, _c;
|
|
143
|
+
const chart = chartRef.current;
|
|
144
|
+
const container = chartContainerRef.current;
|
|
145
|
+
if (!chart || !container || !(container instanceof HTMLElement)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
if (isG6) {
|
|
150
|
+
(_a = chart.resize) == null ? void 0 : _a.call(chart);
|
|
151
|
+
(_b = chart.autoFit) == null ? void 0 : _b.call(chart);
|
|
152
|
+
} else {
|
|
153
|
+
(_c = chart.changeSize) == null ? void 0 : _c.call(chart);
|
|
154
|
+
}
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error("Failed to resize chart:", error);
|
|
157
|
+
}
|
|
158
|
+
}, 150);
|
|
159
|
+
return debouncedFn;
|
|
160
|
+
}, [isG6]);
|
|
161
|
+
if (parseError) {
|
|
135
162
|
if (timeoutRef.current) {
|
|
136
163
|
clearTimeout(timeoutRef.current);
|
|
137
164
|
if (debug) {
|
|
@@ -152,13 +179,13 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
152
179
|
}
|
|
153
180
|
return /* @__PURE__ */ import_react.default.createElement("div", null, labels.parseError);
|
|
154
181
|
}
|
|
155
|
-
const { type, ...chartProps } = chartJson;
|
|
156
|
-
const ChartComponent = components[
|
|
182
|
+
const { type: chartType, ...chartProps } = chartJson;
|
|
183
|
+
const ChartComponent = components[chartType];
|
|
157
184
|
if (debug) {
|
|
158
185
|
console.log("GPT-Vis withChartCode get chartJson parse from vis-chart code block", chartJson);
|
|
159
186
|
}
|
|
160
187
|
if (!ChartComponent) {
|
|
161
|
-
const message = `${labels.unsupportedChart}: "${
|
|
188
|
+
const message = `${labels.unsupportedChart}: "${chartType}"`;
|
|
162
189
|
if (errorRender) {
|
|
163
190
|
return errorRender({
|
|
164
191
|
error: new Error(message),
|
|
@@ -202,14 +229,13 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
202
229
|
const result = await (0, import_snapdom.snapdom)(chartContainerRef.current, { scale: 2 });
|
|
203
230
|
await result.download({
|
|
204
231
|
format: "png",
|
|
205
|
-
filename: `chart-${
|
|
232
|
+
filename: `chart-${chartType}-${Date.now()}`
|
|
206
233
|
});
|
|
207
234
|
}
|
|
208
235
|
} catch (error) {
|
|
209
236
|
console.error("Download image failed:", error);
|
|
210
237
|
}
|
|
211
238
|
};
|
|
212
|
-
const isG6 = G6List.includes(type);
|
|
213
239
|
const handleZoomOut = () => {
|
|
214
240
|
if (chartRef.current && typeof chartRef.current.zoomTo === "function") {
|
|
215
241
|
const currentZoom = chartRef.current.getZoom() || 1;
|
|
@@ -224,29 +250,6 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
224
250
|
chartRef.current.zoomTo(newZoom);
|
|
225
251
|
}
|
|
226
252
|
};
|
|
227
|
-
const handleResize = (0, import_react.useMemo)(() => {
|
|
228
|
-
var _a;
|
|
229
|
-
const debouncedFn = (0, import_lodash.debounce)(() => {
|
|
230
|
-
var _a2, _b, _c;
|
|
231
|
-
const chart = chartRef.current;
|
|
232
|
-
const container = chartContainerRef.current;
|
|
233
|
-
if (!chart || !container || !(container instanceof HTMLElement)) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
try {
|
|
237
|
-
if (isG6) {
|
|
238
|
-
(_a2 = chart.resize) == null ? void 0 : _a2.call(chart);
|
|
239
|
-
(_b = chart.autoFit) == null ? void 0 : _b.call(chart);
|
|
240
|
-
} else {
|
|
241
|
-
(_c = chart.changeSize) == null ? void 0 : _c.call(chart);
|
|
242
|
-
}
|
|
243
|
-
} catch (error) {
|
|
244
|
-
console.error("Failed to resize chart:", error);
|
|
245
|
-
}
|
|
246
|
-
}, 150);
|
|
247
|
-
(_a = debouncedFn.cancel) == null ? void 0 : _a.call(debouncedFn);
|
|
248
|
-
return debouncedFn;
|
|
249
|
-
}, [isG6]);
|
|
250
253
|
if (!showTabs) {
|
|
251
254
|
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_rc_resize_observer.default, { onResize: handleResize }, /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
|
|
252
255
|
import_react_error_boundary.ErrorBoundary,
|
|
@@ -301,7 +304,7 @@ var RenderVisChart = (0, import_react.memo)(
|
|
|
301
304
|
}
|
|
302
305
|
}
|
|
303
306
|
},
|
|
304
|
-
/* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", type }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_rc_resize_observer.default, { onResize: handleResize }, /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
|
|
307
|
+
/* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", type: chartType }, /* @__PURE__ */ import_react.default.createElement(import_styles.GlobalStyles, null), /* @__PURE__ */ import_react.default.createElement(import_rc_resize_observer.default, { onResize: handleResize }, /* @__PURE__ */ import_react.default.createElement(import_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
|
|
305
308
|
ChartComponent,
|
|
306
309
|
{
|
|
307
310
|
...chartProps,
|
|
@@ -47,7 +47,7 @@ var import_styled_components = __toESM(require("styled-components"));
|
|
|
47
47
|
var StyledGPTVis = import_styled_components.default.div`
|
|
48
48
|
min-width: 300px;
|
|
49
49
|
max-width: 100%;
|
|
50
|
-
height: ${({ type }) => type === "table" ? "auto" : "300px"};
|
|
50
|
+
height: ${({ type }) => type === "table" || type === "spreadsheet" ? "auto" : "300px"};
|
|
51
51
|
/* height: 300px; */
|
|
52
52
|
overflow: hidden;
|
|
53
53
|
position: relative;
|
package/dist/cjs/Column/index.js
CHANGED
|
@@ -66,7 +66,7 @@ var defaultConfig = (props) => {
|
|
|
66
66
|
yField,
|
|
67
67
|
colorField: hasGroupField ? "group" : xField,
|
|
68
68
|
tooltip: (d) => {
|
|
69
|
-
const tooltipName = axisYTitle || d[xField];
|
|
69
|
+
const tooltipName = hasGroupField ? d["group"] : axisYTitle || d[xField];
|
|
70
70
|
return {
|
|
71
71
|
name: tooltipName,
|
|
72
72
|
value: d[yField]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import '@antv/s2/dist/s2.min.css';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* 主题名
|
|
5
|
+
*/
|
|
6
|
+
type ThemeName = 'default' | 'dark';
|
|
7
|
+
/**
|
|
8
|
+
* 数据项
|
|
9
|
+
*/
|
|
10
|
+
type DataItem = Record<string, string | number | null | undefined>;
|
|
11
|
+
export type SpreadsheetProps = {
|
|
12
|
+
/** 原始数据 */
|
|
13
|
+
data: DataItem[];
|
|
14
|
+
/** 行头字段(存在时为透视表) */
|
|
15
|
+
rows?: string[];
|
|
16
|
+
/** 列头字段/列顺序 */
|
|
17
|
+
columns?: string[];
|
|
18
|
+
/** 数值字段(存在时为透视表) */
|
|
19
|
+
values?: string[];
|
|
20
|
+
/** 主题名称 */
|
|
21
|
+
theme?: ThemeName;
|
|
22
|
+
/** 宽度 */
|
|
23
|
+
width?: number;
|
|
24
|
+
/** 高度 */
|
|
25
|
+
height?: number;
|
|
26
|
+
};
|
|
27
|
+
declare const Spreadsheet: (props: SpreadsheetProps) => React.JSX.Element;
|
|
28
|
+
export default Spreadsheet;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/Spreadsheet/index.tsx
|
|
30
|
+
var Spreadsheet_exports = {};
|
|
31
|
+
__export(Spreadsheet_exports, {
|
|
32
|
+
default: () => Spreadsheet_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(Spreadsheet_exports);
|
|
35
|
+
var import_s2 = require("@antv/s2");
|
|
36
|
+
var import_s2_min = require("@antv/s2/dist/s2.min.css");
|
|
37
|
+
var import_react = __toESM(require("react"));
|
|
38
|
+
var import_styled_components = __toESM(require("styled-components"));
|
|
39
|
+
var SpreadsheetWrapper = import_styled_components.default.div`
|
|
40
|
+
.spreadsheet-container {
|
|
41
|
+
width: 100%;
|
|
42
|
+
height: 100%;
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
var Spreadsheet = (props) => {
|
|
46
|
+
const { data, rows, columns, values, theme = "default", width = 600, height = 400 } = props;
|
|
47
|
+
const containerRef = (0, import_react.useRef)(null);
|
|
48
|
+
const s2Ref = (0, import_react.useRef)(null);
|
|
49
|
+
const isPivot = rows && rows.length > 0 || values && values.length > 0;
|
|
50
|
+
(0, import_react.useEffect)(() => {
|
|
51
|
+
if (!containerRef.current)
|
|
52
|
+
return;
|
|
53
|
+
const fields = {};
|
|
54
|
+
if (isPivot) {
|
|
55
|
+
if (rows && rows.length > 0) {
|
|
56
|
+
fields.rows = rows;
|
|
57
|
+
}
|
|
58
|
+
if (columns && columns.length > 0) {
|
|
59
|
+
fields.columns = columns;
|
|
60
|
+
}
|
|
61
|
+
if (values && values.length > 0) {
|
|
62
|
+
fields.values = values;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
if (columns && columns.length > 0) {
|
|
66
|
+
fields.columns = columns;
|
|
67
|
+
} else if (data.length > 0) {
|
|
68
|
+
fields.columns = Object.keys(data[0]);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const dataCfg = {
|
|
72
|
+
data,
|
|
73
|
+
fields
|
|
74
|
+
};
|
|
75
|
+
const themeCfg = {
|
|
76
|
+
name: theme
|
|
77
|
+
};
|
|
78
|
+
const options = {
|
|
79
|
+
width,
|
|
80
|
+
height
|
|
81
|
+
};
|
|
82
|
+
if (s2Ref.current) {
|
|
83
|
+
s2Ref.current.destroy();
|
|
84
|
+
}
|
|
85
|
+
const SheetClass = isPivot ? import_s2.PivotSheet : import_s2.TableSheet;
|
|
86
|
+
const s2 = new SheetClass(containerRef.current, dataCfg, options);
|
|
87
|
+
s2.setThemeCfg(themeCfg);
|
|
88
|
+
s2Ref.current = s2;
|
|
89
|
+
(async () => {
|
|
90
|
+
await s2.render();
|
|
91
|
+
if (s2.facet) {
|
|
92
|
+
const { panelBBox } = s2.facet;
|
|
93
|
+
const PADDING = 10;
|
|
94
|
+
const actualWidth = Math.ceil(panelBBox.maxX) + PADDING;
|
|
95
|
+
const actualHeight = Math.ceil(panelBBox.maxY) + PADDING;
|
|
96
|
+
if (actualWidth < width || actualHeight < height) {
|
|
97
|
+
const newWidth = Math.min(actualWidth, width);
|
|
98
|
+
const newHeight = Math.min(actualHeight, height);
|
|
99
|
+
s2.changeSheetSize(newWidth, newHeight);
|
|
100
|
+
await s2.render(false);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})();
|
|
104
|
+
return () => {
|
|
105
|
+
if (s2Ref.current) {
|
|
106
|
+
s2Ref.current.destroy();
|
|
107
|
+
s2Ref.current = null;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}, [data, rows, columns, values, theme, width, height, isPivot]);
|
|
111
|
+
return /* @__PURE__ */ import_react.default.createElement(SpreadsheetWrapper, null, /* @__PURE__ */ import_react.default.createElement("div", { ref: containerRef, className: "spreadsheet-container" }));
|
|
112
|
+
};
|
|
113
|
+
var Spreadsheet_default = Spreadsheet;
|
package/dist/cjs/export.d.ts
CHANGED
|
@@ -31,8 +31,9 @@ export { Map, type MapProps } from './export-map';
|
|
|
31
31
|
import { PinMap, type PinMapProps, HeatMap, type HeatMapProps, PathMap, type PathMapProps } from './export-map';
|
|
32
32
|
/********** NTV **********/
|
|
33
33
|
import { default as Table, type TableProps } from './Table';
|
|
34
|
+
import { default as Spreadsheet, type SpreadsheetProps } from './Spreadsheet';
|
|
34
35
|
export { VisText, type VisTextProps } from './Text';
|
|
35
|
-
export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Waterfall, Table, WordCloud, type AreaProps, type BarProps, type BoxplotProps, type ColumnProps, type DualAxesProps, type FishboneDiagramProps, type FlowDiagramProps, type FunnelProps, type HeatMapProps, type HistogramProps, type IndentedTreeProps, type LineProps, type LiquidProps, type MindMapProps, type NetworkGraphProps, type OrganizationChartProps, type PathMapProps, type PieProps, type PinMapProps, type RadarProps, type SankeyProps, type ScatterProps, type TreemapProps, type VennProps, type ViolinProps, type WaterfallProps, type TableProps, type WordCloudProps, };
|
|
36
|
+
export { Area, Bar, Boxplot, Column, DualAxes, FishboneDiagram, FlowDiagram, Funnel, HeatMap, Histogram, IndentedTree, Line, Liquid, MindMap, NetworkGraph, OrganizationChart, PathMap, Pie, PinMap, Radar, Sankey, Scatter, Treemap, Venn, Violin, Waterfall, Table, Spreadsheet, WordCloud, type AreaProps, type BarProps, type BoxplotProps, type ColumnProps, type DualAxesProps, type FishboneDiagramProps, type FlowDiagramProps, type FunnelProps, type HeatMapProps, type HistogramProps, type IndentedTreeProps, type LineProps, type LiquidProps, type MindMapProps, type NetworkGraphProps, type OrganizationChartProps, type PathMapProps, type PieProps, type PinMapProps, type RadarProps, type SankeyProps, type ScatterProps, type TreemapProps, type VennProps, type ViolinProps, type WaterfallProps, type TableProps, type SpreadsheetProps, type WordCloudProps, };
|
|
36
37
|
export type VisOptionMap = {
|
|
37
38
|
[ChartType.Area]: AreaProps;
|
|
38
39
|
[ChartType.Bar]: BarProps;
|
|
@@ -57,6 +58,7 @@ export type VisOptionMap = {
|
|
|
57
58
|
[ChartType.Sankey]: SankeyProps;
|
|
58
59
|
[ChartType.Scatter]: ScatterProps;
|
|
59
60
|
[ChartType.Table]: TableProps;
|
|
61
|
+
[ChartType.Spreadsheet]: SpreadsheetProps;
|
|
60
62
|
[ChartType.Treemap]: TreemapProps;
|
|
61
63
|
[ChartType.Venn]: VennProps;
|
|
62
64
|
[ChartType.Violin]: ViolinProps;
|
package/dist/cjs/export.js
CHANGED
|
@@ -53,6 +53,7 @@ __export(export_exports, {
|
|
|
53
53
|
Radar: () => import_Radar.default,
|
|
54
54
|
Sankey: () => import_Sankey.default,
|
|
55
55
|
Scatter: () => import_Scatter.default,
|
|
56
|
+
Spreadsheet: () => import_Spreadsheet.default,
|
|
56
57
|
Table: () => import_Table.default,
|
|
57
58
|
Treemap: () => import_Treemap.default,
|
|
58
59
|
Venn: () => import_Venn.default,
|
|
@@ -90,6 +91,7 @@ var import_IndentedTree = __toESM(require("./IndentedTree"));
|
|
|
90
91
|
var import_export_map = require("./export-map");
|
|
91
92
|
var import_export_map2 = require("./export-map");
|
|
92
93
|
var import_Table = __toESM(require("./Table"));
|
|
94
|
+
var import_Spreadsheet = __toESM(require("./Spreadsheet"));
|
|
93
95
|
var import_Text = require("./Text");
|
|
94
96
|
var DEFAULT_CHART_COMPONENTS = {
|
|
95
97
|
[import_types.ChartType.Area]: import_Area.default,
|
|
@@ -146,6 +148,7 @@ var DEFAULT_CHART_COMPONENTS = {
|
|
|
146
148
|
Radar,
|
|
147
149
|
Sankey,
|
|
148
150
|
Scatter,
|
|
151
|
+
Spreadsheet,
|
|
149
152
|
Table,
|
|
150
153
|
Treemap,
|
|
151
154
|
Venn,
|
package/dist/cjs/types/chart.js
CHANGED
|
@@ -50,6 +50,7 @@ var ChartType = /* @__PURE__ */ ((ChartType2) => {
|
|
|
50
50
|
ChartType2["Violin"] = "violin";
|
|
51
51
|
ChartType2["Waterfall"] = "waterfall";
|
|
52
52
|
ChartType2["Table"] = "table";
|
|
53
|
+
ChartType2["Spreadsheet"] = "spreadsheet";
|
|
53
54
|
ChartType2["VisText"] = "vis-text";
|
|
54
55
|
ChartType2["WordCloud"] = "word-cloud";
|
|
55
56
|
return ChartType2;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.
|
|
1
|
+
declare const _default: "0.6.1";
|
|
2
2
|
export default _default;
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/Bar/index.js
CHANGED
|
@@ -49,7 +49,7 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
49
49
|
yField: yField,
|
|
50
50
|
colorField: hasGroupField ? 'group' : xField,
|
|
51
51
|
tooltip: function tooltip(d) {
|
|
52
|
-
var tooltipName = axisYTitle || d[xField];
|
|
52
|
+
var tooltipName = hasGroupField ? d['group'] : axisYTitle || d[xField];
|
|
53
53
|
return {
|
|
54
54
|
name: tooltipName,
|
|
55
55
|
value: d[yField]
|
|
@@ -125,14 +125,50 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
125
125
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
126
126
|
activeTab = _useState8[0],
|
|
127
127
|
setActiveTab = _useState8[1];
|
|
128
|
-
var chartJson;
|
|
129
128
|
|
|
130
|
-
// Parse chart JSON
|
|
129
|
+
// Parse chart JSON early to determine type for hooks
|
|
130
|
+
var chartJson = null;
|
|
131
|
+
var parseError = null;
|
|
132
|
+
var type;
|
|
131
133
|
try {
|
|
134
|
+
var _chartJson;
|
|
132
135
|
chartJson = JSON.parse(content);
|
|
136
|
+
type = (_chartJson = chartJson) === null || _chartJson === void 0 ? void 0 : _chartJson.type;
|
|
133
137
|
} catch (e) {
|
|
134
|
-
|
|
138
|
+
parseError = e;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Check if chart supports G6 zoom functionality
|
|
142
|
+
var isG6 = type ? G6List.includes(type) : false;
|
|
135
143
|
|
|
144
|
+
// Handle chart resizing on container size change
|
|
145
|
+
var handleResize = useMemo(function () {
|
|
146
|
+
var debouncedFn = debounce(function () {
|
|
147
|
+
var chart = chartRef.current;
|
|
148
|
+
var container = chartContainerRef.current;
|
|
149
|
+
if (!chart || !container || !(container instanceof HTMLElement)) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
if (isG6) {
|
|
154
|
+
var _chart$resize, _chart$autoFit;
|
|
155
|
+
// https://github.com/antvis/G6/blob/91c0ac85e4e636a05bd1a3c5e56a4928d1242a9b/packages/g6/src/runtime/graph.ts#L1334
|
|
156
|
+
(_chart$resize = chart.resize) === null || _chart$resize === void 0 || _chart$resize.call(chart);
|
|
157
|
+
(_chart$autoFit = chart.autoFit) === null || _chart$autoFit === void 0 || _chart$autoFit.call(chart);
|
|
158
|
+
} else {
|
|
159
|
+
var _chart$changeSize;
|
|
160
|
+
// https://github.com/antvis/G2/blob/c5b1887408f951f59f8263e7e1a306dbdae50660/src/api/runtime.ts#L236
|
|
161
|
+
(_chart$changeSize = chart.changeSize) === null || _chart$changeSize === void 0 || _chart$changeSize.call(chart);
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error('Failed to resize chart:', error);
|
|
165
|
+
}
|
|
166
|
+
}, 150);
|
|
167
|
+
return debouncedFn;
|
|
168
|
+
}, [isG6]);
|
|
169
|
+
|
|
170
|
+
// Handle parse errors after all hooks are called
|
|
171
|
+
if (parseError) {
|
|
136
172
|
// Clear any existing timeout and set loading timeout
|
|
137
173
|
if (timeoutRef.current) {
|
|
138
174
|
clearTimeout(timeoutRef.current);
|
|
@@ -165,10 +201,12 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
165
201
|
// Return default error message
|
|
166
202
|
return /*#__PURE__*/React.createElement("div", null, labels.parseError);
|
|
167
203
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
204
|
+
|
|
205
|
+
// chartJson is guaranteed to be non-null here
|
|
206
|
+
var _ref2 = chartJson,
|
|
207
|
+
chartType = _ref2.type,
|
|
208
|
+
chartProps = _objectWithoutProperties(_ref2, _excluded);
|
|
209
|
+
var ChartComponent = components[chartType];
|
|
172
210
|
|
|
173
211
|
// Debug mode: print chart JSON
|
|
174
212
|
if (debug) {
|
|
@@ -177,7 +215,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
177
215
|
|
|
178
216
|
// Handle unsupported chart types
|
|
179
217
|
if (!ChartComponent) {
|
|
180
|
-
var message = "".concat(labels.unsupportedChart, ": \"").concat(
|
|
218
|
+
var message = "".concat(labels.unsupportedChart, ": \"").concat(chartType, "\"");
|
|
181
219
|
if (errorRender) {
|
|
182
220
|
return errorRender({
|
|
183
221
|
error: new Error(message),
|
|
@@ -188,8 +226,8 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
188
226
|
}
|
|
189
227
|
|
|
190
228
|
// Error fallback component for chart rendering errors
|
|
191
|
-
var FallbackComponent = function FallbackComponent(
|
|
192
|
-
var error =
|
|
229
|
+
var FallbackComponent = function FallbackComponent(_ref3) {
|
|
230
|
+
var error = _ref3.error;
|
|
193
231
|
// Set render error state and switch to code tab
|
|
194
232
|
if (!hasRenderError) {
|
|
195
233
|
setHasRenderError(true);
|
|
@@ -210,7 +248,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
210
248
|
|
|
211
249
|
// Handle copy functionality
|
|
212
250
|
var handleCopy = /*#__PURE__*/function () {
|
|
213
|
-
var
|
|
251
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
214
252
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
215
253
|
while (1) switch (_context.prev = _context.next) {
|
|
216
254
|
case 0:
|
|
@@ -242,13 +280,13 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
242
280
|
}, _callee, null, [[0, 8]]);
|
|
243
281
|
}));
|
|
244
282
|
return function handleCopy() {
|
|
245
|
-
return
|
|
283
|
+
return _ref4.apply(this, arguments);
|
|
246
284
|
};
|
|
247
285
|
}();
|
|
248
286
|
|
|
249
287
|
// Handle download functionality
|
|
250
288
|
var handleDownload = /*#__PURE__*/function () {
|
|
251
|
-
var
|
|
289
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
252
290
|
var result;
|
|
253
291
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
254
292
|
while (1) switch (_context2.prev = _context2.next) {
|
|
@@ -267,7 +305,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
267
305
|
_context2.next = 7;
|
|
268
306
|
return result.download({
|
|
269
307
|
format: 'png',
|
|
270
|
-
filename: "chart-".concat(
|
|
308
|
+
filename: "chart-".concat(chartType, "-").concat(Date.now())
|
|
271
309
|
});
|
|
272
310
|
case 7:
|
|
273
311
|
_context2.next = 12;
|
|
@@ -283,13 +321,10 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
283
321
|
}, _callee2, null, [[0, 9]]);
|
|
284
322
|
}));
|
|
285
323
|
return function handleDownload() {
|
|
286
|
-
return
|
|
324
|
+
return _ref5.apply(this, arguments);
|
|
287
325
|
};
|
|
288
326
|
}();
|
|
289
327
|
|
|
290
|
-
// Check if chart supports G6 zoom functionality
|
|
291
|
-
var isG6 = G6List.includes(type);
|
|
292
|
-
|
|
293
328
|
// Zoom out functionality
|
|
294
329
|
var handleZoomOut = function handleZoomOut() {
|
|
295
330
|
if (chartRef.current && typeof chartRef.current.zoomTo === 'function') {
|
|
@@ -308,36 +343,6 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
308
343
|
}
|
|
309
344
|
};
|
|
310
345
|
|
|
311
|
-
// Handle chart resizing on container size change
|
|
312
|
-
var handleResize = useMemo(function () {
|
|
313
|
-
var _debouncedFn$cancel;
|
|
314
|
-
var debouncedFn = debounce(function () {
|
|
315
|
-
var chart = chartRef.current;
|
|
316
|
-
var container = chartContainerRef.current;
|
|
317
|
-
|
|
318
|
-
// 增加 null 检查和类型守卫
|
|
319
|
-
if (!chart || !container || !(container instanceof HTMLElement)) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
try {
|
|
323
|
-
if (isG6) {
|
|
324
|
-
var _chart$resize, _chart$autoFit;
|
|
325
|
-
// https://github.com/antvis/G6/blob/91c0ac85e4e636a05bd1a3c5e56a4928d1242a9b/packages/g6/src/runtime/graph.ts#L1334
|
|
326
|
-
(_chart$resize = chart.resize) === null || _chart$resize === void 0 || _chart$resize.call(chart);
|
|
327
|
-
(_chart$autoFit = chart.autoFit) === null || _chart$autoFit === void 0 || _chart$autoFit.call(chart);
|
|
328
|
-
} else {
|
|
329
|
-
var _chart$changeSize;
|
|
330
|
-
// https://github.com/antvis/G2/blob/c5b1887408f951f59f8263e7e1a306dbdae50660/src/api/runtime.ts#L236
|
|
331
|
-
(_chart$changeSize = chart.changeSize) === null || _chart$changeSize === void 0 || _chart$changeSize.call(chart);
|
|
332
|
-
}
|
|
333
|
-
} catch (error) {
|
|
334
|
-
console.error('Failed to resize chart:', error);
|
|
335
|
-
}
|
|
336
|
-
}, 150);
|
|
337
|
-
(_debouncedFn$cancel = debouncedFn.cancel) === null || _debouncedFn$cancel === void 0 || _debouncedFn$cancel.call(debouncedFn);
|
|
338
|
-
return debouncedFn;
|
|
339
|
-
}, [isG6]);
|
|
340
|
-
|
|
341
346
|
// Render without tabs if showTabs is false
|
|
342
347
|
if (!showTabs) {
|
|
343
348
|
return /*#__PURE__*/React.createElement(StyledGPTVis, {
|
|
@@ -415,7 +420,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
|
|
|
415
420
|
}
|
|
416
421
|
}, /*#__PURE__*/React.createElement(StyledGPTVis, {
|
|
417
422
|
className: "gpt-vis",
|
|
418
|
-
type:
|
|
423
|
+
type: chartType
|
|
419
424
|
}, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ResizeObserver, {
|
|
420
425
|
onResize: handleResize
|
|
421
426
|
}, /*#__PURE__*/React.createElement(ChartWrapper, {
|
|
@@ -4,7 +4,7 @@ export var StyledGPTVis = styled.div.withConfig({
|
|
|
4
4
|
componentId: "gpt-vis-c7ef__sc-2dc7ka-0"
|
|
5
5
|
})(["min-width:300px;max-width:100%;height:", ";overflow:hidden;position:relative;padding:16px;"], function (_ref) {
|
|
6
6
|
var type = _ref.type;
|
|
7
|
-
return type === 'table' ? 'auto' : '300px';
|
|
7
|
+
return type === 'table' || type === 'spreadsheet' ? 'auto' : '300px';
|
|
8
8
|
});
|
|
9
9
|
export var TextButton = styled.button.withConfig({
|
|
10
10
|
displayName: "TextButton",
|
package/dist/esm/Column/index.js
CHANGED
|
@@ -49,7 +49,7 @@ var defaultConfig = function defaultConfig(props) {
|
|
|
49
49
|
yField: yField,
|
|
50
50
|
colorField: hasGroupField ? 'group' : xField,
|
|
51
51
|
tooltip: function tooltip(d) {
|
|
52
|
-
var tooltipName = axisYTitle || d[xField];
|
|
52
|
+
var tooltipName = hasGroupField ? d['group'] : axisYTitle || d[xField];
|
|
53
53
|
return {
|
|
54
54
|
name: tooltipName,
|
|
55
55
|
value: d[yField]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import '@antv/s2/dist/s2.min.css';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* 主题名
|
|
5
|
+
*/
|
|
6
|
+
type ThemeName = 'default' | 'dark';
|
|
7
|
+
/**
|
|
8
|
+
* 数据项
|
|
9
|
+
*/
|
|
10
|
+
type DataItem = Record<string, string | number | null | undefined>;
|
|
11
|
+
export type SpreadsheetProps = {
|
|
12
|
+
/** 原始数据 */
|
|
13
|
+
data: DataItem[];
|
|
14
|
+
/** 行头字段(存在时为透视表) */
|
|
15
|
+
rows?: string[];
|
|
16
|
+
/** 列头字段/列顺序 */
|
|
17
|
+
columns?: string[];
|
|
18
|
+
/** 数值字段(存在时为透视表) */
|
|
19
|
+
values?: string[];
|
|
20
|
+
/** 主题名称 */
|
|
21
|
+
theme?: ThemeName;
|
|
22
|
+
/** 宽度 */
|
|
23
|
+
width?: number;
|
|
24
|
+
/** 高度 */
|
|
25
|
+
height?: number;
|
|
26
|
+
};
|
|
27
|
+
declare const Spreadsheet: (props: SpreadsheetProps) => React.JSX.Element;
|
|
28
|
+
export default Spreadsheet;
|