@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,43 @@
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/util/container.ts
20
+ var container_exports = {};
21
+ __export(container_exports, {
22
+ resolveContainer: () => resolveContainer
23
+ });
24
+ module.exports = __toCommonJS(container_exports);
25
+ function resolveContainer(container) {
26
+ if (typeof container === "string") {
27
+ if (typeof document === "undefined") {
28
+ throw new Error(
29
+ `Container element "${container}" cannot be resolved in a non-browser environment.`
30
+ );
31
+ }
32
+ const el = document.querySelector(container);
33
+ if (!el) {
34
+ throw new Error(`Container element "${container}" not found`);
35
+ }
36
+ return el;
37
+ }
38
+ return container;
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ resolveContainer
43
+ });
@@ -19,3 +19,8 @@ export declare const getThemeColors: (theme: string) => string[];
19
19
  * Get background color based on theme.
20
20
  */
21
21
  export declare const getBackgroundColor: (theme: string) => string;
22
+ /**
23
+ * Normalize palette to always return an array.
24
+ * Handles the case where a single color is parsed as a string instead of an array.
25
+ */
26
+ export declare const normalizePalette: (palette: string | string[] | undefined, theme: string) => string[];
@@ -25,7 +25,8 @@ __export(theme_exports, {
25
25
  getBackgroundColor: () => getBackgroundColor,
26
26
  getTheme: () => getTheme,
27
27
  getThemeColors: () => getThemeColors,
28
- getThemeObject: () => getThemeObject
28
+ getThemeObject: () => getThemeObject,
29
+ normalizePalette: () => normalizePalette
29
30
  });
30
31
  module.exports = __toCommonJS(theme_exports);
31
32
  var DEFAULT_COLOR_PALETTE = [
@@ -170,6 +171,11 @@ var getBackgroundColor = (theme) => {
170
171
  return "#FFF";
171
172
  }
172
173
  };
174
+ var normalizePalette = (palette, theme) => {
175
+ if (!palette || Array.isArray(palette) && palette.length === 0)
176
+ return getThemeColors(theme);
177
+ return Array.isArray(palette) ? palette : [palette];
178
+ };
173
179
  // Annotate the CommonJS export names for ESM import in node:
174
180
  0 && (module.exports = {
175
181
  ACADEMY_COLOR_PALETTE,
@@ -178,5 +184,6 @@ var getBackgroundColor = (theme) => {
178
184
  getBackgroundColor,
179
185
  getTheme,
180
186
  getThemeColors,
181
- getThemeObject
187
+ getThemeObject,
188
+ normalizePalette
182
189
  });
@@ -45,7 +45,7 @@ var Area = (options) => {
45
45
  }
46
46
  const { lineWidth = 2 } = style;
47
47
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
48
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
48
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
49
49
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
50
50
  const fillColor = getLinearGradientColor(colors[0] || DEFAULT_COLOR);
51
51
  chart = new import_g2.Chart({
@@ -106,6 +106,7 @@ var Area = (options) => {
106
106
  ];
107
107
  }
108
108
  const chartOptions = {
109
+ animate: false,
109
110
  type: "view",
110
111
  data,
111
112
  title: title ?? "",
@@ -28,7 +28,7 @@ var Bar = (options) => {
28
28
  const { container, width, height, theme: chartTheme = "default" } = options;
29
29
  let chart = null;
30
30
  const render = (config) => {
31
- var _a, _b;
31
+ var _a;
32
32
  const {
33
33
  data = [],
34
34
  theme = chartTheme,
@@ -43,7 +43,7 @@ var Bar = (options) => {
43
43
  chart.destroy();
44
44
  }
45
45
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
46
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
46
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
47
47
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
48
48
  chart = new import_g2.Chart({
49
49
  container,
@@ -54,7 +54,7 @@ var Bar = (options) => {
54
54
  let encode = {};
55
55
  let transform = [];
56
56
  let radiusStyle = {};
57
- if (theme === "default") {
57
+ if (theme !== "academy") {
58
58
  radiusStyle = { radiusTopLeft: 4, radiusTopRight: 4 };
59
59
  }
60
60
  if (hasGroupField && group) {
@@ -70,9 +70,10 @@ var Bar = (options) => {
70
70
  }
71
71
  const scaleConfig = {
72
72
  y: { nice: true },
73
- ...((_b = style.palette) == null ? void 0 : _b.length) ? { color: { range: colors } } : {}
73
+ ...style.palette ? { color: { range: colors } } : {}
74
74
  };
75
75
  const chartOptions = {
76
+ animate: false,
76
77
  type: "interval",
77
78
  data,
78
79
  title: title ?? "",
@@ -33,7 +33,7 @@ var Boxplot = (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 startAtZero = style.startAtZero || false;
39
39
  const hasGroupField = ((_a = (data || [])[0]) == null ? void 0 : _a.group) !== void 0;
@@ -59,6 +59,7 @@ var Boxplot = (options) => {
59
59
  autoFit: true
60
60
  });
61
61
  const chartOptions = {
62
+ animate: false,
62
63
  type: "boxplot",
63
64
  data,
64
65
  title: title ?? "",
@@ -77,7 +78,11 @@ var Boxplot = (options) => {
77
78
  y: { nice: true, zero: startAtZero },
78
79
  color: { range: colors }
79
80
  },
80
- style: { stroke: "black" },
81
+ // When hasGroupField is true, set point to false to prevent G2's Boxplot composite mark
82
+ // from splitting into box + point child marks. The point child mark does not inherit
83
+ // the `scale` config, causing legendFilter interaction to throw
84
+ // "Cannot read properties of undefined (reading 'color')" when clicking legend items.
85
+ style: { stroke: "black", ...hasGroupField ? { point: false } : {} },
81
86
  legend: {
82
87
  color: hasGroupField ? { position: "top" } : false
83
88
  },
@@ -28,7 +28,7 @@ var Column = (options) => {
28
28
  const { container, width, height, theme: chartTheme = "default" } = options;
29
29
  let chart = null;
30
30
  const render = (config) => {
31
- var _a, _b;
31
+ var _a;
32
32
  const {
33
33
  data = [],
34
34
  theme = chartTheme,
@@ -43,7 +43,7 @@ var Column = (options) => {
43
43
  chart.destroy();
44
44
  }
45
45
  const hasGroupField = data.length > 0 && ((_a = data[0]) == null ? void 0 : _a.group) !== void 0;
46
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
46
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
47
47
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
48
48
  chart = new import_g2.Chart({
49
49
  container,
@@ -54,7 +54,7 @@ var Column = (options) => {
54
54
  let encode = {};
55
55
  let transform = [];
56
56
  let radiusStyle = {};
57
- if (theme === "default") {
57
+ if (theme !== "academy") {
58
58
  radiusStyle = { radiusTopLeft: 4, radiusTopRight: 4 };
59
59
  }
60
60
  if (hasGroupField && group) {
@@ -70,9 +70,10 @@ var Column = (options) => {
70
70
  }
71
71
  const scaleConfig = {
72
72
  y: { nice: true },
73
- ...((_b = style.palette) == null ? void 0 : _b.length) ? { color: { range: colors } } : {}
73
+ ...style.palette ? { color: { range: colors } } : {}
74
74
  };
75
75
  const chartOptions = {
76
+ animate: false,
76
77
  type: "interval",
77
78
  data,
78
79
  title: title ?? "",
@@ -43,7 +43,7 @@ var DualAxes = (options) => {
43
43
  chart.destroy();
44
44
  }
45
45
  const { startAtZero = false } = style;
46
- const colors = style.palette || (0, import_theme.getThemeColors)(theme);
46
+ const colors = (0, import_theme.normalizePalette)(style.palette, theme);
47
47
  const backgroundColor = style.backgroundColor || (0, import_theme.getBackgroundColor)(theme);
48
48
  const data = transformData(series, categories);
49
49
  chart = new import_g2.Chart({
@@ -103,6 +103,7 @@ var DualAxes = (options) => {
103
103
  }
104
104
  });
105
105
  const chartOptions = {
106
+ animate: false,
106
107
  type: "view",
107
108
  data,
108
109
  title: title ?? "",
@@ -0,0 +1,35 @@
1
+ import type { VisualizationOptions } from '../../types';
2
+ export interface FishboneNode {
3
+ name: string;
4
+ children?: FishboneNode[];
5
+ }
6
+ /**
7
+ * FishboneDiagramConfig defines the configuration for rendering the fishbone diagram.
8
+ */
9
+ export interface FishboneDiagramConfig {
10
+ type?: 'fishbone-diagram';
11
+ data: FishboneNode;
12
+ theme?: 'default' | 'academy' | 'dark';
13
+ title?: string;
14
+ style?: {
15
+ /** Custom color palette for branch nodes, overrides theme default */
16
+ palette?: string[];
17
+ /** Canvas background color, overrides theme default */
18
+ backgroundColor?: string;
19
+ /** Node rendering style: 'rough' for hand-drawn look, 'default' for smooth */
20
+ texture?: 'rough' | 'default';
21
+ };
22
+ }
23
+ /**
24
+ * FishboneDiagramInstance represents a fishbone diagram instance.
25
+ */
26
+ export interface FishboneDiagramInstance {
27
+ render: (config: FishboneDiagramConfig) => void;
28
+ destroy: () => void;
29
+ zoomTo: (zoom: number) => void;
30
+ getZoom: () => number | undefined;
31
+ }
32
+ /**
33
+ * FishboneDiagram chart component using G6 with fishbone layout.
34
+ */
35
+ export declare const FishboneDiagram: (options: VisualizationOptions) => FishboneDiagramInstance;
@@ -0,0 +1,183 @@
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: 20,
104
+ theme: chartTheme,
105
+ plugins: title ? [{ key: "title", type: "title", title, titleFill: isDark ? "#e0e6ed" : "#1a1a2e" }] : [],
106
+ data: graphData,
107
+ node: {
108
+ type: "rect",
109
+ style: (d) => {
110
+ var _a;
111
+ const depth = d.depth ?? 0;
112
+ const nodeStyle = {
113
+ radius: 8,
114
+ size: getNodeSize(String(d.id), depth),
115
+ labelText: String(d.id),
116
+ labelPlacement: "left",
117
+ labelFontFamily: FONT_FAMILY
118
+ };
119
+ if (depth === 0) {
120
+ Object.assign(nodeStyle, {
121
+ fill: rootFill,
122
+ labelFill: rootLabelFill,
123
+ labelFontWeight: "bold",
124
+ labelFontSize: 24,
125
+ labelOffsetY: 4,
126
+ labelPlacement: "center"
127
+ });
128
+ } else if (depth === 1) {
129
+ const color = ((_a = d.style) == null ? void 0 : _a.branchColor) || palette[0];
130
+ Object.assign(nodeStyle, {
131
+ fill: color,
132
+ labelFill: "#fff",
133
+ labelFontSize: 18,
134
+ labelPlacement: "center"
135
+ });
136
+ } else {
137
+ Object.assign(nodeStyle, {
138
+ fill: "transparent",
139
+ labelFill: leafLabelFill,
140
+ labelFontSize: 16
141
+ });
142
+ }
143
+ if (style.texture === "rough") {
144
+ nodeStyle.lineWidth = 0.5;
145
+ }
146
+ return nodeStyle;
147
+ }
148
+ },
149
+ edge: {
150
+ type: "polyline",
151
+ style: {
152
+ lineWidth: 3,
153
+ stroke: edgeStroke,
154
+ ...style.texture === "rough" ? { labelFontFamily: "Comic Sans MS" } : {}
155
+ }
156
+ },
157
+ layout: {
158
+ type: "fishbone",
159
+ direction: "RL",
160
+ hGap: 40,
161
+ vGap: 60
162
+ },
163
+ behaviors: ["drag-canvas"]
164
+ });
165
+ graph.render();
166
+ };
167
+ const destroy = () => {
168
+ if (graph) {
169
+ graph.destroy();
170
+ graph = null;
171
+ }
172
+ };
173
+ return {
174
+ render,
175
+ destroy,
176
+ zoomTo: (zoom) => graph == null ? void 0 : graph.zoomTo(zoom),
177
+ getZoom: () => (graph == null ? void 0 : graph.getZoom()) ?? 1
178
+ };
179
+ };
180
+ // Annotate the CommonJS export names for ESM import in node:
181
+ 0 && (module.exports = {
182
+ FishboneDiagram
183
+ });
@@ -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;