code wiki / _hdl_build / nx_viz_icicle.nx
nx_viz_icicle.nx source
↩ module page · 139 lines · 7243 B
1// nx_viz_icicle.nx -- COMPOSED live ICICLE: parse a tree TSV (parent/value/label), partition it with
2// nx_viz_partition (subtree-proportional spans), and draw each node as a depth-banded rectangle (x from its span,
3// y from its depth) coloured by tier (nx_viz_color), labelled via nx_viz_shape's serializer. Self-contained HTML
4// for the wiki. usage: nx_viz_icicle [in.tsv] [out.html]. license_tier: ORIGINAL
5import "nx_viz_partition.nx"
6import "nx_viz_shape.nx"
7import "nx_viz_color.nx"
8import "nx_syscalls.nx"
9const K_MAGIC_4096: i64 = 4096
10const K_MAGIC_8192: i64 = 8192
11const K_MAGIC_262144: i64 = 262144
12
13func 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 }
14func emit_hex6(out: *u8, off: i64, color: i64) -> i64 {
15 var o: i64 = off; out[o] = 35 as u8; o = o + 1
16 var sh: i64 = 20
17 while sh >= 0 {
18 let nib: i64 = (color >> sh) & 15
19 var ch: i64 = 48 + nib
20 if nib >= 10 { ch = 87 + nib }
21 out[o] = ch as u8; o = o + 1
22 sh = sh - 4
23 }
24 return o
25}
26func atoi_signed(buf: *u8, s: i64, e: i64) -> i64 {
27 var neg: i64 = 0; var k: i64 = s
28 if k < e { if buf[k] == (45 as u8) { neg = 1; k = k + 1 } }
29 var v: i64 = 0
30 while k < e { let d: i64 = buf[k] as i64; if d >= 48 { if d <= 57 { v = v * 10 + (d - 48) } } k = k + 1 }
31 if neg == 1 { return 0 - v }
32 return v
33}
34func group_of(i: i64, parent: *i64, depth: *i64) -> i64 {
35 var x: i64 = i
36 while depth[x] > 1 { x = parent[x] }
37 return x
38}
39
40func main(argc: i64, argv: *i64) -> i64 {
41 var inp: *u8 = "knowledge/registry/viz_suite_tree.tsv" as *u8
42 var outp: *u8 = "/mnt/c/Users/elder/nishi-core/nxc2/web_assets/viz_icicle.html" as *u8
43 if argc >= 2 { inp = argv[1] as *u8 }
44 if argc >= 3 { outp = argv[2] as *u8 }
45
46 let lenp: *i64 = sys_mmap(16) as *i64
47 let buf: *u8 = sys_read_file(inp, lenp)
48 if (buf as i64) == 0 { cw(2, "nx_viz_icicle: cannot read tree\n" as *u8); return 2 }
49 let n: i64 = lenp[0]
50
51 let parent: *i64 = sys_mmap(K_MAGIC_4096) as *i64
52 let value: *i64 = sys_mmap(K_MAGIC_4096) as *i64
53 let lab_off: *i64 = sys_mmap(K_MAGIC_4096) as *i64
54 let lab_len: *i64 = sys_mmap(K_MAGIC_4096) as *i64
55 let span: *i64 = sys_mmap(K_MAGIC_8192) as *i64
56 let depth: *i64 = sys_mmap(K_MAGIC_4096) as *i64
57 var nc: i64 = 0
58
59 var i: i64 = 0
60 while i < n {
61 let ls: i64 = i
62 var le: i64 = ls
63 while le < n { if buf[le] == (10 as u8) { break } le = le + 1 }
64 if le > ls {
65 if buf[ls] != (35 as u8) {
66 var t1: i64 = ls
67 while t1 < le { if buf[t1] == (9 as u8) { break } t1 = t1 + 1 }
68 if t1 < le {
69 var t2: i64 = t1 + 1
70 while t2 < le { if buf[t2] == (9 as u8) { break } t2 = t2 + 1 }
71 parent[nc] = atoi_signed(buf, ls, t1)
72 value[nc] = atoi_signed(buf, t1 + 1, t2)
73 lab_off[nc] = t2 + 1
74 var ll: i64 = le - (t2 + 1); if ll < 0 { ll = 0 }
75 lab_len[nc] = ll
76 nc = nc + 1
77 }
78 }
79 }
80 i = le + 1
81 }
82 if nc == 0 { cw(2, "nx_viz_icicle: no nodes\n" as *u8); return 3 }
83
84 let total: i64 = vp_partition(nc, parent, value, span, depth)
85 if total <= 0 { cw(2, "nx_viz_icicle: zero total\n" as *u8); return 4 }
86 var maxd: i64 = 0
87 i = 0
88 while i < nc { if depth[i] > maxd { maxd = depth[i] } i = i + 1 }
89
90 let W: i64 = 1000
91 let PAD: i64 = 16
92 let innerW: i64 = W - 2 * PAD
93 let rowH: i64 = 112
94 let top: i64 = 8
95 let H: i64 = top + (maxd + 1) * rowH + 8
96
97 let ob: *u8 = sys_mmap(K_MAGIC_262144)
98 var o: i64 = 0
99 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 — Icicle</title>" as *u8)
100 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:820px;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:12px;display:inline-block}</style></head><body>" as *u8)
101 o = vsh_lit(ob, o, "<h1>Nishi Visualization Suite — icicle (test coverage by tier)</h1>" as *u8)
102 o = vsh_lit(ob, o, "<p>The suite's OWN gate-test counts as a hierarchy, partitioned by <code>nx_viz_partition</code> (subtree-proportional spans), drawn as depth-banded rectangles coloured by tier (<code>nx_viz_color</code>). Width = share of total tests. No d3.js, no CDN. Top band = the suite; middle = tiers (math/core/shape/layout/axis); bottom = organs.</p>" as *u8)
103 o = vsh_lit(ob, o, "<div class=\"card\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"" as *u8)
104 o = vsh_n(ob, o, W); o = vsh_lit(ob, o, "\" height=\"" as *u8); o = vsh_n(ob, o, H); o = vsh_lit(ob, o, "\" font-family=\"system-ui,sans-serif\">" as *u8)
105
106 var q: i64 = 0
107 while q < nc {
108 let x0: i64 = PAD + (span[q * 2] * innerW) / total
109 let x1: i64 = PAD + (span[q * 2 + 1] * innerW) / total
110 let w: i64 = x1 - x0
111 let y: i64 = top + depth[q] * rowH
112 let h: i64 = rowH - 3
113 o = vsh_lit(ob, o, "<g><title>" as *u8)
114 var tk: i64 = lab_off[q]; let te: i64 = lab_off[q] + lab_len[q]
115 while tk < te { ob[o] = buf[tk]; o = o + 1; tk = tk + 1 }
116 o = vsh_lit(ob, o, "</title><rect x=\"" as *u8); o = vsh_n(ob, o, x0); o = vsh_lit(ob, o, "\" y=\"" as *u8); o = vsh_n(ob, o, y)
117 o = vsh_lit(ob, o, "\" width=\"" as *u8); o = vsh_n(ob, o, w); o = vsh_lit(ob, o, "\" height=\"" as *u8); o = vsh_n(ob, o, h)
118 o = vsh_lit(ob, o, "\" rx=\"3\" fill=\"" as *u8); o = emit_hex6(ob, o, vc_categorical(group_of(q, parent, depth), nc)); o = vsh_lit(ob, o, "\" stroke=\"#0d1117\" stroke-width=\"1.5\"/>" as *u8)
119 if w > 30 {
120 o = vsh_lit(ob, o, "<text x=\"" as *u8); o = vsh_n(ob, o, x0 + w / 2); o = vsh_lit(ob, o, "\" y=\"" as *u8); o = vsh_n(ob, o, y + h / 2 + 4)
121 o = vsh_lit(ob, o, "\" text-anchor=\"middle\" font-size=\"12\" fill=\"#0d1117\" font-weight=\"600\">" as *u8)
122 var lk: i64 = lab_off[q]; let lend: i64 = lab_off[q] + lab_len[q]
123 while lk < lend { ob[o] = buf[lk]; o = o + 1; lk = lk + 1 }
124 o = vsh_lit(ob, o, "</text>" as *u8)
125 }
126 o = vsh_lit(ob, o, "</g>" as *u8)
127 q = q + 1
128 }
129 o = vsh_lit(ob, o, "</svg></div>" as *u8)
130 o = vsh_lit(ob, o, "<p style=\"margin-top:16px;font-size:13px\">Generated by <code>nx_viz_icicle</code> from <code>viz_suite_tree.tsv</code>. <a href=\"viz-loop.html\">← build loop</a> · <a href=\"viz-graph.html\">module graph</a></p>" as *u8)
131 o = vsh_lit(ob, o, "</body></html>" as *u8)
132
133 let fd: i64 = sys_openat_wr(outp, 0x1a4)
134 if fd < 0 { cw(2, "nx_viz_icicle: cannot open output\n" as *u8); return 5 }
135 sys_write(fd, ob, o)
136 sys_close(fd)
137 cw(1, "[nx_viz_icicle] wrote " as *u8); cw(1, outp); cw(1, "\n" as *u8)
138 return 0
139}