@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.
- package/README.md +223 -47
- package/README.zh-CN.md +227 -51
- package/dist/cjs/gpt-vis/index.d.ts +8 -1
- package/dist/cjs/gpt-vis/index.js +43 -20
- package/dist/cjs/index.d.ts +15 -2
- package/dist/cjs/index.js +22 -2
- package/dist/cjs/syntax/parser.d.ts +17 -2
- package/dist/cjs/syntax/parser.js +151 -38
- package/dist/cjs/util/container.d.ts +5 -0
- package/dist/cjs/util/container.js +43 -0
- package/dist/cjs/util/theme.d.ts +5 -0
- package/dist/cjs/util/theme.js +9 -2
- package/dist/cjs/vis/area/index.js +2 -1
- package/dist/cjs/vis/bar/index.js +5 -4
- package/dist/cjs/vis/boxplot/index.js +7 -2
- package/dist/cjs/vis/column/index.js +5 -4
- package/dist/cjs/vis/dual-axes/index.js +3 -3
- package/dist/cjs/vis/fishbone-diagram/index.d.ts +35 -0
- package/dist/cjs/vis/fishbone-diagram/index.js +191 -0
- package/dist/cjs/vis/flow-diagram/index.d.ts +27 -0
- package/dist/cjs/vis/flow-diagram/index.js +287 -0
- package/dist/cjs/vis/funnel/index.js +2 -1
- package/dist/cjs/vis/histogram/index.js +3 -7
- package/dist/cjs/vis/indented-tree/index.d.ts +40 -0
- package/dist/cjs/vis/indented-tree/index.js +385 -0
- package/dist/cjs/vis/line/index.js +2 -1
- package/dist/cjs/vis/liquid/index.js +2 -1
- package/dist/cjs/vis/mindmap/index.d.ts +32 -0
- package/dist/cjs/vis/mindmap/index.js +222 -0
- package/dist/cjs/vis/network-graph/index.d.ts +59 -0
- package/dist/cjs/vis/network-graph/index.js +175 -0
- package/dist/cjs/vis/organization-chart/index.d.ts +64 -0
- package/dist/cjs/vis/organization-chart/index.js +200 -0
- package/dist/cjs/vis/pie/index.js +3 -3
- package/dist/cjs/vis/radar/index.d.ts +1 -0
- package/dist/cjs/vis/radar/index.js +10 -9
- package/dist/cjs/vis/sankey/index.js +2 -1
- package/dist/cjs/vis/scatter/index.d.ts +2 -0
- package/dist/cjs/vis/scatter/index.js +9 -4
- package/dist/cjs/vis/summary/index.js +17 -3
- package/dist/cjs/vis/table/index.d.ts +1 -0
- package/dist/cjs/vis/table/index.js +37 -1
- package/dist/cjs/vis/treemap/index.js +2 -1
- package/dist/cjs/vis/venn/index.d.ts +2 -1
- package/dist/cjs/vis/venn/index.js +18 -3
- package/dist/cjs/vis/violin/index.js +2 -1
- package/dist/cjs/vis/waterfall/index.d.ts +6 -9
- package/dist/cjs/vis/waterfall/index.js +29 -6
- package/dist/cjs/vis/word-cloud/index.js +2 -1
- package/dist/cjs/vis-wrapper/icons.js +2 -2
- package/dist/cjs/vis-wrapper/index.d.ts +1 -0
- package/dist/cjs/vis-wrapper/index.js +27 -16
- package/dist/cjs/vis-wrapper/styles.d.ts +1 -1
- package/dist/cjs/vis-wrapper/styles.js +8 -1
- package/dist/esm/gpt-vis/index.d.ts +8 -1
- package/dist/esm/gpt-vis/index.js +47 -26
- package/dist/esm/index.d.ts +15 -2
- package/dist/esm/index.js +7 -1
- package/dist/esm/syntax/parser.d.ts +17 -2
- package/dist/esm/syntax/parser.js +248 -90
- package/dist/esm/util/container.d.ts +5 -0
- package/dist/esm/util/container.js +20 -0
- package/dist/esm/util/theme.d.ts +5 -0
- package/dist/esm/util/theme.js +9 -0
- package/dist/esm/vis/area/index.js +3 -2
- package/dist/esm/vis/bar/index.js +7 -6
- package/dist/esm/vis/boxplot/index.js +17 -4
- package/dist/esm/vis/column/index.js +7 -6
- package/dist/esm/vis/dual-axes/index.js +13 -5
- package/dist/esm/vis/fishbone-diagram/index.d.ts +35 -0
- package/dist/esm/vis/fishbone-diagram/index.js +219 -0
- package/dist/esm/vis/flow-diagram/index.d.ts +27 -0
- package/dist/esm/vis/flow-diagram/index.js +349 -0
- package/dist/esm/vis/funnel/index.js +3 -2
- package/dist/esm/vis/histogram/index.js +6 -7
- package/dist/esm/vis/indented-tree/index.d.ts +40 -0
- package/dist/esm/vis/indented-tree/index.js +569 -0
- package/dist/esm/vis/line/index.js +3 -2
- package/dist/esm/vis/liquid/index.js +3 -2
- package/dist/esm/vis/mindmap/index.d.ts +32 -0
- package/dist/esm/vis/mindmap/index.js +316 -0
- package/dist/esm/vis/network-graph/index.d.ts +59 -0
- package/dist/esm/vis/network-graph/index.js +242 -0
- package/dist/esm/vis/organization-chart/index.d.ts +64 -0
- package/dist/esm/vis/organization-chart/index.js +271 -0
- package/dist/esm/vis/pie/index.js +4 -8
- package/dist/esm/vis/radar/index.d.ts +1 -0
- package/dist/esm/vis/radar/index.js +20 -4
- package/dist/esm/vis/sankey/index.js +3 -2
- package/dist/esm/vis/scatter/index.d.ts +2 -0
- package/dist/esm/vis/scatter/index.js +15 -4
- package/dist/esm/vis/summary/index.js +25 -4
- package/dist/esm/vis/table/index.d.ts +1 -0
- package/dist/esm/vis/table/index.js +9 -2
- package/dist/esm/vis/treemap/index.js +3 -2
- package/dist/esm/vis/venn/index.d.ts +2 -1
- package/dist/esm/vis/venn/index.js +29 -4
- package/dist/esm/vis/violin/index.js +3 -2
- package/dist/esm/vis/waterfall/index.d.ts +6 -9
- package/dist/esm/vis/waterfall/index.js +33 -13
- package/dist/esm/vis/word-cloud/index.js +3 -2
- package/dist/esm/vis-wrapper/icons.js +2 -2
- package/dist/esm/vis-wrapper/index.d.ts +1 -0
- package/dist/esm/vis-wrapper/index.js +15 -10
- package/dist/esm/vis-wrapper/styles.d.ts +1 -1
- package/dist/esm/vis-wrapper/styles.js +1 -1
- package/dist/umd/index.min.js +1 -1
- package/package.json +17 -21
- package/src/gpt-vis/index.ts +0 -283
- package/src/index.ts +0 -44
- package/src/readme.md +0 -37
- package/src/syntax/index.ts +0 -2
- package/src/syntax/parser.ts +0 -411
- package/src/types/index.ts +0 -29
- package/src/util/theme.ts +0 -167
- package/src/vis/area/README.md +0 -143
- package/src/vis/area/index.ts +0 -212
- package/src/vis/bar/README.md +0 -158
- package/src/vis/bar/index.ts +0 -186
- package/src/vis/boxplot/README.md +0 -168
- package/src/vis/boxplot/index.ts +0 -162
- package/src/vis/column/README.md +0 -158
- package/src/vis/column/index.ts +0 -185
- package/src/vis/dual-axes/README.md +0 -191
- package/src/vis/dual-axes/index.ts +0 -218
- package/src/vis/funnel/README.md +0 -143
- package/src/vis/funnel/index.ts +0 -238
- package/src/vis/histogram/README.md +0 -130
- package/src/vis/histogram/index.ts +0 -153
- package/src/vis/line/README.md +0 -138
- package/src/vis/line/index.ts +0 -159
- package/src/vis/liquid/README.md +0 -150
- package/src/vis/liquid/index.ts +0 -130
- package/src/vis/pie/README.md +0 -127
- package/src/vis/pie/index.ts +0 -163
- package/src/vis/radar/README.md +0 -184
- package/src/vis/radar/index.ts +0 -214
- package/src/vis/sankey/README.md +0 -144
- package/src/vis/sankey/index.ts +0 -144
- package/src/vis/scatter/README.md +0 -145
- package/src/vis/scatter/index.ts +0 -147
- package/src/vis/summary/README.md +0 -272
- package/src/vis/summary/index.ts +0 -91
- package/src/vis/table/README.md +0 -174
- package/src/vis/table/index.ts +0 -241
- package/src/vis/treemap/README.md +0 -199
- package/src/vis/treemap/index.ts +0 -167
- package/src/vis/venn/README.md +0 -153
- package/src/vis/venn/index.ts +0 -149
- package/src/vis/violin/README.md +0 -168
- package/src/vis/violin/index.ts +0 -216
- package/src/vis/waterfall/README.md +0 -178
- package/src/vis/waterfall/index.ts +0 -258
- package/src/vis/word-cloud/README.md +0 -137
- package/src/vis/word-cloud/index.ts +0 -137
- package/src/vis-wrapper/README.md +0 -159
- package/src/vis-wrapper/icons.ts +0 -35
- package/src/vis-wrapper/index.ts +0 -276
- 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,
|
|
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
|
|
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
|
|
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
|
-
//
|
|
97
|
-
if (theme
|
|
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
|
-
},
|
|
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,
|
|
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
|
|
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;
|