code wiki / _hdl_build / nx_eco_graph_atlas.nx

nx_eco_graph_atlas.nx source

↩ module page · 177 lines · 11017 B

1// nx_eco_graph_atlas.nx -- SOVEREIGN VISUAL: a generational "family tree from god" of a capability's lineage, 2// rendered as pure SVG (zero-JS, zero third-party graphing lib) from the seg_store graph. God (nx_syscalls, 3// the ultimate ancestor everything roots to) sits at the APEX; each generation is a layer BELOW it by 4// longest-path-to-god depth; dependency ribbons fan up and converge on god. This is "access any part and see 5// its roots to god each generation" as a real drawn tree. Composes nx_eco_graph (store + ancestry queries). 6// Usage: nx_eco_graph_atlas <store-prefix> <seed-basename> [out.svg.html] license_tier: ORIGINAL expect_exit:0 7import "nx_syscalls.nx" 8import "nx_eco_graph.nx" 9 10const AT_MAXS: i64 = 200 // cap rendered lineage nodes (readability) 11const AT_W: i64 = 1180 // svg width 12const AT_LAYH: i64 = 104 // generation layer height 13 14func fw(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 } 15func fwn(fd: i64, v: i64) -> i64 { let b:*u8=sys_mmap(24); var m:i64=v; if m<0{sys_write(fd,"-" as *u8,1);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var j:i64=0; while j<k{b[j]=t[k-1-j];j=j+1} sys_write(fd,b,k); return 0 } 16func slen(s: *u8) -> i64 { var n:i64=0; while s[n]!=(0 as u8){n=n+1} return n } 17// write node name WITHOUT the trailing ".nx" (display brevity). fd, graph, global idx. 18func fwshort(fd: i64, g: *EcoGraph, idx: i64) -> i64 { 19 let off: i64 = g.node_off[idx] 20 var n: i64 = 0 21 while g.arena[off+n] != (0 as u8) { n = n + 1 } 22 var e: i64 = n 23 if n > 3 { if g.arena[off+n-3]==(46 as u8) { if g.arena[off+n-2]==(110 as u8) { if g.arena[off+n-1]==(120 as u8) { e = n - 3 } } } } 24 sys_write(fd, ((g.arena as i64)+off) as *u8, e) 25 return 0 26} 27 28func main(argc: i64, argv: *i64) -> i64 { 29 if argc < 3 { fw(1, "usage: nx_eco_graph_atlas <store-prefix> <seed-basename> [out]\n" as *u8); return 2 } 30 let g: *EcoGraph = eg_load(argv[1] as *u8) 31 if (g as i64) == 0 { fw(1, "ERROR store not found\n" as *u8); return 3 } 32 let seedname: *u8 = argv[2] as *u8 33 let seed: i64 = eg_find(g, seedname, slen(seedname)) 34 if seed < 0 { fw(1, "ERROR seed not in graph\n" as *u8); return 4 } 35 36 // ---- collect the ancestry subgraph S = seed + transitive imports (roots to god) ---- 37 let visited: *u8 = sys_mmap(g.node_count + 2) 38 var vi: i64 = 0 39 while vi < g.node_count { visited[vi] = 0 as u8; vi = vi + 1 } 40 visited[seed] = 1 as u8 41 let anc: *i64 = sys_mmap((AT_MAXS+2)*8) as *i64 42 let ancn: *i64 = sys_mmap(16) as *i64 43 ancn[0] = 0 44 eg_ancestors(g, seed, visited, anc, ancn, AT_MAXS - 1) 45 // S local list: sidx[0]=seed, then ancestors 46 let sidx: *i64 = sys_mmap((AT_MAXS+2)*8) as *i64 47 sidx[0] = seed 48 var sn: i64 = 1 49 var ai: i64 = 0 50 while ai < ancn[0] { sidx[sn] = anc[ai]; sn = sn + 1; ai = ai + 1 } 51 // global -> local map 52 let g2l: *i64 = sys_mmap((g.node_count+2)*8) as *i64 53 vi = 0 54 while vi < g.node_count { g2l[vi] = 0 - 1; vi = vi + 1 } 55 var li: i64 = 0 56 while li < sn { g2l[sidx[li]] = li; li = li + 1 } 57 58 // ---- generation: gen(v)=longest path v->god (leaf). Relax over in-S import edges, sn passes. god=0 top. ---- 59 let gen: *i64 = sys_mmap((AT_MAXS+2)*8) as *i64 60 li = 0; while li < sn { gen[li] = 0; li = li + 1 } 61 var pass: i64 = 0 62 while pass < sn { 63 li = 0 64 while li < sn { 65 let v: i64 = sidx[li] 66 var p: i64 = g.out_head[v]; let e: i64 = g.out_head[v+1] 67 while p < e { 68 let dl: i64 = g2l[g.out_list[p]] 69 if dl >= 0 { if gen[li] < gen[dl] + 1 { gen[li] = gen[dl] + 1 } } 70 p = p + 1 71 } 72 li = li + 1 73 } 74 pass = pass + 1 75 } 76 var maxgen: i64 = 0 77 li = 0; while li < sn { if gen[li] > maxgen { maxgen = gen[li] } li = li + 1 } 78 79 // ---- positions: y by generation (gen0=god at top), x spread within each generation band ---- 80 let px: *i64 = sys_mmap((AT_MAXS+2)*8) as *i64 81 let py: *i64 = sys_mmap((AT_MAXS+2)*8) as *i64 82 var lvl: i64 = 0 83 while lvl <= maxgen { 84 var tot: i64 = 0 85 li = 0; while li < sn { if gen[li] == lvl { tot = tot + 1 } li = li + 1 } 86 var cnt: i64 = 0 87 li = 0 88 while li < sn { 89 if gen[li] == lvl { 90 px[li] = 70 + (cnt+1) * (AT_W - 140) / (tot+1) 91 py[li] = 54 + lvl * AT_LAYH 92 cnt = cnt + 1 93 } 94 li = li + 1 95 } 96 lvl = lvl + 1 97 } 98 let H: i64 = 54 + maxgen * AT_LAYH + 60 99 100 // ---- destination ---- 101 var outp: *u8 = "knowledge/atlas_tree.html\x00" as *u8 102 if argc >= 4 { outp = argv[3] as *u8 } 103 let fd: i64 = sys_openat_wr(outp, 0x1a4) 104 if fd < 0 { fw(1, "ERROR cannot open out\n" as *u8); return 5 } 105 106 // ---- page + SVG ---- 107 fw(fd, "<!doctype html><html lang=en><head><meta charset=utf-8><meta name=viewport content=\"width=device-width,initial-scale=1\"><title>Lineage &mdash; " as *u8); fwshort(fd, g, seed); fw(fd, "</title><style>body{margin:0;background:#0b0e16;color:#e8ecf6;font:14px/1.5 -apple-system,Segoe UI,system-ui,sans-serif}.wrap{max-width:1180px;margin:0 auto;padding:22px 16px 70px}.crumb{font-size:.8rem;color:#8a97ad;margin-bottom:10px}a{color:#c9a0ff;text-decoration:none}h1{font-size:24px;margin:0 0 2px}.sub{color:#8a97ad;margin:0 0 14px}.leg{font-size:.78rem;color:#8a97ad;margin:10px 0}.leg b{color:#ffd479}.svgwrap{background:#0d1220;border:1px solid #222c44;border-radius:14px;overflow-x:auto}text{font:11px ui-monospace,Menlo,monospace}</style></head><body><div class=wrap>" as *u8) 108 fw(fd, "<p class=crumb><a href=/>Nishi Family</a> &rsaquo; <a href=/compare/atlas>Atlas</a> &rsaquo; Lineage</p>" as *u8) 109 fw(fd, "<h1>" as *u8); fwshort(fd, g, seed); fw(fd, " &mdash; roots to god</h1>" as *u8) 110 fw(fd, "<p class=sub>The dependency family tree, drawn from the sovereign graph. The <b style=color:#ffd479>foundational primitives</b> (gen 0 &mdash; the deepest roots, e.g. nx_tier / nx_syscalls) sit at the apex; this organ is at the base; each generation up is one import-hop closer to god; ribbons fan up and converge on the roots. " as *u8) 111 fw(fd, "lineage nodes=" as *u8); fwn(fd, sn); fw(fd, " &middot; generations=" as *u8); fwn(fd, maxgen+1); fw(fd, " &middot; this organ Ca=" as *u8); fwn(fd, eg_ca(g,seed)); fw(fd, " Ce=" as *u8); fwn(fd, eg_ce(g,seed)); fw(fd, "</p>" as *u8) 112 fw(fd, "<div class=svgwrap><svg width=\"" as *u8); fwn(fd, AT_W); fw(fd, "\" height=\"" as *u8); fwn(fd, H); fw(fd, "\" viewBox=\"0 0 " as *u8); fwn(fd, AT_W); fw(fd, " " as *u8); fwn(fd, H); fw(fd, "\" xmlns=\"http://www.w3.org/2000/svg\">" as *u8) 113 fw(fd, "<rect x=\"0\" y=\"0\" width=\"" as *u8); fwn(fd, AT_W); fw(fd, "\" height=\"" as *u8); fwn(fd, H); fw(fd, "\" fill=\"#0b0e16\"/>" as *u8) 114 // generation bands (subtle alternating tint) + a left-margin generation label 115 var bl: i64 = 0 116 while bl <= maxgen { 117 if (bl - (bl/2)*2) == 0 { 118 fw(fd, "<rect x=\"0\" y=\"" as *u8); fwn(fd, 2 + bl*AT_LAYH); fw(fd, "\" width=\"" as *u8); fwn(fd, AT_W); fw(fd, "\" height=\"" as *u8); fwn(fd, AT_LAYH); fw(fd, "\" fill=\"#152036\"/>" as *u8) 119 } 120 fw(fd, "<text x=\"14\" y=\"" as *u8); fwn(fd, 58 + bl*AT_LAYH); fw(fd, "\" fill=\"#3c4a66\" font-size=\"10\">gen " as *u8); fwn(fd, maxgen - bl); fw(fd, "</text>" as *u8) 121 bl = bl + 1 122 } 123 // ---- edges (v -> its imports in S): draw a cubic curve fanning UP toward god ---- 124 li = 0 125 while li < sn { 126 let v: i64 = sidx[li] 127 var p: i64 = g.out_head[v]; let e: i64 = g.out_head[v+1] 128 while p < e { 129 let dl: i64 = g2l[g.out_list[p]] 130 if dl >= 0 { 131 let x1: i64 = px[li]; let y1: i64 = py[li] 132 let x2: i64 = px[dl]; let y2: i64 = py[dl] 133 let my: i64 = (y1 + y2) / 2 134 fw(fd, "<path d=\"M" as *u8); fwn(fd, x1); fw(fd, " " as *u8); fwn(fd, y1); fw(fd, "C" as *u8); fwn(fd, x1); fw(fd, " " as *u8); fwn(fd, my); fw(fd, " " as *u8); fwn(fd, x2); fw(fd, " " as *u8); fwn(fd, my); fw(fd, " " as *u8); fwn(fd, x2); fw(fd, " " as *u8); fwn(fd, y2); fw(fd, "\" fill=\"none\" stroke=\"#3d7fd6\" stroke-opacity=\"0.35\" stroke-width=\"1.3\"/>" as *u8) 135 } 136 p = p + 1 137 } 138 li = li + 1 139 } 140 // ---- nodes: radius by importance (Ca), gen-0 = gold roots, seed = purple, hubs brighter; native 141 // <title> hover on EVERY node (zero-JS interactivity); labels only for seed/roots/hubs to declutter ---- 142 li = 0 143 while li < sn { 144 let v: i64 = sidx[li] 145 let x: i64 = px[li]; let y: i64 = py[li] 146 let ca: i64 = eg_ca(g, v) 147 var r: i64 = 5 148 if ca > 3 { r = 6 } 149 if ca > 12 { r = 8 } 150 if ca > 40 { r = 10 } 151 if ca > 150 { r = 13 } 152 var fill: *u8 = "#6f8bd8" as *u8 153 var isgod: i64 = 0 154 if ca >= 20 { fill = "#8fb4ff" as *u8 } 155 if gen[li] == 0 { isgod = 1; fill = "#ffd479" as *u8; if r < 8 { r = 8 } } 156 if li == 0 { fill = "#c9a0ff" as *u8; if r < 11 { r = 11 } } 157 // circle carries a <title> so hovering shows the full name + coupling (native, no JS) 158 fw(fd, "<circle cx=\"" as *u8); fwn(fd, x); fw(fd, "\" cy=\"" as *u8); fwn(fd, y); fw(fd, "\" r=\"" as *u8); fwn(fd, r); fw(fd, "\" fill=\"" as *u8); fw(fd, fill); fw(fd, "\" stroke=\"#0a0d16\" stroke-width=\"1.5\"><title>" as *u8); fwshort(fd, g, v); fw(fd, " &#8212; Ca=" as *u8); fwn(fd, ca); fw(fd, " Ce=" as *u8); fwn(fd, eg_ce(g, v)); fw(fd, "</title></circle>" as *u8) 159 // label only the seed, the roots (gen 0), and hubs (Ca>=6) -> readable, not cluttered 160 var showlbl: i64 = 0 161 if li == 0 { showlbl = 1 } 162 if isgod == 1 { showlbl = 1 } 163 if ca >= 6 { showlbl = 1 } 164 if showlbl == 1 { 165 let ty: i64 = y - r - 5 166 fw(fd, "<text x=\"" as *u8); fwn(fd, x); fw(fd, "\" y=\"" as *u8); fwn(fd, ty); fw(fd, "\" text-anchor=\"middle\" fill=\"#aeb9cf\" font-size=\"10\">" as *u8); fwshort(fd, g, v); fw(fd, "</text>" as *u8) 167 } 168 li = li + 1 169 } 170 fw(fd, "</svg></div>" as *u8) 171 fw(fd, "<p class=leg><b>&#9679; god</b> nx_syscalls (apex) &middot; <span style=color:#c9a0ff>&#9679; this organ</span> &middot; <span style=color:#6f8bd8>&#9679; ancestors</span> &mdash; each higher generation is one import-hop closer to god. Sovereign SVG, generated from the seg_store, zero JavaScript.</p>" as *u8) 172 fw(fd, "<p class=sub><a href=/compare/atlas/graph>&#9776; full walkable graph</a> &middot; <a href=/compare/atlas>&#8592; Atlas home</a></p>" as *u8) 173 fw(fd, "</div></body></html>" as *u8) 174 sys_close(fd) 175 fw(1, "wrote lineage family-tree SVG -> " as *u8); fw(1, outp); fw(1, " (nodes=" as *u8); fwn(1, sn); fw(1, " gens=" as *u8); fwn(1, maxgen+1); fw(1, ")\n" as *u8) 176 return 0 177}