Files
fn_registry/cpp/functions/viz/treemap.md
T
egutierrez 958189227d chore(registry): notes en huerfanas usadas por framework/apps
Auditoria del issue 0044: anota en notes: el contexto de consumo de
huerfanos que no pueden registrarse en uses_functions porque sus
consumidores no son funciones del registry:
- consumido por cpp/framework/app_base.cpp (framework no indexado)
- consumido por cpp/apps/{shaders_lab,chart_demo,text_editor_smoke}/main.cpp
- scaffolding/demo en primitives_gallery

31 huerfanas anotadas. Las que quedan en uses_functions=[] tras esto
son hojas legitimas (no llaman a nada) o realmente sin uso (lista
DEAD reportada en el issue 0044).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 23:40:51 +02:00

68 lines
2.3 KiB
Markdown

---
name: treemap
kind: component
lang: cpp
domain: viz
version: "1.0.0"
purity: pure
signature: "void treemap(const char* id, const std::vector<TreemapItem>& items, ImVec2 size)"
description: "Squarified treemap (Bruls, Huijbrechts, van Wijk) para jerarquias planas con valores. Layout puro separado del render."
tags: [imgui, drawlist, chart, visualization, treemap, hierarchy, squarified]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: [imgui]
tested: false
tests: []
test_file_path: ""
file_path: "cpp/functions/viz/treemap.cpp"
framework: imgui
params:
- name: id
desc: "Identificador unico para PushID (evita colisiones entre treemaps)"
- name: items
desc: "Vector de TreemapItem {label, value, color}. Items con value <= 0 se ignoran"
- name: size
desc: "Tamano del rect del treemap. x <= 0 usa el ancho disponible"
output: "Renderiza el treemap en el frame ImGui actual usando AddRectFilled + AddText sobre el WindowDrawList"
notes: "scaffolding/demo en primitives_gallery"
---
# treemap
Treemap squarified: dado un vector de items con valor numerico, divide el rect dado en cells cuya area es proporcional al valor del item. El algoritmo de Bruls et al. minimiza el aspect ratio (cells lo mas cuadradas posibles).
## API
```cpp
struct TreemapItem { std::string label; float value; ImU32 color; };
struct TreemapRect { ImVec2 min, max; const TreemapItem* item; };
std::vector<TreemapRect> treemap_layout(const std::vector<TreemapItem>&, ImVec2 region); // pure
void treemap(const char* id, const std::vector<TreemapItem>&, ImVec2 size = {-1, 300});
```
`treemap_layout` es pura — devuelve rects en coords [0..region]. `treemap` invoca el layout y renderiza con `AddRectFilled` + label + valor cuando caben.
## Conservacion del area
La suma de areas de los rects es igual al area de la region (modulo errores de redondeo). Util para tests.
## Limitaciones MVP
- Solo jerarquia plana (no recursivo). Para jerarquias anidadas, llamar `treemap_layout` recursivamente sobre cada cell.
- Sin interaccion (click, zoom).
## Ejemplo
```cpp
std::vector<TreemapItem> items = {
{"vivienda", 950, IM_COL32(180,120,200,255)},
{"comida", 320, IM_COL32(120,180,200,255)},
{"transporte", 180, IM_COL32(200,180,120,255)},
};
treemap("##gastos", items, ImVec2(-1, 300));
```