|
@@ -77,14 +77,15 @@ export default function GraphModel() {
|
|
|
},
|
|
|
],
|
|
|
});
|
|
|
+ return pageNodeRef.current;
|
|
|
};
|
|
|
|
|
|
const initCells = (cells: Cell.Properties[]) => {
|
|
|
if (graphRef.current) {
|
|
|
// 添加节点
|
|
|
- (cells || []).forEach((item) => {
|
|
|
+ const list = (cells || []).map((item) => {
|
|
|
if (item.shape !== "edge") {
|
|
|
- graphRef.current?.addNode({
|
|
|
+ return {
|
|
|
...item,
|
|
|
data: JSON.parse(item?.data),
|
|
|
ports: JSON.parse(item?.ports || "{}"),
|
|
@@ -96,22 +97,19 @@ export default function GraphModel() {
|
|
|
menu: nodeMenu,
|
|
|
},
|
|
|
}]
|
|
|
- });
|
|
|
+ };
|
|
|
}
|
|
|
- });
|
|
|
- // 添加边
|
|
|
- (cells || []).forEach((item) => {
|
|
|
if (item.shape === "edge") {
|
|
|
- graphRef.current?.addEdge({
|
|
|
+ return {
|
|
|
...item,
|
|
|
data: JSON.parse(item?.data),
|
|
|
attrs: JSON.parse(item?.attrs as unknown as string || "{}"),
|
|
|
source: JSON.parse(item?.source),
|
|
|
target: JSON.parse(item?.target),
|
|
|
- connector: item?.connector ? JSON.parse(item.connector) : undefined,
|
|
|
- labels: item?.labels ? JSON.parse(item.labels) : undefined,
|
|
|
- router: 'manhattan',
|
|
|
- // router: JSON.parse(item?.router || "{}"),
|
|
|
+ ...(item?.connector ? {connector: JSON.parse(item.connector)} : {}),
|
|
|
+ ...(item?.labels ? {labels: JSON.parse(item.labels)} : {}),
|
|
|
+ // router: 'manhattan',
|
|
|
+ router: item.router,
|
|
|
tools: [
|
|
|
{
|
|
|
name: "contextmenu",
|
|
@@ -120,10 +118,11 @@ export default function GraphModel() {
|
|
|
},
|
|
|
},
|
|
|
]
|
|
|
- });
|
|
|
+ };
|
|
|
}
|
|
|
- })
|
|
|
-
|
|
|
+ });
|
|
|
+ graphRef.current.fromJSON({ cells: list as any });
|
|
|
+ addPageNode();
|
|
|
graphRef.current.on("cell:change:*", handleChangeAll);
|
|
|
handleGraphApiEvent(graphRef.current);
|
|
|
}
|