cfdf515228
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
2.1 KiB
Markdown
60 lines
2.1 KiB
Markdown
---
|
|
name: sankey
|
|
kind: component
|
|
lang: cpp
|
|
domain: viz
|
|
version: "1.0.0"
|
|
purity: pure
|
|
signature: "void sankey(const char* id, const std::vector<SankeyNode>& nodes, const std::vector<SankeyLink>& links, ImVec2 size)"
|
|
description: "Sankey diagram para flujos source -> target con magnitudes. BFS topologico para columnas, bandas curvas (bezier cubico) para los links."
|
|
tags: [imgui, drawlist, chart, visualization, sankey, flow, dag, pendiente-usar]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: ""
|
|
imports: [imgui]
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "cpp/functions/viz/sankey.cpp"
|
|
framework: imgui
|
|
params:
|
|
- name: id
|
|
desc: "Identificador unico para PushID"
|
|
- name: nodes
|
|
desc: "Vector de SankeyNode (label)"
|
|
- name: links
|
|
desc: "Vector de SankeyLink {src, dst, value}. src/dst son indices en nodes"
|
|
- name: size
|
|
desc: "Tamano del diagrama. x <= 0 usa el ancho disponible"
|
|
output: "Renderiza nodos como rectangulos verticales por columna y links como bandas con bezier cubico, con alpha bajo y color del nodo origen"
|
|
notes: "scaffolding/demo en primitives_gallery"
|
|
---
|
|
|
|
# sankey
|
|
|
|
Sankey diagram. Asigna nodos a columnas via BFS topologico (level = max(level(src))+1) y los apila verticalmente en cada columna proporcionalmente a max(in_total, out_total). Los links se renderizan como bandas curvas con bezier cubico, color del nodo origen + alpha bajo.
|
|
|
|
## Limitaciones
|
|
|
|
- **Asume DAG** (sin ciclos). Si hay ciclos, los nodos del ciclo se quedan en su nivel parcial calculado por BFS — el render no rompe pero puede solapar visualmente.
|
|
- Sin orden de nodos optimizado para minimizar cruces (heuristica simple por orden de insercion).
|
|
- Sin interaccion (hover, click).
|
|
|
|
## Ejemplo
|
|
|
|
```cpp
|
|
std::vector<SankeyNode> nodes = {
|
|
{"clientes_premium"}, {"clientes_basicos"},
|
|
{"laptops"}, {"phones"}, {"tablets"},
|
|
{"hw"}, {"sw"},
|
|
};
|
|
std::vector<SankeyLink> links = {
|
|
{0, 2, 80}, {0, 3, 30},
|
|
{1, 3, 60}, {1, 4, 40},
|
|
{2, 5, 80}, {3, 5, 90}, {4, 5, 40},
|
|
};
|
|
sankey("##flow", nodes, links, ImVec2(-1, 400));
|
|
```
|