tile method

  1. @override
void tile(
  1. TreeNode<Object> node
)

Uses squarification as the tiling algorithm for this tree map.

The idea is to present treemap layouts in which the rectangles approximate squares.

For more information about squarify technique, see: Squarified Treemaps: https://www.win.tue.nl/~vanwijk/stm.pdf Squarify algorithm from Charted: https://cs.corp.google.com/piper///depot/google3/third_party/dart/charted/lib/layout/src/treemap_layout.dart?l=158

Implementation

@override
void tile(TreeNode<Object> node) {
  final children = node.children;
  if (children.isNotEmpty) {
    final remainingNodes = Queue.of(children);
    final rect = availableLayoutBoundingRect(node);
    final analyzer = _SquarifyRatioAnalyzer(_ratio, areaForTreeNode);

    var bestScore = double.infinity;
    var width = math.min(rect.width, rect.height);
    final measure = measureForTreeNode(node);
    final scaleFactor = measure == 0 ? 0 : areaForRectangle(rect) / measure;
    scaleArea(children, scaleFactor);

    while (remainingNodes.isNotEmpty) {
      final child = remainingNodes.first;
      analyzer.addNode(child);
      final score = analyzer.worst(width).toDouble();

      // Adding a new child rectangle improves score for the aspect ratio .
      if (score <= bestScore) {
        remainingNodes.removeFirst();
        bestScore = score;
      } else {
        analyzer.removeLast();
        position(analyzer.nodes, rect, width, analyzer.layoutArea);
        width = math.min(rect.width, rect.height);
        analyzer.reset();
        bestScore = double.infinity;
      }
    }
    if (analyzer.nodes.isNotEmpty) {
      position(analyzer.nodes, rect, width, analyzer.layoutArea);
      analyzer.reset();
    }
  }
}