createGroupAnnotation method
Implementation
GroupAnnotation createGroupAnnotation({
required String id,
required String title,
required Set<String> nodeIds,
required Map<String, Node<T>> nodes,
EdgeInsets padding = const EdgeInsets.all(20.0),
Color color = Colors.blue,
}) {
// Calculate initial position and size based on dependent nodes
final dependentNodes = nodeIds
.map((nodeId) => nodes[nodeId])
.where((node) => node != null)
.cast<Node<T>>()
.toList();
Offset initialPosition = Offset.zero;
Size initialSize = const Size(100, 100);
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) {
// Use visual position (what's actually rendered) not logical position!
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);
}
final groupAnnotation = GroupAnnotation(
id: id,
position: initialPosition,
title: title,
padding: padding,
color: color,
dependencies: nodeIds,
);
// Set the initial calculated size
groupAnnotation.updateCalculatedSize(initialSize);
return groupAnnotation;
}