Skip to content

Commit

Permalink
fix: lift transition nodes to lowest common parent
Browse files Browse the repository at this point in the history
  • Loading branch information
abrgr committed Sep 19, 2023
1 parent 3e1d2b5 commit f68a758
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions src/transformers/elk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,29 +258,27 @@ export function _flowToElkGraph(
(edge) => !edge.sources[0].startsWith("synth:")
);

const syntheticEdgeNodes = ourEdges
.filter((edge) => edge.targets[0].startsWith("synth:"))
.map((edge) => {
const transitionId = edge.data.transitionId;
const pos = sizeMap.get(transitionId);

return {
id: transitionId,
height: pos?.height,
width: pos?.width,
layoutOptions: layoutOpts,
sourceState: edge.data.source,
syntheticEdgeNodes: [],
ports: [
{
id: `synth:target:${transitionId}`,
},
{
id: `synth:source:${transitionId}`,
},
],
};
});
const syntheticEdgeNodes = syntheticEdges.map((edge) => {
const transitionId = edge.data.transitionId;
const pos = sizeMap.get(transitionId);

return {
id: transitionId,
height: pos?.height,
width: pos?.width,
layoutOptions: layoutOpts,
sourceState: edge.data.source,
syntheticEdgeNodes: [],
ports: [
{
id: `synth:target:${transitionId}`,
},
{
id: `synth:source:${transitionId}`,
},
],
};
});

const sourcePorts = ourEdges.map((edge) => ({
edge,
Expand Down Expand Up @@ -345,11 +343,19 @@ export function _flowToElkGraph(
}
);

const transitionsToLift = new Set(
otherEdges.map((e) => e.data.transitionId)
);
const [liftedChildren, properChildren] = partition(
subGraph.children || [],
(child) => transitionsToLift.has(child.id as PositionedItemId)
);

edges = edges.concat(otherEdges);

return subGraph.syntheticEdgeNodes.concat([
{ ...subGraph, edges: localEdges },
]);
return subGraph.syntheticEdgeNodes
.concat([{ ...subGraph, children: properChildren, edges: localEdges }])
.concat(liftedChildren);
})
.sort((a, b) =>
a.id === initialChildStatePositionId
Expand Down

0 comments on commit f68a758

Please sign in to comment.