aligned graph

This commit is contained in:
ari committed 2022-04-30 23:10:04 -04:00
1 parent 7ae50e634a
commit 1ed1e63330
2 files changed
+34 -11

No files matched your search

@@ -307,6 +307,13 @@ Complex.args = {
}
]
}
},
{
"$smType": "condition",
"condition": "and",
"condition_data": {
"conditions": []
}
}
]
}
@@ -13,13 +13,19 @@ export const sequenceToFlow = (
prefix: string = "",
) => {
let lastPointId = fromPoint;
let lasPos: XYPosition | null = null;
for (let i = 0; i < sequence.length; i++) {
const node = sequence[i];
const nodeId = `${prefix}n-${i}`;
const position = computeNodePos(i, dims);
let position: XYPosition;
if (lasPos) {
position = { x: lasPos.x + dims.nodeWidth * dims.distanceFactor, y: dims.padding.y }
} else {
position = computeNodePos(i, dims);
}
if (node.$smType === 'action') {
if (node.action === 'choose') {
addChooseNode(flowData, node, i, nodeId, lastPointId, dims)
position = addChooseNode(flowData, node, position, nodeId, lastPointId, dims)
} else {
addSingleNode(flowData, node, position, nodeId, dims);
}
@@ -33,7 +39,12 @@ export const sequenceToFlow = (
target: nodeId,
});
lastPointId = nodeId;
lasPos = position;
}
return {
position: lasPos,
pointId: lastPointId,
};
}
const computeNodePos = (i: number, { padding, distanceFactor, nodeWidth }: DAGFlowDims): XYPosition => ({
@@ -71,28 +82,33 @@ const addSingleNode = (
const addChooseNode = (
flowData: FlowData,
node: ChooseAction,
i: number,
position: XYPosition,
nodeId: string,
lastPointId: string,
dims: DAGFlowDims,
) => {
const { x, y } = computeNodePos(i, dims);
addSingleNode(flowData, node, { x, y }, nodeId, dims);
addSingleNode(flowData, node, position, nodeId, dims);
let lastPos: XYPosition = position;
node.action_data.choose.forEach(({ sequence, conditions }, j) => {
sequenceToFlow(flowData, sequence, nodeId, {
const { y } = lastPos;
const lastPoint = sequenceToFlow(flowData, sequence, nodeId, {
...dims,
padding: {
x: x - dims.nodeWidth,
y: y + dims.nodeHeight * (j + 0.25) * dims.distanceFactor,
x: position.x - dims.nodeWidth,
y: y + dims.nodeHeight * dims.distanceFactor,
},
}, `${nodeId}.${j}.`)
}, `${nodeId}.${j}.`);
if (lastPoint.position) {
lastPos = lastPoint.position;
}
})
const totalChildren = node.action_data.choose.length;
sequenceToFlow(flowData, node.action_data.default, nodeId, {
...dims,
padding: {
x: x - dims.nodeWidth,
y: y + dims.nodeHeight * (totalChildren + 0.25) * dims.distanceFactor,
x: position.x - dims.nodeWidth,
y: lastPos.y + dims.nodeHeight * (totalChildren + 0.25) * dims.distanceFactor,
},
}, `${nodeId}.${totalChildren}.`)
return lastPos
}