@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,191 @@
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/fishbone-diagram/index.ts
20
+ var fishbone_diagram_exports = {};
21
+ __export(fishbone_diagram_exports, {
22
+ FishboneDiagram: () => FishboneDiagram
23
+ });
24
+ module.exports = __toCommonJS(fishbone_diagram_exports);
25
+ var import_g6 = require("@antv/g6");
26
+ var import_theme = require("../../util/theme");
27
+ var FONT_FAMILY = "system-ui, sans-serif";
28
+ function getNodeSize(id, depth) {
29
+ return depth === 0 ? [measureText(id, 24, "bold") + 80, 70] : depth === 1 ? [measureText(id, 18) + 50, 42] : [2, 30];
30
+ }
31
+ var measureText = function() {
32
+ let canvas = null;
33
+ return (text, fontSize = 12, fontWeight = "normal") => {
34
+ if (typeof document === "undefined")
35
+ return text.length * fontSize * 0.6;
36
+ if (!canvas)
37
+ canvas = document.createElement("canvas");
38
+ const ctx = canvas.getContext("2d");
39
+ if (!ctx)
40
+ return 0;
41
+ ctx.font = `${fontWeight} ${fontSize}px ${FONT_FAMILY}`;
42
+ return ctx.measureText(text).width;
43
+ };
44
+ }();
45
+ function toG6TreeData(node) {
46
+ return {
47
+ id: node.name,
48
+ children: (node.children || []).map(toG6TreeData)
49
+ };
50
+ }
51
+ function convertData(data) {
52
+ return (0, import_g6.treeToGraphData)(toG6TreeData(data), {
53
+ getNodeData: (datum, depth) => {
54
+ datum.depth = depth;
55
+ if (!datum.children)
56
+ return datum;
57
+ const { children, ...rest } = datum;
58
+ return { ...rest, children: children.map((c) => c.id) };
59
+ }
60
+ });
61
+ }
62
+ function assignBranchColors(graphData, palette) {
63
+ const nodes = graphData.nodes || [];
64
+ let colorIndex = 0;
65
+ nodes.filter((n) => n.depth === 1).forEach((n) => {
66
+ n.style = n.style || {};
67
+ n.style.branchColor = palette[colorIndex++ % palette.length];
68
+ });
69
+ }
70
+ var FishboneDiagram = (options) => {
71
+ const { container, width, height, theme: chartTheme = "default" } = options;
72
+ let graph = null;
73
+ const render = (config) => {
74
+ const { data, theme = chartTheme, title, style = {} } = config;
75
+ if (!(data == null ? void 0 : data.name)) {
76
+ throw new Error("FishboneDiagram: data with a name field is required");
77
+ }
78
+ if (graph) {
79
+ graph.destroy();
80
+ graph = null;
81
+ }
82
+ const containerEl = typeof container === "string" ? document.querySelector(container) : container;
83
+ if (!containerEl)
84
+ throw new Error("FishboneDiagram: container element not found");
85
+ containerEl.innerHTML = "";
86
+ const isDark = theme === "dark";
87
+ const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
88
+ const palette = (0, import_theme.normalizePalette)(style.palette, theme);
89
+ const rootFill = isDark ? "#2a2a2a" : "#EFF0F0";
90
+ const rootLabelFill = isDark ? "#e0e0e0" : "#262626";
91
+ const leafLabelFill = isDark ? "#c0c0c0" : "#262626";
92
+ const edgeStroke = isDark ? "#555" : "#99ADD1";
93
+ containerEl.style.backgroundColor = backgroundColor;
94
+ const graphData = convertData(data);
95
+ assignBranchColors(graphData, palette);
96
+ graph = new import_g6.Graph({
97
+ animation: false,
98
+ container: containerEl,
99
+ width,
100
+ height,
101
+ autoFit: "view",
102
+ autoResize: true,
103
+ padding: title ? [46, 20, 20, 20] : 20,
104
+ theme: (0, import_theme.getTheme)(theme),
105
+ plugins: title ? [
106
+ {
107
+ key: "title",
108
+ type: "title",
109
+ title,
110
+ titleFill: isDark ? "#e0e6ed" : "#000",
111
+ titleFontFamily: "sans-serif"
112
+ }
113
+ ] : [],
114
+ data: graphData,
115
+ node: {
116
+ type: "rect",
117
+ style: (d) => {
118
+ var _a;
119
+ const depth = d.depth ?? 0;
120
+ const nodeStyle = {
121
+ radius: theme === "academy" ? 0 : 8,
122
+ size: getNodeSize(String(d.id), depth),
123
+ labelText: String(d.id),
124
+ labelPlacement: "left",
125
+ labelFontFamily: FONT_FAMILY
126
+ };
127
+ if (depth === 0) {
128
+ Object.assign(nodeStyle, {
129
+ fill: rootFill,
130
+ labelFill: rootLabelFill,
131
+ labelFontWeight: "bold",
132
+ labelFontSize: 24,
133
+ labelOffsetY: 4,
134
+ labelPlacement: "center"
135
+ });
136
+ } else if (depth === 1) {
137
+ const color = ((_a = d.style) == null ? void 0 : _a.branchColor) || palette[0];
138
+ Object.assign(nodeStyle, {
139
+ fill: color,
140
+ labelFill: "#fff",
141
+ labelFontSize: 18,
142
+ labelPlacement: "center"
143
+ });
144
+ } else {
145
+ Object.assign(nodeStyle, {
146
+ fill: "transparent",
147
+ labelFill: leafLabelFill,
148
+ labelFontSize: 16
149
+ });
150
+ }
151
+ if (style.texture === "rough") {
152
+ nodeStyle.lineWidth = 0.5;
153
+ }
154
+ return nodeStyle;
155
+ }
156
+ },
157
+ edge: {
158
+ type: "polyline",
159
+ style: {
160
+ lineWidth: 3,
161
+ stroke: edgeStroke,
162
+ ...style.texture === "rough" ? { labelFontFamily: "Comic Sans MS" } : {}
163
+ }
164
+ },
165
+ layout: {
166
+ type: "fishbone",
167
+ direction: "RL",
168
+ hGap: 40,
169
+ vGap: 60
170
+ },
171
+ behaviors: ["drag-canvas"]
172
+ });
173
+ graph.render();
174
+ };
175
+ const destroy = () => {
176
+ if (graph) {
177
+ graph.destroy();
178
+ graph = null;
179
+ }
180
+ };
181
+ return {
182
+ render,
183
+ destroy,
184
+ zoomTo: (zoom) => graph == null ? void 0 : graph.zoomTo(zoom),
185
+ getZoom: () => (graph == null ? void 0 : graph.getZoom()) ?? 1
186
+ };
187
+ };
188
+ // Annotate the CommonJS export names for ESM import in node:
189
+ 0 && (module.exports = {
190
+ FishboneDiagram
191
+ });
@@ -0,0 +1,27 @@
1
+ import type { GraphData, VisualizationOptions } from '../../types';
2
+ /**
3
+ * FlowDiagramConfig defines the configuration for rendering the flow diagram.
4
+ */
5
+ export interface FlowDiagramConfig {
6
+ type?: 'flow-diagram';
7
+ data: GraphData;
8
+ title?: string;
9
+ theme?: 'default' | 'academy' | 'dark';
10
+ style?: {
11
+ backgroundColor?: string;
12
+ palette?: string[];
13
+ };
14
+ }
15
+ /**
16
+ * FlowDiagramInstance represents a flow diagram instance with render and destroy methods.
17
+ */
18
+ export interface FlowDiagramInstance {
19
+ render: (config: FlowDiagramConfig) => void;
20
+ destroy: () => void;
21
+ zoomTo: (zoom: number) => void;
22
+ getZoom: () => number | undefined;
23
+ }
24
+ /**
25
+ * FlowDiagram chart component using G6 5.0 with dagre layout.
26
+ */
27
+ export declare const FlowDiagram: (options: VisualizationOptions) => FlowDiagramInstance;
@@ -0,0 +1,287 @@
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/flow-diagram/index.ts
20
+ var flow_diagram_exports = {};
21
+ __export(flow_diagram_exports, {
22
+ FlowDiagram: () => FlowDiagram
23
+ });
24
+ module.exports = __toCommonJS(flow_diagram_exports);
25
+ var import_g6 = require("@antv/g6");
26
+ var import_theme = require("../../util/theme");
27
+ var ACTIVE_COLOR = "#f6c523";
28
+ var DEFAULT_NODE_WIDTH = 200;
29
+ var DEFAULT_NODE_HEIGHT = 80;
30
+ var HoverElement = class extends import_g6.HoverActivate {
31
+ getActiveIds(event) {
32
+ const { model, graph } = this.context;
33
+ const { targetType, target } = event;
34
+ const targetId = target.id;
35
+ const ids = [targetId];
36
+ if (targetType === "edge") {
37
+ const edge = model.getEdgeDatum(targetId);
38
+ ids.push(edge.source, edge.target);
39
+ } else if (targetType === "node") {
40
+ ids.push(...model.getRelatedEdgesData(targetId).map(import_g6.idOf));
41
+ }
42
+ graph.frontElement(ids);
43
+ return ids;
44
+ }
45
+ };
46
+ var behaviorRegistered = false;
47
+ function ensureBehaviorRegistered() {
48
+ if (!behaviorRegistered) {
49
+ (0, import_g6.register)(import_g6.ExtensionCategory.BEHAVIOR, "hover-element", HoverElement);
50
+ behaviorRegistered = true;
51
+ }
52
+ }
53
+ function escapeHtml(str = "") {
54
+ return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
55
+ }
56
+ function createNodeHTML(d, color, selectedBorderColor = "#000", theme = "default") {
57
+ var _a, _b, _c;
58
+ const text = escapeHtml(((_a = d.data) == null ? void 0 : _a.text) || "");
59
+ const isHovered = (_b = d.states) == null ? void 0 : _b.includes("active");
60
+ const isSelected = (_c = d.states) == null ? void 0 : _c.includes("selected");
61
+ const nodeColor = isHovered ? ACTIVE_COLOR : color;
62
+ const borderRadius = theme === "academy" ? "0px" : "8px";
63
+ return `
64
+ <div
65
+ data-node-key="${escapeHtml(String(d.id))}"
66
+ style="
67
+ box-sizing: border-box;
68
+ width: ${DEFAULT_NODE_WIDTH}px;
69
+ min-height: ${DEFAULT_NODE_HEIGHT}px;
70
+ padding: 16px;
71
+ background: ${nodeColor};
72
+ border: 3px solid ${isSelected ? selectedBorderColor : nodeColor};
73
+ border-radius: ${borderRadius};
74
+ color: #fff;
75
+ font-size: 16px;
76
+ font-weight: 600;
77
+ line-height: 22px;
78
+ text-align: center;
79
+ white-space: normal;
80
+ word-break: break-word;
81
+ overflow-wrap: anywhere;
82
+ display: flex;
83
+ align-items: center;
84
+ justify-content: center;
85
+ cursor: pointer;
86
+ "
87
+ >
88
+ <div style="width: 100%;">
89
+ ${text}
90
+ </div>
91
+ </div>
92
+ `;
93
+ }
94
+ function measureAndUpdateNodeSizes(graph, container, nodeColorMap, selectedBorderColor, theme = "default") {
95
+ const nodes = graph.getNodeData();
96
+ const updatedNodes = nodes.map((node) => {
97
+ const dom = container.querySelector(`[data-node-key="${CSS.escape(String(node.id))}"]`);
98
+ let height = DEFAULT_NODE_HEIGHT;
99
+ if (dom) {
100
+ height = Math.max(DEFAULT_NODE_HEIGHT, Math.ceil(dom.getBoundingClientRect().height));
101
+ }
102
+ return {
103
+ id: node.id,
104
+ style: {
105
+ size: [DEFAULT_NODE_WIDTH, height],
106
+ dx: -DEFAULT_NODE_WIDTH / 2,
107
+ dy: -height / 2,
108
+ innerHTML: createNodeHTML(
109
+ node,
110
+ nodeColorMap.get(String(node.id)) || "#1783FF",
111
+ selectedBorderColor,
112
+ theme
113
+ )
114
+ }
115
+ };
116
+ });
117
+ graph.updateNodeData(updatedNodes);
118
+ graph.render();
119
+ }
120
+ var FlowDiagram = (options) => {
121
+ const { container, width, height, theme: chartTheme = "default" } = options;
122
+ let graph = null;
123
+ const render = (config) => {
124
+ const { data, title, theme = chartTheme, style = {} } = config;
125
+ if (graph) {
126
+ graph.destroy();
127
+ graph = null;
128
+ }
129
+ ensureBehaviorRegistered();
130
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
131
+ const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
132
+ let containerEl;
133
+ if (typeof container === "string") {
134
+ const el = document.getElementById(container.replace(/^#/, ""));
135
+ if (!el)
136
+ throw new Error(`Container element "${container}" not found`);
137
+ containerEl = el;
138
+ } else {
139
+ containerEl = container;
140
+ }
141
+ containerEl.style.backgroundColor = backgroundColor;
142
+ const nodeRankMap = /* @__PURE__ */ new Map();
143
+ const incomingTargets = new Set(data.edges.map((e) => e.target));
144
+ const childrenMap = /* @__PURE__ */ new Map();
145
+ for (const edge of data.edges) {
146
+ const list = childrenMap.get(edge.source) || [];
147
+ list.push(edge.target);
148
+ childrenMap.set(edge.source, list);
149
+ }
150
+ const roots = data.nodes.filter((n) => !incomingTargets.has(n.name)).map((n) => n.name);
151
+ const queue = roots.map((name) => ({ name, rank: 0 }));
152
+ let head = 0;
153
+ while (head < queue.length) {
154
+ const { name, rank } = queue[head++];
155
+ if (nodeRankMap.has(name))
156
+ continue;
157
+ nodeRankMap.set(name, rank);
158
+ for (const child of childrenMap.get(name) || []) {
159
+ if (!nodeRankMap.has(child)) {
160
+ queue.push({ name: child, rank: rank + 1 });
161
+ }
162
+ }
163
+ }
164
+ const nodeColorMap = /* @__PURE__ */ new Map();
165
+ const g6Nodes = data.nodes.map((node) => {
166
+ const rank = nodeRankMap.get(node.name) || 0;
167
+ const color = colors[rank % colors.length];
168
+ nodeColorMap.set(node.name, color);
169
+ return {
170
+ id: node.name,
171
+ data: { text: node.name }
172
+ };
173
+ });
174
+ const nodeNames = new Set(data.nodes.map((n) => n.name));
175
+ const g6Edges = data.edges.filter((edge) => nodeNames.has(edge.source) && nodeNames.has(edge.target)).map((edge, index) => ({
176
+ id: `edge-${index}`,
177
+ source: edge.source,
178
+ target: edge.target,
179
+ data: { text: edge.name || "" }
180
+ }));
181
+ const isDark = theme === "dark";
182
+ const edgeStroke = isDark ? "#5a6b7f" : "#8b9baf";
183
+ const labelFill = isDark ? "#aab4c0" : "#8b9baf";
184
+ const labelBgFill = isDark ? "#1a1a2e" : "#f8f8f8";
185
+ const labelBgStroke = isDark ? "#5a6b7f" : "#8b9baf";
186
+ const selectedBorder = isDark ? "#fff" : "#000";
187
+ graph = new import_g6.Graph({
188
+ animation: false,
189
+ container: containerEl,
190
+ width,
191
+ height,
192
+ theme: (0, import_theme.getTheme)(theme),
193
+ data: { nodes: g6Nodes, edges: g6Edges },
194
+ autoFit: "view",
195
+ autoResize: true,
196
+ padding: title ? [46, 20, 20, 20] : 20,
197
+ plugins: title ? [
198
+ {
199
+ key: "title",
200
+ type: "title",
201
+ title,
202
+ titleFill: isDark ? "#e0e6ed" : "#000",
203
+ titleFontFamily: "sans-serif"
204
+ }
205
+ ] : [],
206
+ node: {
207
+ type: "html",
208
+ style: (d) => {
209
+ var _a;
210
+ const color = nodeColorMap.get(String(d.id)) || colors[0];
211
+ const size = ((_a = d.style) == null ? void 0 : _a.size) || [
212
+ DEFAULT_NODE_WIDTH,
213
+ DEFAULT_NODE_HEIGHT
214
+ ];
215
+ const height2 = size[1];
216
+ return {
217
+ size,
218
+ dx: -DEFAULT_NODE_WIDTH / 2,
219
+ dy: -height2 / 2,
220
+ innerHTML: createNodeHTML(d, color, selectedBorder, theme),
221
+ ports: [{ placement: "top" }, { placement: "bottom" }]
222
+ };
223
+ },
224
+ state: {
225
+ active: { halo: false },
226
+ selected: { halo: false }
227
+ }
228
+ },
229
+ edge: {
230
+ type: "polyline",
231
+ style: {
232
+ lineWidth: 3,
233
+ radius: 20,
234
+ stroke: edgeStroke,
235
+ endArrow: true,
236
+ labelText: (d) => {
237
+ var _a;
238
+ return ((_a = d.data) == null ? void 0 : _a.text) || "";
239
+ },
240
+ labelFill,
241
+ labelFontWeight: 600,
242
+ labelBackground: true,
243
+ labelBackgroundFill: labelBgFill,
244
+ labelBackgroundOpacity: 1,
245
+ labelBackgroundLineWidth: 3,
246
+ labelBackgroundStroke: labelBgStroke,
247
+ labelPadding: [1, 10],
248
+ labelBackgroundRadius: 4,
249
+ router: { type: "orth", padding: 40 }
250
+ },
251
+ state: {
252
+ active: {
253
+ stroke: ACTIVE_COLOR,
254
+ labelBackgroundStroke: ACTIVE_COLOR,
255
+ halo: false
256
+ }
257
+ }
258
+ },
259
+ layout: {
260
+ type: "antv-dagre"
261
+ },
262
+ behaviors: ["drag-canvas", "hover-element", "click-select"]
263
+ });
264
+ graph.render();
265
+ graph.once("afterrender", () => {
266
+ if (graph) {
267
+ measureAndUpdateNodeSizes(graph, containerEl, nodeColorMap, selectedBorder, theme);
268
+ }
269
+ });
270
+ };
271
+ const destroy = () => {
272
+ if (graph) {
273
+ graph.destroy();
274
+ graph = null;
275
+ }
276
+ };
277
+ return {
278
+ render,
279
+ destroy,
280
+ zoomTo: (zoom) => graph == null ? void 0 : graph.zoomTo(zoom),
281
+ getZoom: () => graph == null ? void 0 : graph.getZoom()
282
+ };
283
+ };
284
+ // Annotate the CommonJS export names for ESM import in node:
285
+ 0 && (module.exports = {
286
+ FlowDiagram
287
+ });
@@ -33,7 +33,7 @@ var Funnel = (options) => {
33
33
  if (chart) {
34
34
  chart.destroy();
35
35
  }
36
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
36
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
37
37
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
38
38
  const conversionRate = (start, end) => `${(end / start * 100).toFixed(2)} %`;
39
39
  chart = new import_g2.Chart({
@@ -45,6 +45,7 @@ var Funnel = (options) => {
45
45
  paddingRight: 68
46
46
  });
47
47
  const chartOptions = {
48
+ animate: false,
48
49
  type: "view",
49
50
  data,
50
51
  title: title ?? "",
@@ -40,7 +40,7 @@ var Histogram = (options) => {
40
40
  if (chart) {
41
41
  chart.destroy();
42
42
  }
43
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
43
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
44
44
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
45
45
  chart = new import_g2.Chart({
46
46
  container,
@@ -49,6 +49,7 @@ var Histogram = (options) => {
49
49
  autoFit: true
50
50
  });
51
51
  const chartOptions = {
52
+ animate: false,
52
53
  type: "interval",
53
54
  data,
54
55
  title: title ?? "",
@@ -80,12 +81,7 @@ var Histogram = (options) => {
80
81
  },
81
82
  legend: false,
82
83
  tooltip: {
83
- items: [
84
- (d) => ({
85
- name: "频数",
86
- value: d.count
87
- })
88
- ]
84
+ items: [{ channel: "y", name: "频数" }]
89
85
  },
90
86
  viewStyle: {
91
87
  viewFill: backgroundColor
@@ -0,0 +1,40 @@
1
+ import type { VisualizationOptions } from '../../types';
2
+ /**
3
+ * Indented tree node data — only name + optional children, no description.
4
+ * Aligns with the official G6 indented tree example data structure.
5
+ */
6
+ export interface IndentedTreeData {
7
+ name: string;
8
+ children?: IndentedTreeData[];
9
+ }
10
+ /**
11
+ * IndentedTreeConfig defines the configuration for rendering the indented tree.
12
+ */
13
+ export interface IndentedTreeConfig {
14
+ type?: 'indented-tree';
15
+ data: IndentedTreeData;
16
+ theme?: 'default' | 'academy' | 'dark';
17
+ title?: string;
18
+ /** Layout direction: 'LR' = root left (default), 'RL' = root right, 'H' = root center */
19
+ direction?: 'LR' | 'RL' | 'H';
20
+ style?: {
21
+ backgroundColor?: string;
22
+ palette?: string[];
23
+ };
24
+ }
25
+ /**
26
+ * IndentedTreeInstance represents a chart instance with render and destroy methods.
27
+ */
28
+ export interface IndentedTreeInstance {
29
+ render: (config: IndentedTreeConfig) => void;
30
+ destroy: () => void;
31
+ zoomTo: (zoom: number) => void;
32
+ getZoom: () => number | undefined;
33
+ }
34
+ /**
35
+ * IndentedTree — G6 5 indented layout for static DSL trees (no collapse/add UI).
36
+ * Uses built-in `rect` nodes and `line` edges. Tree edges must have explicit ids (see render) to avoid
37
+ * colliding with path-based node ids under G6's default `${source}-${target}` edge id rule.
38
+ * Based on: https://g6.antv.antgroup.com/examples/scene-case/tree-graph#indented-tree
39
+ */
40
+ export declare const IndentedTree: (options: VisualizationOptions) => IndentedTreeInstance;