calculateBoundingBox static method
Calculate bounding box for diagram (for centering view)
Implementation
static Rect calculateBoundingBox(Map<String, Offset> positions) {
if (positions.isEmpty) {
return const Rect.fromLTWH(0, 0, 800, 600);
}
double minX = double.infinity;
double minY = double.infinity;
double maxX = double.negativeInfinity;
double maxY = double.negativeInfinity;
const double nodeW = kNodeWidth;
const double nodeH = kNodeHeight;
for (final pos in positions.values) {
minX = minX < pos.dx ? minX : pos.dx;
minY = minY < pos.dy ? minY : pos.dy;
maxX = maxX > (pos.dx + nodeW) ? maxX : (pos.dx + nodeW);
maxY = maxY > (pos.dy + nodeH) ? maxY : (pos.dy + nodeH);
}
const padding = 100.0;
return Rect.fromLTRB(
minX - padding,
minY - padding,
maxX + padding,
maxY + padding,
);
}