fitToNodes method
Recomputes the group's position and size to fit all member nodes.
Only meaningful for GroupBehavior.explicit. For other behaviors, this method does nothing.
The lookup function is used to retrieve node objects by ID.
Nodes that cannot be found are ignored.
The resulting bounds will be the bounding box of all member nodes plus padding on each side.
Implementation
void fitToNodes(NodeLookup lookup) {
if (behavior != GroupBehavior.explicit) return;
if (_nodeIds.isEmpty) return;
final nodeBounds = _computeNodeBounds(lookup);
if (nodeBounds == null) return;
runInAction(() {
final newPos = Offset(
nodeBounds.left - padding.left,
nodeBounds.top - padding.top,
);
position = newPos;
visualPosition = newPos;
setSize(
Size(
nodeBounds.width + padding.horizontal,
nodeBounds.height + padding.vertical,
),
);
});
}