@antv/gpt-vis 0.5.11 → 0.5.13

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.
@@ -1,3 +1,6 @@
1
1
  import React from 'react';
2
- declare const Loading: () => React.JSX.Element;
2
+ type LoadingProps = {
3
+ text: string;
4
+ };
5
+ declare const Loading: React.FC<LoadingProps>;
3
6
  export default Loading;
@@ -48,7 +48,7 @@ var StyledLoading = import_styled_components.default.div`
48
48
  margin-bottom: 6px;
49
49
  }
50
50
  `;
51
- var Loading = () => {
52
- return /* @__PURE__ */ import_react.default.createElement(StyledLoading, { className: "gpt-vis-loading" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "gpt-vis-loading-icon" }, /* @__PURE__ */ import_react.default.createElement(import_icons.LoadingOutlined, { style: { fontSize: "24px", color: "rgb(56, 177, 246)" } })), /* @__PURE__ */ import_react.default.createElement("p", null, "数据生成中"));
51
+ var Loading = ({ text }) => {
52
+ return /* @__PURE__ */ import_react.default.createElement(StyledLoading, { className: "gpt-vis-loading" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "gpt-vis-loading-icon" }, /* @__PURE__ */ import_react.default.createElement(import_icons.LoadingOutlined, { style: { fontSize: "24px", color: "rgb(56, 177, 246)" } })), /* @__PURE__ */ import_react.default.createElement("p", null, text));
53
53
  };
54
54
  var Loading_default = Loading;
@@ -33,6 +33,8 @@ __export(VisChart_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(VisChart_exports);
35
35
  var import_snapdom = require("@zumer/snapdom");
36
+ var import_lodash = require("lodash");
37
+ var import_rc_resize_observer = __toESM(require("rc-resize-observer"));
36
38
  var import_react = __toESM(require("react"));
37
39
  var import_react_error_boundary = require("react-error-boundary");
38
40
  var import_react_syntax_highlighter = require("react-syntax-highlighter");
@@ -60,7 +62,8 @@ var DEFAULT_LABELS = {
60
62
  copied: "完成",
61
63
  renderError: "图表渲染失败",
62
64
  parseError: "GPT-Vis parse content error!",
63
- unsupportedChart: "Chart type not supported"
65
+ unsupportedChart: "Chart type not supported",
66
+ loading: "数据生成中"
64
67
  },
65
68
  "en-US": {
66
69
  chartTab: "Chart",
@@ -70,7 +73,8 @@ var DEFAULT_LABELS = {
70
73
  copied: "Copied",
71
74
  renderError: "Chart render failed",
72
75
  parseError: "Parse content error!",
73
- unsupportedChart: "Chart type not supported"
76
+ unsupportedChart: "Chart type not supported",
77
+ loading: "Generating data"
74
78
  },
75
79
  "pt-BR": {
76
80
  chartTab: "Gráfico",
@@ -80,7 +84,8 @@ var DEFAULT_LABELS = {
80
84
  copied: "Copiado",
81
85
  renderError: "Erro ao renderizar gráfico",
82
86
  parseError: "Erro ao analisar conteúdo!",
83
- unsupportedChart: "Tipo de gráfico não suportado"
87
+ unsupportedChart: "Tipo de gráfico não suportado",
88
+ loading: "Gerando dados"
84
89
  }
85
90
  };
86
91
  var RenderVisChart = (0, import_react.memo)(
@@ -137,7 +142,7 @@ var RenderVisChart = (0, import_react.memo)(
137
142
  setLoading(false);
138
143
  }, loadingTimeout);
139
144
  if (loading) {
140
- return /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", style }, /* @__PURE__ */ import_react.default.createElement(import_Loading.default, null));
145
+ return /* @__PURE__ */ import_react.default.createElement(import_styles.StyledGPTVis, { className: "gpt-vis", style }, /* @__PURE__ */ import_react.default.createElement(import_Loading.default, { text: labels.loading || "" }));
141
146
  }
142
147
  if (errorRender) {
143
148
  return errorRender({
@@ -220,8 +225,31 @@ var RenderVisChart = (0, import_react.memo)(
220
225
  chartRef.current.zoomTo(newZoom);
221
226
  }
222
227
  };
228
+ const handleResize = (0, import_react.useMemo)(() => {
229
+ var _a;
230
+ const debouncedFn = (0, import_lodash.debounce)(() => {
231
+ var _a2, _b, _c;
232
+ const chart = chartRef.current;
233
+ const container = chartContainerRef.current;
234
+ if (!chart || !container || !(container instanceof HTMLElement)) {
235
+ return;
236
+ }
237
+ try {
238
+ if (isG6) {
239
+ (_a2 = chart.resize) == null ? void 0 : _a2.call(chart);
240
+ (_b = chart.autoFit) == null ? void 0 : _b.call(chart);
241
+ } else {
242
+ (_c = chart.changeSize) == null ? void 0 : _c.call(chart);
243
+ }
244
+ } catch (error) {
245
+ console.error("Failed to resize chart:", error);
246
+ }
247
+ }, 150);
248
+ (_a = debouncedFn.cancel) == null ? void 0 : _a.call(debouncedFn);
249
+ return debouncedFn;
250
+ }, [isG6]);
223
251
  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(
252
+ 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(
225
253
  import_react_error_boundary.ErrorBoundary,
226
254
  {
227
255
  FallbackComponent,
@@ -241,7 +269,7 @@ var RenderVisChart = (0, import_react.memo)(
241
269
  }
242
270
  }
243
271
  )
244
- )));
272
+ ))));
245
273
  }
246
274
  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(
247
275
  import_styles.TextButton,
@@ -274,7 +302,7 @@ var RenderVisChart = (0, import_react.memo)(
274
302
  }
275
303
  }
276
304
  },
277
- /* @__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_styles.ChartWrapper, { ref: chartContainerRef }, /* @__PURE__ */ import_react.default.createElement(
305
+ /* @__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(
278
306
  ChartComponent,
279
307
  {
280
308
  ...chartProps,
@@ -282,7 +310,7 @@ var RenderVisChart = (0, import_react.memo)(
282
310
  chartRef.current = chart;
283
311
  }
284
312
  }
285
- )))
313
+ ))))
286
314
  ) : /* @__PURE__ */ import_react.default.createElement("div", { style: { maxHeight: 500, overflow: "auto" } }, /* @__PURE__ */ import_react.default.createElement(
287
315
  import_react_syntax_highlighter.Light,
288
316
  {
@@ -13,6 +13,7 @@ export type TextLabels = {
13
13
  renderError?: string;
14
14
  parseError?: string;
15
15
  unsupportedChart?: string;
16
+ loading?: string;
16
17
  };
17
18
  /**
18
19
  * Chart enhancement options - contains all new feature configurations
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { BasePlotProps, Style, Theme } from '../types';
2
+ import type { BasePlotProps, Theme } from '../types';
3
3
  type WaterfallDataItem = {
4
4
  category: string;
5
5
  value?: number;
@@ -7,14 +7,17 @@ type WaterfallDataItem = {
7
7
  isIntermediateTotal?: boolean;
8
8
  [key: string]: string | number | boolean | undefined;
9
9
  };
10
+ type WaterfallPalette = {
11
+ positiveColor?: string;
12
+ negativeColor?: string;
13
+ totalColor?: string;
14
+ };
10
15
  type WaterfallStyle = {
11
16
  backgroundColor?: string;
12
- } & Style;
17
+ palette?: WaterfallPalette;
18
+ };
13
19
  export type WaterfallProps = BasePlotProps<WaterfallDataItem> & Theme & {
14
20
  style?: WaterfallStyle;
15
- positiveColor?: string;
16
- negativeColor?: string;
17
- totalColor?: string;
18
21
  axisXTitle?: string;
19
22
  axisYTitle?: string;
20
23
  };
@@ -80,21 +80,11 @@ function generateLinkData(data) {
80
80
  }, []);
81
81
  }
82
82
  var defaultConfig = (props) => {
83
- const {
84
- data = [],
85
- title,
86
- style = {},
87
- positiveColor: customPositiveColor,
88
- negativeColor: customNegativeColor,
89
- totalColor: customTotalColor,
90
- axisXTitle,
91
- axisYTitle,
92
- theme = "default"
93
- } = props;
94
- const { backgroundColor } = style;
95
- const positiveColor = customPositiveColor || DEFAULT_POSITIVE_COLOR;
96
- const negativeColor = customNegativeColor || DEFAULT_NEGATIVE_COLOR;
97
- const totalColor = customTotalColor || DEFAULT_TOTAL_COLOR;
83
+ const { data = [], title, style = {}, axisXTitle, axisYTitle, theme = "default" } = props;
84
+ const { backgroundColor, palette = {} } = style;
85
+ const positiveColor = palette.positiveColor || DEFAULT_POSITIVE_COLOR;
86
+ const negativeColor = palette.negativeColor || DEFAULT_NEGATIVE_COLOR;
87
+ const totalColor = palette.totalColor || DEFAULT_TOTAL_COLOR;
98
88
  const transformedData = transformWaterfallData(data);
99
89
  const linkData = generateLinkData(transformedData);
100
90
  return {
@@ -1,2 +1,2 @@
1
- declare const _default: "0.5.11";
1
+ declare const _default: "0.5.13";
2
2
  export default _default;
@@ -22,4 +22,4 @@ __export(version_exports, {
22
22
  default: () => version_default
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- var version_default = "0.5.11";
25
+ var version_default = "0.5.13";
@@ -1,3 +1,6 @@
1
1
  import React from 'react';
2
- declare const Loading: () => React.JSX.Element;
2
+ type LoadingProps = {
3
+ text: string;
4
+ };
5
+ declare const Loading: React.FC<LoadingProps>;
3
6
  export default Loading;
@@ -5,7 +5,8 @@ var StyledLoading = styled.div.withConfig({
5
5
  displayName: "StyledLoading",
6
6
  componentId: "gpt-vis-c7ef__sc-4x7w8p-0"
7
7
  })(["display:flex;align-items:center;justify-content:center;flex-direction:column;height:300px;background-image:linear-gradient(135deg,#e3f3ff 0%,#f1eeff 100%);color:rgba(0,0,0,88%);&-icon{margin-bottom:6px;}"]);
8
- var Loading = function Loading() {
8
+ var Loading = function Loading(_ref) {
9
+ var text = _ref.text;
9
10
  return /*#__PURE__*/React.createElement(StyledLoading, {
10
11
  className: "gpt-vis-loading"
11
12
  }, /*#__PURE__*/React.createElement("div", {
@@ -15,6 +16,6 @@ var Loading = function Loading() {
15
16
  fontSize: '24px',
16
17
  color: 'rgb(56, 177, 246)'
17
18
  }
18
- })), /*#__PURE__*/React.createElement("p", null, "\u6570\u636E\u751F\u6210\u4E2D"));
19
+ })), /*#__PURE__*/React.createElement("p", null, text));
19
20
  };
20
21
  export default Loading;
@@ -18,7 +18,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
18
18
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
19
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
20
  import { snapdom } from '@zumer/snapdom';
21
- import React, { memo, useRef, useState } from 'react';
21
+ import { debounce } from 'lodash';
22
+ import ResizeObserver from 'rc-resize-observer';
23
+ import React, { memo, useMemo, useRef, useState } from 'react';
22
24
  import { ErrorBoundary } from 'react-error-boundary';
23
25
  import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
24
26
  import json from 'react-syntax-highlighter/dist/esm/languages/hljs/json';
@@ -44,7 +46,8 @@ var DEFAULT_LABELS = {
44
46
  copied: '完成',
45
47
  renderError: '图表渲染失败',
46
48
  parseError: 'GPT-Vis parse content error!',
47
- unsupportedChart: 'Chart type not supported'
49
+ unsupportedChart: 'Chart type not supported',
50
+ loading: '数据生成中'
48
51
  },
49
52
  'en-US': {
50
53
  chartTab: 'Chart',
@@ -54,7 +57,8 @@ var DEFAULT_LABELS = {
54
57
  copied: 'Copied',
55
58
  renderError: 'Chart render failed',
56
59
  parseError: 'Parse content error!',
57
- unsupportedChart: 'Chart type not supported'
60
+ unsupportedChart: 'Chart type not supported',
61
+ loading: 'Generating data'
58
62
  },
59
63
  'pt-BR': {
60
64
  chartTab: 'Gráfico',
@@ -64,7 +68,8 @@ var DEFAULT_LABELS = {
64
68
  copied: 'Copiado',
65
69
  renderError: 'Erro ao renderizar gráfico',
66
70
  parseError: 'Erro ao analisar conteúdo!',
67
- unsupportedChart: 'Tipo de gráfico não suportado'
71
+ unsupportedChart: 'Tipo de gráfico não suportado',
72
+ loading: 'Gerando dados'
68
73
  }
69
74
  };
70
75
  export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
@@ -144,7 +149,9 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
144
149
  return /*#__PURE__*/React.createElement(StyledGPTVis, {
145
150
  className: "gpt-vis",
146
151
  style: style
147
- }, /*#__PURE__*/React.createElement(Loading, null));
152
+ }, /*#__PURE__*/React.createElement(Loading, {
153
+ text: labels.loading || ''
154
+ }));
148
155
  }
149
156
 
150
157
  // Use custom error render function if provided
@@ -302,12 +309,44 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
302
309
  }
303
310
  };
304
311
 
312
+ // Handle chart resizing on container size change
313
+ var handleResize = useMemo(function () {
314
+ var _debouncedFn$cancel;
315
+ var debouncedFn = debounce(function () {
316
+ var chart = chartRef.current;
317
+ var container = chartContainerRef.current;
318
+
319
+ // 增加 null 检查和类型守卫
320
+ if (!chart || !container || !(container instanceof HTMLElement)) {
321
+ return;
322
+ }
323
+ try {
324
+ if (isG6) {
325
+ var _chart$resize, _chart$autoFit;
326
+ // https://github.com/antvis/G6/blob/91c0ac85e4e636a05bd1a3c5e56a4928d1242a9b/packages/g6/src/runtime/graph.ts#L1334
327
+ (_chart$resize = chart.resize) === null || _chart$resize === void 0 || _chart$resize.call(chart);
328
+ (_chart$autoFit = chart.autoFit) === null || _chart$autoFit === void 0 || _chart$autoFit.call(chart);
329
+ } else {
330
+ var _chart$changeSize;
331
+ // https://github.com/antvis/G2/blob/c5b1887408f951f59f8263e7e1a306dbdae50660/src/api/runtime.ts#L236
332
+ (_chart$changeSize = chart.changeSize) === null || _chart$changeSize === void 0 || _chart$changeSize.call(chart);
333
+ }
334
+ } catch (error) {
335
+ console.error('Failed to resize chart:', error);
336
+ }
337
+ }, 150);
338
+ (_debouncedFn$cancel = debouncedFn.cancel) === null || _debouncedFn$cancel === void 0 || _debouncedFn$cancel.call(debouncedFn);
339
+ return debouncedFn;
340
+ }, [isG6]);
341
+
305
342
  // Render without tabs if showTabs is false
306
343
  if (!showTabs) {
307
344
  return /*#__PURE__*/React.createElement(StyledGPTVis, {
308
345
  className: "gpt-vis",
309
346
  style: style
310
- }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ChartWrapper, {
347
+ }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ResizeObserver, {
348
+ onResize: handleResize
349
+ }, /*#__PURE__*/React.createElement(ChartWrapper, {
311
350
  ref: chartContainerRef
312
351
  }, /*#__PURE__*/React.createElement(ErrorBoundary, {
313
352
  FallbackComponent: FallbackComponent,
@@ -321,7 +360,7 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
321
360
  onReady: function onReady(chart) {
322
361
  chartRef.current = chart;
323
362
  }
324
- })))));
363
+ }))))));
325
364
  }
326
365
 
327
366
  // Render with tabs
@@ -378,13 +417,15 @@ export var RenderVisChart = /*#__PURE__*/memo(function (_ref) {
378
417
  }, /*#__PURE__*/React.createElement(StyledGPTVis, {
379
418
  className: "gpt-vis",
380
419
  type: type
381
- }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ChartWrapper, {
420
+ }, /*#__PURE__*/React.createElement(GlobalStyles, null), /*#__PURE__*/React.createElement(ResizeObserver, {
421
+ onResize: handleResize
422
+ }, /*#__PURE__*/React.createElement(ChartWrapper, {
382
423
  ref: chartContainerRef
383
424
  }, /*#__PURE__*/React.createElement(ChartComponent, _extends({}, chartProps, {
384
425
  onReady: function onReady(chart) {
385
426
  chartRef.current = chart;
386
427
  }
387
- }))))) : /*#__PURE__*/React.createElement("div", {
428
+ })))))) : /*#__PURE__*/React.createElement("div", {
388
429
  style: {
389
430
  maxHeight: 500,
390
431
  overflow: 'auto'
@@ -13,6 +13,7 @@ export type TextLabels = {
13
13
  renderError?: string;
14
14
  parseError?: string;
15
15
  unsupportedChart?: string;
16
+ loading?: string;
16
17
  };
17
18
  /**
18
19
  * Chart enhancement options - contains all new feature configurations
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import type { BasePlotProps, Style, Theme } from '../types';
2
+ import type { BasePlotProps, Theme } from '../types';
3
3
  type WaterfallDataItem = {
4
4
  category: string;
5
5
  value?: number;
@@ -7,14 +7,17 @@ type WaterfallDataItem = {
7
7
  isIntermediateTotal?: boolean;
8
8
  [key: string]: string | number | boolean | undefined;
9
9
  };
10
+ type WaterfallPalette = {
11
+ positiveColor?: string;
12
+ negativeColor?: string;
13
+ totalColor?: string;
14
+ };
10
15
  type WaterfallStyle = {
11
16
  backgroundColor?: string;
12
- } & Style;
17
+ palette?: WaterfallPalette;
18
+ };
13
19
  export type WaterfallProps = BasePlotProps<WaterfallDataItem> & Theme & {
14
20
  style?: WaterfallStyle;
15
- positiveColor?: string;
16
- negativeColor?: string;
17
- totalColor?: string;
18
21
  axisXTitle?: string;
19
22
  axisYTitle?: string;
20
23
  };
@@ -71,17 +71,16 @@ var defaultConfig = function defaultConfig(props) {
71
71
  title = props.title,
72
72
  _props$style = props.style,
73
73
  style = _props$style === void 0 ? {} : _props$style,
74
- customPositiveColor = props.positiveColor,
75
- customNegativeColor = props.negativeColor,
76
- customTotalColor = props.totalColor,
77
74
  axisXTitle = props.axisXTitle,
78
75
  axisYTitle = props.axisYTitle,
79
76
  _props$theme = props.theme,
80
77
  theme = _props$theme === void 0 ? 'default' : _props$theme;
81
- var backgroundColor = style.backgroundColor;
82
- var positiveColor = customPositiveColor || DEFAULT_POSITIVE_COLOR;
83
- var negativeColor = customNegativeColor || DEFAULT_NEGATIVE_COLOR;
84
- var totalColor = customTotalColor || DEFAULT_TOTAL_COLOR;
78
+ var backgroundColor = style.backgroundColor,
79
+ _style$palette = style.palette,
80
+ palette = _style$palette === void 0 ? {} : _style$palette;
81
+ var positiveColor = palette.positiveColor || DEFAULT_POSITIVE_COLOR;
82
+ var negativeColor = palette.negativeColor || DEFAULT_NEGATIVE_COLOR;
83
+ var totalColor = palette.totalColor || DEFAULT_TOTAL_COLOR;
85
84
  var transformedData = transformWaterfallData(data);
86
85
  var linkData = generateLinkData(transformedData);
87
86
  return _objectSpread({
@@ -1,2 +1,2 @@
1
- declare const _default: "0.5.11";
1
+ declare const _default: "0.5.13";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '0.5.11';
1
+ export default '0.5.13';