━━━━━━━━━━ c o d e c h u · t r e e v i z ━━━━━━━━━━
input output
┌────────────────────┐ ┌────────────────────┐
│ / │ │ ┌─────────┬──────┐ │
│ ├── photos (450) │ → │ │ photos │ src │ │
│ ├── src (200) │ layout │ ├─────────┴──────┤ │
│ ├── cache (180) │ │ │ cache │ logs │ │
│ └── logs (120) │ │ ├─────────┴──────┤ │
└────────────────────┘ │ └────────────────┘ │
per-node (x, y, w, h)
━━━━━━━━━ rectangles and arcs. you render. ━━━━━━━━━━
Squarified treemap + sunburst layouts — rectangles and arcs, you render.
Squarified treemap and sunburst layout algorithms for hierarchical data. Pure Python, no GUI dependency — gives you rectangles and arcs and lets you render them with whatever toolkit you prefer (Cairo, SVG, Matplotlib, browser canvas, Pillow PNG).
pip install codechu-treevizPython 3.10+. Pure stdlib + math, zero third-party deps.
from codechu_treeviz import build_tree, TreemapStrategy
# 1. Walk a directory into a TreeNode
root = build_tree("~/Pictures")
# 2. Lay it out — writes (x, y, w, h) onto every node.rect
strategy = TreemapStrategy(min_frac=0.005)
strategy.layout(root, w=800, h=600)
# 3. Render however you like (Cairo, SVG, browser canvas, …)
for child in root.children:
if child.rect is not None:
x, y, w, h = child.rect
print(child.path, (x, y, w, h))
# 4. Hit test for hover/click
node = strategy.hit_test(root, x=120, y=80)Swap TreemapStrategy() for SunburstStrategy() and the same code
renders a radial chart (rects become 7-tuples — see the API docs).
- Squarified treemap — Bruls/Huijsen/van Wijk algorithm, aspect-ratio optimized rectangles.
- Sunburst — circular hierarchical chart with concentric rings.
TreeNodebuilder — turn a(path, size)list into a hierarchical tree with cancel + progress callbacks.- Hit testing — find the node at any (x, y) coordinate.
- "Other" bundling — collapse small slivers into one
"(N items)"bucket. - Color palette — perceptually balanced default fill colors.
No rendering, no GUI dependency, bounded depth
(TREEMAP_MAX_DEPTH = 40) so pathological nesting can't OOM you.
- API reference — TreeNode, SizeProvider, VizStrategy, layout functions, hit-test, color helpers.
- Recipes — disk-usage treemap, sunburst from a
directory tree, custom
SizeProvider, subclassingVizStrategy, hit-test plumbing. - Migration guide
- Changelog
| Library | Purpose |
|---|---|
| codechu-treedata | N-ary tree data structures and algorithms |
| codechu-spark | Unicode sparklines, mini bar charts, heatmaps |
| codechu-fmt | Human-readable sizes, durations, rates |
| codechu-cli | CLI primitives — colors, progress, prompts |
| codechu-color | Color palettes, WCAG contrast, color-blind variants |
Full ecosystem: github.com/codechu.
- Squarified treemap algorithm by Bruls, Huijsen, van Wijk (2000).
- Sunburst layout following Stasko & Zhang radial visualizations.
- Inspiration from squarify — single-algorithm; codechu-treeviz extends to multiple strategies.
MIT — see LICENSE.
Part of Codechu.