@knowvah/dot-engine 2.10.3 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/dist/gvc/context.d.ts.map +1 -1
  2. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  3. package/dist/gvc/layout-reset.d.ts +38 -1
  4. package/dist/gvc/layout-reset.d.ts.map +1 -1
  5. package/dist/index.js +1191 -372
  6. package/dist/index.js.map +4 -4
  7. package/dist/layout/circo/circular.d.ts.map +1 -1
  8. package/dist/layout/dot/edge-route-helpers.d.ts +6 -1
  9. package/dist/layout/dot/edge-route-helpers.d.ts.map +1 -1
  10. package/dist/layout/dot/edge-route-rank.d.ts +4 -1
  11. package/dist/layout/dot/edge-route-rank.d.ts.map +1 -1
  12. package/dist/layout/dot/index.d.ts.map +1 -1
  13. package/dist/layout/dot/init.d.ts.map +1 -1
  14. package/dist/layout/fdp/cluster-edges.d.ts +11 -0
  15. package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
  16. package/dist/layout/neato/closest.d.ts +20 -0
  17. package/dist/layout/neato/closest.d.ts.map +1 -0
  18. package/dist/layout/neato/constrained-majorization.d.ts +13 -0
  19. package/dist/layout/neato/constrained-majorization.d.ts.map +1 -1
  20. package/dist/layout/neato/embed-graph.d.ts +20 -0
  21. package/dist/layout/neato/embed-graph.d.ts.map +1 -0
  22. package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
  23. package/dist/layout/neato/index.d.ts.map +1 -1
  24. package/dist/layout/neato/init-dim.d.ts +54 -0
  25. package/dist/layout/neato/init-dim.d.ts.map +1 -0
  26. package/dist/layout/neato/init.d.ts +1 -11
  27. package/dist/layout/neato/init.d.ts.map +1 -1
  28. package/dist/layout/neato/kk.d.ts +4 -2
  29. package/dist/layout/neato/kk.d.ts.map +1 -1
  30. package/dist/layout/neato/matrix-ops-dense.d.ts +34 -0
  31. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -0
  32. package/dist/layout/neato/pca.d.ts +14 -0
  33. package/dist/layout/neato/pca.d.ts.map +1 -0
  34. package/dist/layout/neato/sgd.d.ts +2 -3
  35. package/dist/layout/neato/sgd.d.ts.map +1 -1
  36. package/dist/layout/neato/start.d.ts +5 -5
  37. package/dist/layout/neato/start.d.ts.map +1 -1
  38. package/dist/layout/neato/stress-kernel.d.ts +10 -2
  39. package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
  40. package/dist/layout/neato/stress-subspace.d.ts +39 -0
  41. package/dist/layout/neato/stress-subspace.d.ts.map +1 -0
  42. package/dist/layout/neato/vpsc-adjust.d.ts.map +1 -1
  43. package/dist/layout/pack/ccomps.d.ts +4 -2
  44. package/dist/layout/pack/ccomps.d.ts.map +1 -1
  45. package/dist/layout/sfdp/index.d.ts.map +1 -1
  46. package/dist/layout/sfdp/init.d.ts +6 -7
  47. package/dist/layout/sfdp/init.d.ts.map +1 -1
  48. package/dist/layout/twopi/circle.d.ts.map +1 -1
  49. package/dist/layout/twopi/index.d.ts.map +1 -1
  50. package/dist/render/dot/attrs.d.ts +7 -0
  51. package/dist/render/dot/attrs.d.ts.map +1 -1
  52. package/dist/render.js +1574 -755
  53. package/dist/render.js.map +4 -4
  54. package/package.json +4 -4
  55. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +20 -0
  56. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +20 -0
  57. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +20 -0
  58. package/src/gvc/__fixtures__/rerender/abom-shift-pack.gv +1 -0
  59. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.1 +22 -0
  60. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +22 -0
  61. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +22 -0
  62. package/src/gvc/__fixtures__/rerender/abom-shift-parity.gv +1 -0
  63. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.1 +13 -0
  64. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.2 +13 -0
  65. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.3 +13 -0
  66. package/src/gvc/__fixtures__/rerender/abom-shift.gv +1 -0
  67. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.1 +10 -0
  68. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.2 +11 -0
  69. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.gv +9 -0
  70. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.1 +40 -0
  71. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.2 +40 -0
  72. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.1 +15 -0
  73. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.2 +17 -0
  74. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.1 +40 -0
  75. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.2 +15 -0
  76. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.1 +40 -0
  77. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.2 +99 -0
  78. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.1 +489 -0
  79. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.2 +503 -0
  80. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.1 +40 -0
  81. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.2 +109 -0
  82. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.1 +69 -0
  83. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.2 +70 -0
  84. package/src/gvc/__fixtures__/rerender/cluster-edges.gv +15 -0
  85. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.1 +104 -0
  86. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.2 +104 -0
  87. package/src/gvc/__fixtures__/rerender/fdp-1581.gv +26 -0
  88. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +34 -0
  89. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +34 -0
  90. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +34 -0
  91. package/src/gvc/__fixtures__/rerender/flat-rev-stale.gv +33 -0
  92. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +181 -0
  93. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +218 -0
  94. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +255 -0
  95. package/src/gvc/__fixtures__/rerender/regen.sh +25 -0
  96. package/src/gvc/context.ts +7 -2
  97. package/src/gvc/emit-xdot.ts +37 -7
  98. package/src/gvc/layout-reset.ts +59 -1
  99. package/src/layout/circo/circular.ts +3 -1
  100. package/src/layout/dot/edge-route-helpers.ts +8 -2
  101. package/src/layout/dot/edge-route-rank.ts +20 -2
  102. package/src/layout/dot/index.ts +17 -2
  103. package/src/layout/dot/init.ts +9 -17
  104. package/src/layout/dot/splines-flat.ts +12 -12
  105. package/src/layout/fdp/cluster-edges.ts +0 -0
  106. package/src/layout/neato/__fixtures__/dim/circuit-dim3.dot +33 -0
  107. package/src/layout/neato/__fixtures__/dim/circuit-dim3.gv +12 -0
  108. package/src/layout/neato/__fixtures__/dim/circuit-dim3.stderr +0 -0
  109. package/src/layout/neato/__fixtures__/dim/circuit-dim3.xdot +54 -0
  110. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.dot +32 -0
  111. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.gv +11 -0
  112. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.stderr +0 -0
  113. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.xdot +53 -0
  114. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.dot +32 -0
  115. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.gv +11 -0
  116. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  117. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  118. package/src/layout/neato/__fixtures__/dim/dim3.dot +31 -0
  119. package/src/layout/neato/__fixtures__/dim/dim3.gv +10 -0
  120. package/src/layout/neato/__fixtures__/dim/dim3.stderr +0 -0
  121. package/src/layout/neato/__fixtures__/dim/dim3.xdot +52 -0
  122. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.dot +32 -0
  123. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.gv +11 -0
  124. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  125. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  126. package/src/layout/neato/__fixtures__/dim/dimen3.dot +31 -0
  127. package/src/layout/neato/__fixtures__/dim/dimen3.gv +10 -0
  128. package/src/layout/neato/__fixtures__/dim/dimen3.stderr +0 -0
  129. package/src/layout/neato/__fixtures__/dim/dimen3.xdot +52 -0
  130. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +267 -0
  131. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.gv +84 -0
  132. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.stderr +0 -0
  133. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +468 -0
  134. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +267 -0
  135. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.gv +84 -0
  136. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.stderr +0 -0
  137. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +468 -0
  138. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +268 -0
  139. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.gv +85 -0
  140. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.stderr +0 -0
  141. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +469 -0
  142. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +484 -0
  143. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.gv +151 -0
  144. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.stderr +0 -0
  145. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +852 -0
  146. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +34 -0
  147. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.gv +13 -0
  148. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.stderr +0 -0
  149. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +55 -0
  150. package/src/layout/neato/__fixtures__/dim/hier-dim3.dot +33 -0
  151. package/src/layout/neato/__fixtures__/dim/hier-dim3.gv +12 -0
  152. package/src/layout/neato/__fixtures__/dim/hier-dim3.stderr +0 -0
  153. package/src/layout/neato/__fixtures__/dim/hier-dim3.xdot +54 -0
  154. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +33 -0
  155. package/src/layout/neato/__fixtures__/dim/hier-dim4.gv +12 -0
  156. package/src/layout/neato/__fixtures__/dim/hier-dim4.stderr +0 -0
  157. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +54 -0
  158. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.dot +32 -0
  159. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.gv +11 -0
  160. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.stderr +0 -0
  161. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.xdot +53 -0
  162. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.dot +34 -0
  163. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.gv +13 -0
  164. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.stderr +0 -0
  165. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.xdot +55 -0
  166. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +37 -0
  167. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.gv +12 -0
  168. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.stderr +0 -0
  169. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +58 -0
  170. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +141 -0
  171. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.gv +48 -0
  172. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.stderr +1 -0
  173. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +233 -0
  174. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.dot +21 -0
  175. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.gv +8 -0
  176. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.stderr +1 -0
  177. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.xdot +33 -0
  178. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.dot +23 -0
  179. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.gv +10 -0
  180. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.stderr +1 -0
  181. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.xdot +35 -0
  182. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.dot +23 -0
  183. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.gv +10 -0
  184. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.stderr +1 -0
  185. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.xdot +35 -0
  186. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.dot +26 -0
  187. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.gv +7 -0
  188. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.stderr +0 -0
  189. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.xdot +44 -0
  190. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.dot +28 -0
  191. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.gv +9 -0
  192. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.stderr +0 -0
  193. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.xdot +46 -0
  194. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.dot +48 -0
  195. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.gv +15 -0
  196. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.stderr +0 -0
  197. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.xdot +79 -0
  198. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +56 -0
  199. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.gv +17 -0
  200. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.stderr +0 -0
  201. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +94 -0
  202. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +47 -0
  203. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.gv +14 -0
  204. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.stderr +0 -0
  205. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +78 -0
  206. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.dot +34 -0
  207. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.gv +13 -0
  208. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.stderr +0 -0
  209. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.xdot +55 -0
  210. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +34 -0
  211. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.gv +13 -0
  212. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.stderr +0 -0
  213. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +55 -0
  214. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +34 -0
  215. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.gv +13 -0
  216. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.stderr +0 -0
  217. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +55 -0
  218. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.dot +15 -0
  219. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.gv +6 -0
  220. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.stderr +0 -0
  221. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.xdot +22 -0
  222. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.dot +33 -0
  223. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.gv +12 -0
  224. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.stderr +0 -0
  225. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.xdot +54 -0
  226. package/src/layout/neato/__fixtures__/dim/kk-dim3.dot +33 -0
  227. package/src/layout/neato/__fixtures__/dim/kk-dim3.gv +12 -0
  228. package/src/layout/neato/__fixtures__/dim/kk-dim3.stderr +0 -0
  229. package/src/layout/neato/__fixtures__/dim/kk-dim3.xdot +54 -0
  230. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.dot +33 -0
  231. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.gv +12 -0
  232. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.stderr +0 -0
  233. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.xdot +54 -0
  234. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.dot +39 -0
  235. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.gv +15 -0
  236. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.stderr +0 -0
  237. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.xdot +60 -0
  238. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.dot +33 -0
  239. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.gv +12 -0
  240. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.stderr +0 -0
  241. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.xdot +54 -0
  242. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.dot +33 -0
  243. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.gv +12 -0
  244. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.stderr +0 -0
  245. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.xdot +54 -0
  246. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.dot +33 -0
  247. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.gv +12 -0
  248. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.stderr +0 -0
  249. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.xdot +54 -0
  250. package/src/layout/neato/__fixtures__/dim/pack-dim3.dot +47 -0
  251. package/src/layout/neato/__fixtures__/dim/pack-dim3.gv +14 -0
  252. package/src/layout/neato/__fixtures__/dim/pack-dim3.stderr +0 -0
  253. package/src/layout/neato/__fixtures__/dim/pack-dim3.xdot +78 -0
  254. package/src/layout/neato/__fixtures__/dim/pins-dim3.dot +38 -0
  255. package/src/layout/neato/__fixtures__/dim/pins-dim3.gv +14 -0
  256. package/src/layout/neato/__fixtures__/dim/pins-dim3.stderr +0 -0
  257. package/src/layout/neato/__fixtures__/dim/pins-dim3.xdot +59 -0
  258. package/src/layout/neato/__fixtures__/dim/regen.sh +24 -0
  259. package/src/layout/neato/__fixtures__/dim/regular-dim3.dot +33 -0
  260. package/src/layout/neato/__fixtures__/dim/regular-dim3.gv +12 -0
  261. package/src/layout/neato/__fixtures__/dim/regular-dim3.stderr +0 -0
  262. package/src/layout/neato/__fixtures__/dim/regular-dim3.xdot +54 -0
  263. package/src/layout/neato/__fixtures__/dim/sgd-dim3.dot +33 -0
  264. package/src/layout/neato/__fixtures__/dim/sgd-dim3.gv +12 -0
  265. package/src/layout/neato/__fixtures__/dim/sgd-dim3.stderr +0 -0
  266. package/src/layout/neato/__fixtures__/dim/sgd-dim3.xdot +54 -0
  267. package/src/layout/neato/__fixtures__/dim/smart-units.json +16 -0
  268. package/src/layout/neato/__fixtures__/dim/subset-dim3.dot +33 -0
  269. package/src/layout/neato/__fixtures__/dim/subset-dim3.gv +12 -0
  270. package/src/layout/neato/__fixtures__/dim/subset-dim3.stderr +0 -0
  271. package/src/layout/neato/__fixtures__/dim/subset-dim3.xdot +54 -0
  272. package/src/layout/neato/closest.ts +206 -0
  273. package/src/layout/neato/constrained-majorization.ts +4 -23
  274. package/src/layout/neato/embed-graph.ts +81 -0
  275. package/src/layout/neato/fdp-adjust.ts +22 -8
  276. package/src/layout/neato/index.ts +26 -17
  277. package/src/layout/neato/init-dim.ts +165 -0
  278. package/src/layout/neato/init.ts +9 -35
  279. package/src/layout/neato/kk.ts +47 -41
  280. package/src/layout/neato/matrix-ops-dense.ts +232 -0
  281. package/src/layout/neato/pca.ts +60 -0
  282. package/src/layout/neato/sgd.ts +11 -4
  283. package/src/layout/neato/start.ts +8 -5
  284. package/src/layout/neato/stress-kernel.ts +65 -5
  285. package/src/layout/neato/stress-subspace.ts +371 -0
  286. package/src/layout/neato/vpsc-adjust.ts +3 -1
  287. package/src/layout/pack/__fixtures__/cc-reuse/circo.dot +23 -0
  288. package/src/layout/pack/__fixtures__/cc-reuse/circo.gv +1 -0
  289. package/src/layout/pack/__fixtures__/cc-reuse/circo.stderr +0 -0
  290. package/src/layout/pack/__fixtures__/cc-reuse/circo.xdot +38 -0
  291. package/src/layout/pack/__fixtures__/cc-reuse/neato.dot +23 -0
  292. package/src/layout/pack/__fixtures__/cc-reuse/neato.gv +1 -0
  293. package/src/layout/pack/__fixtures__/cc-reuse/neato.stderr +0 -0
  294. package/src/layout/pack/__fixtures__/cc-reuse/neato.xdot +38 -0
  295. package/src/layout/pack/__fixtures__/cc-reuse/osage.dot +23 -0
  296. package/src/layout/pack/__fixtures__/cc-reuse/osage.gv +1 -0
  297. package/src/layout/pack/__fixtures__/cc-reuse/osage.stderr +0 -0
  298. package/src/layout/pack/__fixtures__/cc-reuse/osage.xdot +38 -0
  299. package/src/layout/pack/__fixtures__/cc-reuse/regen.sh +24 -0
  300. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.dot +21 -0
  301. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.gv +1 -0
  302. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.stderr +0 -0
  303. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.xdot +36 -0
  304. package/src/layout/pack/__fixtures__/cc-reuse/twopi.dot +21 -0
  305. package/src/layout/pack/__fixtures__/cc-reuse/twopi.gv +1 -0
  306. package/src/layout/pack/__fixtures__/cc-reuse/twopi.stderr +1 -0
  307. package/src/layout/pack/__fixtures__/cc-reuse/twopi.xdot +36 -0
  308. package/src/layout/pack/ccomps.ts +34 -6
  309. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +32 -0
  310. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.gv +11 -0
  311. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  312. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  313. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +31 -0
  314. package/src/layout/sfdp/__fixtures__/dim/dim3.gv +10 -0
  315. package/src/layout/sfdp/__fixtures__/dim/dim3.stderr +0 -0
  316. package/src/layout/sfdp/__fixtures__/dim/dim3.xdot +52 -0
  317. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +32 -0
  318. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.gv +11 -0
  319. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  320. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  321. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +33 -0
  322. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.gv +12 -0
  323. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.stderr +0 -0
  324. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.xdot +54 -0
  325. package/src/layout/sfdp/__fixtures__/dim/regen.sh +24 -0
  326. package/src/layout/sfdp/index.ts +15 -10
  327. package/src/layout/sfdp/init.ts +26 -11
  328. package/src/layout/twopi/circle.ts +5 -1
  329. package/src/layout/twopi/index.ts +3 -0
  330. package/src/render/dot/agwrite.ts +2 -2
  331. package/src/render/dot/attrs.ts +16 -0
  332. package/src/render/dot/write-back.ts +2 -2
@@ -0,0 +1,81 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * High-dimensional embedding of a graph: each coordinate is a pivot's
5
+ * graph-theoretic distance to every node. `DistType` is C `int` (Int32Array).
6
+ *
7
+ * @see lib/neatogen/embed_graph.c
8
+ */
9
+
10
+ import { crand } from '../../common/crand.js';
11
+ import { bfs } from './bfs.js';
12
+ import { ngdijkstra, type VtxData } from './dijkstra.js';
13
+ import { computeNewWeights, restoreOldWeights } from './kkutils.js';
14
+
15
+ /**
16
+ * `old_weights = graph[0].ewgts`. C keeps one block; the port's weights are one
17
+ * array per vertex, and `null` is C `NULL`.
18
+ */
19
+ export function saveWeights(graph: readonly VtxData[], n: number): number[][] | null {
20
+ return graph[0]!.ewgts.length === 0 ? null : graph.slice(0, n).map((v) => v.ewgts);
21
+ }
22
+
23
+ /** The distances from `node`: Dijkstra over the new weights, else BFS. */
24
+ export function pivotDistances(
25
+ node: number, graph: VtxData[], n: number, reweightGraph: boolean, dist: Int32Array,
26
+ ): void {
27
+ if (reweightGraph) ngdijkstra(node, graph, n, dist);
28
+ else bfs(node, graph, n, dist);
29
+ }
30
+
31
+ /**
32
+ * Compute a `dim`-dimensional embedding of the `n` nodes, choosing `dim` pivots,
33
+ * each as far as possible from those already chosen.
34
+ * @see lib/neatogen/embed_graph.c:embed_graph
35
+ */
36
+ export function embedGraph(graph: VtxData[], n: number, dim: number, reweightGraph: boolean): Int32Array[] {
37
+ const dist = new Int32Array(n); // distances of each node to the selected pivots
38
+ const oldWeights = saveWeights(graph, n);
39
+ const coords = Array.from({ length: dim }, () => new Int32Array(n));
40
+ if (reweightGraph) computeNewWeights(graph, n);
41
+
42
+ let node = crand() % n; // select the first pivot
43
+ pivotDistances(node, graph, n, reweightGraph, coords[0]!);
44
+ let maxDist = 0;
45
+ for (let i = 0; i < n; i++) {
46
+ dist[i] = coords[0]![i]!;
47
+ if (dist[i]! > maxDist) {
48
+ node = i;
49
+ maxDist = dist[i]!;
50
+ }
51
+ }
52
+
53
+ // select other dim-1 nodes as pivots
54
+ for (let i = 1; i < dim; i++) {
55
+ pivotDistances(node, graph, n, reweightGraph, coords[i]!);
56
+ maxDist = 0;
57
+ for (let j = 0; j < n; j++) {
58
+ dist[j] = Math.min(dist[j]!, coords[i]![j]!);
59
+ if (dist[j]! > maxDist) {
60
+ node = j;
61
+ maxDist = dist[j]!;
62
+ }
63
+ }
64
+ }
65
+
66
+ if (reweightGraph) restoreOldWeights(graph, n, oldWeights);
67
+ return coords;
68
+ }
69
+
70
+ /**
71
+ * Make each axis centered around 0; the average is truncated to `DistType`.
72
+ * @see lib/neatogen/embed_graph.c:center_coordinate
73
+ */
74
+ export function centerCoordinate(coords: readonly Int32Array[], n: number, dim: number): void {
75
+ for (let i = 0; i < dim; i++) {
76
+ let sum = 0;
77
+ for (let j = 0; j < n; j++) sum += coords[i]![j]!;
78
+ const avg = Math.trunc(sum / n);
79
+ for (let j = 0; j < n; j++) coords[i]![j] = coords[i]![j]! - avg;
80
+ }
81
+ }
@@ -24,13 +24,28 @@ import { AM_ORTHO, AM_ORTHO_YX, AM_ORTHOXY, AM_ORTHOYX, AM_PORTHO, AM_PORTHO_YX,
24
24
  import { countOverlapIn, sAdjustGraph } from './adjust-info.js';
25
25
  import { vpscAdjust } from './vpsc-adjust.js';
26
26
  import { sepFactor } from './sep-factor.js';
27
+ import { ndimOf } from './init-dim.js';
27
28
  import { lateDouble } from '../../common/nodeinit.js';
28
29
  import { RenderError } from '../../errors.js';
29
30
  import { agwarningf } from '../../common/agerr.js';
30
31
 
31
32
  /** @see lib/neatogen/adjust.c:DFLT_MARGIN (points) */
32
33
  const DFLT_MARGIN = 4;
33
- const NDIM = 2;
34
+
35
+ /**
36
+ * getSizes lays `sizes` out Ndim apart (x, y, then zeros); sfdp's getSizes
37
+ * returns the 2-wide layout, so widen it to `ndim`.
38
+ * @see lib/neatogen/adjust.c:getSizes
39
+ */
40
+ function sizesByNdim(sizes2: number[], ndim: number): number[] {
41
+ if (ndim === 2) return sizes2;
42
+ const sizes = new Array<number>((sizes2.length / 2) * ndim).fill(0);
43
+ for (let i = 0; i < sizes2.length / 2; i++) {
44
+ sizes[i * ndim] = sizes2[i * 2]!;
45
+ sizes[i * ndim + 1] = sizes2[i * 2 + 1]!;
46
+ }
47
+ return sizes;
48
+ }
34
49
 
35
50
  /** @see lib/common/utils.c:mapBool */
36
51
  function mapBoolDflt(p: string | undefined, defaultValue: boolean): boolean {
@@ -81,17 +96,17 @@ export function overlapPrismTries(flag: string | undefined): number | null {
81
96
  */
82
97
  export function fdpAdjust(g: Graph, ntry: number): void {
83
98
  const A0 = makeMatrix(g);
84
- const pos = new Array<number>(NDIM * g.nodes.size).fill(0);
99
+ const ndim = ndimOf(g);
100
+ const pos = new Array<number>(ndim * g.nodes.size).fill(0);
85
101
  const sep = sepFactor(g);
86
102
  const pad = sep.doAdd
87
103
  ? { x: sep.x / 72, y: sep.y / 72 }
88
104
  : { x: DFLT_MARGIN / 72, y: DFLT_MARGIN / 72 };
89
- const sizes = getSizes(g, pad);
105
+ const sizes = sizesByNdim(getSizes(g, pad), ndim);
90
106
 
91
107
  for (const n of g.nodes.values()) {
92
108
  const i = n.info.id!;
93
- pos[i * NDIM] = n.info.pos?.[0] ?? 0;
94
- pos[i * NDIM + 1] = n.info.pos?.[1] ?? 0;
109
+ for (let k = 0; k < ndim; k++) pos[i * ndim + k] = n.info.pos?.[k] ?? 0;
95
110
  }
96
111
 
97
112
  const A = !smIsSymmetric(A0, false) || A0.type !== MATRIX_TYPE_REAL
@@ -103,13 +118,12 @@ export function fdpAdjust(g: Graph, ntry: number): void {
103
118
  const doShrinking = mapBoolDflt(
104
119
  g.attrs.get('overlap_shrink') ?? g.root.attrs.get('overlap_shrink'), true);
105
120
 
106
- removeOverlapPrism(NDIM, A, pos, sizes, ntry, scaling, doShrinking);
121
+ removeOverlapPrism(ndim, A, pos, sizes, ntry, scaling, doShrinking);
107
122
 
108
123
  for (const n of g.nodes.values()) {
109
124
  const i = n.info.id!;
110
125
  if (!n.info.pos) n.info.pos = [0, 0];
111
- n.info.pos[0] = pos[i * NDIM]!;
112
- n.info.pos[1] = pos[i * NDIM + 1]!;
126
+ for (let k = 0; k < ndim; k++) n.info.pos[k] = pos[i * ndim + k]!;
113
127
  }
114
128
  }
115
129
 
@@ -25,6 +25,7 @@ import {
25
25
  MODEL_MDS,
26
26
  } from './init.js';
27
27
  import { neatoMode } from './start.js';
28
+ import { neatoInitGraphDim, addZ } from './init-dim.js';
28
29
  import { agerr, agwarningf } from '../../common/agerr.js';
29
30
  import { agNameOf } from '../../model/cgraph-ops.js';
30
31
  import { removeOverlapWith, graphAdjustMode, type AdjustData } from './fdp-adjust.js';
@@ -141,6 +142,27 @@ export function maybeRemoveOverlap(g: Graph, am: AdjustData): void {
141
142
  // neatoLayout
142
143
  // ---------------------------------------------------------------------------
143
144
 
145
+ /**
146
+ * C's neato_init_node_edge: neato_init_node then user_pos per node (user_pos
147
+ * seeds a `pos=` input into the initial layout, P_SET/hasPos, so majorization
148
+ * starts from it instead of a random init), then a SECOND loop calling
149
+ * neato_init_edge -> common_init_edge, which creates ED_label(e) and ORs
150
+ * GD_has_labels with EDGE_LABEL. Without it the edge label object never exists
151
+ * and addXLabels' gate (has_labels & EDGE_LABEL) is dead.
152
+ * @see lib/neatogen/neatoinit.c:128 neato_init_node_edge
153
+ * @see lib/neatogen/neatoinit.c:68 neato_init_edge
154
+ */
155
+ function neatoInitNodeEdge(g: Graph, ndim: number): void {
156
+ for (const [, n] of g.nodes) {
157
+ neatoInitNode(n, ndim);
158
+ userPos(n, ndim, g.nodes.size);
159
+ }
160
+ const measurer = layoutMeasurer(g);
161
+ if (measurer !== undefined) {
162
+ for (const e of g.edges) initEdgeLabels(e, g, measurer);
163
+ }
164
+ }
165
+
144
166
  /**
145
167
  * Full neato layout pipeline for a single graph.
146
168
  *
@@ -171,23 +193,8 @@ export function neatoLayout(g: Graph): void {
171
193
  // @see lib/neatogen/neatoinit.c:598
172
194
  setEdgeTypeFromAttr(g, EDGETYPE_LINE);
173
195
  commonInitNodeEdge(g);
174
- // C neato_init_node_edge: neato_init_node then user_pos, per node. user_pos
175
- // seeds a `pos=` input into the initial layout (P_SET/hasPos) so majorization
176
- // starts from it instead of a random init. @see neatoinit.c:139-141
177
- for (const [, n] of g.nodes) {
178
- neatoInitNode(n);
179
- userPos(n);
180
- }
181
- // C neato_init_node_edge runs a SECOND loop calling neato_init_edge ->
182
- // common_init_edge, which creates ED_label(e) and ORs GD_has_labels with
183
- // EDGE_LABEL. Without it the edge label object never exists and addXLabels'
184
- // gate (has_labels & EDGE_LABEL) is dead.
185
- // @see lib/neatogen/neatoinit.c:142 neato_init_node_edge (edge loop)
186
- // @see lib/neatogen/neatoinit.c:68 neato_init_edge -> common_init_edge
187
- const measurer = layoutMeasurer(g);
188
- if (measurer !== undefined) {
189
- for (const e of g.edges) initEdgeLabels(e, g, measurer);
190
- }
196
+ // neato_init_graph reads dim/dimen first, so ND_pos has GD_ndim entries.
197
+ neatoInitNodeEdge(g, neatoInitGraphDim(g));
191
198
 
192
199
  const mode = parseMode(g);
193
200
  // C resolves the overlap mode once, before any component. @see neatoinit.c:1369
@@ -207,6 +214,8 @@ export function neatoLayout(g: Graph): void {
207
214
  // C: spline_edges shifts pos to the origin, syncs coord, routes.
208
215
  splineEdgesShifted(g);
209
216
  }
217
+ // C: addZ before gv_postprocess on every path (neatoinit.c:1417,1433).
218
+ addZ(g);
210
219
  // C: addCluster registers top-level clusters (label + compute_bb)
211
220
  // after layout; gv_postprocess then places the cluster labels.
212
221
  addClusters(g);
@@ -0,0 +1,165 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+ /**
3
+ * Neato's layout dimension: the `dim`/`dimen` reads, the third and later
4
+ * coordinates of `pos`, the `z` attribute, and the jitter that fills the
5
+ * dimensions a 2-D input leaves open.
6
+ *
7
+ * C keeps the dimension in the global `Ndim` and in `GD_ndim`/`GD_odim` of the
8
+ * root. The port keeps it on the root's `info` only (part-10 AD-2): solvers
9
+ * take it as a parameter.
10
+ *
11
+ * @see lib/neatogen/neatoinit.c:neato_init_graph, user_pos, addZ
12
+ * @see lib/neatogen/stuff.c:jitter_d, jitter3d
13
+ */
14
+
15
+ import type { Graph } from '../../model/graph.js';
16
+ import type { Node } from '../../model/node.js';
17
+ import { ownAttrs } from '../../model/lazy-attrs.js';
18
+ import { lateInt } from '../../common/nodeinit.js';
19
+ import { drand48 } from '../../common/random.js';
20
+ import { inputscaleDivisor } from '../../common/utils-inputscale.js';
21
+ import { mapbool } from '../dot/rank.js';
22
+
23
+ /** Default layout dimension. @see lib/neatogen/neatoinit.c:neato_init_graph */
24
+ export const DFLT_DIM = 2;
25
+ /** Largest layout dimension. @see lib/common/const.h:MAXDIM */
26
+ export const MAXDIM = 10;
27
+
28
+ const POINTS_PER_INCH = 72;
29
+ const NUM = '(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)';
30
+ /** `%lf,%lf,%lf%c` and `%lf,%lf%c`, the `%c` capturing the next character. */
31
+ const POS3 = new RegExp(`^\\s*${NUM}\\s*,\\s*${NUM}\\s*,\\s*${NUM}(.?)`);
32
+ const POS2 = new RegExp(`^\\s*${NUM}\\s*,\\s*${NUM}(.?)`);
33
+ const Z_NUM = new RegExp(`^\\s*${NUM}`);
34
+
35
+ /**
36
+ * Read `dimen`, then `dim`, and clamp at MAXDIM, into the root's `ndim` and
37
+ * `odim`. Runs before any node is initialised and before any solver.
38
+ * @see lib/neatogen/neatoinit.c:neato_init_graph
39
+ */
40
+ export function neatoInitGraphDim(g: Graph): number {
41
+ const root = g.root;
42
+ const outdim = lateInt(root.attrs.get('dimen'), DFLT_DIM, 2);
43
+ const ndim = Math.min(lateInt(root.attrs.get('dim'), outdim, 2), MAXDIM);
44
+ root.info.ndim = ndim;
45
+ root.info.odim = Math.min(outdim, ndim);
46
+ return ndim;
47
+ }
48
+
49
+ /** The layout dimension of the root `neatoInitGraphDim` set (C's `Ndim`). */
50
+ export function ndimOf(g: Graph): number {
51
+ return g.root.info.ndim ?? DFLT_DIM;
52
+ }
53
+
54
+ /**
55
+ * Fill dimensions `n`.. of a node's position with `nG * drand48()`.
56
+ * @see lib/neatogen/stuff.c:jitter_d
57
+ */
58
+ export function jitterD(np: Node, nG: number, n: number, ndim: number): void {
59
+ const pos = np.info.pos;
60
+ if (pos === undefined) return;
61
+ for (let k = n; k < ndim; k++) pos[k] = nG * drand48();
62
+ }
63
+
64
+ /** @see lib/neatogen/stuff.c:jitter3d */
65
+ export function jitter3d(np: Node, nG: number, ndim: number): void {
66
+ jitterD(np, nG, 2, ndim);
67
+ }
68
+
69
+ /** Is node attribute `name` declared anywhere in the graph (C's agfindnodeattr)? */
70
+ function nodeAttrDeclared(g: Graph, name: string): boolean {
71
+ if (g.nodeDefaults.has(name)) return true;
72
+ for (const n of g.nodes.values()) if (n.attrs.has(name)) return true;
73
+ for (const sub of g.subgraphs.values()) if (nodeAttrDeclared(sub, name)) return true;
74
+ return false;
75
+ }
76
+
77
+ /** C's `N_z`: the `z` symbol exists once any scope declares it. */
78
+ export function zDeclared(g: Graph): boolean {
79
+ return nodeAttrDeclared(g.root, 'z');
80
+ }
81
+
82
+ /** `agxget(np, N_z)`: the node's own `z`, else the default it was created under. */
83
+ function zValue(np: Node): string {
84
+ return np.attrs.get('z') ?? np.nodeDefaultsSnapshot?.get('z') ?? '';
85
+ }
86
+
87
+ /** `if (PSinputscale > 0) pvec[i] /= PSinputscale` for i below `ndim`. */
88
+ function scalePos(pvec: number[], ndim: number, div: number): void {
89
+ for (let i = 0; i < ndim; i++) pvec[i] = pvec[i]! / div;
90
+ }
91
+
92
+ /** The 3-D branch of user_pos. @see lib/neatogen/neatoinit.c:user_pos */
93
+ function userPos3(np: Node, m: RegExpExecArray, nG: number, ndim: number): void {
94
+ const pvec = np.info.pos!;
95
+ pvec[0] = Number(m[1]);
96
+ pvec[1] = Number(m[2]);
97
+ pvec[2] = Number(m[3]);
98
+ scalePos(pvec, ndim, inputscaleDivisor(np.root));
99
+ if (ndim > 3) jitterD(np, nG, 3, ndim);
100
+ }
101
+
102
+ /** The 2-D branch of user_pos, with `z` or jitter for the third coordinate. */
103
+ function userPos2(np: Node, m: RegExpExecArray, nG: number, ndim: number): void {
104
+ const pvec = np.info.pos!;
105
+ const div = inputscaleDivisor(np.root);
106
+ pvec[0] = Number(m[1]);
107
+ pvec[1] = Number(m[2]);
108
+ scalePos(pvec, ndim, div);
109
+ if (ndim <= 2) return;
110
+ const zm = zDeclared(np.root) ? Z_NUM.exec(zValue(np)) : null;
111
+ if (zm === null) {
112
+ jitter3d(np, nG, ndim);
113
+ return;
114
+ }
115
+ pvec[2] = Number(zm[1]) / div;
116
+ jitterD(np, nG, 3, ndim);
117
+ }
118
+
119
+ /** neato_init_node's calloc(ndim); a caller that skipped it gets the same. */
120
+ function ensurePos(n: Node, ndim: number): void {
121
+ if (n.info.pos === undefined || n.info.pos.length < ndim) n.info.pos = new Array<number>(ndim).fill(0);
122
+ }
123
+
124
+ /** `c == '!' || (pinptr && mapbool(agxget(np, pinptr)))`. @see lib/neatogen/neatoinit.c:user_pos */
125
+ function pinRequested(n: Node, c: string | undefined): boolean {
126
+ const pin = n.attrs.get('pin');
127
+ return c === '!' || (pin !== undefined && mapbool(pin));
128
+ }
129
+
130
+ /**
131
+ * Seed a node's initial position from its `pos=` attribute (C's P_SET),
132
+ * mirroring user_pos. Sets info.pos + info.posSet so hasPos is true and neato
133
+ * majorization starts from the input layout instead of a random init; a `!`
134
+ * suffix or `pin=true` additionally sets info.pinned (P_PIN → isFixed).
135
+ *
136
+ * With `ndim` of 3 or more a third coordinate comes from `pos` or from `z`;
137
+ * otherwise (and for the dimensions beyond) it is `nG * drand48()`.
138
+ * `pos` is divided by PSinputscale when > 0. Must run AFTER neatoInitNode,
139
+ * which zeroes info.pos.
140
+ * @see lib/neatogen/neatoinit.c:user_pos
141
+ */
142
+ export function userPos(n: Node, ndim: number = DFLT_DIM, nG: number = n.root.nodes.size): boolean {
143
+ const p = n.attrs.get('pos');
144
+ if (p === undefined || p.length === 0) return false;
145
+ const m3 = ndim >= 3 ? POS3.exec(p) : null;
146
+ const m = m3 ?? POS2.exec(p);
147
+ if (m === null) return false; // C agerrorf: malformed pos, non-fatal
148
+ n.info.posSet = true;
149
+ ensurePos(n, ndim);
150
+ if (m3 !== null) userPos3(n, m3, nG, ndim);
151
+ else userPos2(n, m, nG, ndim);
152
+ if (pinRequested(n, m[m.length - 1])) n.info.pinned = true;
153
+ return true;
154
+ }
155
+
156
+ /**
157
+ * With ndim of 3 or more and `z` declared, write each node's `z` (points).
158
+ * @see lib/neatogen/neatoinit.c:addZ
159
+ */
160
+ export function addZ(g: Graph): void {
161
+ if (ndimOf(g) < 3 || !zDeclared(g)) return;
162
+ for (const n of g.nodes.values()) {
163
+ ownAttrs(n).set('z', (POINTS_PER_INCH * (n.info.pos?.[2] ?? 0)).toFixed(6));
164
+ }
165
+ }
@@ -37,11 +37,11 @@ import { AM_NONE, type AdjustData } from './fdp-adjust.js';
37
37
  import { agerr } from '../../common/agerr.js';
38
38
 
39
39
  export { makeGraphDataC, graphHasLen, checkStart };
40
- import { mapbool } from '../dot/rank.js';
40
+ export { userPos } from './init-dim.js';
41
41
  import { stressMajorizationKDMkernel } from './stress-kernel.js';
42
42
  import { stressModelDij } from './stress-models.js';
43
43
  import { lateDouble } from '../../common/nodeinit.js';
44
- import { inputscaleDivisor } from '../../common/utils-inputscale.js';
44
+ import { DFLT_DIM, ndimOf } from './init-dim.js';
45
45
  import { parseNeatoDrawing, neatoSetAspectRatio } from './set-aspect.js';
46
46
 
47
47
  // ---------------------------------------------------------------------------
@@ -73,9 +73,6 @@ export const MODEL_SUBSET = 2;
73
73
  /** MDS distance model. @see lib/neatogen/defs.h */
74
74
  export const MODEL_MDS = 3;
75
75
 
76
- /** Default layout dimension (2D). */
77
- const DFLT_DIM = 2;
78
-
79
76
  /** Points per inch conversion factor. */
80
77
  const POINTS_PER_INCH = 72;
81
78
 
@@ -107,31 +104,6 @@ export function neatoInitNode(n: Node, dim = DFLT_DIM): void {
107
104
  if (!n.info.height && !plainShaped) n.info.height = 0.5;
108
105
  }
109
106
 
110
- /**
111
- * Seed a node's initial position from its `pos=` attribute (C's P_SET),
112
- * mirroring user_pos. Sets info.pos + info.posSet so hasPos is true and neato
113
- * majorization starts from the input layout instead of a random init; a `!`
114
- * suffix or `pin=true` additionally sets info.pinned (P_PIN → isFixed).
115
- *
116
- * `pos` is divided by PSinputscale when > 0 (neatoinit.c:90-95). Must run
117
- * AFTER neatoInitNode, which zeroes info.pos.
118
- * @see lib/neatogen/neatoinit.c:user_pos
119
- */
120
- export function userPos(n: Node): boolean {
121
- const p = n.attrs.get('pos');
122
- if (p === undefined || p.length === 0) return false;
123
- // 2-D "x,y" with an optional trailing '!' (3-D is absent from the 2-D suite).
124
- const num = '(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)';
125
- const m = new RegExp(`^\\s*${num}\\s*,\\s*${num}(.?)`).exec(p);
126
- if (m === null) return false; // C agerrorf: malformed pos, non-fatal
127
- const div = inputscaleDivisor(n.root);
128
- n.info.pos = [Number(m[1]) / div, Number(m[2]) / div];
129
- n.info.posSet = true;
130
- const pin = n.attrs.get('pin');
131
- if (m[3] === '!' || (pin !== undefined && mapbool(pin))) n.info.pinned = true;
132
- return true;
133
- }
134
-
135
107
  /**
136
108
  * Classify the first character of `p` as 'alpha', 'digit', or 'other'.
137
109
  *
@@ -340,22 +312,23 @@ function solveStress(
340
312
  const { g, mode, model, opts } = c;
341
313
  const n = nodeList.length;
342
314
  const maxi = neatoMaxIter(g.attrs.get('maxiter'), mode, n);
315
+ const dim = ndimOf(g);
343
316
  const epsilon = lateDouble(g.attrs.get('epsilon'), 1e-4, 0); // DFLT_TOLERANCE
344
317
  if (mode === MODE_HIER) {
345
318
  return stressMajorizationWithHierarchy(vtx, n, dCoords, nodeList, {
346
- dim: DFLT_DIM, opts, model, maxi, epsilon, levelsGap: levelsGapOf(g),
319
+ dim, opts, model, maxi, epsilon, levelsGap: levelsGapOf(g),
347
320
  });
348
321
  }
349
322
  if (mode === MODE_IPSEP) {
350
323
  // mg is the root graph, g the component. @see neatoinit.c:1121-1170
351
324
  const opt = ipsepOptions(g.root, g, nodeList, c.am);
352
325
  return stressMajorizationCola(vtx, n, dCoords, nodeList, {
353
- dim: DFLT_DIM, model, maxi, epsilon, opt,
326
+ dim, model, maxi, epsilon, opt,
354
327
  });
355
328
  }
356
329
  const Dij = stressModelDij(vtx, n, model); // inside kD_mkernel in C (AD-2)
357
330
  return stressMajorizationKDMkernel(Dij, n, dCoords, nodeList, {
358
- dim: DFLT_DIM, opts, maxi, epsilon,
331
+ dim, opts, maxi, epsilon,
359
332
  });
360
333
  }
361
334
 
@@ -370,13 +343,14 @@ export function runMajorization(g: Graph, mode: number, model: number, am: Adjus
370
343
  const opts = checkExp(g) | (init === INIT_SELF ? STRESS_OPT_SMART_INIT : 0);
371
344
  const haveDir = mode === MODE_HIER || mode === MODE_IPSEP;
372
345
  const vtx = makeGraphDataC(g, nodeList, haveLen, haveDir, mode);
373
- const dCoords = [new Float64Array(n), new Float64Array(n)];
346
+ const ndim = ndimOf(g);
347
+ const dCoords = Array.from({ length: ndim }, () => new Float64Array(n));
374
348
  if (solveStress({ g, mode, model, opts, am }, vtx, dCoords, nodeList) < 0) {
375
349
  agerr('prev', 'layout aborted');
376
350
  return;
377
351
  }
378
352
  for (let i = 0; i < n; i++) {
379
- nodeList[i]!.info.pos = [dCoords[0]![i]!, dCoords[1]![i]!];
353
+ nodeList[i]!.info.pos = dCoords.map((c) => c[i]!);
380
354
  }
381
355
  }
382
356