code wiki / _hdl_build / nx_viz_sankey.nx
nx_viz_sankey.nx source
↩ module page · 41 lines · 1475 B
1// nx_viz_sankey.nx -- the SANKEY layer of the sovereign Nishi viz library (the d3-sankey core, bits-up).
2// Flow diagram: node height = throughput (max of in/out flow), nodes stacked vertically per column (x-layer)
3// with a gap. Links (rendered as ribbons) route between stacked nodes. Pure integer. Closes layout-sankey.
4// license_tier: ORIGINAL
5import "nx_syscalls.nx"
6
7// column[i] = node's x-layer. links src[e]->dst[e] carry val[e]. node_h = throughput, node_y = stacked y per
8// column. returns the number of columns.
9func vsk_layout(n: i64, column: *i64, m: i64, src: *i64, dst: *i64, val: *i64, gap: i64, node_h: *i64, node_y: *i64) -> i64 {
10 var i: i64 = 0
11 while i < n {
12 var out_f: i64 = 0; var in_f: i64 = 0; var e: i64 = 0
13 while e < m {
14 if src[e] == i { out_f = out_f + val[e] }
15 if dst[e] == i { in_f = in_f + val[e] }
16 e = e + 1
17 }
18 var th: i64 = out_f
19 if in_f > th { th = in_f }
20 node_h[i] = th
21 i = i + 1
22 }
23 var maxcol: i64 = 0
24 i = 0
25 while i < n { if column[i] > maxcol { maxcol = column[i] } i = i + 1 }
26 var col: i64 = 0
27 while col <= maxcol {
28 var cy: i64 = 0
29 i = 0
30 while i < n {
31 if column[i] == col {
32 node_y[i] = cy
33 cy = cy + node_h[i] + gap
34 }
35 i = i + 1
36 }
37 col = col + 1
38 }
39 return maxcol + 1
40}
41func main() -> i64 { return 0 }