@antv/gpt-vis 1.0.0-beta.1 → 1.0.0-beta.2

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 (157) hide show
  1. package/README.md +6 -4
  2. package/README.zh-CN.md +6 -4
  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 +2 -1
  18. package/dist/cjs/vis/fishbone-diagram/index.d.ts +35 -0
  19. package/dist/cjs/vis/fishbone-diagram/index.js +183 -0
  20. package/dist/cjs/vis/flow-diagram/index.d.ts +27 -0
  21. package/dist/cjs/vis/flow-diagram/index.js +271 -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 +375 -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 +214 -0
  30. package/dist/cjs/vis/network-graph/index.d.ts +59 -0
  31. package/dist/cjs/vis/network-graph/index.js +166 -0
  32. package/dist/cjs/vis/organization-chart/index.d.ts +64 -0
  33. package/dist/cjs/vis/organization-chart/index.js +191 -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.js +2 -1
  39. package/dist/cjs/vis/summary/index.js +17 -3
  40. package/dist/cjs/vis/table/index.d.ts +1 -0
  41. package/dist/cjs/vis/table/index.js +37 -1
  42. package/dist/cjs/vis/treemap/index.js +2 -1
  43. package/dist/cjs/vis/venn/index.d.ts +2 -1
  44. package/dist/cjs/vis/venn/index.js +18 -3
  45. package/dist/cjs/vis/violin/index.js +2 -1
  46. package/dist/cjs/vis/waterfall/index.d.ts +6 -9
  47. package/dist/cjs/vis/waterfall/index.js +28 -5
  48. package/dist/cjs/vis/word-cloud/index.js +2 -1
  49. package/dist/cjs/vis-wrapper/icons.js +2 -2
  50. package/dist/cjs/vis-wrapper/index.d.ts +1 -0
  51. package/dist/cjs/vis-wrapper/index.js +27 -16
  52. package/dist/cjs/vis-wrapper/styles.d.ts +1 -1
  53. package/dist/cjs/vis-wrapper/styles.js +8 -1
  54. package/dist/esm/gpt-vis/index.d.ts +8 -1
  55. package/dist/esm/gpt-vis/index.js +47 -26
  56. package/dist/esm/index.d.ts +15 -2
  57. package/dist/esm/index.js +7 -1
  58. package/dist/esm/syntax/parser.d.ts +17 -2
  59. package/dist/esm/syntax/parser.js +248 -90
  60. package/dist/esm/util/container.d.ts +5 -0
  61. package/dist/esm/util/container.js +20 -0
  62. package/dist/esm/util/theme.d.ts +5 -0
  63. package/dist/esm/util/theme.js +9 -0
  64. package/dist/esm/vis/area/index.js +3 -2
  65. package/dist/esm/vis/bar/index.js +7 -6
  66. package/dist/esm/vis/boxplot/index.js +17 -4
  67. package/dist/esm/vis/column/index.js +7 -6
  68. package/dist/esm/vis/dual-axes/index.js +3 -2
  69. package/dist/esm/vis/fishbone-diagram/index.d.ts +35 -0
  70. package/dist/esm/vis/fishbone-diagram/index.js +218 -0
  71. package/dist/esm/vis/flow-diagram/index.d.ts +27 -0
  72. package/dist/esm/vis/flow-diagram/index.js +342 -0
  73. package/dist/esm/vis/funnel/index.js +3 -2
  74. package/dist/esm/vis/histogram/index.js +6 -7
  75. package/dist/esm/vis/indented-tree/index.d.ts +40 -0
  76. package/dist/esm/vis/indented-tree/index.js +564 -0
  77. package/dist/esm/vis/line/index.js +3 -2
  78. package/dist/esm/vis/liquid/index.js +3 -2
  79. package/dist/esm/vis/mindmap/index.d.ts +32 -0
  80. package/dist/esm/vis/mindmap/index.js +315 -0
  81. package/dist/esm/vis/network-graph/index.d.ts +59 -0
  82. package/dist/esm/vis/network-graph/index.js +240 -0
  83. package/dist/esm/vis/organization-chart/index.d.ts +64 -0
  84. package/dist/esm/vis/organization-chart/index.js +269 -0
  85. package/dist/esm/vis/pie/index.js +4 -8
  86. package/dist/esm/vis/radar/index.d.ts +1 -0
  87. package/dist/esm/vis/radar/index.js +20 -4
  88. package/dist/esm/vis/sankey/index.js +3 -2
  89. package/dist/esm/vis/scatter/index.js +3 -2
  90. package/dist/esm/vis/summary/index.js +25 -4
  91. package/dist/esm/vis/table/index.d.ts +1 -0
  92. package/dist/esm/vis/table/index.js +9 -2
  93. package/dist/esm/vis/treemap/index.js +3 -2
  94. package/dist/esm/vis/venn/index.d.ts +2 -1
  95. package/dist/esm/vis/venn/index.js +29 -4
  96. package/dist/esm/vis/violin/index.js +3 -2
  97. package/dist/esm/vis/waterfall/index.d.ts +6 -9
  98. package/dist/esm/vis/waterfall/index.js +27 -9
  99. package/dist/esm/vis/word-cloud/index.js +3 -2
  100. package/dist/esm/vis-wrapper/icons.js +2 -2
  101. package/dist/esm/vis-wrapper/index.d.ts +1 -0
  102. package/dist/esm/vis-wrapper/index.js +15 -10
  103. package/dist/esm/vis-wrapper/styles.d.ts +1 -1
  104. package/dist/esm/vis-wrapper/styles.js +1 -1
  105. package/dist/umd/index.min.js +1 -1
  106. package/package.json +19 -19
  107. package/src/gpt-vis/index.ts +0 -283
  108. package/src/index.ts +0 -44
  109. package/src/readme.md +0 -37
  110. package/src/syntax/index.ts +0 -2
  111. package/src/syntax/parser.ts +0 -411
  112. package/src/types/index.ts +0 -29
  113. package/src/util/theme.ts +0 -167
  114. package/src/vis/area/README.md +0 -143
  115. package/src/vis/area/index.ts +0 -212
  116. package/src/vis/bar/README.md +0 -158
  117. package/src/vis/bar/index.ts +0 -186
  118. package/src/vis/boxplot/README.md +0 -168
  119. package/src/vis/boxplot/index.ts +0 -162
  120. package/src/vis/column/README.md +0 -158
  121. package/src/vis/column/index.ts +0 -185
  122. package/src/vis/dual-axes/README.md +0 -191
  123. package/src/vis/dual-axes/index.ts +0 -218
  124. package/src/vis/funnel/README.md +0 -143
  125. package/src/vis/funnel/index.ts +0 -238
  126. package/src/vis/histogram/README.md +0 -130
  127. package/src/vis/histogram/index.ts +0 -153
  128. package/src/vis/line/README.md +0 -138
  129. package/src/vis/line/index.ts +0 -159
  130. package/src/vis/liquid/README.md +0 -150
  131. package/src/vis/liquid/index.ts +0 -130
  132. package/src/vis/pie/README.md +0 -127
  133. package/src/vis/pie/index.ts +0 -163
  134. package/src/vis/radar/README.md +0 -184
  135. package/src/vis/radar/index.ts +0 -214
  136. package/src/vis/sankey/README.md +0 -144
  137. package/src/vis/sankey/index.ts +0 -144
  138. package/src/vis/scatter/README.md +0 -145
  139. package/src/vis/scatter/index.ts +0 -147
  140. package/src/vis/summary/README.md +0 -272
  141. package/src/vis/summary/index.ts +0 -91
  142. package/src/vis/table/README.md +0 -174
  143. package/src/vis/table/index.ts +0 -241
  144. package/src/vis/treemap/README.md +0 -199
  145. package/src/vis/treemap/index.ts +0 -167
  146. package/src/vis/venn/README.md +0 -153
  147. package/src/vis/venn/index.ts +0 -149
  148. package/src/vis/violin/README.md +0 -168
  149. package/src/vis/violin/index.ts +0 -216
  150. package/src/vis/waterfall/README.md +0 -178
  151. package/src/vis/waterfall/index.ts +0 -258
  152. package/src/vis/word-cloud/README.md +0 -137
  153. package/src/vis/word-cloud/index.ts +0 -137
  154. package/src/vis-wrapper/README.md +0 -159
  155. package/src/vis-wrapper/icons.ts +0 -35
  156. package/src/vis-wrapper/index.ts +0 -276
  157. package/src/vis-wrapper/styles.ts +0 -195
@@ -0,0 +1,375 @@
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
+ padding: 20,
285
+ data: graphData,
286
+ node: {
287
+ type: GPT_VIS_INDENTED_NODE,
288
+ style: {
289
+ size: (d) => [measureTextWidth(String(d.id ?? ""), 12) + 6, NODE_HEIGHT],
290
+ labelBackground: (datum) => datum.id === rootId,
291
+ labelBackgroundRadius: 0,
292
+ labelBackgroundFill: palette[0] ?? "#1783FF",
293
+ labelFill: (datum) => datum.id === rootId ? "#fff" : isDark ? "#d0d0d0" : "#666",
294
+ labelText: (d) => {
295
+ var _a;
296
+ return ((_a = d.style) == null ? void 0 : _a.labelText) || d.id;
297
+ },
298
+ labelTextAlign: (datum) => datum.id === rootId ? "center" : "left",
299
+ labelTextBaseline: "top",
300
+ color: (datum) => {
301
+ try {
302
+ const depth = graph.getAncestorsData(datum.id, "tree").length - 1;
303
+ return palette[depth % palette.length] ?? palette[0] ?? "#1783FF";
304
+ } catch {
305
+ return palette[0] ?? "#1783FF";
306
+ }
307
+ }
308
+ },
309
+ state: {
310
+ selected: {
311
+ lineWidth: 0,
312
+ labelFill: "#40A8FF",
313
+ labelBackground: true,
314
+ labelFontWeight: "normal",
315
+ labelBackgroundFill: "#e8f7ff",
316
+ labelBackgroundRadius: 10
317
+ }
318
+ }
319
+ },
320
+ edge: {
321
+ type: GPT_VIS_INDENTED_EDGE,
322
+ style: {
323
+ radius: 16,
324
+ lineWidth: 2,
325
+ sourcePort: "out",
326
+ targetPort: "in",
327
+ stroke: (datum) => {
328
+ try {
329
+ if ((datum == null ? void 0 : datum.source) == null)
330
+ return palette[0] ?? "#1783FF";
331
+ const depth = graph.getAncestorsData(datum.source, "tree").length;
332
+ return palette[depth % palette.length] ?? palette[0] ?? "#1783FF";
333
+ } catch {
334
+ return palette[0] ?? "#1783FF";
335
+ }
336
+ }
337
+ }
338
+ },
339
+ layout: {
340
+ type: "indented",
341
+ direction,
342
+ isHorizontal: true,
343
+ indent: 40,
344
+ getHeight: () => NODE_HEIGHT,
345
+ getVGap: () => 10
346
+ },
347
+ behaviors: [
348
+ "drag-canvas",
349
+ GPT_VIS_COLLAPSE_BEHAVIOR,
350
+ {
351
+ type: "click-select",
352
+ enable: (event) => event.targetType === "node" && event.target.id !== rootId
353
+ }
354
+ ],
355
+ plugins: title ? [{ key: "title", type: "title", title, titleFill: isDark ? "#e0e6ed" : "#1a1a2e" }] : []
356
+ });
357
+ graph.render();
358
+ };
359
+ const destroy = () => {
360
+ if (graph) {
361
+ graph.destroy();
362
+ graph = null;
363
+ }
364
+ };
365
+ return {
366
+ render,
367
+ destroy,
368
+ zoomTo: (zoom) => graph == null ? void 0 : graph.zoomTo(zoom),
369
+ getZoom: () => graph == null ? void 0 : graph.getZoom()
370
+ };
371
+ };
372
+ // Annotate the CommonJS export names for ESM import in node:
373
+ 0 && (module.exports = {
374
+ IndentedTree
375
+ });
@@ -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,214 @@
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: 20,
115
+ zoomRange: [0.1, 5],
116
+ zoom: 1,
117
+ theme: chartTheme,
118
+ data: graphData,
119
+ plugins: title ? [{ key: "title", type: "title", title, titleFill: isDark ? "#e0e6ed" : "#1a1a2e" }] : [],
120
+ node: {
121
+ type: "rect",
122
+ animation: { translate: false, update: false },
123
+ style: function(d) {
124
+ var _a;
125
+ const depth = d.depth ?? 0;
126
+ const color = (_a = d.style) == null ? void 0 : _a.color;
127
+ const label = String((0, import_g6.idOf)(d));
128
+ const parentData = this.getParentData((0, import_g6.idOf)(d), "tree");
129
+ const [nodeWidth, nodeHeight] = d.layoutSize || [120, 48];
130
+ const side = direction === "RL" ? "left" : direction === "LR" ? "right" : getNodeSide(d, parentData);
131
+ const fontSize = depth === 0 ? 24 : 16;
132
+ const fontWeight = depth <= 1 ? 600 : 400;
133
+ const dx = side === "left" ? -nodeWidth : side === "center" ? -nodeWidth / 2 : 0;
134
+ const base = {
135
+ size: [nodeWidth, nodeHeight],
136
+ dx,
137
+ radius: 8,
138
+ labelText: label,
139
+ labelPlacement: "center",
140
+ labelFontSize: fontSize,
141
+ labelFontWeight: fontWeight,
142
+ ports: [{ placement: "left" }, { placement: "right" }]
143
+ };
144
+ if (depth === 0) {
145
+ return {
146
+ ...base,
147
+ fill: isDark ? "#333" : "#f1f4f5",
148
+ labelFill: isDark ? "#e0e0e0" : "#252525"
149
+ };
150
+ }
151
+ if (depth === 1) {
152
+ return {
153
+ ...base,
154
+ fill: color || "#99ADD1",
155
+ labelFill: "#fff"
156
+ };
157
+ }
158
+ return {
159
+ ...base,
160
+ fill: backgroundColor,
161
+ stroke: color || (isDark ? "#555" : "#99ADD1"),
162
+ lineWidth: 3,
163
+ labelFill: isDark ? color || "#ccc" : color || "#333"
164
+ };
165
+ }
166
+ },
167
+ edge: {
168
+ type: "cubic-horizontal",
169
+ animation: { translate: false, update: false },
170
+ style: {
171
+ lineWidth: 3,
172
+ stroke: function(edgeData) {
173
+ var _a;
174
+ const sourceNode = this.getNodeData(edgeData.source);
175
+ return ((_a = sourceNode == null ? void 0 : sourceNode.style) == null ? void 0 : _a.color) || (isDark ? "#555" : "#99ADD1");
176
+ }
177
+ }
178
+ },
179
+ layout: {
180
+ type: "mindmap",
181
+ direction,
182
+ preLayout: false,
183
+ getWidth: (nodeData) => {
184
+ var _a;
185
+ return ((_a = nodeData.layoutSize) == null ? void 0 : _a[0]) ?? 120;
186
+ },
187
+ getHeight: (nodeData) => {
188
+ var _a;
189
+ return ((_a = nodeData.layoutSize) == null ? void 0 : _a[1]) ?? 48;
190
+ },
191
+ getHGap: () => 64,
192
+ getVGap: () => 14
193
+ },
194
+ behaviors: ["drag-canvas"]
195
+ });
196
+ graph.render();
197
+ };
198
+ const destroy = () => {
199
+ if (graph) {
200
+ graph.destroy();
201
+ graph = null;
202
+ }
203
+ };
204
+ return {
205
+ render,
206
+ destroy,
207
+ zoomTo: (zoom) => graph == null ? void 0 : graph.zoomTo(zoom),
208
+ getZoom: () => graph == null ? void 0 : graph.getZoom()
209
+ };
210
+ };
211
+ // Annotate the CommonJS export names for ESM import in node:
212
+ 0 && (module.exports = {
213
+ Mindmap
214
+ });