@antv/gpt-vis 0.3.1 → 0.3.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.
- package/dist/cjs/ConfigProvider/hooks/useConfig.d.ts +1 -1
- package/dist/cjs/ConfigProvider/hooks/useConfig.js +2 -2
- package/dist/cjs/FlowDiagram/helper.d.ts +7 -0
- package/dist/cjs/FlowDiagram/helper.js +83 -0
- package/dist/cjs/FlowDiagram/index.js +10 -2
- package/dist/cjs/Text/utils/useAntdDarkAlgorithm.js +3 -3
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/ConfigProvider/hooks/useConfig.d.ts +1 -1
- package/dist/esm/ConfigProvider/hooks/useConfig.js +5 -2
- package/dist/esm/FlowDiagram/helper.d.ts +7 -0
- package/dist/esm/FlowDiagram/helper.js +76 -0
- package/dist/esm/FlowDiagram/index.js +5 -2
- package/dist/esm/Text/utils/useAntdDarkAlgorithm.js +2 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/640.async.js +1 -0
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
- package/dist/umd/708.async.js +0 -1
|
@@ -8,6 +8,6 @@ export declare function useMapConfig<T extends MapProps>(name: Charts, props: T)
|
|
|
8
8
|
mapType: string | undefined;
|
|
9
9
|
token: string | undefined;
|
|
10
10
|
} & T;
|
|
11
|
-
export declare function useGraphConfig<T extends GraphOptions>(name: Charts,
|
|
11
|
+
export declare function useGraphConfig<T extends GraphOptions>(name: Charts, ...configs: Partial<T>[]): {
|
|
12
12
|
[x: string]: any;
|
|
13
13
|
};
|
|
@@ -95,9 +95,9 @@ function useGraphGlobalConfig(name) {
|
|
|
95
95
|
const componentConfig = useComponentGlobalConfig(name);
|
|
96
96
|
return (0, import_config.mergeGraphOptions)(graphConfig, componentConfig || {});
|
|
97
97
|
}
|
|
98
|
-
function useGraphConfig(name,
|
|
98
|
+
function useGraphConfig(name, ...configs) {
|
|
99
99
|
const globalConfig = useGraphGlobalConfig(name);
|
|
100
|
-
return (0, import_config.mergeGraphOptions)(
|
|
100
|
+
return (0, import_config.mergeGraphOptions)(globalConfig, ...configs);
|
|
101
101
|
}
|
|
102
102
|
// Annotate the CommonJS export names for ESM import in node:
|
|
103
103
|
0 && (module.exports = {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FlowGraphOptions, G6 } from '@ant-design/graphs';
|
|
2
|
+
/**
|
|
3
|
+
* Adjust graph configuration based on data characteristics.
|
|
4
|
+
* @param data - graph data
|
|
5
|
+
* @returns graph options
|
|
6
|
+
*/
|
|
7
|
+
export declare function getGraphOptionsByData(data: G6.GraphData): FlowGraphOptions;
|
|
@@ -0,0 +1,83 @@
|
|
|
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/FlowDiagram/helper.ts
|
|
20
|
+
var helper_exports = {};
|
|
21
|
+
__export(helper_exports, {
|
|
22
|
+
getGraphOptionsByData: () => getGraphOptionsByData
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(helper_exports);
|
|
25
|
+
function getGraphOptionsByData(data) {
|
|
26
|
+
if (isLinearStructure(data))
|
|
27
|
+
return {
|
|
28
|
+
node: {
|
|
29
|
+
style: {
|
|
30
|
+
ports: [
|
|
31
|
+
{ placement: "right" },
|
|
32
|
+
{ placement: "left" },
|
|
33
|
+
{ placement: "top" },
|
|
34
|
+
{ placement: "bottom" }
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
layout: {
|
|
39
|
+
type: "snake",
|
|
40
|
+
cols: 3,
|
|
41
|
+
rowGap: 40
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
function isLinearStructure(data) {
|
|
47
|
+
const { nodes = [], edges = [] } = data;
|
|
48
|
+
const inDegree = {};
|
|
49
|
+
const outDegree = {};
|
|
50
|
+
const adjList = {};
|
|
51
|
+
nodes.forEach((node) => {
|
|
52
|
+
inDegree[node.id] = 0;
|
|
53
|
+
outDegree[node.id] = 0;
|
|
54
|
+
adjList[node.id] = [];
|
|
55
|
+
});
|
|
56
|
+
edges.forEach((edge) => {
|
|
57
|
+
inDegree[edge.target]++;
|
|
58
|
+
outDegree[edge.source]++;
|
|
59
|
+
adjList[edge.source].push(edge.target);
|
|
60
|
+
});
|
|
61
|
+
const visited = /* @__PURE__ */ new Set();
|
|
62
|
+
const dfs = (nodeId) => {
|
|
63
|
+
if (visited.has(nodeId))
|
|
64
|
+
return;
|
|
65
|
+
visited.add(nodeId);
|
|
66
|
+
adjList[nodeId].forEach(dfs);
|
|
67
|
+
};
|
|
68
|
+
dfs(nodes[0].id);
|
|
69
|
+
if (visited.size !== nodes.length)
|
|
70
|
+
return false;
|
|
71
|
+
const sourceNodes = nodes.filter((node) => inDegree[node.id] === 0);
|
|
72
|
+
const sinkNodes = nodes.filter((node) => outDegree[node.id] === 0);
|
|
73
|
+
if (sourceNodes.length !== 1 || sinkNodes.length !== 1)
|
|
74
|
+
return false;
|
|
75
|
+
const middleNodes = nodes.filter((node) => inDegree[node.id] === 1 && outDegree[node.id] === 1);
|
|
76
|
+
if (middleNodes.length !== nodes.length - 2)
|
|
77
|
+
return false;
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
getGraphOptionsByData
|
|
83
|
+
});
|
|
@@ -36,9 +36,11 @@ var import_graphs = require("@ant-design/graphs");
|
|
|
36
36
|
var import_react = __toESM(require("react"));
|
|
37
37
|
var import_hooks = require("../ConfigProvider/hooks");
|
|
38
38
|
var import_graph = require("../utils/graph");
|
|
39
|
+
var import_helper = require("./helper");
|
|
39
40
|
var { TextNode } = import_graphs.RCNode;
|
|
40
41
|
var defaultConfig = {
|
|
41
42
|
autoResize: true,
|
|
43
|
+
autoFit: "center",
|
|
42
44
|
node: {
|
|
43
45
|
style: {
|
|
44
46
|
component: (d) => {
|
|
@@ -53,7 +55,8 @@ var defaultConfig = {
|
|
|
53
55
|
style: {
|
|
54
56
|
fontSize: 12,
|
|
55
57
|
background: "linear-gradient(-89deg, #64b7f2 0%, #4c95f3 100%)"
|
|
56
|
-
}
|
|
58
|
+
},
|
|
59
|
+
borderWidth: 2
|
|
57
60
|
}
|
|
58
61
|
);
|
|
59
62
|
},
|
|
@@ -94,7 +97,12 @@ var defaultConfig = {
|
|
|
94
97
|
var FlowDiagram = (props) => {
|
|
95
98
|
const { data: propsData, ...restProps } = props;
|
|
96
99
|
const data = (0, import_react.useMemo)(() => (0, import_graph.visGraphData2GraphData)(propsData), [propsData]);
|
|
97
|
-
const config = (0, import_hooks.useGraphConfig)(
|
|
100
|
+
const config = (0, import_hooks.useGraphConfig)(
|
|
101
|
+
"FlowDiagram",
|
|
102
|
+
defaultConfig,
|
|
103
|
+
(0, import_helper.getGraphOptionsByData)(data),
|
|
104
|
+
restProps
|
|
105
|
+
);
|
|
98
106
|
return /* @__PURE__ */ import_react.default.createElement(import_graphs.FlowGraph, { data, ...config });
|
|
99
107
|
};
|
|
100
108
|
var FlowDiagram_default = FlowDiagram;
|
|
@@ -25,11 +25,11 @@ module.exports = __toCommonJS(useAntdDarkAlgorithm_exports);
|
|
|
25
25
|
var import_antd = require("antd");
|
|
26
26
|
var import_lodash = require("lodash");
|
|
27
27
|
var import_react = require("react");
|
|
28
|
-
var { darkAlgorithm } = import_antd.theme;
|
|
29
28
|
var useAntdDarkAlgorithm = () => {
|
|
30
|
-
var _a;
|
|
29
|
+
var _a, _b;
|
|
30
|
+
const darkAlgorithm = (_a = import_antd.theme) == null ? void 0 : _a.darkAlgorithm;
|
|
31
31
|
const config = (0, import_react.useContext)(import_antd.ConfigProvider.ConfigContext);
|
|
32
|
-
const currentAlgorithm = (
|
|
32
|
+
const currentAlgorithm = (_b = config.theme) == null ? void 0 : _b.algorithm;
|
|
33
33
|
if ((0, import_lodash.isArray)(currentAlgorithm) && currentAlgorithm.includes(darkAlgorithm))
|
|
34
34
|
return true;
|
|
35
35
|
return currentAlgorithm === darkAlgorithm;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.3.
|
|
1
|
+
declare const _default: "0.3.2";
|
|
2
2
|
export default _default;
|
package/dist/cjs/version.js
CHANGED
|
@@ -8,6 +8,6 @@ export declare function useMapConfig<T extends MapProps>(name: Charts, props: T)
|
|
|
8
8
|
mapType: string | undefined;
|
|
9
9
|
token: string | undefined;
|
|
10
10
|
} & T;
|
|
11
|
-
export declare function useGraphConfig<T extends GraphOptions>(name: Charts,
|
|
11
|
+
export declare function useGraphConfig<T extends GraphOptions>(name: Charts, ...configs: Partial<T>[]): {
|
|
12
12
|
[x: string]: any;
|
|
13
13
|
};
|
|
@@ -51,7 +51,10 @@ function useGraphGlobalConfig(name) {
|
|
|
51
51
|
var componentConfig = useComponentGlobalConfig(name);
|
|
52
52
|
return mergeGraphOptions(graphConfig, componentConfig || {});
|
|
53
53
|
}
|
|
54
|
-
export function useGraphConfig(name
|
|
54
|
+
export function useGraphConfig(name) {
|
|
55
55
|
var globalConfig = useGraphGlobalConfig(name);
|
|
56
|
-
|
|
56
|
+
for (var _len = arguments.length, configs = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
57
|
+
configs[_key - 1] = arguments[_key];
|
|
58
|
+
}
|
|
59
|
+
return mergeGraphOptions.apply(void 0, [globalConfig].concat(configs));
|
|
57
60
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FlowGraphOptions, G6 } from '@ant-design/graphs';
|
|
2
|
+
/**
|
|
3
|
+
* Adjust graph configuration based on data characteristics.
|
|
4
|
+
* @param data - graph data
|
|
5
|
+
* @returns graph options
|
|
6
|
+
*/
|
|
7
|
+
export declare function getGraphOptionsByData(data: G6.GraphData): FlowGraphOptions;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adjust graph configuration based on data characteristics.
|
|
3
|
+
* @param data - graph data
|
|
4
|
+
* @returns graph options
|
|
5
|
+
*/
|
|
6
|
+
export function getGraphOptionsByData(data) {
|
|
7
|
+
if (isLinearStructure(data)) return {
|
|
8
|
+
node: {
|
|
9
|
+
style: {
|
|
10
|
+
ports: [{
|
|
11
|
+
placement: 'right'
|
|
12
|
+
}, {
|
|
13
|
+
placement: 'left'
|
|
14
|
+
}, {
|
|
15
|
+
placement: 'top'
|
|
16
|
+
}, {
|
|
17
|
+
placement: 'bottom'
|
|
18
|
+
}]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
layout: {
|
|
22
|
+
type: 'snake',
|
|
23
|
+
cols: 3,
|
|
24
|
+
rowGap: 40
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
function isLinearStructure(data) {
|
|
30
|
+
var _data$nodes = data.nodes,
|
|
31
|
+
nodes = _data$nodes === void 0 ? [] : _data$nodes,
|
|
32
|
+
_data$edges = data.edges,
|
|
33
|
+
edges = _data$edges === void 0 ? [] : _data$edges;
|
|
34
|
+
var inDegree = {};
|
|
35
|
+
var outDegree = {};
|
|
36
|
+
var adjList = {};
|
|
37
|
+
nodes.forEach(function (node) {
|
|
38
|
+
inDegree[node.id] = 0;
|
|
39
|
+
outDegree[node.id] = 0;
|
|
40
|
+
adjList[node.id] = [];
|
|
41
|
+
});
|
|
42
|
+
edges.forEach(function (edge) {
|
|
43
|
+
inDegree[edge.target]++;
|
|
44
|
+
outDegree[edge.source]++;
|
|
45
|
+
adjList[edge.source].push(edge.target);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// 检查图是否连通
|
|
49
|
+
// Check if the graph is connected
|
|
50
|
+
var visited = new Set();
|
|
51
|
+
var dfs = function dfs(nodeId) {
|
|
52
|
+
if (visited.has(nodeId)) return;
|
|
53
|
+
visited.add(nodeId);
|
|
54
|
+
adjList[nodeId].forEach(dfs);
|
|
55
|
+
};
|
|
56
|
+
dfs(nodes[0].id);
|
|
57
|
+
if (visited.size !== nodes.length) return false;
|
|
58
|
+
|
|
59
|
+
// 检查是否有且仅有一个源节点和一个汇节点
|
|
60
|
+
// Check if there is exactly one source node and one sink node
|
|
61
|
+
var sourceNodes = nodes.filter(function (node) {
|
|
62
|
+
return inDegree[node.id] === 0;
|
|
63
|
+
});
|
|
64
|
+
var sinkNodes = nodes.filter(function (node) {
|
|
65
|
+
return outDegree[node.id] === 0;
|
|
66
|
+
});
|
|
67
|
+
if (sourceNodes.length !== 1 || sinkNodes.length !== 1) return false;
|
|
68
|
+
|
|
69
|
+
// 检查中间节点是否只有一个前驱和一个后继
|
|
70
|
+
// Check if the middle nodes have only one predecessor and one successor
|
|
71
|
+
var middleNodes = nodes.filter(function (node) {
|
|
72
|
+
return inDegree[node.id] === 1 && outDegree[node.id] === 1;
|
|
73
|
+
});
|
|
74
|
+
if (middleNodes.length !== nodes.length - 2) return false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
@@ -6,9 +6,11 @@ import { FlowGraph as ADCFlowGraph, RCNode } from '@ant-design/graphs';
|
|
|
6
6
|
import React, { useMemo } from 'react';
|
|
7
7
|
import { useGraphConfig } from "../ConfigProvider/hooks";
|
|
8
8
|
import { visGraphData2GraphData } from "../utils/graph";
|
|
9
|
+
import { getGraphOptionsByData } from "./helper";
|
|
9
10
|
var TextNode = RCNode.TextNode;
|
|
10
11
|
var defaultConfig = {
|
|
11
12
|
autoResize: true,
|
|
13
|
+
autoFit: 'center',
|
|
12
14
|
node: {
|
|
13
15
|
style: {
|
|
14
16
|
component: function component(d) {
|
|
@@ -21,7 +23,8 @@ var defaultConfig = {
|
|
|
21
23
|
style: {
|
|
22
24
|
fontSize: 12,
|
|
23
25
|
background: 'linear-gradient(-89deg, #64b7f2 0%, #4c95f3 100%)'
|
|
24
|
-
}
|
|
26
|
+
},
|
|
27
|
+
borderWidth: 2
|
|
25
28
|
});
|
|
26
29
|
},
|
|
27
30
|
size: [140, 32]
|
|
@@ -67,7 +70,7 @@ var FlowDiagram = function FlowDiagram(props) {
|
|
|
67
70
|
var data = useMemo(function () {
|
|
68
71
|
return visGraphData2GraphData(propsData);
|
|
69
72
|
}, [propsData]);
|
|
70
|
-
var config = useGraphConfig('FlowDiagram', defaultConfig, restProps);
|
|
73
|
+
var config = useGraphConfig('FlowDiagram', defaultConfig, getGraphOptionsByData(data), restProps);
|
|
71
74
|
return /*#__PURE__*/React.createElement(ADCFlowGraph, _extends({
|
|
72
75
|
data: data
|
|
73
76
|
}, config));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { ConfigProvider, theme as antdTheme } from 'antd';
|
|
2
2
|
import { isArray } from 'lodash';
|
|
3
3
|
import { useContext } from 'react';
|
|
4
|
-
var darkAlgorithm = antdTheme.darkAlgorithm;
|
|
5
4
|
|
|
6
5
|
/** 判断是否运用了 antd dark algorithm */
|
|
7
6
|
export var useAntdDarkAlgorithm = function useAntdDarkAlgorithm() {
|
|
8
7
|
var _config$theme;
|
|
8
|
+
// 放到函数内部,避免用户使用 antd@4,theme 变量不存在情况!!!
|
|
9
|
+
var darkAlgorithm = antdTheme === null || antdTheme === void 0 ? void 0 : antdTheme.darkAlgorithm;
|
|
9
10
|
var config = useContext(ConfigProvider.ConfigContext);
|
|
10
11
|
var currentAlgorithm = (_config$theme = config.theme) === null || _config$theme === void 0 ? void 0 : _config$theme.algorithm;
|
|
11
12
|
if (isArray(currentAlgorithm) && currentAlgorithm.includes(darkAlgorithm)) return true;
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "0.3.
|
|
1
|
+
declare const _default: "0.3.2";
|
|
2
2
|
export default _default;
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.3.
|
|
1
|
+
export default '0.3.2';
|