getPortPosition method

Offset getPortPosition(
  1. String portId, {
  2. required double portSize,
  3. EdgeInsets? padding,
  4. NodeShape? shape,
})

Gets the connection point for a port where line endpoints should attach.

Connections should align with the flat edge of the capsule half shapes that represent ports. This method returns absolute coordinates in the graph coordinate space.

Parameters:

  • portId - The unique identifier of the port
  • portSize - The size of the port widget
  • padding - Optional padding for shaped nodes (defaults to standard 4px for shapes)
  • shape - Optional shape to use for port position calculation

Returns the absolute Offset where connection lines should attach.

Throws ArgumentError if no port with the given portId is found.

Implementation

Offset getPortPosition(
  String portId, {
  required double portSize,
  EdgeInsets? padding,
  NodeShape? shape,
}) {
  final portHalfSize = portSize / 2;

  // For shaped nodes, use padding (default to standard 4px if not provided)
  final effectivePadding = shape != null
      ? (padding ?? const EdgeInsets.all(4.0))
      : EdgeInsets.zero;

  // Convert from node coordinates to absolute graph coordinates
  // Use visual position for consistent rendering
  return visualPosition.value +
      getVisualPortPosition(
        portId,
        portSize: portSize,
        padding: effectivePadding,
        shape: shape,
      ) +
      Offset(portHalfSize, portHalfSize);
}