createGroupAnnotationAroundNodes method
Creates a group annotation that surrounds the specified nodes.
This is a convenience method that calculates the bounding box of the given nodes and creates a group that encompasses them with padding.
Parameters
id: Unique identifier for the grouptitle: Display title shown in the group headernodeIds: Set of node IDs to surroundpadding: Space between the group boundary and the nodescolor: Color for the group header and background tint
Implementation
GroupAnnotation createGroupAnnotationAroundNodes({
required String id,
required String title,
required Set<String> nodeIds,
EdgeInsets padding = const EdgeInsets.all(20.0),
Color color = Colors.blue,
}) {
final nodes = _parentController.nodes;
final dependentNodes = nodeIds
.map((nodeId) => nodes[nodeId])
.where((node) => node != null)
.cast<Node<T>>()
.toList();
Offset initialPosition = Offset.zero;
Size initialSize = const Size(200, 150);
if (dependentNodes.isNotEmpty) {
// Calculate bounding box of all dependent nodes
double minX = double.infinity;
double minY = double.infinity;
double maxX = double.negativeInfinity;
double maxY = double.negativeInfinity;
for (final node in dependentNodes) {
final pos = node.visualPosition.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);
}
// Add padding around the nodes
minX -= padding.left;
minY -= padding.top;
maxX += padding.right;
maxY += padding.bottom;
initialPosition = Offset(minX, minY);
initialSize = Size(maxX - minX, maxY - minY);
}
return GroupAnnotation(
id: id,
position: initialPosition,
size: initialSize,
title: title,
color: color,
);
}