@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.
Files changed (159) hide show
  1. package/README.md +223 -47
  2. package/README.zh-CN.md +227 -51
  3. package/dist/cjs/gpt-vis/index.d.ts +8 -1
  4. package/dist/cjs/gpt-vis/index.js +43 -20
  5. package/dist/cjs/index.d.ts +15 -2
  6. package/dist/cjs/index.js +22 -2
  7. package/dist/cjs/syntax/parser.d.ts +17 -2
  8. package/dist/cjs/syntax/parser.js +151 -38
  9. package/dist/cjs/util/container.d.ts +5 -0
  10. package/dist/cjs/util/container.js +43 -0
  11. package/dist/cjs/util/theme.d.ts +5 -0
  12. package/dist/cjs/util/theme.js +9 -2
  13. package/dist/cjs/vis/area/index.js +2 -1
  14. package/dist/cjs/vis/bar/index.js +5 -4
  15. package/dist/cjs/vis/boxplot/index.js +7 -2
  16. package/dist/cjs/vis/column/index.js +5 -4
  17. package/dist/cjs/vis/dual-axes/index.js +3 -3
  18. package/dist/cjs/vis/fishbone-diagram/index.d.ts +35 -0
  19. package/dist/cjs/vis/fishbone-diagram/index.js +191 -0
  20. package/dist/cjs/vis/flow-diagram/index.d.ts +27 -0
  21. package/dist/cjs/vis/flow-diagram/index.js +287 -0
  22. package/dist/cjs/vis/funnel/index.js +2 -1
  23. package/dist/cjs/vis/histogram/index.js +3 -7
  24. package/dist/cjs/vis/indented-tree/index.d.ts +40 -0
  25. package/dist/cjs/vis/indented-tree/index.js +385 -0
  26. package/dist/cjs/vis/line/index.js +2 -1
  27. package/dist/cjs/vis/liquid/index.js +2 -1
  28. package/dist/cjs/vis/mindmap/index.d.ts +32 -0
  29. package/dist/cjs/vis/mindmap/index.js +222 -0
  30. package/dist/cjs/vis/network-graph/index.d.ts +59 -0
  31. package/dist/cjs/vis/network-graph/index.js +175 -0
  32. package/dist/cjs/vis/organization-chart/index.d.ts +64 -0
  33. package/dist/cjs/vis/organization-chart/index.js +200 -0
  34. package/dist/cjs/vis/pie/index.js +3 -3
  35. package/dist/cjs/vis/radar/index.d.ts +1 -0
  36. package/dist/cjs/vis/radar/index.js +10 -9
  37. package/dist/cjs/vis/sankey/index.js +2 -1
  38. package/dist/cjs/vis/scatter/index.d.ts +2 -0
  39. package/dist/cjs/vis/scatter/index.js +9 -4
  40. package/dist/cjs/vis/summary/index.js +17 -3
  41. package/dist/cjs/vis/table/index.d.ts +1 -0
  42. package/dist/cjs/vis/table/index.js +37 -1
  43. package/dist/cjs/vis/treemap/index.js +2 -1
  44. package/dist/cjs/vis/venn/index.d.ts +2 -1
  45. package/dist/cjs/vis/venn/index.js +18 -3
  46. package/dist/cjs/vis/violin/index.js +2 -1
  47. package/dist/cjs/vis/waterfall/index.d.ts +6 -9
  48. package/dist/cjs/vis/waterfall/index.js +29 -6
  49. package/dist/cjs/vis/word-cloud/index.js +2 -1
  50. package/dist/cjs/vis-wrapper/icons.js +2 -2
  51. package/dist/cjs/vis-wrapper/index.d.ts +1 -0
  52. package/dist/cjs/vis-wrapper/index.js +27 -16
  53. package/dist/cjs/vis-wrapper/styles.d.ts +1 -1
  54. package/dist/cjs/vis-wrapper/styles.js +8 -1
  55. package/dist/esm/gpt-vis/index.d.ts +8 -1
  56. package/dist/esm/gpt-vis/index.js +47 -26
  57. package/dist/esm/index.d.ts +15 -2
  58. package/dist/esm/index.js +7 -1
  59. package/dist/esm/syntax/parser.d.ts +17 -2
  60. package/dist/esm/syntax/parser.js +248 -90
  61. package/dist/esm/util/container.d.ts +5 -0
  62. package/dist/esm/util/container.js +20 -0
  63. package/dist/esm/util/theme.d.ts +5 -0
  64. package/dist/esm/util/theme.js +9 -0
  65. package/dist/esm/vis/area/index.js +3 -2
  66. package/dist/esm/vis/bar/index.js +7 -6
  67. package/dist/esm/vis/boxplot/index.js +17 -4
  68. package/dist/esm/vis/column/index.js +7 -6
  69. package/dist/esm/vis/dual-axes/index.js +13 -5
  70. package/dist/esm/vis/fishbone-diagram/index.d.ts +35 -0
  71. package/dist/esm/vis/fishbone-diagram/index.js +219 -0
  72. package/dist/esm/vis/flow-diagram/index.d.ts +27 -0
  73. package/dist/esm/vis/flow-diagram/index.js +349 -0
  74. package/dist/esm/vis/funnel/index.js +3 -2
  75. package/dist/esm/vis/histogram/index.js +6 -7
  76. package/dist/esm/vis/indented-tree/index.d.ts +40 -0
  77. package/dist/esm/vis/indented-tree/index.js +569 -0
  78. package/dist/esm/vis/line/index.js +3 -2
  79. package/dist/esm/vis/liquid/index.js +3 -2
  80. package/dist/esm/vis/mindmap/index.d.ts +32 -0
  81. package/dist/esm/vis/mindmap/index.js +316 -0
  82. package/dist/esm/vis/network-graph/index.d.ts +59 -0
  83. package/dist/esm/vis/network-graph/index.js +242 -0
  84. package/dist/esm/vis/organization-chart/index.d.ts +64 -0
  85. package/dist/esm/vis/organization-chart/index.js +271 -0
  86. package/dist/esm/vis/pie/index.js +4 -8
  87. package/dist/esm/vis/radar/index.d.ts +1 -0
  88. package/dist/esm/vis/radar/index.js +20 -4
  89. package/dist/esm/vis/sankey/index.js +3 -2
  90. package/dist/esm/vis/scatter/index.d.ts +2 -0
  91. package/dist/esm/vis/scatter/index.js +15 -4
  92. package/dist/esm/vis/summary/index.js +25 -4
  93. package/dist/esm/vis/table/index.d.ts +1 -0
  94. package/dist/esm/vis/table/index.js +9 -2
  95. package/dist/esm/vis/treemap/index.js +3 -2
  96. package/dist/esm/vis/venn/index.d.ts +2 -1
  97. package/dist/esm/vis/venn/index.js +29 -4
  98. package/dist/esm/vis/violin/index.js +3 -2
  99. package/dist/esm/vis/waterfall/index.d.ts +6 -9
  100. package/dist/esm/vis/waterfall/index.js +33 -13
  101. package/dist/esm/vis/word-cloud/index.js +3 -2
  102. package/dist/esm/vis-wrapper/icons.js +2 -2
  103. package/dist/esm/vis-wrapper/index.d.ts +1 -0
  104. package/dist/esm/vis-wrapper/index.js +15 -10
  105. package/dist/esm/vis-wrapper/styles.d.ts +1 -1
  106. package/dist/esm/vis-wrapper/styles.js +1 -1
  107. package/dist/umd/index.min.js +1 -1
  108. package/package.json +17 -21
  109. package/src/gpt-vis/index.ts +0 -283
  110. package/src/index.ts +0 -44
  111. package/src/readme.md +0 -37
  112. package/src/syntax/index.ts +0 -2
  113. package/src/syntax/parser.ts +0 -411
  114. package/src/types/index.ts +0 -29
  115. package/src/util/theme.ts +0 -167
  116. package/src/vis/area/README.md +0 -143
  117. package/src/vis/area/index.ts +0 -212
  118. package/src/vis/bar/README.md +0 -158
  119. package/src/vis/bar/index.ts +0 -186
  120. package/src/vis/boxplot/README.md +0 -168
  121. package/src/vis/boxplot/index.ts +0 -162
  122. package/src/vis/column/README.md +0 -158
  123. package/src/vis/column/index.ts +0 -185
  124. package/src/vis/dual-axes/README.md +0 -191
  125. package/src/vis/dual-axes/index.ts +0 -218
  126. package/src/vis/funnel/README.md +0 -143
  127. package/src/vis/funnel/index.ts +0 -238
  128. package/src/vis/histogram/README.md +0 -130
  129. package/src/vis/histogram/index.ts +0 -153
  130. package/src/vis/line/README.md +0 -138
  131. package/src/vis/line/index.ts +0 -159
  132. package/src/vis/liquid/README.md +0 -150
  133. package/src/vis/liquid/index.ts +0 -130
  134. package/src/vis/pie/README.md +0 -127
  135. package/src/vis/pie/index.ts +0 -163
  136. package/src/vis/radar/README.md +0 -184
  137. package/src/vis/radar/index.ts +0 -214
  138. package/src/vis/sankey/README.md +0 -144
  139. package/src/vis/sankey/index.ts +0 -144
  140. package/src/vis/scatter/README.md +0 -145
  141. package/src/vis/scatter/index.ts +0 -147
  142. package/src/vis/summary/README.md +0 -272
  143. package/src/vis/summary/index.ts +0 -91
  144. package/src/vis/table/README.md +0 -174
  145. package/src/vis/table/index.ts +0 -241
  146. package/src/vis/treemap/README.md +0 -199
  147. package/src/vis/treemap/index.ts +0 -167
  148. package/src/vis/venn/README.md +0 -153
  149. package/src/vis/venn/index.ts +0 -149
  150. package/src/vis/violin/README.md +0 -168
  151. package/src/vis/violin/index.ts +0 -216
  152. package/src/vis/waterfall/README.md +0 -178
  153. package/src/vis/waterfall/index.ts +0 -258
  154. package/src/vis/word-cloud/README.md +0 -137
  155. package/src/vis/word-cloud/index.ts +0 -137
  156. package/src/vis-wrapper/README.md +0 -159
  157. package/src/vis-wrapper/icons.ts +0 -35
  158. package/src/vis-wrapper/index.ts +0 -276
  159. package/src/vis-wrapper/styles.ts +0 -195
@@ -0,0 +1,385 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/vis/indented-tree/index.ts
20
+ var indented_tree_exports = {};
21
+ __export(indented_tree_exports, {
22
+ IndentedTree: () => IndentedTree
23
+ });
24
+ module.exports = __toCommonJS(indented_tree_exports);
25
+ var import_g6 = require("@antv/g6");
26
+ var import_theme = require("../../util/theme");
27
+ var TreeEvent = {
28
+ COLLAPSE_EXPAND: "collapse-expand",
29
+ ADD_CHILD: "add-child"
30
+ };
31
+ var _iconfontInjected = false;
32
+ function ensureIconfontInjected() {
33
+ if (_iconfontInjected)
34
+ return;
35
+ if (typeof document === "undefined")
36
+ return;
37
+ const style = document.createElement("style");
38
+ style.innerHTML = `@import url('${import_g6.iconfont.css}');`;
39
+ document.head.appendChild(style);
40
+ _iconfontInjected = true;
41
+ }
42
+ var _measureCanvas = null;
43
+ var _measureCtx = null;
44
+ function measureTextWidth(text, fontSize = 12) {
45
+ if (!text)
46
+ return 0;
47
+ if (typeof document === "undefined" || typeof HTMLCanvasElement === "undefined") {
48
+ let w = 0;
49
+ for (const ch of text)
50
+ w += ch.charCodeAt(0) > 19968 ? fontSize : fontSize * 0.6;
51
+ return w;
52
+ }
53
+ if (!_measureCanvas) {
54
+ _measureCanvas = document.createElement("canvas");
55
+ _measureCtx = _measureCanvas.getContext("2d");
56
+ }
57
+ if (!_measureCtx)
58
+ return text.length * fontSize * 0.6;
59
+ _measureCtx.font = `${fontSize}px system-ui,-apple-system,BlinkMacSystemFont,sans-serif`;
60
+ return _measureCtx.measureText(text).width;
61
+ }
62
+ var _IndentedNode = class extends import_g6.BaseNode {
63
+ constructor(options) {
64
+ Object.assign(options.style, _IndentedNode.defaultStyleProps);
65
+ super(options);
66
+ }
67
+ get childrenData() {
68
+ return this.context.model.getChildrenData(this.id);
69
+ }
70
+ getKeyStyle(attributes) {
71
+ const [width, height] = this.getSize(attributes);
72
+ const keyStyle = super.getKeyStyle(attributes);
73
+ return { width, height, ...keyStyle, fill: "transparent" };
74
+ }
75
+ drawKeyShape(attributes, container) {
76
+ const keyStyle = this.getKeyStyle(attributes);
77
+ return this.upsert("key", "rect", keyStyle, container);
78
+ }
79
+ getLabelStyle(attributes) {
80
+ if (attributes.label === false || !attributes.labelText)
81
+ return false;
82
+ return (0, import_g6.subStyleProps)(this.getGraphicStyle(attributes), "label");
83
+ }
84
+ drawIconArea(attributes, container) {
85
+ const [, h] = this.getSize(attributes);
86
+ const iconAreaStyle = { fill: "transparent", height: 30, width: 12, x: -6, y: h, zIndex: -1 };
87
+ this.upsert("icon-area", "rect", iconAreaStyle, container);
88
+ }
89
+ forwardEvent(target, type, listener) {
90
+ if (target && !Reflect.has(target, "__bind__")) {
91
+ Reflect.set(target, "__bind__", true);
92
+ target.addEventListener(type, listener);
93
+ }
94
+ }
95
+ getCountStyle(attributes) {
96
+ const { collapsed, color } = attributes;
97
+ if (collapsed) {
98
+ const [, height] = this.getSize(attributes);
99
+ return {
100
+ backgroundFill: color,
101
+ cursor: "pointer",
102
+ fill: "#fff",
103
+ fontSize: 8,
104
+ padding: [0, 10],
105
+ text: `${this.childrenData.length}`,
106
+ textAlign: "center",
107
+ y: height + 8
108
+ };
109
+ }
110
+ return false;
111
+ }
112
+ drawCountShape(attributes, container) {
113
+ const countStyle = this.getCountStyle(attributes);
114
+ const btn = this.upsert("count", import_g6.Badge, countStyle, container);
115
+ this.forwardEvent(btn, import_g6.CommonEvent.CLICK, (event) => {
116
+ event.stopPropagation();
117
+ this.context.graph.emit(TreeEvent.COLLAPSE_EXPAND, { id: this.id, collapsed: false });
118
+ });
119
+ }
120
+ isShowCollapse(attributes) {
121
+ return !attributes.collapsed && this.childrenData.length > 0;
122
+ }
123
+ getCollapseStyle(attributes) {
124
+ const { showIcon, color } = attributes;
125
+ if (!this.isShowCollapse(attributes))
126
+ return false;
127
+ const [, height] = this.getSize(attributes);
128
+ return {
129
+ visibility: showIcon ? "visible" : "hidden",
130
+ backgroundFill: color,
131
+ backgroundHeight: 12,
132
+ backgroundWidth: 12,
133
+ cursor: "pointer",
134
+ fill: "#fff",
135
+ fontFamily: "iconfont",
136
+ fontSize: 8,
137
+ text: "",
138
+ textAlign: "center",
139
+ x: -1,
140
+ y: height + 8
141
+ };
142
+ }
143
+ drawCollapseShape(attributes, container) {
144
+ const iconStyle = this.getCollapseStyle(attributes);
145
+ const btn = this.upsert("collapse-expand", import_g6.Badge, iconStyle, container);
146
+ this.forwardEvent(btn, import_g6.CommonEvent.CLICK, (event) => {
147
+ event.stopPropagation();
148
+ this.context.graph.emit(TreeEvent.COLLAPSE_EXPAND, {
149
+ id: this.id,
150
+ collapsed: !attributes.collapsed
151
+ });
152
+ });
153
+ }
154
+ render(attributes = this.parsedAttributes, container = this) {
155
+ super.render(attributes, container);
156
+ this.drawCountShape(attributes, container);
157
+ this.drawIconArea(attributes, container);
158
+ this.drawCollapseShape(attributes, container);
159
+ }
160
+ };
161
+ var IndentedNode = _IndentedNode;
162
+ IndentedNode.defaultStyleProps = {
163
+ ports: [
164
+ { key: "in", placement: "right-bottom" },
165
+ { key: "out", placement: "left-bottom" }
166
+ ]
167
+ };
168
+ var IndentedEdge = class extends import_g6.Polyline {
169
+ getControlPoints(attributes) {
170
+ const [sourcePoint, targetPoint] = this.getEndpoints(attributes, false);
171
+ const [sx] = sourcePoint;
172
+ const [, ty] = targetPoint;
173
+ return [[sx, ty]];
174
+ }
175
+ };
176
+ var CollapseExpandTree = class extends import_g6.BaseBehavior {
177
+ constructor(context, options) {
178
+ super(context, options);
179
+ this.status = "idle";
180
+ this.showIcon = (event) => {
181
+ this.setIcon(event, true);
182
+ };
183
+ this.hideIcon = (event) => {
184
+ this.setIcon(event, false);
185
+ };
186
+ this.setIcon = (event, show) => {
187
+ var _a;
188
+ if (this.status !== "idle")
189
+ return;
190
+ const { target } = event;
191
+ const id = target.id;
192
+ const { graph, element } = this.context;
193
+ graph.updateNodeData([{ id, style: { showIcon: show } }]);
194
+ (_a = element == null ? void 0 : element.draw) == null ? void 0 : _a.call(element, { animation: false, silence: true });
195
+ };
196
+ this.onCollapseExpand = async (event) => {
197
+ this.status = "busy";
198
+ const { id, collapsed } = event;
199
+ const { graph } = this.context;
200
+ if (collapsed)
201
+ await graph.collapseElement(id);
202
+ else
203
+ await graph.expandElement(id);
204
+ this.status = "idle";
205
+ };
206
+ // GPT-Vis 版本只保留官方的折叠/展开交互;新增子节点会引入额外数据模型管理,暂不启用。
207
+ this.addChild = () => {
208
+ };
209
+ this.bindEvents();
210
+ }
211
+ update(options) {
212
+ this.unbindEvents();
213
+ super.update(options);
214
+ this.bindEvents();
215
+ }
216
+ bindEvents() {
217
+ const { graph } = this.context;
218
+ graph.on(import_g6.NodeEvent.POINTER_ENTER, this.showIcon);
219
+ graph.on(import_g6.NodeEvent.POINTER_LEAVE, this.hideIcon);
220
+ graph.on(TreeEvent.COLLAPSE_EXPAND, this.onCollapseExpand);
221
+ graph.on(TreeEvent.ADD_CHILD, this.addChild);
222
+ }
223
+ unbindEvents() {
224
+ const { graph } = this.context;
225
+ graph.off(import_g6.NodeEvent.POINTER_ENTER, this.showIcon);
226
+ graph.off(import_g6.NodeEvent.POINTER_LEAVE, this.hideIcon);
227
+ graph.off(TreeEvent.COLLAPSE_EXPAND, this.onCollapseExpand);
228
+ graph.off(TreeEvent.ADD_CHILD, this.addChild);
229
+ }
230
+ };
231
+ var GPT_VIS_INDENTED_NODE = "gpt-vis-indented";
232
+ var GPT_VIS_INDENTED_EDGE = "gpt-vis-indented-edge";
233
+ var GPT_VIS_COLLAPSE_BEHAVIOR = "gpt-vis-collapse-expand-tree";
234
+ var _extensionsRegistered = false;
235
+ function ensureExtensionsRegistered() {
236
+ if (_extensionsRegistered)
237
+ return;
238
+ (0, import_g6.register)(import_g6.ExtensionCategory.NODE, GPT_VIS_INDENTED_NODE, IndentedNode);
239
+ (0, import_g6.register)(import_g6.ExtensionCategory.EDGE, GPT_VIS_INDENTED_EDGE, IndentedEdge);
240
+ (0, import_g6.register)(import_g6.ExtensionCategory.BEHAVIOR, GPT_VIS_COLLAPSE_BEHAVIOR, CollapseExpandTree);
241
+ _extensionsRegistered = true;
242
+ }
243
+ var NODE_HEIGHT = 20;
244
+ function toG6TreeData(node) {
245
+ return {
246
+ id: node.name,
247
+ children: (node.children || []).map(toG6TreeData)
248
+ };
249
+ }
250
+ var IndentedTree = (options) => {
251
+ const { container, width, height, theme: chartTheme = "default" } = options;
252
+ let graph = null;
253
+ const render = (config) => {
254
+ const { data, theme = chartTheme, title, style = {}, direction = "LR" } = config;
255
+ if (!(data == null ? void 0 : data.name)) {
256
+ throw new Error("IndentedTree: data with a name field is required");
257
+ }
258
+ if (graph) {
259
+ graph.destroy();
260
+ graph = null;
261
+ }
262
+ const containerEl = typeof container === "string" ? document.querySelector(container) : container;
263
+ if (!containerEl)
264
+ throw new Error("IndentedTree: container element not found");
265
+ containerEl.innerHTML = "";
266
+ const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
267
+ const isDark = theme === "dark";
268
+ const palette = (0, import_theme.normalizePalette)(style.palette, theme);
269
+ containerEl.style.background = backgroundColor;
270
+ containerEl.style.borderRadius = "4px";
271
+ containerEl.style.overflow = "hidden";
272
+ ensureIconfontInjected();
273
+ ensureExtensionsRegistered();
274
+ const rootId = data.name;
275
+ const graphData = (0, import_g6.treeToGraphData)(toG6TreeData(data));
276
+ graph = new import_g6.Graph({
277
+ animation: false,
278
+ container: containerEl,
279
+ x: 60,
280
+ width,
281
+ height,
282
+ autoFit: "view",
283
+ autoResize: true,
284
+ theme: (0, import_theme.getTheme)(theme),
285
+ padding: title ? [46, 20, 20, 20] : 20,
286
+ data: graphData,
287
+ node: {
288
+ type: GPT_VIS_INDENTED_NODE,
289
+ style: {
290
+ size: (d) => [measureTextWidth(String(d.id ?? ""), 12) + 6, NODE_HEIGHT],
291
+ labelBackground: (datum) => datum.id === rootId,
292
+ labelBackgroundRadius: theme === "academy" ? 0 : 4,
293
+ labelBackgroundFill: palette[0] ?? "#1783FF",
294
+ labelPadding: (datum) => datum.id === rootId ? [2, 8] : 0,
295
+ labelFill: (datum) => datum.id === rootId ? "#fff" : isDark ? "#d0d0d0" : "#666",
296
+ labelText: (d) => {
297
+ var _a;
298
+ return ((_a = d.style) == null ? void 0 : _a.labelText) || d.id;
299
+ },
300
+ labelTextAlign: (datum) => datum.id === rootId ? "center" : "left",
301
+ labelTextBaseline: "top",
302
+ color: (datum) => {
303
+ try {
304
+ const depth = graph.getAncestorsData(datum.id, "tree").length - 1;
305
+ return palette[depth % palette.length] ?? palette[0] ?? "#1783FF";
306
+ } catch {
307
+ return palette[0] ?? "#1783FF";
308
+ }
309
+ }
310
+ },
311
+ state: {
312
+ selected: {
313
+ lineWidth: 0,
314
+ labelFill: "#40A8FF",
315
+ labelBackground: true,
316
+ labelFontWeight: "normal",
317
+ labelBackgroundFill: "#e8f7ff",
318
+ labelBackgroundRadius: 10
319
+ }
320
+ }
321
+ },
322
+ edge: {
323
+ type: GPT_VIS_INDENTED_EDGE,
324
+ style: {
325
+ radius: 16,
326
+ lineWidth: 2,
327
+ sourcePort: "out",
328
+ targetPort: "in",
329
+ stroke: (datum) => {
330
+ try {
331
+ if ((datum == null ? void 0 : datum.source) == null)
332
+ return palette[0] ?? "#1783FF";
333
+ const depth = graph.getAncestorsData(datum.source, "tree").length;
334
+ return palette[depth % palette.length] ?? palette[0] ?? "#1783FF";
335
+ } catch {
336
+ return palette[0] ?? "#1783FF";
337
+ }
338
+ }
339
+ }
340
+ },
341
+ layout: {
342
+ type: "indented",
343
+ direction,
344
+ isHorizontal: true,
345
+ indent: 40,
346
+ getHeight: () => NODE_HEIGHT,
347
+ getVGap: () => 10
348
+ },
349
+ behaviors: [
350
+ "drag-canvas",
351
+ GPT_VIS_COLLAPSE_BEHAVIOR,
352
+ {
353
+ type: "click-select",
354
+ enable: (event) => event.targetType === "node" && event.target.id !== rootId
355
+ }
356
+ ],
357
+ plugins: title ? [
358
+ {
359
+ key: "title",
360
+ type: "title",
361
+ title,
362
+ titleFill: isDark ? "#e0e6ed" : "#000",
363
+ titleFontFamily: "sans-serif"
364
+ }
365
+ ] : []
366
+ });
367
+ graph.render();
368
+ };
369
+ const destroy = () => {
370
+ if (graph) {
371
+ graph.destroy();
372
+ graph = null;
373
+ }
374
+ };
375
+ return {
376
+ render,
377
+ destroy,
378
+ zoomTo: (zoom) => graph == null ? void 0 : graph.zoomTo(zoom),
379
+ getZoom: () => graph == null ? void 0 : graph.getZoom()
380
+ };
381
+ };
382
+ // Annotate the CommonJS export names for ESM import in node:
383
+ 0 && (module.exports = {
384
+ IndentedTree
385
+ });
@@ -35,7 +35,7 @@ var Line = (options) => {
35
35
  }
36
36
  const { lineWidth = 2 } = style;
37
37
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
38
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
38
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
39
39
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
40
40
  chart = new import_g2.Chart({
41
41
  container,
@@ -52,6 +52,7 @@ var Line = (options) => {
52
52
  encode = { x: "time", y: "value" };
53
53
  }
54
54
  const chartOptions = {
55
+ animate: false,
55
56
  type: "view",
56
57
  data,
57
58
  title: title ?? "",
@@ -34,7 +34,7 @@ var Liquid = (options) => {
34
34
  if (chart) {
35
35
  chart.destroy();
36
36
  }
37
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
37
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
38
38
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
39
39
  const inferFontSize = Math.min(width ?? DEFAULT_WIDTH, height ?? DEFAULT_HEIGHT) / 10;
40
40
  const fontSize = Math.min(Math.max(inferFontSize, 24), 64);
@@ -45,6 +45,7 @@ var Liquid = (options) => {
45
45
  autoFit: true
46
46
  });
47
47
  const chartOptions = {
48
+ animate: false,
48
49
  type: "liquid",
49
50
  data: percent,
50
51
  title: title ?? "",
@@ -0,0 +1,32 @@
1
+ import type { TreeGraphData, VisualizationOptions } from '../../types';
2
+ export type MindmapData = TreeGraphData;
3
+ /**
4
+ * MindmapConfig defines the configuration for rendering the mindmap.
5
+ */
6
+ export interface MindmapConfig {
7
+ type?: 'mindmap';
8
+ data: MindmapData;
9
+ direction?: 'H' | 'LR' | 'RL';
10
+ theme?: 'default' | 'academy' | 'dark';
11
+ title?: string;
12
+ style?: {
13
+ backgroundColor?: string;
14
+ palette?: string[];
15
+ };
16
+ }
17
+ /**
18
+ * MindmapInstance represents a mindmap instance with render and destroy methods.
19
+ */
20
+ export interface MindmapInstance {
21
+ render: (config: MindmapConfig) => void;
22
+ destroy: () => void;
23
+ zoomTo: (zoom: number) => void;
24
+ getZoom: () => number | undefined;
25
+ }
26
+ /** Props type for SSR package to import */
27
+ export type MindMapProps = Pick<MindmapConfig, 'data' | 'direction'>;
28
+ /**
29
+ * Mindmap component using G6 5.0 with mindmap layout.
30
+ * Follows the "boxed" type style from 0.x @ant-design/graphs MindMap.
31
+ */
32
+ export declare const Mindmap: (options: VisualizationOptions) => MindmapInstance;
@@ -0,0 +1,222 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/vis/mindmap/index.ts
20
+ var mindmap_exports = {};
21
+ __export(mindmap_exports, {
22
+ Mindmap: () => Mindmap
23
+ });
24
+ module.exports = __toCommonJS(mindmap_exports);
25
+ var import_g6 = require("@antv/g6");
26
+ var import_theme = require("../../util/theme");
27
+ function toG6TreeData(node) {
28
+ return {
29
+ id: node.name,
30
+ children: (node.children || []).map(toG6TreeData)
31
+ };
32
+ }
33
+ function convertTreeData(treeData) {
34
+ return (0, import_g6.treeToGraphData)(toG6TreeData(treeData), {
35
+ getNodeData: (datum, depth) => {
36
+ datum.depth = depth;
37
+ if (!datum.children)
38
+ return datum;
39
+ const { children, ...rest } = datum;
40
+ return {
41
+ ...rest,
42
+ children: children.map((child) => child.id)
43
+ };
44
+ }
45
+ });
46
+ }
47
+ function assignBranchColors(graphData, colors) {
48
+ const nodes = graphData.nodes || [];
49
+ let colorIndex = 0;
50
+ const nodeMap = /* @__PURE__ */ new Map();
51
+ for (const node of nodes) {
52
+ nodeMap.set(String(node.id), node);
53
+ }
54
+ const dfs = (nodeId, color) => {
55
+ var _a;
56
+ const node = nodeMap.get(String(nodeId));
57
+ if (!node)
58
+ return;
59
+ node.style = node.style || {};
60
+ node.style.color = color || colors[colorIndex++ % colors.length];
61
+ (_a = node.children) == null ? void 0 : _a.forEach((childId) => dfs(childId, node.style.color));
62
+ };
63
+ nodes.filter((n) => n.depth === 1).forEach((n) => dfs(String(n.id)));
64
+ }
65
+ function getNodeSide(nodeData, parentData) {
66
+ if (!parentData)
67
+ return "center";
68
+ return (0, import_g6.positionOf)(parentData)[0] > (0, import_g6.positionOf)(nodeData)[0] ? "left" : "right";
69
+ }
70
+ function estimateNodeWidth(text, fontSize, padding) {
71
+ const avgCharWidth = fontSize * 0.58;
72
+ const cjkCount = (text.match(/[\u4e00-\u9fff\u3000-\u303f\uff00-\uffef]/g) || []).length;
73
+ const otherCount = text.length - cjkCount;
74
+ const textWidth = cjkCount * fontSize + otherCount * avgCharWidth;
75
+ return Math.min(Math.max(textWidth + padding, 120), 300);
76
+ }
77
+ var Mindmap = (options) => {
78
+ const { container, width, height, theme: chartTheme = "default" } = options;
79
+ let graph = null;
80
+ const render = (config) => {
81
+ const { data, direction = "H", theme = chartTheme, title, style = {} } = config;
82
+ if (!data || !data.name) {
83
+ throw new Error("Mindmap: data with a name field is required");
84
+ }
85
+ if (graph) {
86
+ graph.destroy();
87
+ graph = null;
88
+ }
89
+ const containerEl = typeof container === "string" ? document.querySelector(container) : container;
90
+ if (!containerEl) {
91
+ throw new Error("Mindmap: container element not found");
92
+ }
93
+ containerEl.innerHTML = "";
94
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
95
+ const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
96
+ const isDark = theme === "dark";
97
+ containerEl.style.background = backgroundColor;
98
+ const graphData = convertTreeData(data);
99
+ assignBranchColors(graphData, colors);
100
+ for (const node of graphData.nodes || []) {
101
+ const label = String(node.id);
102
+ const depth = node.depth ?? 0;
103
+ const fontSize = depth === 0 ? 24 : 16;
104
+ const pad = depth === 0 ? 64 : 36;
105
+ node.layoutSize = [estimateNodeWidth(label, fontSize, pad), depth === 0 ? 60 : 48];
106
+ }
107
+ graph = new import_g6.Graph({
108
+ animation: false,
109
+ container: containerEl,
110
+ width,
111
+ height,
112
+ autoFit: "view",
113
+ autoResize: true,
114
+ padding: title ? [46, 20, 20, 20] : 20,
115
+ zoomRange: [0.1, 5],
116
+ zoom: 1,
117
+ theme: (0, import_theme.getTheme)(theme),
118
+ data: graphData,
119
+ plugins: title ? [
120
+ {
121
+ key: "title",
122
+ type: "title",
123
+ title,
124
+ titleFill: isDark ? "#e0e6ed" : "#000",
125
+ titleFontFamily: "sans-serif"
126
+ }
127
+ ] : [],
128
+ node: {
129
+ type: "rect",
130
+ animation: { translate: false, update: false },
131
+ style: function(d) {
132
+ var _a;
133
+ const depth = d.depth ?? 0;
134
+ const color = (_a = d.style) == null ? void 0 : _a.color;
135
+ const label = String((0, import_g6.idOf)(d));
136
+ const parentData = this.getParentData((0, import_g6.idOf)(d), "tree");
137
+ const [nodeWidth, nodeHeight] = d.layoutSize || [120, 48];
138
+ const side = direction === "RL" ? "left" : direction === "LR" ? "right" : getNodeSide(d, parentData);
139
+ const fontSize = depth === 0 ? 24 : 16;
140
+ const fontWeight = depth <= 1 ? 600 : 400;
141
+ const dx = side === "left" ? -nodeWidth : side === "center" ? -nodeWidth / 2 : 0;
142
+ const base = {
143
+ size: [nodeWidth, nodeHeight],
144
+ dx,
145
+ radius: theme === "academy" ? 0 : 8,
146
+ labelText: label,
147
+ labelPlacement: "center",
148
+ labelFontSize: fontSize,
149
+ labelFontWeight: fontWeight,
150
+ ports: [{ placement: "left" }, { placement: "right" }]
151
+ };
152
+ if (depth === 0) {
153
+ return {
154
+ ...base,
155
+ fill: isDark ? "#333" : "#f1f4f5",
156
+ labelFill: isDark ? "#e0e0e0" : "#252525"
157
+ };
158
+ }
159
+ if (depth === 1) {
160
+ return {
161
+ ...base,
162
+ fill: color || "#99ADD1",
163
+ labelFill: "#fff"
164
+ };
165
+ }
166
+ return {
167
+ ...base,
168
+ fill: backgroundColor,
169
+ stroke: color || (isDark ? "#555" : "#99ADD1"),
170
+ lineWidth: 3,
171
+ labelFill: isDark ? color || "#ccc" : color || "#333"
172
+ };
173
+ }
174
+ },
175
+ edge: {
176
+ type: "cubic-horizontal",
177
+ animation: { translate: false, update: false },
178
+ style: {
179
+ lineWidth: 3,
180
+ stroke: function(edgeData) {
181
+ var _a;
182
+ const sourceNode = this.getNodeData(edgeData.source);
183
+ return ((_a = sourceNode == null ? void 0 : sourceNode.style) == null ? void 0 : _a.color) || (isDark ? "#555" : "#99ADD1");
184
+ }
185
+ }
186
+ },
187
+ layout: {
188
+ type: "mindmap",
189
+ direction,
190
+ preLayout: false,
191
+ getWidth: (nodeData) => {
192
+ var _a;
193
+ return ((_a = nodeData.layoutSize) == null ? void 0 : _a[0]) ?? 120;
194
+ },
195
+ getHeight: (nodeData) => {
196
+ var _a;
197
+ return ((_a = nodeData.layoutSize) == null ? void 0 : _a[1]) ?? 48;
198
+ },
199
+ getHGap: () => 64,
200
+ getVGap: () => 14
201
+ },
202
+ behaviors: ["drag-canvas"]
203
+ });
204
+ graph.render();
205
+ };
206
+ const destroy = () => {
207
+ if (graph) {
208
+ graph.destroy();
209
+ graph = null;
210
+ }
211
+ };
212
+ return {
213
+ render,
214
+ destroy,
215
+ zoomTo: (zoom) => graph == null ? void 0 : graph.zoomTo(zoom),
216
+ getZoom: () => graph == null ? void 0 : graph.getZoom()
217
+ };
218
+ };
219
+ // Annotate the CommonJS export names for ESM import in node:
220
+ 0 && (module.exports = {
221
+ Mindmap
222
+ });