code wiki / _hdl_build / nx_chart.nx
nx_chart.nx
buildroot/runtime/_hdl_build/nx_chart.nx
about
nx_chart.nx -- IMS Thrust D R2: a SOVEREIGN, REUSABLE native-SVG bar-chart renderer.
THE GAP IT FILLS: nx_viz_chart.nx is a whole-PAGE main() that reads a fixed TSV and writes an HTML
file -- not a reusable function. nx_wiki_graph emits SVG but only a circular link-graph. So the gap
is a clean LIBRARY function chart_svg(labels[], values[], n, title) -> <svg>...</svg> that any organ
can call to drop a bar chart inline into a page. Pure + deterministic (no I/O, no wall-clock).
REUSE (zero geometry reinvented): imports nx_viz_axis -> which transitively gives the proven viz
primitives the d3-equivalent suite already KAT-grades:
vs_linear (nx_viz_scale) -- map a data value -> a pixel height (the bar scaling).
va_axis_left(nx_viz_axis) -- the y-axis: baseline + tick marks + numeric labels.
vsh_lit / vsh_n (nx_viz_shape) -- append a literal / an integer into the SVG buffer.
We add ONLY the bar-chart composition (the bars, the x-labels, the title) -- the part that did not
exist as a reusable call.
SVG is static (no <script>) -> sovereign, renders identically everywhere. license_tier: ORIGINAL
dependencies 2 imports · 2 importers
imports: nx_viz_axis.nxnx_syscalls.nx
imported by: nx_figure_gate.nxnx_figures_page.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 19 | const CH_MAGIC_8192: i64 = 8192 |
| 22 | const CH_OK: i64 = 0 |
| 23 | const CH_BAD_INPUT: i64 = 2900 |
| 24 | const CH_OVERFLOW: i64 = 2901 |
| 27 | const CH_M_L: i64 = 56 // left margin (room for the y-axis labels) |
| 28 | const CH_M_T: i64 = 40 // top margin (room for the title) |
| 29 | const CH_PLOT_H: i64 = 300 // plot area height in px (data range maps into this) |
| 30 | const CH_BW: i64 = 64 // bar width |
| 31 | const CH_GAP: i64 = 34 // gap between bars |
| 32 | const CH_M_B: i64 = 44 // bottom margin (room for the x-axis labels) |
| 33 | const CH_TICKS: i64 = 6 // y-axis tick target |
| 34 | const CH_LBLCAP: i64 = 64 // per-label byte cap (defensive) |
functions
| 37 | func ch_maxv(values: *i64, n: i64) -> i64 called by 1: chart_svg |
| 49 | func ch_nice_top(v: i64) -> i64 |
| 75 | func chart_svg(labels_ptr: *i64, labels_len: *i64, values: *i64, n: i64, |
| 184 | func main() -> i64 |