layoutLaneFrames function

Map<String, DiagramRect> layoutLaneFrames(
  1. Map<String, DiagramRect> lanes, {
  2. DiagramLaneDirection direction = DiagramLaneDirection.rows,
  3. DiagramSize? laneSize,
  4. double gap = 0,
})

Places lane boundaries in the supplied order. Contents are handled by the engine's ordinary ownership translation, never scaled by this planner.

Implementation

Map<String, DiagramRect> layoutLaneFrames(
  Map<String, DiagramRect> lanes, {
  DiagramLaneDirection direction = DiagramLaneDirection.rows,
  DiagramSize? laneSize,
  double gap = 0,
}) {
  if (!gap.isFinite ||
      gap < 0 ||
      (laneSize != null &&
          (!laneSize.width.isFinite ||
              !laneSize.height.isFinite ||
              laneSize.width <= 0 ||
              laneSize.height <= 0))) {
    throw ArgumentError('Lane size must be positive and gap nonnegative.');
  }
  if (lanes.isEmpty) return const {};
  final bounds = DiagramRect.union(lanes.values);
  var x = bounds.left;
  var y = bounds.top;
  final result = <String, DiagramRect>{};
  for (final entry in lanes.entries) {
    final size = laneSize ?? entry.value.size;
    result[entry.key] = DiagramRect.fromLTWH(x, y, size.width, size.height);
    switch (direction) {
      case DiagramLaneDirection.rows:
        y += size.height + gap;
      case DiagramLaneDirection.columns:
        x += size.width + gap;
    }
  }
  return Map.unmodifiable(result);
}