code wiki / _hdl_build / nx_viz_chart.nx
nx_viz_chart.nx source
↩ module page · 111 lines · 6463 B
1// nx_viz_chart.nx -- COMPOSED live chart: the measured-build loop as a bar chart, rendered BY the suite itself
2// (bar heights from nx_viz_scale vs_linear, the y-axis from nx_viz_axis va_axis_left, the SVG from nx_viz_shape's
3// serializer), data-driven from viz_loop_history.tsv. Writes a self-contained HTML page (inline SVG, no d3.js,
4// no CDN) for the wiki. Re-run after any new layer to refresh -> autonomous. usage: nx_viz_chart [in.tsv] [out.html]
5// license_tier: ORIGINAL
6import "nx_viz_axis.nx"
7import "nx_syscalls.nx"
8const K_MAGIC_2048: i64 = 2048
9const K_MAGIC_131072: i64 = 131072
10const K_MAGIC_8192: i64 = 8192
11
12func cw(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
13
14func main(argc: i64, argv: *i64) -> i64 {
15 var inp: *u8 = "knowledge/registry/viz_loop_history.tsv" as *u8
16 var outp: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/web_assets/viz_loop.html" as *u8
17 if argc >= 2 { inp = argv[1] as *u8 }
18 if argc >= 3 { outp = argv[2] as *u8 }
19
20 let lenp: *i64 = sys_mmap(16) as *i64
21 let buf: *u8 = sys_read_file(inp, lenp)
22 if (buf as i64) == 0 { cw(2, "nx_viz_chart: cannot read history\n" as *u8); return 2 }
23 let n: i64 = lenp[0]
24
25 let lab_off: *i64 = sys_mmap(K_MAGIC_2048) as *i64
26 let lab_len: *i64 = sys_mmap(K_MAGIC_2048) as *i64
27 let cov: *i64 = sys_mmap(K_MAGIC_2048) as *i64
28 var cnt: i64 = 0
29 var i: i64 = 0
30 while i < n {
31 let ls: i64 = i
32 var le: i64 = ls
33 while le < n { if buf[le] == (10 as u8) { break } le = le + 1 }
34 if le > ls {
35 if buf[ls] != (35 as u8) {
36 var tab: i64 = ls
37 while tab < le { if buf[tab] == (9 as u8) { break } tab = tab + 1 }
38 if tab < le {
39 lab_off[cnt] = ls
40 lab_len[cnt] = tab - ls
41 var v: i64 = 0
42 var k: i64 = tab + 1
43 while k < le {
44 let d: i64 = buf[k] as i64
45 if d >= 48 { if d <= 57 { v = v * 10 + (d - 48) } }
46 k = k + 1
47 }
48 cov[cnt] = v
49 cnt = cnt + 1
50 }
51 }
52 }
53 i = le + 1
54 }
55 if cnt == 0 { cw(2, "nx_viz_chart: no data rows\n" as *u8); return 3 }
56
57 let M_L: i64 = 64
58 let M_T: i64 = 28
59 let CH: i64 = 330
60 let BW: i64 = 80
61 let GAP: i64 = 40
62 let DOM: i64 = 500
63 let baseline: i64 = M_T + CH
64 let width: i64 = M_L + cnt * (BW + GAP) + 30
65 let svgh: i64 = baseline + 52
66
67 let ob: *u8 = sys_mmap(K_MAGIC_131072)
68 var o: i64 = 0
69 o = vsh_lit(ob, o, "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><title>Nishi Viz — Measured-Build Loop</title>" as *u8)
70 o = vsh_lit(ob, o, "<style>body{margin:0;background:#0d1117;color:#e6edf3;font-family:system-ui,-apple-system,sans-serif;padding:28px}h1{font-size:20px;margin:0 0 6px}p{color:#9aa4b2;max-width:780px;line-height:1.55}code{color:#79c0ff}a{color:#58a6ff;text-decoration:none}.card{margin-top:18px;background:#161b22;border:1px solid #30363d;border-radius:10px;padding:16px;display:inline-block}</style></head><body>" as *u8)
71 o = vsh_lit(ob, o, "<h1>Nishi Visualization Suite — the measured-build loop</h1>" as *u8)
72 o = vsh_lit(ob, o, "<p>Coverage vs <b>d3</b> (per-mille), organ-graded by <code>nx_viz_exceed</code> (never self-scored), after each sovereign layer landed. This chart is rendered <b>by the suite itself</b> — bar heights from <code>nx_viz_scale</code>, the axis from <code>nx_viz_axis</code>, the SVG path/text from <code>nx_viz_shape</code> — 100% bits-up, no d3.js, no CDN. The library drawing its own progress.</p>" as *u8)
73 o = vsh_lit(ob, o, "<div class=\"card\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" as *u8)
74 o = vsh_n(ob, o, width); o = vsh_lit(ob, o, "\" height=\"" as *u8); o = vsh_n(ob, o, svgh); o = vsh_lit(ob, o, "\" font-family=\"system-ui,sans-serif\">" as *u8)
75
76 let axfrag: *u8 = sys_mmap(K_MAGIC_8192)
77 va_axis_left(0, DOM, baseline, M_T, 6, M_L, axfrag)
78 o = vsh_lit(ob, o, axfrag)
79
80 var b: i64 = 0
81 while b < cnt {
82 let bx: i64 = M_L + 16 + b * (BW + GAP)
83 let bh: i64 = vs_linear(0, DOM, 0, CH, cov[b])
84 let by: i64 = baseline - bh
85 o = vsh_lit(ob, o, "<rect x=\"" as *u8); o = vsh_n(ob, o, bx); o = vsh_lit(ob, o, "\" y=\"" as *u8); o = vsh_n(ob, o, by)
86 o = vsh_lit(ob, o, "\" width=\"" as *u8); o = vsh_n(ob, o, BW); o = vsh_lit(ob, o, "\" height=\"" as *u8); o = vsh_n(ob, o, bh); o = vsh_lit(ob, o, "\" rx=\"5\" fill=\"#238636\"/>" as *u8)
87 o = vsh_lit(ob, o, "<text x=\"" as *u8); o = vsh_n(ob, o, bx + BW / 2); o = vsh_lit(ob, o, "\" y=\"" as *u8); o = vsh_n(ob, o, by - 8)
88 o = vsh_lit(ob, o, "\" text-anchor=\"middle\" font-size=\"13\" fill=\"#7ee787\">" as *u8); o = vsh_n(ob, o, cov[b]); o = vsh_lit(ob, o, "</text>" as *u8)
89 o = vsh_lit(ob, o, "<text x=\"" as *u8); o = vsh_n(ob, o, bx + BW / 2); o = vsh_lit(ob, o, "\" y=\"" as *u8); o = vsh_n(ob, o, baseline + 20)
90 o = vsh_lit(ob, o, "\" text-anchor=\"middle\" font-size=\"12\" fill=\"#c9d1d9\">" as *u8)
91 var kk: i64 = lab_off[b]; let ke: i64 = lab_off[b] + lab_len[b]
92 while kk < ke { ob[o] = buf[kk]; o = o + 1; kk = kk + 1 }
93 o = vsh_lit(ob, o, "</text>" as *u8)
94 b = b + 1
95 }
96 o = vsh_lit(ob, o, "</svg></div>" as *u8)
97 o = vsh_lit(ob, o, "<p style=\"margin-top:16px;font-size:13px\">Generated by <code>nx_viz_chart</code> from <code>viz_loop_history.tsv</code>; append a row + re-run to refresh. <a href=\"atlas.html\">← viz atlas</a></p>" as *u8)
98 o = vsh_lit(ob, o, "</body></html>" as *u8)
99
100 let fd: i64 = sys_openat_wr(outp, 0x1a4)
101 if fd < 0 { cw(2, "nx_viz_chart: cannot open output\n" as *u8); return 4 }
102 sys_write(fd, ob, o)
103 sys_close(fd)
104 cw(1, "[nx_viz_chart] wrote " as *u8); cw(1, outp); cw(1, " (" as *u8)
105 var nb: i64 = o; let t: *u8 = sys_mmap(28); var tk: i64 = 0
106 if nb == 0 { t[0] = 48 as u8; tk = 1 }
107 while nb > 0 { t[tk] = (48 + (nb % 10)) as u8; nb = nb / 10; tk = tk + 1 }
108 var z: i64 = 0; let nb2: *u8 = sys_mmap(28); while z < tk { nb2[z] = t[tk - 1 - z]; z = z + 1 } sys_write(1, nb2, tk)
109 cw(1, " bytes)\n" as *u8)
110 return 0
111}