LabelCalculator class

Utility class for calculating connection label positions.

This calculator determines the exact rectangular bounds for connection labels positioned anywhere along the connection path using anchor values (0.0-1.0) and perpendicular offsets.

Key Features

  • Arbitrary positioning: Labels can be placed at any point (0.0-1.0) along the path
  • Perpendicular offset: Labels can be offset perpendicular to the path direction
  • Path-accurate: Uses actual connection path geometry for precise positioning
  • Multiple labels: Supports any number of labels per connection

Usage Example

final labelRects = EdgeLabelPositionCalculator.calculateAllLabelPositions(
  connection: myConnection,
  sourceNode: sourceNode,
  targetNode: targetNode,
  connectionStyle: ConnectionStyles.smoothstep,
  curvature: 0.5,
  portSize: 8.0,
  endpointSize: Size.square(5.0),
  labelTheme: myLabelTheme,
);

// Render each label at its calculated position
for (final rect in labelRects) {
  // Draw label at rect
}

See also:

Constructors

LabelCalculator()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

calculateAllLabelPositions({required Connection connection, required Node sourceNode, required Node targetNode, required ConnectionStyle connectionStyle, required double curvature, required Size endpointSize, required LabelTheme labelTheme, ConnectionPathCache? pathCache, double portExtension = 10.0, double startGap = 0.0, double endGap = 0.0}) List<Rect>
Calculates all label positions for a connection.
calculatePositionAtAnchor({required ConnectionStyle connectionStyle, required Offset start, required Offset end, required double anchor, required double curvature, Port? sourcePort, Port? targetPort, double portExtension = 10.0}) Offset
Calculates a position at an arbitrary point along a connection.