@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
@@ -5,7 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import { Chart } from '@antv/g2';
8
- import { getBackgroundColor, getThemeColors, getThemeObject } from "../../util/theme";
8
+ import { getBackgroundColor, getThemeObject, normalizePalette } from "../../util/theme";
9
9
 
10
10
  /**
11
11
  * ColumnDataItem is the type for each data item in the column chart.
@@ -57,7 +57,7 @@ export var Column = function Column(options) {
57
57
  * Render the column chart with the given configuration.
58
58
  */
59
59
  var render = function render(config) {
60
- var _data$, _style$palette;
60
+ var _data$;
61
61
  var _config$data = config.data,
62
62
  data = _config$data === void 0 ? [] : _config$data,
63
63
  _config$theme = config.theme,
@@ -77,7 +77,7 @@ export var Column = function Column(options) {
77
77
  chart.destroy();
78
78
  }
79
79
  var hasGroupField = data.length > 0 && ((_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.group) !== undefined;
80
- var colors = style.palette || getThemeColors(theme);
80
+ var colors = normalizePalette(style.palette, theme);
81
81
  var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
82
82
 
83
83
  // Create chart
@@ -93,8 +93,8 @@ export var Column = function Column(options) {
93
93
  var transform = [];
94
94
  var radiusStyle = {};
95
95
 
96
- // Set radius style for default theme
97
- if (theme === 'default') {
96
+ // academy theme uses no rounded corners; other themes use rounded top corners
97
+ if (theme !== 'academy') {
98
98
  radiusStyle = {
99
99
  radiusTopLeft: 4,
100
100
  radiusTopRight: 4
@@ -133,7 +133,7 @@ export var Column = function Column(options) {
133
133
  y: {
134
134
  nice: true
135
135
  }
136
- }, (_style$palette = style.palette) !== null && _style$palette !== void 0 && _style$palette.length ? {
136
+ }, style.palette ? {
137
137
  color: {
138
138
  range: colors
139
139
  }
@@ -143,6 +143,7 @@ export var Column = function Column(options) {
143
143
  // Note: Using 'any' type due to G2's complex type system with transformations
144
144
  // This is consistent with how G2 5.0 is used elsewhere in the codebase
145
145
  var chartOptions = {
146
+ animate: false,
146
147
  type: 'interval',
147
148
  data: data,
148
149
  title: title !== null && title !== void 0 ? title : '',
@@ -1,3 +1,9 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
8
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
9
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -5,7 +11,7 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
5
11
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
12
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
13
  import { Chart } from '@antv/g2';
8
- import { getBackgroundColor, getThemeColors, getThemeObject } from "../../util/theme";
14
+ import { getBackgroundColor, getThemeObject, normalizePalette } from "../../util/theme";
9
15
 
10
16
  /**
11
17
  * DualAxesSeriesItem defines a single series in the dual-axes chart.
@@ -94,7 +100,7 @@ export var DualAxes = function DualAxes(options) {
94
100
  }
95
101
  var _style$startAtZero = style.startAtZero,
96
102
  startAtZero = _style$startAtZero === void 0 ? false : _style$startAtZero;
97
- var colors = style.palette || getThemeColors(theme);
103
+ var colors = normalizePalette(style.palette, theme);
98
104
  var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
99
105
 
100
106
  // Transform data
@@ -142,11 +148,12 @@ export var DualAxes = function DualAxes(options) {
142
148
  title: item.axisYTitle || ''
143
149
  }
144
150
  },
145
- style: {
146
- columnWidthRatio: 0.8,
151
+ style: _objectSpread({
152
+ columnWidthRatio: 0.8
153
+ }, theme !== 'academy' ? {
147
154
  radiusTopLeft: 4,
148
155
  radiusTopRight: 4
149
- }
156
+ } : {})
150
157
  };
151
158
  } else {
152
159
  // line type
@@ -186,6 +193,7 @@ export var DualAxes = function DualAxes(options) {
186
193
  // Note: Using 'any' type due to G2's complex type system with transformations
187
194
  // This is consistent with how G2 5.0 is used elsewhere in the codebase
188
195
  var chartOptions = {
196
+ animate: false,
189
197
  type: 'view',
190
198
  data: data,
191
199
  title: title !== null && title !== void 0 ? 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,219 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["children"];
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
+ import { Graph, treeToGraphData } from '@antv/g6';
11
+ import { getBackgroundColor, getTheme, normalizePalette } from "../../util/theme";
12
+
13
+ /**
14
+ * FishboneDiagramConfig defines the configuration for rendering the fishbone diagram.
15
+ */
16
+
17
+ /**
18
+ * FishboneDiagramInstance represents a fishbone diagram instance.
19
+ */
20
+
21
+ var FONT_FAMILY = 'system-ui, sans-serif';
22
+ function getNodeSize(id, depth) {
23
+ return depth === 0 ? [measureText(id, 24, 'bold') + 80, 70] : depth === 1 ? [measureText(id, 18) + 50, 42] : [2, 30];
24
+ }
25
+ var measureText = function () {
26
+ var canvas = null;
27
+ return function (text) {
28
+ var fontSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 12;
29
+ var fontWeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'normal';
30
+ if (typeof document === 'undefined') return text.length * fontSize * 0.6;
31
+ if (!canvas) canvas = document.createElement('canvas');
32
+ var ctx = canvas.getContext('2d');
33
+ if (!ctx) return 0;
34
+ ctx.font = "".concat(fontWeight, " ").concat(fontSize, "px ").concat(FONT_FAMILY);
35
+ return ctx.measureText(text).width;
36
+ };
37
+ }();
38
+
39
+ /**
40
+ * Convert name-based tree to G6 tree format (name → id).
41
+ */
42
+ function toG6TreeData(node) {
43
+ return {
44
+ id: node.name,
45
+ children: (node.children || []).map(toG6TreeData)
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Convert GPT-Vis tree data to flat G6 graph data, attaching depth to each node.
51
+ */
52
+ function convertData(data) {
53
+ return treeToGraphData(toG6TreeData(data), {
54
+ getNodeData: function getNodeData(datum, depth) {
55
+ datum.depth = depth;
56
+ if (!datum.children) return datum;
57
+ var children = datum.children,
58
+ rest = _objectWithoutProperties(datum, _excluded);
59
+ return _objectSpread(_objectSpread({}, rest), {}, {
60
+ children: children.map(function (c) {
61
+ return c.id;
62
+ })
63
+ });
64
+ }
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Assign a unique palette color to each depth-1 branch node so that each
70
+ * branch is visually distinct, matching the v0.6.1 multi-color style.
71
+ */
72
+ function assignBranchColors(graphData, palette) {
73
+ var nodes = graphData.nodes || [];
74
+ var colorIndex = 0;
75
+ nodes.filter(function (n) {
76
+ return n.depth === 1;
77
+ }).forEach(function (n) {
78
+ n.style = n.style || {};
79
+ n.style.branchColor = palette[colorIndex++ % palette.length];
80
+ });
81
+ }
82
+
83
+ /**
84
+ * FishboneDiagram chart component using G6 with fishbone layout.
85
+ */
86
+ export var FishboneDiagram = function FishboneDiagram(options) {
87
+ var container = options.container,
88
+ width = options.width,
89
+ height = options.height,
90
+ _options$theme = options.theme,
91
+ chartTheme = _options$theme === void 0 ? 'default' : _options$theme;
92
+ var graph = null;
93
+ var render = function render(config) {
94
+ var data = config.data,
95
+ _config$theme = config.theme,
96
+ theme = _config$theme === void 0 ? chartTheme : _config$theme,
97
+ title = config.title,
98
+ _config$style = config.style,
99
+ _style = _config$style === void 0 ? {} : _config$style;
100
+ if (!(data !== null && data !== void 0 && data.name)) {
101
+ throw new Error('FishboneDiagram: data with a name field is required');
102
+ }
103
+ if (graph) {
104
+ graph.destroy();
105
+ graph = null;
106
+ }
107
+ var containerEl = typeof container === 'string' ? document.querySelector(container) : container;
108
+ if (!containerEl) throw new Error('FishboneDiagram: container element not found');
109
+ containerEl.innerHTML = '';
110
+
111
+ // Theme-derived colors, allowing style.palette to override the theme default
112
+ var isDark = theme === 'dark';
113
+ var backgroundColor = _style.backgroundColor || getBackgroundColor(theme);
114
+ var palette = normalizePalette(_style.palette, theme);
115
+ var rootFill = isDark ? '#2a2a2a' : '#EFF0F0';
116
+ var rootLabelFill = isDark ? '#e0e0e0' : '#262626';
117
+ var leafLabelFill = isDark ? '#c0c0c0' : '#262626';
118
+ var edgeStroke = isDark ? '#555' : '#99ADD1';
119
+ containerEl.style.backgroundColor = backgroundColor;
120
+ var graphData = convertData(data);
121
+ assignBranchColors(graphData, palette);
122
+ graph = new Graph({
123
+ animation: false,
124
+ container: containerEl,
125
+ width: width,
126
+ height: height,
127
+ autoFit: 'view',
128
+ autoResize: true,
129
+ padding: title ? [46, 20, 20, 20] : 20,
130
+ theme: getTheme(theme),
131
+ plugins: title ? [{
132
+ key: 'title',
133
+ type: 'title',
134
+ title: title,
135
+ titleFill: isDark ? '#e0e6ed' : '#000',
136
+ titleFontFamily: 'sans-serif'
137
+ }] : [],
138
+ data: graphData,
139
+ node: {
140
+ type: 'rect',
141
+ style: function style(d) {
142
+ var _d$depth;
143
+ var depth = (_d$depth = d.depth) !== null && _d$depth !== void 0 ? _d$depth : 0;
144
+ var nodeStyle = {
145
+ radius: theme === 'academy' ? 0 : 8,
146
+ size: getNodeSize(String(d.id), depth),
147
+ labelText: String(d.id),
148
+ labelPlacement: 'left',
149
+ labelFontFamily: FONT_FAMILY
150
+ };
151
+ if (depth === 0) {
152
+ Object.assign(nodeStyle, {
153
+ fill: rootFill,
154
+ labelFill: rootLabelFill,
155
+ labelFontWeight: 'bold',
156
+ labelFontSize: 24,
157
+ labelOffsetY: 4,
158
+ labelPlacement: 'center'
159
+ });
160
+ } else if (depth === 1) {
161
+ var _d$style;
162
+ var color = ((_d$style = d.style) === null || _d$style === void 0 ? void 0 : _d$style.branchColor) || palette[0];
163
+ Object.assign(nodeStyle, {
164
+ fill: color,
165
+ labelFill: '#fff',
166
+ labelFontSize: 18,
167
+ labelPlacement: 'center'
168
+ });
169
+ } else {
170
+ Object.assign(nodeStyle, {
171
+ fill: 'transparent',
172
+ labelFill: leafLabelFill,
173
+ labelFontSize: 16
174
+ });
175
+ }
176
+ if (_style.texture === 'rough') {
177
+ nodeStyle.lineWidth = 0.5;
178
+ }
179
+ return nodeStyle;
180
+ }
181
+ },
182
+ edge: {
183
+ type: 'polyline',
184
+ style: _objectSpread({
185
+ lineWidth: 3,
186
+ stroke: edgeStroke
187
+ }, _style.texture === 'rough' ? {
188
+ labelFontFamily: 'Comic Sans MS'
189
+ } : {})
190
+ },
191
+ layout: {
192
+ type: 'fishbone',
193
+ direction: 'RL',
194
+ hGap: 40,
195
+ vGap: 60
196
+ },
197
+ behaviors: ['drag-canvas']
198
+ });
199
+ graph.render();
200
+ };
201
+ var destroy = function destroy() {
202
+ if (graph) {
203
+ graph.destroy();
204
+ graph = null;
205
+ }
206
+ };
207
+ return {
208
+ render: render,
209
+ destroy: destroy,
210
+ zoomTo: function zoomTo(zoom) {
211
+ var _graph;
212
+ return (_graph = graph) === null || _graph === void 0 ? void 0 : _graph.zoomTo(zoom);
213
+ },
214
+ getZoom: function getZoom() {
215
+ var _graph$getZoom, _graph2;
216
+ return (_graph$getZoom = (_graph2 = graph) === null || _graph2 === void 0 ? void 0 : _graph2.getZoom()) !== null && _graph$getZoom !== void 0 ? _graph$getZoom : 1;
217
+ }
218
+ };
219
+ };
@@ -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;