code wiki / _hdl_build / nx_viz_treemap.nx

nx_viz_treemap.nx source

↩ module page · 35 lines · 1296 B

1// nx_viz_treemap.nx -- the TREEMAP layer of the sovereign Nishi viz library (the d3-hierarchy treemap equivalent, 2// bits-up). Slice-and-dice: partition a rectangle among N weighted values proportionally, slicing along the 3// LONGER axis (better aspect than always-horizontal). One level; recurse per child for nesting. Pure integer. 4// rects_out = 4 ints/value: x, y, w, h. Closes layout-treemap. license_tier: ORIGINAL 5import "nx_syscalls.nx" 6 7func vt_treemap(values: *i64, n: i64, x: i64, y: i64, w: i64, h: i64, rects_out: *i64) -> i64 { 8 var sum: i64 = 0 9 var i: i64 = 0 10 while i < n { sum = sum + values[i]; i = i + 1 } 11 if sum == 0 { return 0 } 12 var pos: i64 = 0 13 i = 0 14 while i < n { 15 if w >= h { 16 let ww: i64 = (w * values[i]) / sum 17 rects_out[i * 4] = x + pos 18 rects_out[i * 4 + 1] = y 19 rects_out[i * 4 + 2] = ww 20 rects_out[i * 4 + 3] = h 21 pos = pos + ww 22 } 23 if w < h { 24 let hh: i64 = (h * values[i]) / sum 25 rects_out[i * 4] = x 26 rects_out[i * 4 + 1] = y + pos 27 rects_out[i * 4 + 2] = w 28 rects_out[i * 4 + 3] = hh 29 pos = pos + hh 30 } 31 i = i + 1 32 } 33 return n 34} 35func main() -> i64 { return 0 }