TreeLinePlan.forRow constructor

TreeLinePlan.forRow({
  1. required FlatNode row,
  2. required double lineWidth,
})

Derives the line plan for row. Each column is lineWidth wide and lines are centred within their column.

Implementation

factory TreeLinePlan.forRow({
  required FlatNode row,
  required double lineWidth,
}) {
  final continuationXs = <double>[];
  for (var d = 0; d < row.depth; d++) {
    // Bit d clear => the ancestor at depth d still has siblings below, so its
    // vertical guide continues through this row.
    if ((row.ancestorIsLastMask >> d) & 1 == 0) {
      continuationXs.add(d * lineWidth + lineWidth / 2);
    }
  }

  if (row.isRoot) {
    return TreeLinePlan(
      continuationXs: continuationXs,
      connectorX: null,
      connectorIsLast: false,
      connectorEndX: 0,
    );
  }

  return TreeLinePlan(
    continuationXs: continuationXs,
    connectorX: (row.depth - 1) * lineWidth + lineWidth / 2,
    connectorIsLast: row.isLast,
    connectorEndX: row.depth * lineWidth,
  );
}