Files
fn_registry/cpp/functions/viz/bar_chart.md
T
egutierrez 96fcd05511 chore(registry): añadir uses_functions a consumidores reales (viz)
Auditoria del issue 0044: 9 archivos .md de cpp/functions/viz/ con
uses_functions actualizado. Resuelve dependencias detectadas via
#include: plot_static (consumido por bar_chart, histogram, line_plot,
pie_chart, scatter_plot), gl_loader, gl_framebuffer, gl_shader,
graph_force_layout, graph_renderer, graph_spatial_hash, orbit_camera,
sparkline y tokens.

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

2.6 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path, framework, params, output, notes
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path framework params output notes
bar_chart component cpp viz 1.2.0 pure void bar_chart(const char* title, const char* const* labels, const float* values, int count, float bar_width = 0.67f, float height = 200.0f) Barras verticales ImPlot con ejes pineados, altura explicita, tooltip al hover y auto-rotacion 45 de labels cuando no caben horizontales
implot
chart
visualization
gpu
bar
tooltip
rotated-labels
locked-axes
plot_static_cpp_viz
false
implot
false
cpp/functions/viz/bar_chart.cpp imgui
name desc
title Titulo / id interno del plot
name desc
labels Array de etiquetas para el eje X, una por barra
name desc
values Array de valores numericos (altura de cada barra)
name desc
count Numero de barras (longitud de labels y values)
name desc
bar_width Ancho de cada barra como fraccion del hueco de celda (default 0.67)
name desc
height Altura del plot en pixeles (default 200). Explicita para evitar feedback loops con AutoResizeY
Renderiza barras, tooltip al hover con label+valor, y si los labels horizontales no caben los dibuja rotados 45 grados consumido por cpp/apps/chart_demo/main.cpp; scaffolding/demo en primitives_gallery

bar_chart

Barras verticales ImPlot pensadas para dashboards. Tres cosas no triviales:

  1. Ejes pineadosplot_static::kPlotFlags + kAxisFlags (Lock + NoInitialFit + Cond_Always) con y_max pre-calculado + 15% headroom. Sin esto ImPlot auto-fitea cada frame y las barras oscilan.
  2. Tooltip — si IsPlotHovered(), detecta la barra bajo el cursor (round(mouse.x) con tolerancia bar_width/2) y muestra label + valor.
  3. Labels auto-rotados — mide la suma de CalcTextSize(label) + 12px contra el ancho del plot; si no caben, dibuja los labels rotados 45° manualmente con ImDrawList::PrimQuadUV + glyphs del font atlas (ImFontBaked::FindGlyph — API ImGui 1.92+). Reserva 48px abajo del plot para los labels rotados. Si caben se usan los ticks horizontales normales de ImPlot.

Altura explicita (height) rompe el feedback loop con contenedores AutoResizeY (ver viz/plot_static.h).

Ejemplo

const char* domains[] = {"core", "finance", "cybersecurity", "datascience", "infra"};
float counts[] = {412, 187, 94, 63, 36};
bar_chart("##domains", domains, counts, 5);             // horizontal si cabe
bar_chart("##domains", domains, counts, 5, 0.8f, 240);  // rotated si no cabe