insertLoopEdges method
Implementation
void insertLoopEdges(NodeOutput item, State state, List<LoopNode> loopNodes) {
var mtx = state.mtx, initialX = state.x, initialY = state.y;
loopNodes.forEach((LoopNode income) {
var id = income.id, node = income.node, renderIncomeId = item.id;
if (income.isSelfLoop) {
state.x = initialX + 1;
state.y = initialY;
String selfLoopId = "$id-self";
renderIncomeId = selfLoopId;
insertNodeOnMatrix(
NodeOutput(
id: selfLoopId,
next: [EdgeInput(outcome: id)],
anchorType: AnchorType.loop,
anchorMargin: AnchorMargin.start,
orientation: AnchorOrientation.bottomRight,
from: item.id,
to: id,
isAnchor: true,
renderIncomes: [node.id],
passedIncomes: [item.id],
childrenOnMatrix: 1,
),
state,
false);
}
state.y = min(income.y, state.y);
int initialHeight = mtx.height();
String fromId = "$id-${item.id}-from";
String toId = "$id-${item.id}-to";
node.renderIncomes.add(fromId);
if (state.y == 0 ||
mtx.hasLoopAnchorCollision(state.x, state.y - 1, income.x, toId)) {
mtx.insertRowBefore(state.y);
} else {
state.y--;
}
insertNodeOnMatrix(
NodeOutput(
id: toId,
next: [EdgeInput(outcome: id)],
anchorMargin: AnchorMargin.start,
anchorType: AnchorType.loop,
orientation: AnchorOrientation.topRight,
from: item.id,
to: id,
isAnchor: true,
renderIncomes: [renderIncomeId],
passedIncomes: [item.id],
childrenOnMatrix: 1,
),
state,
true,
);
if (initialHeight != mtx.height()) {
initialY++;
}
state.x = income.x;
insertNodeOnMatrix(
NodeOutput(
id: fromId,
next: [EdgeInput(outcome: id)],
anchorType: AnchorType.loop,
anchorMargin: AnchorMargin.end,
orientation: AnchorOrientation.topLeft,
from: item.id,
to: id,
isAnchor: true,
renderIncomes: [toId],
passedIncomes: [item.id],
childrenOnMatrix: 1,
),
state,
false,
);
state.x = initialX;
});
state.y = initialY;
return;
}