measureNode method

Size measureNode(
  1. MermaidNode node,
  2. MermaidStyle style
)

Measures the size of a node

Implementation

Size measureNode(MermaidNode node, MermaidStyle style) {
  final nodeStyle = style.getNodeStyle(node.className);

  // Calculate text size
  final fontSize = nodeStyle.fontSize;
  final textWidth = node.label.length * fontSize * 0.6;
  final textHeight = fontSize * 1.4;

  // Add padding based on shape
  double horizontalPadding = 24.0;
  double verticalPadding = 16.0;

  switch (node.shape) {
    case NodeShape.circle:
    case NodeShape.doubleCircle:
      // Circle needs equal dimensions
      final diameter = math.max(textWidth, textHeight) + 32;
      return Size(diameter, diameter);

    case NodeShape.diamond:
    case NodeShape.hexagon:
      // These shapes need more horizontal space
      horizontalPadding = 40.0;
      verticalPadding = 24.0;
      break;

    case NodeShape.stadium:
      // Stadium is wider
      horizontalPadding = 32.0;
      break;

    case NodeShape.cylinder:
      // Cylinder needs extra height for the 3D effect
      verticalPadding = 28.0;
      break;

    default:
      break;
  }

  return Size(
    textWidth + horizontalPadding,
    textHeight + verticalPadding,
  );
}