firstWalk method
Implementation
void firstWalk(Graph graph, Node node, int depth, int number) {
final nodeData = getNodeData(node)!;
nodeData.depth = depth;
nodeData.number = number;
minNodeHeight = min(minNodeHeight, node.height);
minNodeWidth = min(minNodeWidth, node.width);
maxNodeWidth = max(maxNodeWidth, node.width);
maxNodeHeight = max(maxNodeHeight, node.height);
if (isLeaf(graph, node)) {
// if the node has no left sibling, prelim(node) should be set to 0, but we don't have to set it
// here, because it's already initialized with 0
if (hasLeftSibling(graph, node)) {
final leftSibling = getLeftSibling(graph, node);
nodeData.prelim = getPrelim(leftSibling) + getSpacing(graph, leftSibling, node);
}
} else {
final leftMost = getLeftMostChild(graph, node);
final rightMost = getRightMostChild(graph, node);
var defaultAncestor = leftMost;
Node? next = leftMost;
var i = 1;
while (next != null) {
firstWalk(graph, next, depth + 1, i++);
defaultAncestor = apportion(graph, next, defaultAncestor);
next = getRightSibling(graph, next);
}
executeShifts(graph, node);
var vertical = isVertical();
var midPoint = 0.5 *
((getPrelim(leftMost) + getPrelim(rightMost) + (vertical ? rightMost!.width : rightMost!.height)) -
(vertical ? node.width : node.height));
if (hasLeftSibling(graph, node)) {
final leftSibling = getLeftSibling(graph, node);
nodeData.prelim = getPrelim(leftSibling) + getSpacing(graph, leftSibling, node);
nodeData.modifier = nodeData.prelim - midPoint;
} else {
nodeData.prelim = midPoint;
}
}
}