Skip to content

Commit

Permalink
fix: filter elements before applying auto-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Feb 19, 2024
1 parent 70518b8 commit bb525ce
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/services/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,27 @@ export const layout = async (
return [];
}

const invertEdges = algorithm === model.LayoutAlgorithm.TREE;
const nodeIds = nodes
.filter((node) => node.type === "atom" || node.type === "scheme")
.map((node) => node.data.id);

const elkNodes: ElkNode[] = nodes.map((node) => ({
id: node.id,
width: node.width ?? DEFAULT_WIDTH,
height: node.height ?? DEFAULT_HEIGHT,
}));
const elkNodes: ElkNode[] = nodes
.filter((node) => nodeIds.includes(node.id))
.map((node) => ({
id: node.id,
width: node.width ?? DEFAULT_WIDTH,
height: node.height ?? DEFAULT_HEIGHT,
}));

const elkEdges: ElkExtendedEdge[] = edges.map((edge) => {
const target = invertEdges ? edge.source : edge.target;
const source = invertEdges ? edge.target : edge.source;

return {
const elkEdges: ElkExtendedEdge[] = edges
.filter(
(edge) => nodeIds.includes(edge.source) && nodeIds.includes(edge.target)
)
.map((edge) => ({
id: edge.id,
targets: [target],
sources: [source],
};
});
targets: [edge.target],
sources: [edge.source],
}));

const elk = new Elk({ defaultLayoutOptions: layoutOptions[algorithm] });
const elkGraph = await elk.layout({
Expand Down

0 comments on commit bb525ce

Please sign in to comment.