position method

  1. @protected
void position(
  1. Iterable<TreeNode<Object>> nodes,
  2. MutableRectangle<num> boundingRect,
  3. num side,
  4. num layoutArea,
)
inherited

Positions each renderer element in nodes within the boundingRect.

side is defined as the smallest side of the layoutArea.

Consider the following boundingRect:

boundingRect:
         ------------------
        |************|     |
 (side) |*layoutArea*|     | height
        |************|     |
         ------------------
                width

Implementation

@protected
void position(Iterable<TreeNode<Object>> nodes, MutableRectangle boundingRect,
    num side, num layoutArea) {
  var top = boundingRect.top;
  var left = boundingRect.left;
  var length = side > 0 ? (layoutArea / side) : 0;

  // [side] is equal to the height of the boundingRect, so stacks rectangles
  // vertically. [length] is the width of the stacking rectangles.
  if (side == boundingRect.height) {
    // Truncates the length since it is out of bounds.
    if (length > boundingRect.width) length = boundingRect.width.toInt();
    for (final node in nodes) {
      final element = _getRendererElement(node);
      final height = min(boundingRect.top + boundingRect.height - top,
          length > 0 ? (element.area / length) : 0);
      element.boundingRect = Rectangle(left, top, length, height);
      top += height;
    }
    boundingRect.left += length;
    boundingRect.width -= length;
  } else {
    // Positions rectangles horizontally.
    if (length > boundingRect.height) length = boundingRect.height.toInt();
    for (final node in nodes) {
      final element = _getRendererElement(node);
      final width = min(boundingRect.left + boundingRect.width - left,
          length > 0 ? (element.area / length) : 0);
      element.boundingRect = Rectangle(left, top, width, length);
      left += width;
    }
    boundingRect.top += length;
    boundingRect.height -= length;
  }
}