Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: common util func handleSingleNodeGraph #224

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from

Conversation

ayu-exorcist
Copy link

comboCombined 调用 handleSingleNodeGraph 函数的前提是: 移除了 _isCombo 状态的 nodes 的个数 <= 1

const nodes: Node[] = graph
.getAllNodes()
.filter((node) => !node.data._isCombo);
const combos: Node[] = graph
.getAllNodes()
.filter((node) => node.data._isCombo);
const edges: Edge[] = graph.getAllEdges();
const n = nodes?.length;
if (!n || n === 1) {
return handleSingleNodeGraph(graph, assign, center);
}

但是 handleSingleNodeGraph 函数内部处理时, 获取到的是包含 _isCombo 状态的 nodes.

export const handleSingleNodeGraph = (
graph: Graph,
assign: boolean,
center: PointTuple,
) => {
const nodes = graph.getAllNodes();
const edges = graph.getAllEdges();
if (!nodes?.length) {
const result = { nodes: [] as any[], edges };
return result;
}
if (nodes.length === 1) {
if (assign) {
graph.mergeNodeData(nodes[0].id, {
x: center[0],
y: center[1],
});
}
const result = {
nodes: [
{
...nodes[0],
data: {
...nodes[0].data,
x: center[0],
y: center[1],
},
},
],
edges,
};
return result;
}
};

这会导致使用 combo-combined 布局时, 存在某些异常->handleSingleNodeGraph 函数返回 undefined, 异常数据如下所示:

{
  nodes: [{id: 'node1'}, {id: 'node2', combo: 'combo1'}, {id: 'node3', combo: 'combo1'}],
  combos: [{id: 'combo1'}],
}

Copy link
Author

@ayu-exorcist ayu-exorcist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样改动可能会对其他布局造成影响, 或许这里可以将 nodes 和 edges 主动传入, 来屏蔽不同布局调用 handleSingleNodeGraph() 函数和该函数定义处数据不一致导致的问题

export const handleSingleNodeGraph = (
  nodes: Node[],
  edges: Edge[],
  graph: Graph,
  assign: boolean,
  center: PointTuple,
) => {

或者传入布局的 id, 在 handleSingleNodeGraph() 进行判断处理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant