nodesBounds property
Rect
get
nodesBounds
Gets the bounding rectangle that encompasses all nodes in the graph.
Calculates the minimal rectangle that contains all nodes based on their positions and sizes.
Returns Rect.zero if there are no nodes.
Example:
final bounds = controller.nodesBounds;
print('Graph size: ${bounds.width} x ${bounds.height}');
Implementation
Rect get nodesBounds {
if (_nodes.isEmpty) return Rect.zero;
double minX = double.infinity;
double minY = double.infinity;
double maxX = double.negativeInfinity;
double maxY = double.negativeInfinity;
for (final node in _nodes.values) {
final pos = node.position.value;
final size = node.size.value;
minX = math.min(minX, pos.dx);
minY = math.min(minY, pos.dy);
maxX = math.max(maxX, pos.dx + size.width);
maxY = math.max(maxY, pos.dy + size.height);
}
return Rect.fromLTRB(minX, minY, maxX, maxY);
}