MCPcopy Index your code
hub / github.com/bacongobbler/treemap-rs

github.com/bacongobbler/treemap-rs @v0.2.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.2.1 ↗ · + Follow
30 symbols 50 edges 3 files 3 documented · 10% updated 3y ago★ 38
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Treemap

Implements the Squarified Treemap algorithm published by Mark Bruls, Kees Huizing, and Jarke J. van Wijk.

The Squarified Treemap algorithm paper can be found here: https://www.win.tue.nl/~vanwijk/stm.pdf

Uses

Suppose we have a rectangle with a width of 6 and a height of 4, and furthermore suppose that this rectangle must be subdivided in seven rectangles with areas 6, 6, 4, 3, 2, 2, and 1. The standard treemap algorithm uses a simple approach: The rectangle is subdivided either horizontally or vertically. Thin rectangles emerge, with aspect ratios of 16 and 36, respectively.

In other words, it'll look something like this:

+------+------+----+---+--+-+
|      |      |    |   |  | |
|      |      |    |   |  | |
|   6  |   6  |  4 | 3 | 2|1|
|      |      |    |   |  | |
+------+------+----+---+--+-+

The Squarified Treemap algorithm tesselates a rectangle recursively into rectangles, such that their aspect ratios approach 1 as close as possible.

+-------------+-----+-----+--+
|             |  2  |  2  | 1|
|      6      +-----+-+---+--|
|-------------+       |      |
|             |       |      |
|      6      |    4  |   3  |
+-------------+-------+------+

This can be useful for a variety of purposes:

  • visualizing hierarchal structures, such as showing how much space each directory uses in a file drive
  • generating a floor map given an area on how each room should be subdivided (bathrooms would need a smaller amount of space than a living room, for example)

Example

This example will tesselate a rectangle with a width of 6 and a height of 4 with seven rectangles with areas 6, 6, 4, 3, 2, 2, and 1, then display each rectangle's top-left corner's x and y position within the larger rectangle (the bounds), as well as their respective height and width.

To start, generate a new project:

$ cargo new --bin treemap-example
     Created binary (application) `treemap-example` package

Add treemap to Cargo.toml:

[dependencies]
treemap = "0.2.1"

Then, in src/main.rs:

extern crate treemap;

use treemap::{MapItem, Mappable, Rect, TreemapLayout};

fn main() {
    let mut layout = TreemapLayout::new();
    let bounds = Rect::new_from_points(0.0, 0.0, 6.0, 4.0);
    let mut items: Vec<Box<Mappable>> = vec![
        Box::new(MapItem::new_with_size(6.0)),
        Box::new(MapItem::new_with_size(6.0)),
        Box::new(MapItem::new_with_size(4.0)),
        Box::new(MapItem::new_with_size(3.0)),
        Box::new(MapItem::new_with_size(2.0)),
        Box::new(MapItem::new_with_size(2.0)),
        Box::new(MapItem::new_with_size(1.0)),
    ];

    layout.layout_items(&mut items, bounds);

    for item in items {
        let item_bounds = item.get_bounds();
        println!("x={} y={} w={} h={}", item_bounds.x, item_bounds.y, item_bounds.w, item_bounds.h);
        println!("------");
    }
}

Extension points exported contracts — how you extend this code

Mappable (Interface)
Interface representing an object that can be placed in a treemap layout. # Properties - size: corresponds to area in m [1 …
src/lib.rs
Layout (Interface)
The interface for the treemap layout algorithm. [1 implementers]
src/lib.rs
MapModel (Interface)
Model object used by MapLayout to represent data for a treemap.
src/lib.rs

Core symbols most depended-on inside this repo

get_size
called by 8
src/lib.rs
norm_aspect
called by 4
src/lib.rs
layout_row
called by 3
src/lib.rs
layout_items
called by 2
src/lib.rs
total_item_size_with_range
called by 2
src/lib.rs
get_bounds
called by 1
src/lib.rs
set_bounds_from_rect
called by 1
src/lib.rs
layout_items_at
called by 1
src/lib.rs

Shape

Method 17
Function 7
Class 3
Interface 3

Languages

Rust100%

Modules by API surface

src/lib.rs26 symbols
tests/rect.rs2 symbols
tests/layout.rs2 symbols

For agents

$ claude mcp add treemap-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page