@knowvah/dot-engine 2.10.3 → 2.12.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 (342) hide show
  1. package/dist/common/agerr.d.ts +12 -0
  2. package/dist/common/agerr.d.ts.map +1 -1
  3. package/dist/gvc/context.d.ts.map +1 -1
  4. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  5. package/dist/gvc/layout-reset.d.ts +38 -1
  6. package/dist/gvc/layout-reset.d.ts.map +1 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1260 -387
  10. package/dist/index.js.map +4 -4
  11. package/dist/layout/circo/circular.d.ts.map +1 -1
  12. package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
  13. package/dist/layout/dot/edge-route-helpers.d.ts +6 -1
  14. package/dist/layout/dot/edge-route-helpers.d.ts.map +1 -1
  15. package/dist/layout/dot/edge-route-rank.d.ts +4 -1
  16. package/dist/layout/dot/edge-route-rank.d.ts.map +1 -1
  17. package/dist/layout/dot/index.d.ts.map +1 -1
  18. package/dist/layout/dot/init.d.ts.map +1 -1
  19. package/dist/layout/fdp/cluster-edges.d.ts +11 -0
  20. package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
  21. package/dist/layout/neato/closest.d.ts +20 -0
  22. package/dist/layout/neato/closest.d.ts.map +1 -0
  23. package/dist/layout/neato/constrained-majorization.d.ts +13 -0
  24. package/dist/layout/neato/constrained-majorization.d.ts.map +1 -1
  25. package/dist/layout/neato/embed-graph.d.ts +20 -0
  26. package/dist/layout/neato/embed-graph.d.ts.map +1 -0
  27. package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
  28. package/dist/layout/neato/index.d.ts.map +1 -1
  29. package/dist/layout/neato/init-dim.d.ts +54 -0
  30. package/dist/layout/neato/init-dim.d.ts.map +1 -0
  31. package/dist/layout/neato/init.d.ts +1 -11
  32. package/dist/layout/neato/init.d.ts.map +1 -1
  33. package/dist/layout/neato/kk.d.ts +4 -2
  34. package/dist/layout/neato/kk.d.ts.map +1 -1
  35. package/dist/layout/neato/matrix-ops-dense.d.ts +34 -0
  36. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -0
  37. package/dist/layout/neato/pca.d.ts +14 -0
  38. package/dist/layout/neato/pca.d.ts.map +1 -0
  39. package/dist/layout/neato/sgd.d.ts +2 -3
  40. package/dist/layout/neato/sgd.d.ts.map +1 -1
  41. package/dist/layout/neato/start.d.ts +5 -5
  42. package/dist/layout/neato/start.d.ts.map +1 -1
  43. package/dist/layout/neato/stress-kernel.d.ts +10 -2
  44. package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
  45. package/dist/layout/neato/stress-subspace.d.ts +39 -0
  46. package/dist/layout/neato/stress-subspace.d.ts.map +1 -0
  47. package/dist/layout/neato/vpsc-adjust.d.ts.map +1 -1
  48. package/dist/layout/pack/ccomps.d.ts +4 -2
  49. package/dist/layout/pack/ccomps.d.ts.map +1 -1
  50. package/dist/layout/sfdp/index.d.ts.map +1 -1
  51. package/dist/layout/sfdp/init.d.ts +6 -7
  52. package/dist/layout/sfdp/init.d.ts.map +1 -1
  53. package/dist/layout/twopi/circle.d.ts.map +1 -1
  54. package/dist/layout/twopi/index.d.ts.map +1 -1
  55. package/dist/render/dot/attrs.d.ts +7 -0
  56. package/dist/render/dot/attrs.d.ts.map +1 -1
  57. package/dist/render.js +1637 -770
  58. package/dist/render.js.map +4 -4
  59. package/package.json +4 -4
  60. package/src/common/agerr.ts +49 -1
  61. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +20 -0
  62. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +20 -0
  63. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +20 -0
  64. package/src/gvc/__fixtures__/rerender/abom-shift-pack.gv +1 -0
  65. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.1 +22 -0
  66. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +22 -0
  67. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +22 -0
  68. package/src/gvc/__fixtures__/rerender/abom-shift-parity.gv +1 -0
  69. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.1 +13 -0
  70. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.2 +13 -0
  71. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.3 +13 -0
  72. package/src/gvc/__fixtures__/rerender/abom-shift.gv +1 -0
  73. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.1 +10 -0
  74. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.2 +11 -0
  75. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.gv +9 -0
  76. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.1 +40 -0
  77. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.2 +40 -0
  78. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.1 +15 -0
  79. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.2 +17 -0
  80. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.1 +40 -0
  81. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.2 +15 -0
  82. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.1 +40 -0
  83. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.2 +99 -0
  84. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.1 +489 -0
  85. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.2 +503 -0
  86. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.1 +40 -0
  87. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.2 +109 -0
  88. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.1 +69 -0
  89. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.2 +70 -0
  90. package/src/gvc/__fixtures__/rerender/cluster-edges.gv +15 -0
  91. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.1 +104 -0
  92. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.2 +104 -0
  93. package/src/gvc/__fixtures__/rerender/fdp-1581.gv +26 -0
  94. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +34 -0
  95. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +34 -0
  96. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +34 -0
  97. package/src/gvc/__fixtures__/rerender/flat-rev-stale.gv +33 -0
  98. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +181 -0
  99. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +218 -0
  100. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +255 -0
  101. package/src/gvc/__fixtures__/rerender/regen.sh +25 -0
  102. package/src/gvc/context.ts +7 -2
  103. package/src/gvc/emit-xdot.ts +37 -7
  104. package/src/gvc/layout-reset.ts +59 -1
  105. package/src/index.ts +4 -0
  106. package/src/layout/circo/circular.ts +3 -1
  107. package/src/layout/dot/edge-route-chain.ts +79 -7
  108. package/src/layout/dot/edge-route-helpers.ts +8 -2
  109. package/src/layout/dot/edge-route-rank.ts +20 -2
  110. package/src/layout/dot/index.ts +17 -2
  111. package/src/layout/dot/init.ts +9 -17
  112. package/src/layout/dot/splines-flat.ts +12 -12
  113. package/src/layout/dot/splines.ts +2 -2
  114. package/src/layout/fdp/cluster-edges.ts +0 -0
  115. package/src/layout/fdp/index.ts +2 -2
  116. package/src/layout/neato/__fixtures__/dim/circuit-dim3.dot +33 -0
  117. package/src/layout/neato/__fixtures__/dim/circuit-dim3.gv +12 -0
  118. package/src/layout/neato/__fixtures__/dim/circuit-dim3.stderr +0 -0
  119. package/src/layout/neato/__fixtures__/dim/circuit-dim3.xdot +54 -0
  120. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.dot +32 -0
  121. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.gv +11 -0
  122. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.stderr +0 -0
  123. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.xdot +53 -0
  124. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.dot +32 -0
  125. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.gv +11 -0
  126. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  127. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  128. package/src/layout/neato/__fixtures__/dim/dim3.dot +31 -0
  129. package/src/layout/neato/__fixtures__/dim/dim3.gv +10 -0
  130. package/src/layout/neato/__fixtures__/dim/dim3.stderr +0 -0
  131. package/src/layout/neato/__fixtures__/dim/dim3.xdot +52 -0
  132. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.dot +32 -0
  133. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.gv +11 -0
  134. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  135. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  136. package/src/layout/neato/__fixtures__/dim/dimen3.dot +31 -0
  137. package/src/layout/neato/__fixtures__/dim/dimen3.gv +10 -0
  138. package/src/layout/neato/__fixtures__/dim/dimen3.stderr +0 -0
  139. package/src/layout/neato/__fixtures__/dim/dimen3.xdot +52 -0
  140. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +267 -0
  141. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.gv +84 -0
  142. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.stderr +0 -0
  143. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +468 -0
  144. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +267 -0
  145. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.gv +84 -0
  146. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.stderr +0 -0
  147. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +468 -0
  148. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +268 -0
  149. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.gv +85 -0
  150. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.stderr +0 -0
  151. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +469 -0
  152. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +484 -0
  153. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.gv +151 -0
  154. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.stderr +0 -0
  155. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +852 -0
  156. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +34 -0
  157. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.gv +13 -0
  158. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.stderr +0 -0
  159. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +55 -0
  160. package/src/layout/neato/__fixtures__/dim/hier-dim3.dot +33 -0
  161. package/src/layout/neato/__fixtures__/dim/hier-dim3.gv +12 -0
  162. package/src/layout/neato/__fixtures__/dim/hier-dim3.stderr +0 -0
  163. package/src/layout/neato/__fixtures__/dim/hier-dim3.xdot +54 -0
  164. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +33 -0
  165. package/src/layout/neato/__fixtures__/dim/hier-dim4.gv +12 -0
  166. package/src/layout/neato/__fixtures__/dim/hier-dim4.stderr +0 -0
  167. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +54 -0
  168. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.dot +32 -0
  169. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.gv +11 -0
  170. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.stderr +0 -0
  171. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.xdot +53 -0
  172. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.dot +34 -0
  173. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.gv +13 -0
  174. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.stderr +0 -0
  175. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.xdot +55 -0
  176. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +37 -0
  177. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.gv +12 -0
  178. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.stderr +0 -0
  179. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +58 -0
  180. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +141 -0
  181. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.gv +48 -0
  182. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.stderr +1 -0
  183. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +233 -0
  184. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.dot +21 -0
  185. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.gv +8 -0
  186. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.stderr +1 -0
  187. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.xdot +33 -0
  188. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.dot +23 -0
  189. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.gv +10 -0
  190. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.stderr +1 -0
  191. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.xdot +35 -0
  192. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.dot +23 -0
  193. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.gv +10 -0
  194. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.stderr +1 -0
  195. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.xdot +35 -0
  196. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.dot +26 -0
  197. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.gv +7 -0
  198. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.stderr +0 -0
  199. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.xdot +44 -0
  200. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.dot +28 -0
  201. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.gv +9 -0
  202. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.stderr +0 -0
  203. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.xdot +46 -0
  204. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.dot +48 -0
  205. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.gv +15 -0
  206. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.stderr +0 -0
  207. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.xdot +79 -0
  208. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +56 -0
  209. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.gv +17 -0
  210. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.stderr +0 -0
  211. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +94 -0
  212. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +47 -0
  213. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.gv +14 -0
  214. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.stderr +0 -0
  215. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +78 -0
  216. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.dot +34 -0
  217. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.gv +13 -0
  218. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.stderr +0 -0
  219. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.xdot +55 -0
  220. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +34 -0
  221. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.gv +13 -0
  222. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.stderr +0 -0
  223. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +55 -0
  224. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +34 -0
  225. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.gv +13 -0
  226. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.stderr +0 -0
  227. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +55 -0
  228. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.dot +15 -0
  229. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.gv +6 -0
  230. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.stderr +0 -0
  231. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.xdot +22 -0
  232. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.dot +33 -0
  233. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.gv +12 -0
  234. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.stderr +0 -0
  235. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.xdot +54 -0
  236. package/src/layout/neato/__fixtures__/dim/kk-dim3.dot +33 -0
  237. package/src/layout/neato/__fixtures__/dim/kk-dim3.gv +12 -0
  238. package/src/layout/neato/__fixtures__/dim/kk-dim3.stderr +0 -0
  239. package/src/layout/neato/__fixtures__/dim/kk-dim3.xdot +54 -0
  240. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.dot +33 -0
  241. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.gv +12 -0
  242. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.stderr +0 -0
  243. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.xdot +54 -0
  244. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.dot +39 -0
  245. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.gv +15 -0
  246. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.stderr +0 -0
  247. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.xdot +60 -0
  248. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.dot +33 -0
  249. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.gv +12 -0
  250. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.stderr +0 -0
  251. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.xdot +54 -0
  252. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.dot +33 -0
  253. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.gv +12 -0
  254. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.stderr +0 -0
  255. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.xdot +54 -0
  256. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.dot +33 -0
  257. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.gv +12 -0
  258. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.stderr +0 -0
  259. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.xdot +54 -0
  260. package/src/layout/neato/__fixtures__/dim/pack-dim3.dot +47 -0
  261. package/src/layout/neato/__fixtures__/dim/pack-dim3.gv +14 -0
  262. package/src/layout/neato/__fixtures__/dim/pack-dim3.stderr +0 -0
  263. package/src/layout/neato/__fixtures__/dim/pack-dim3.xdot +78 -0
  264. package/src/layout/neato/__fixtures__/dim/pins-dim3.dot +38 -0
  265. package/src/layout/neato/__fixtures__/dim/pins-dim3.gv +14 -0
  266. package/src/layout/neato/__fixtures__/dim/pins-dim3.stderr +0 -0
  267. package/src/layout/neato/__fixtures__/dim/pins-dim3.xdot +59 -0
  268. package/src/layout/neato/__fixtures__/dim/regen.sh +24 -0
  269. package/src/layout/neato/__fixtures__/dim/regular-dim3.dot +33 -0
  270. package/src/layout/neato/__fixtures__/dim/regular-dim3.gv +12 -0
  271. package/src/layout/neato/__fixtures__/dim/regular-dim3.stderr +0 -0
  272. package/src/layout/neato/__fixtures__/dim/regular-dim3.xdot +54 -0
  273. package/src/layout/neato/__fixtures__/dim/sgd-dim3.dot +33 -0
  274. package/src/layout/neato/__fixtures__/dim/sgd-dim3.gv +12 -0
  275. package/src/layout/neato/__fixtures__/dim/sgd-dim3.stderr +0 -0
  276. package/src/layout/neato/__fixtures__/dim/sgd-dim3.xdot +54 -0
  277. package/src/layout/neato/__fixtures__/dim/smart-units.json +16 -0
  278. package/src/layout/neato/__fixtures__/dim/subset-dim3.dot +33 -0
  279. package/src/layout/neato/__fixtures__/dim/subset-dim3.gv +12 -0
  280. package/src/layout/neato/__fixtures__/dim/subset-dim3.stderr +0 -0
  281. package/src/layout/neato/__fixtures__/dim/subset-dim3.xdot +54 -0
  282. package/src/layout/neato/closest.ts +206 -0
  283. package/src/layout/neato/constrained-majorization.ts +4 -23
  284. package/src/layout/neato/embed-graph.ts +81 -0
  285. package/src/layout/neato/fdp-adjust.ts +22 -8
  286. package/src/layout/neato/index.ts +26 -17
  287. package/src/layout/neato/init-dim.ts +165 -0
  288. package/src/layout/neato/init.ts +9 -35
  289. package/src/layout/neato/kk.ts +47 -41
  290. package/src/layout/neato/matrix-ops-dense.ts +232 -0
  291. package/src/layout/neato/pca.ts +60 -0
  292. package/src/layout/neato/sgd.ts +14 -13
  293. package/src/layout/neato/start.ts +8 -5
  294. package/src/layout/neato/stress-kernel.ts +65 -5
  295. package/src/layout/neato/stress-subspace.ts +371 -0
  296. package/src/layout/neato/vpsc-adjust.ts +3 -1
  297. package/src/layout/pack/__fixtures__/cc-reuse/circo.dot +23 -0
  298. package/src/layout/pack/__fixtures__/cc-reuse/circo.gv +1 -0
  299. package/src/layout/pack/__fixtures__/cc-reuse/circo.stderr +0 -0
  300. package/src/layout/pack/__fixtures__/cc-reuse/circo.xdot +38 -0
  301. package/src/layout/pack/__fixtures__/cc-reuse/neato.dot +23 -0
  302. package/src/layout/pack/__fixtures__/cc-reuse/neato.gv +1 -0
  303. package/src/layout/pack/__fixtures__/cc-reuse/neato.stderr +0 -0
  304. package/src/layout/pack/__fixtures__/cc-reuse/neato.xdot +38 -0
  305. package/src/layout/pack/__fixtures__/cc-reuse/osage.dot +23 -0
  306. package/src/layout/pack/__fixtures__/cc-reuse/osage.gv +1 -0
  307. package/src/layout/pack/__fixtures__/cc-reuse/osage.stderr +0 -0
  308. package/src/layout/pack/__fixtures__/cc-reuse/osage.xdot +38 -0
  309. package/src/layout/pack/__fixtures__/cc-reuse/regen.sh +24 -0
  310. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.dot +21 -0
  311. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.gv +1 -0
  312. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.stderr +0 -0
  313. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.xdot +36 -0
  314. package/src/layout/pack/__fixtures__/cc-reuse/twopi.dot +21 -0
  315. package/src/layout/pack/__fixtures__/cc-reuse/twopi.gv +1 -0
  316. package/src/layout/pack/__fixtures__/cc-reuse/twopi.stderr +1 -0
  317. package/src/layout/pack/__fixtures__/cc-reuse/twopi.xdot +36 -0
  318. package/src/layout/pack/ccomps.ts +34 -6
  319. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +32 -0
  320. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.gv +11 -0
  321. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  322. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  323. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +31 -0
  324. package/src/layout/sfdp/__fixtures__/dim/dim3.gv +10 -0
  325. package/src/layout/sfdp/__fixtures__/dim/dim3.stderr +0 -0
  326. package/src/layout/sfdp/__fixtures__/dim/dim3.xdot +52 -0
  327. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +32 -0
  328. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.gv +11 -0
  329. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  330. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  331. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +33 -0
  332. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.gv +12 -0
  333. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.stderr +0 -0
  334. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.xdot +54 -0
  335. package/src/layout/sfdp/__fixtures__/dim/regen.sh +24 -0
  336. package/src/layout/sfdp/index.ts +15 -10
  337. package/src/layout/sfdp/init.ts +26 -11
  338. package/src/layout/twopi/circle.ts +5 -1
  339. package/src/layout/twopi/index.ts +3 -0
  340. package/src/render/dot/agwrite.ts +2 -2
  341. package/src/render/dot/attrs.ts +16 -0
  342. package/src/render/dot/write-back.ts +2 -2
package/dist/render.js CHANGED
@@ -121,6 +121,24 @@ function rethrowAtBoundary(err) {
121
121
  throw new InternalError(messageOf(err), { cause: err });
122
122
  }
123
123
 
124
+ // src/model/lazy-attrs.ts
125
+ var SharedEmptyAttrs = class extends Map {
126
+ set(key, _value) {
127
+ throw new Error(`attrs.set("${key}") on a shared empty map; use ownAttrs()`);
128
+ }
129
+ delete(key) {
130
+ throw new Error(`attrs.delete("${key}") on a shared empty map; use ownAttrs()`);
131
+ }
132
+ clear() {
133
+ throw new Error("attrs.clear() on a shared empty map; use ownAttrs()");
134
+ }
135
+ };
136
+ var EMPTY_ATTRS = new SharedEmptyAttrs();
137
+ function ownAttrs(o) {
138
+ if (o.attrs === EMPTY_ATTRS) o.attrs = /* @__PURE__ */ new Map();
139
+ return o.attrs;
140
+ }
141
+
124
142
  // src/model/edgeInfo.ts
125
143
  function makePort() {
126
144
  return {
@@ -181,6 +199,70 @@ function makeEdgeInfo(tailPort, headPort) {
181
199
  };
182
200
  }
183
201
 
202
+ // src/model/edge.ts
203
+ var Edge = class _Edge {
204
+ // Code review: process-wide static seq counter, never reset between renders
205
+ // (C's AGSEQ lives in a per-agopen Agclos_t). Safe today — every reader only
206
+ // compares .seq values within one graph's own edges for relative ordering —
207
+ // and it evades the module-globals fitness scan (a private static field, not
208
+ // a module-scope `let`). Revisit if any consumer serializes an absolute .seq
209
+ // or relies on the counter resetting per parse/createGraph.
210
+ /** @see lib/cgraph/cgraph.h:AGSEQ */
211
+ static _nextSeq = 0;
212
+ /**
213
+ * Monotone sequence number — equivalent to AGSEQ(e) in C.
214
+ * Used by edgeidcmpf for stable sort ordering.
215
+ *
216
+ * Mutable because C's new_virtual_edge overwrites a virtual edge's AGSEQ
217
+ * with AGSEQ(orig) after allocation; copyVirtualEdgeInfo mirrors that.
218
+ * @see lib/cgraph/cgraph.h:AGSEQ, lib/dotgen/fastgr.c:new_virtual_edge
219
+ */
220
+ seq;
221
+ /**
222
+ * Per-graph creation-order index (1-based).
223
+ * Set by the parser after root.edges.push(). Used as the SVG edge id,
224
+ * matching C's AGSEQ-based edge id assignment.
225
+ */
226
+ graphSeq = 0;
227
+ /**
228
+ * Source node (arrow origin).
229
+ * C: AGTAIL(e) = AGMKIN(e)->node = in.node
230
+ * @see lib/cgraph/cgraph.h:AGTAIL
231
+ */
232
+ tail;
233
+ /**
234
+ * Destination node (arrow target).
235
+ * C: AGHEAD(e) = AGMKOUT(e)->node = out.node
236
+ * @see lib/cgraph/cgraph.h:AGHEAD
237
+ */
238
+ head;
239
+ /**
240
+ * Edge key; empty string for anonymous edges.
241
+ * Corresponds to the `name` argument of agedge().
242
+ * @see lib/cgraph/cgraph.h:agedge
243
+ */
244
+ name;
245
+ /**
246
+ * String attributes (agget/agset equivalents).
247
+ * @see lib/cgraph/cgraph.h:Agattr_s
248
+ */
249
+ attrs;
250
+ /**
251
+ * Layout-engine info; replaces ED_* macros via agbindrec (AD-1).
252
+ * @see lib/cgraph/cgraph.h:agbindrec
253
+ */
254
+ info;
255
+ /** @see lib/cgraph/edge.c:agedge */
256
+ constructor(tail, head, name, lazyAttrs = false) {
257
+ this.seq = _Edge._nextSeq++;
258
+ this.tail = tail;
259
+ this.head = head;
260
+ this.name = name;
261
+ this.attrs = lazyAttrs ? EMPTY_ATTRS : /* @__PURE__ */ new Map();
262
+ this.info = makeEdgeInfo(makePort(), makePort());
263
+ }
264
+ };
265
+
184
266
  // src/model/layoutParams.ts
185
267
  var FontnameKind = {
186
268
  NativeFonts: 0,
@@ -220,6 +302,146 @@ function makeGraphInfo() {
220
302
  };
221
303
  }
222
304
 
305
+ // src/model/graph.ts
306
+ var Graph = class {
307
+ /** Graph name; agnameof equivalent. @see lib/cgraph/cgraph.h:agnameof */
308
+ name;
309
+ /**
310
+ * True when the graph was declared with NO name (`digraph {`), as opposed to
311
+ * an explicit empty name (`digraph "" {`). Both store `name === ''`, but
312
+ * cgraph gives the truly-anonymous root the internal id `%1` (agnameof) while
313
+ * the empty-named one keeps `""`. Only the imagemap `<map id/name>` reads this
314
+ * (map.ts:mapGraphName); dot/xdot re-serialization keeps `name` so an
315
+ * anonymous root round-trips as `digraph {`, not `digraph %1 {`.
316
+ * @see lib/cgraph/id.c:idmap (anon → `%1`) ; lib/cgraph/agraph.c:agnameof
317
+ */
318
+ anonymous;
319
+ /**
320
+ * Directed/strict classification; mirrors Agdesc_t.directed and
321
+ * Agdesc_t.strict. @see lib/cgraph/cgraph.h:Agdesc_s
322
+ */
323
+ kind;
324
+ /**
325
+ * Node set in insertion order, keyed by name.
326
+ * Mirrors Agraph_t.n_seq (sequence dict) merged with n_id access.
327
+ * @see lib/cgraph/cgraph.h:Agraph_s
328
+ */
329
+ nodes;
330
+ /**
331
+ * All edges owned by this graph (root graph only for ownership; subgraphs
332
+ * reference a subset). Mirrors Agraph_t.e_seq.
333
+ * @see lib/cgraph/cgraph.h:Agraph_s
334
+ */
335
+ edges;
336
+ /**
337
+ * Named subgraphs, keyed by name. Mirrors Agraph_t.g_seq/g_id.
338
+ * @see lib/cgraph/cgraph.h:Agraph_s
339
+ */
340
+ subgraphs;
341
+ /**
342
+ * String attributes (agget/agset equivalents).
343
+ * Replaces the Agattr_t / Agsym_t machinery for simple key-value access.
344
+ * @see lib/cgraph/cgraph.h:Agattr_s
345
+ */
346
+ attrs;
347
+ /** Default attributes applied to all nodes in this graph scope. */
348
+ nodeDefaults;
349
+ /** Default attributes applied to all edges in this graph scope. */
350
+ edgeDefaults;
351
+ /**
352
+ * Snapshot of the enclosing graphs' graph-attribute defaults (this graph ->
353
+ * root, inner wins) captured when this subgraph was OPENED during parsing.
354
+ * Graph attributes set on an ancestor AFTER this subgraph was created are not
355
+ * included — mirroring cgraph's parse-time agsubg defval copy. Used for
356
+ * order-correct label/font inheritance (e.g. a root `label=` declared after a
357
+ * cluster must NOT apply to that cluster). Undefined on the root graph.
358
+ * @see lib/cgraph/graph.c:agsubg (attr defval copy)
359
+ */
360
+ graphDefaultsSnapshot;
361
+ /**
362
+ * Keys in `attrs` the BUILDER seeded from `graphDefaultsSnapshot` rather than
363
+ * the input declaring them in this scope (see builder.ts GRAPH_LABEL_INHERIT_
364
+ * KEYS). cgraph distinguishes these structurally — a seeded value is inherited
365
+ * through the dict view and has no local symbol, while a local declaration
366
+ * creates one even when its value equals the inherited value — so the
367
+ * serializer needs the provenance to decide what write_dict would print.
368
+ * Undefined on the root graph and on any scope that seeded nothing.
369
+ * @see lib/cgraph/write.c:262 write_dict
370
+ */
371
+ seededAttrs;
372
+ /**
373
+ * Graph-attribute keys whose declaration in THIS scope was the first anywhere
374
+ * in the graph. cgraph's `setattr` splits on exactly this: a key with no
375
+ * existing symbol takes the global-declaration branch, which ends up seeding
376
+ * every direct subgraph that already exists with a local empty value (see
377
+ * `eagerEmptyParts`); a key some earlier scope already declared takes the
378
+ * "new local definition" branch and touches no subgraph at all. So an
379
+ * identical `graph [fill=x]` statement makes a child print `fill=""` or print
380
+ * nothing purely according to whether a SIBLING declared `fill` first.
381
+ * Undefined on any scope that declared nothing new.
382
+ * @see lib/cgraph/attr.c:257 setattr (lsym / psym / global branches)
383
+ */
384
+ firstGraphDecl;
385
+ /**
386
+ * Layout-engine info; replaces GD_* macros via agbindrec (AD-1).
387
+ * @see lib/cgraph/cgraph.h:agbindrec
388
+ */
389
+ info;
390
+ /**
391
+ * Immediate parent graph. null for root graphs.
392
+ * @see lib/cgraph/cgraph.h:Agraph_s
393
+ */
394
+ parent;
395
+ /**
396
+ * Root (main) graph. Self-referential for root graphs;
397
+ * points up for subgraphs.
398
+ * @see lib/cgraph/cgraph.h:Agraph_s
399
+ */
400
+ root;
401
+ /**
402
+ * Subgraph sequence number (AGSEQ). A global counter on the root, assigned
403
+ * at creation in source order, counting anonymous subgraphs. The root keeps
404
+ * the default 0 (par == NULL never calls agnextseq). Consumed by getObjId to
405
+ * emit cluster ids `clust<seq>`.
406
+ * @see lib/cgraph/cgraph.h:AGSEQ
407
+ * @see lib/cgraph/graph.c:agopen (AGSEQ(g) = agnextseq(par, AGRAPH))
408
+ */
409
+ seq = 0;
410
+ /**
411
+ * Root-only counter mirroring `clos->seq[AGRAPH]`: the running maximum AGSEQ
412
+ * handed out to subgraphs. Meaningful only on the root graph; `assignSubgSeq`
413
+ * pre-increments it. Other graphs leave it at 0.
414
+ * @see lib/cgraph/graph.c:agnextseq (++clos->seq[AGRAPH])
415
+ */
416
+ subgSeqCounter = 0;
417
+ /**
418
+ * Names of graph attributes (AGRAPH) declared anywhere in this hierarchy —
419
+ * the port's stand-in for cgraph's `Agsym_t` symbol table. Populated on the
420
+ * ROOT only, at parse time, whenever a graph attribute is assigned on any
421
+ * (sub)graph: setting `ordering=out` on a subgraph declares "ordering"
422
+ * graph-wide with an empty default, so `agGraphAttr(root, "ordering")` returns
423
+ * `""` (not undefined) — mirroring `agfindgraphattr`/`late_string`. Read via
424
+ * `agGraphAttr` (model/cgraph-ops.ts); empty on non-root graphs.
425
+ * @see lib/cgraph/attr.c:agattr (graph-wide declaration, "" default)
426
+ */
427
+ declaredGraphAttrs = /* @__PURE__ */ new Set();
428
+ /** @see lib/cgraph/graph.c:agopen */
429
+ constructor(name, kind, anonymous = false) {
430
+ this.name = name;
431
+ this.anonymous = anonymous;
432
+ this.kind = kind;
433
+ this.nodes = /* @__PURE__ */ new Map();
434
+ this.edges = [];
435
+ this.subgraphs = /* @__PURE__ */ new Map();
436
+ this.attrs = /* @__PURE__ */ new Map();
437
+ this.nodeDefaults = /* @__PURE__ */ new Map();
438
+ this.edgeDefaults = /* @__PURE__ */ new Map();
439
+ this.info = makeGraphInfo();
440
+ this.parent = null;
441
+ this.root = this;
442
+ }
443
+ };
444
+
223
445
  // src/model/algData.ts
224
446
  var THETA_UNSET = 10;
225
447
 
@@ -287,12 +509,348 @@ function makeNodeInfo() {
287
509
  };
288
510
  }
289
511
 
512
+ // src/model/node.ts
513
+ var Node = class {
514
+ /**
515
+ * Unique integer ID per root graph; maps to AGID in the C implementation.
516
+ * @see lib/cgraph/cgraph.h:AGID
517
+ */
518
+ id;
519
+ /** Node name; agnameof equivalent. @see lib/cgraph/cgraph.h:agnameof */
520
+ name;
521
+ /**
522
+ * String attributes (agget/agset equivalents).
523
+ * @see lib/cgraph/cgraph.h:Agattr_s
524
+ */
525
+ attrs;
526
+ /**
527
+ * Layout-engine info; replaces ND_* macros via agbindrec (AD-1).
528
+ * @see lib/cgraph/cgraph.h:agbindrec
529
+ */
530
+ info;
531
+ /**
532
+ * Root graph that owns this node.
533
+ * @see lib/cgraph/cgraph.h:Agnode_s
534
+ */
535
+ root;
536
+ /**
537
+ * Frozen snapshot of the node-attribute defaults (`node [...]`) in effect —
538
+ * from the declaring subgraph up through its ancestors — at the moment this
539
+ * node was first created. Captured at creation (not read live at render) so
540
+ * that a `node [...]` declared *after* this node in the same or an ancestor
541
+ * scope does not retroactively apply, matching DOT semantics. Present on
542
+ * parser-built nodes (even when empty); undefined on programmatically created
543
+ * nodes, which fall back to live graph defaults in `nodeAttr`.
544
+ */
545
+ nodeDefaultsSnapshot;
546
+ /** @see lib/cgraph/node.c:agnode */
547
+ constructor(id, name, root, lazyAttrs = false) {
548
+ this.id = id;
549
+ this.name = name;
550
+ this.attrs = lazyAttrs ? EMPTY_ATTRS : /* @__PURE__ */ new Map();
551
+ this.info = makeNodeInfo();
552
+ this.root = root;
553
+ }
554
+ /**
555
+ * Returns out-edges of this node in graph g (where this node is the tail).
556
+ *
557
+ * ORDER: cgraph's per-node out-edge dict sorts by the SEQ of the edge's
558
+ * out-half node — the HEAD — then by edge seq (edge.c:agedgeseqcmpf,
559
+ * Ag_mainedge_seq_disc). Iteration is therefore by (head creation order,
560
+ * edge creation order), NOT by plain edge insertion order. This ordering
561
+ * is load-bearing for emission order and for force-accumulation order in
562
+ * the iterative engines.
563
+ *
564
+ * INVARIANT: In the C cgraph library, the adjacency list for a node begins
565
+ * with the node's own self-loop (index 0), and neighbor traversal MUST start
566
+ * at index 1. This convention originates from lib/cgraph/edge.c and
567
+ * agfstedge/agnxtedge. In this TypeScript implementation, self-loops are
568
+ * included in outEdges() but are excluded from inEdges() — matching the
569
+ * agnxtedge behavior that skips self-loops as in-edges. Callers iterating
570
+ * over neighbors must account for self-loop edges appearing in outEdges().
571
+ *
572
+ * @see lib/cgraph/edge.c:agfstout
573
+ * @see lib/cgraph/edge.c:agnxtout
574
+ * @see lib/cgraph/edge.c:agedgeseqcmpf
575
+ */
576
+ outEdges(g) {
577
+ return g.edges.filter((e) => e.tail === this).sort((a, b) => a.head.id - b.head.id || a.seq - b.seq);
578
+ }
579
+ /**
580
+ * Returns in-edges of this node in graph g (where this node is the head).
581
+ * Self-loops are excluded per C agnxtedge semantics. Ordered by the SEQ
582
+ * of the in-half node — the TAIL — then edge seq (agedgeseqcmpf).
583
+ *
584
+ * @see lib/cgraph/edge.c:agfstin
585
+ * @see lib/cgraph/edge.c:agnxtin
586
+ * @see lib/cgraph/edge.c:agnxtedge (skips self-loops as in-edges)
587
+ * @see lib/cgraph/edge.c:agedgeseqcmpf
588
+ */
589
+ inEdges(g) {
590
+ return g.edges.filter((e) => e.head === this && e.tail !== this).sort((a, b) => a.tail.id - b.tail.id || a.seq - b.seq);
591
+ }
592
+ };
593
+ function buildOutEdgeIndex(g) {
594
+ const m = /* @__PURE__ */ new Map();
595
+ for (const e of g.edges) {
596
+ const l = m.get(e.tail);
597
+ if (l !== void 0) l.push(e);
598
+ else m.set(e.tail, [e]);
599
+ }
600
+ for (const l of m.values()) {
601
+ l.sort((a, b) => a.head.id - b.head.id || a.seq - b.seq);
602
+ }
603
+ return m;
604
+ }
605
+
606
+ // src/model/cgraph-ops.ts
607
+ var LOCALNAMEPREFIX = "%";
608
+ var ANONYMOUS_ROOT_ID = 1;
609
+ function agNameOf(g) {
610
+ return g.anonymous ? `${LOCALNAMEPREFIX}${ANONYMOUS_ROOT_ID}` : g.name;
611
+ }
612
+ function freshNodeId(root) {
613
+ let max = -1;
614
+ for (const n of root.nodes.values()) {
615
+ if (n.id > max) max = n.id;
616
+ }
617
+ return max + 1;
618
+ }
619
+ function agnode(g, name, create) {
620
+ const root = g.root;
621
+ if (name !== null && name !== "") {
622
+ const existing = root.nodes.get(name);
623
+ if (existing !== void 0) return existing;
624
+ if (!create) return null;
625
+ const node2 = new Node(freshNodeId(root), name, root);
626
+ root.nodes.set(name, node2);
627
+ return node2;
628
+ }
629
+ if (!create) return null;
630
+ const id = freshNodeId(root);
631
+ const anonName = LOCALNAMEPREFIX + String(id);
632
+ const node = new Node(id, anonName, root);
633
+ root.nodes.set(anonName, node);
634
+ return node;
635
+ }
636
+ function assignSubgSeq(parent2, sg) {
637
+ sg.seq = ++parent2.root.subgSeqCounter;
638
+ }
639
+ function agsubg(parent2, name, create) {
640
+ const existing = parent2.subgraphs.get(name);
641
+ if (existing !== void 0) return existing;
642
+ if (!create) return null;
643
+ const subg = new Graph(name, parent2.kind);
644
+ subg.parent = parent2;
645
+ subg.root = parent2.root;
646
+ assignSubgSeq(parent2, subg);
647
+ parent2.subgraphs.set(name, subg);
648
+ return subg;
649
+ }
650
+ function agsubnode(g, n, create) {
651
+ if (g.root !== n.root) return null;
652
+ const existing = g.nodes.get(n.name);
653
+ if (existing !== void 0) return existing;
654
+ if (!create) return null;
655
+ const par = g.parent;
656
+ if (par !== null) {
657
+ agsubnode(par, n, create);
658
+ }
659
+ g.nodes.set(n.name, n);
660
+ return n;
661
+ }
662
+ function agdelnode(g, n) {
663
+ for (let cur = g; cur !== null; cur = cur.parent) {
664
+ cur.nodes.delete(n.name);
665
+ }
666
+ }
667
+ function agdelsubg(parent2, sg) {
668
+ parent2.subgraphs.delete(sg.name);
669
+ }
670
+ function agGraphAttr(g, name) {
671
+ const own = g.attrs.get(name);
672
+ if (own !== void 0) return own;
673
+ return g.root.declaredGraphAttrs.has(name) ? "" : void 0;
674
+ }
675
+
676
+ // src/layout/fdp/cluster-edges.ts
677
+ function fillMap(g, map) {
678
+ const n = g.info.n_cluster ?? 0;
679
+ for (let c = 0; c < n; c++) {
680
+ const cl = g.info.clust[c];
681
+ const s = cl.name;
682
+ if (!map.has(s)) map.set(s, cl);
683
+ fillMap(cl, map);
684
+ }
685
+ }
686
+ function mkClustMap(g) {
687
+ const map = /* @__PURE__ */ new Map();
688
+ fillMap(g, map);
689
+ return map;
690
+ }
691
+ function mapc(cmap, n) {
692
+ if (n.name.startsWith("cluster")) return cmap.get(n.name) ?? null;
693
+ return null;
694
+ }
695
+ function edgeKey(t, h) {
696
+ return `${t.name}\0${h.name}`;
697
+ }
698
+ function mapEdge(map, t, h) {
699
+ return map.get(edgeKey(t, h));
700
+ }
701
+ function insertEdge(map, t, h, ce) {
702
+ map.set(edgeKey(t, h), { t: ce.tail, h: ce.head });
703
+ map.set(edgeKey(h, t), { t: ce.head, h: ce.tail });
704
+ }
705
+ function clustNode(n, cg, root, delSet, idx) {
706
+ const name = `__${idx.v}:${cg.name}`;
707
+ const cn = agnode(root, name, true);
708
+ cn.info.clustnode = true;
709
+ agsubnode(cg, cn, true);
710
+ delSet.add(n);
711
+ cn.attrs.set("label", "");
712
+ cn.attrs.set("style", "invis");
713
+ cn.attrs.set("shape", "box");
714
+ return cn;
715
+ }
716
+ function nextEdgeSeq(root) {
717
+ let max = 0;
718
+ for (const e of root.edges) max = Math.max(max, e.graphSeq);
719
+ return max + 1;
720
+ }
721
+ function cloneEdge(root, e, ct, ch) {
722
+ const ce = new Edge(ct, ch, "");
723
+ for (const [k, v] of e.attrs) ce.attrs.set(k, v);
724
+ ce.info.compound = 1;
725
+ ce.graphSeq = nextEdgeSeq(root);
726
+ root.edges.push(ce);
727
+ return ce;
728
+ }
729
+ function checkCompound(e, root, cmap, map, delSet, idx) {
730
+ const t = e.tail;
731
+ const h = e.head;
732
+ if (h.info.clustnode) return 0;
733
+ const tg = mapc(cmap, t);
734
+ const hg = mapc(cmap, h);
735
+ if (!tg && !hg) return 0;
736
+ if (tg === hg) return 0;
737
+ const ip = mapEdge(map, t, h);
738
+ if (ip) {
739
+ cloneEdge(root, e, ip.t, ip.h);
740
+ return 1;
741
+ }
742
+ let cn;
743
+ let ce;
744
+ if (hg) {
745
+ if (tg) {
746
+ if (agContains(hg, tg) || agContains(tg, hg)) return 0;
747
+ cn = clustNode(t, tg, root, delSet, idx);
748
+ const cn1 = clustNode(h, hg, root, delSet, idx);
749
+ ce = cloneEdge(root, e, cn, cn1);
750
+ insertEdge(map, t, h, ce);
751
+ } else {
752
+ if (agContainsNode(hg, t)) return 0;
753
+ cn = clustNode(h, hg, root, delSet, idx);
754
+ ce = cloneEdge(root, e, t, cn);
755
+ insertEdge(map, t, h, ce);
756
+ }
757
+ } else {
758
+ if (agContainsNode(tg, h)) return 0;
759
+ cn = clustNode(t, tg, root, delSet, idx);
760
+ ce = cloneEdge(root, e, cn, h);
761
+ insertEdge(map, t, h, ce);
762
+ }
763
+ return 1;
764
+ }
765
+ function agContains(a, b) {
766
+ for (let g = b; g !== null; g = g.parent) {
767
+ if (g === a) return true;
768
+ }
769
+ return false;
770
+ }
771
+ function agContainsNode(cg, n) {
772
+ return cg.nodes.has(n.name);
773
+ }
774
+ function deleteNodeAndEdges(root, n) {
775
+ const purge = (gr) => {
776
+ if (gr.edges.length > 0) {
777
+ gr.edges = gr.edges.filter((e) => e.tail !== n && e.head !== n);
778
+ }
779
+ gr.nodes.delete(n.name);
780
+ for (const sg of gr.subgraphs.values()) purge(sg);
781
+ };
782
+ purge(root);
783
+ }
784
+ function processClusterEdges(g) {
785
+ const root = g.root;
786
+ const cmap = mkClustMap(g);
787
+ if (cmap.size === 0) return;
788
+ const map = /* @__PURE__ */ new Map();
789
+ const delSet = /* @__PURE__ */ new Set();
790
+ const idx = { v: 0 };
791
+ let numClEdges = 0;
792
+ for (const n of [...g.nodes.values()]) {
793
+ if (n.info.clustnode) continue;
794
+ for (const e of n.outEdges(g)) {
795
+ numClEdges += checkCompound(e, root, cmap, map, delSet, idx);
796
+ }
797
+ }
798
+ for (const n of delSet) deleteNodeAndEdges(root, n);
799
+ if (numClEdges > 0) g.info.n_cluster_edges = numClEdges;
800
+ }
801
+ function mapN(n, delSet) {
802
+ if (!n.info.clustnode) return n;
803
+ delSet.add(n);
804
+ const name = n.name.slice(n.name.indexOf(":") + 1);
805
+ const existing = agnode(n.root, name, false);
806
+ if (existing !== null) return existing;
807
+ const nn = agnode(n.root, name, true);
808
+ nn.info.clustnode = true;
809
+ return nn;
810
+ }
811
+ function undoCompound(root, e, delSet) {
812
+ const ntail = mapN(e.tail, delSet);
813
+ const nhead = mapN(e.head, delSet);
814
+ const ce = cloneEdge(root, e, ntail, nhead);
815
+ ce.info.spl = e.info.spl;
816
+ e.info.spl = void 0;
817
+ ce.info.label = e.info.label;
818
+ e.info.label = void 0;
819
+ ce.info.xlabel = e.info.xlabel;
820
+ e.info.xlabel = void 0;
821
+ ce.info.head_label = e.info.head_label;
822
+ e.info.head_label = void 0;
823
+ ce.info.tail_label = e.info.tail_label;
824
+ e.info.tail_label = void 0;
825
+ }
826
+ function undoClusterEdges(g) {
827
+ if (!g.info.n_cluster_edges) return;
828
+ const root = g.root;
829
+ const delSet = /* @__PURE__ */ new Set();
830
+ const edgelist = [];
831
+ for (const n of g.nodes.values()) {
832
+ for (const e of n.outEdges(g)) {
833
+ if (e.info.compound && isProxyEdge(e)) edgelist.push(e);
834
+ }
835
+ }
836
+ for (const e of edgelist) undoCompound(root, e, delSet);
837
+ for (const n of delSet) deleteNodeAndEdges(root, n);
838
+ }
839
+ function isProxyEdge(e) {
840
+ return e.tail.info.clustnode && e.tail.name.includes(":") || e.head.info.clustnode && e.head.name.includes(":");
841
+ }
842
+
290
843
  // src/gvc/layout-reset.ts
291
844
  function layoutWasFreed(g) {
292
845
  return g.info?.laidOut === true && g.info.cleanup === void 0;
293
846
  }
847
+ function undoRenderedClusterEdges(g) {
848
+ if (g.info?.n_cluster_edges && g.attrs.get("bb")?.includes(",")) undoClusterEdges(g);
849
+ }
294
850
  function resetGraphRecords(g) {
851
+ const clusterEdges = g.info.n_cluster_edges;
295
852
  g.info = makeGraphInfo();
853
+ if (clusterEdges !== void 0) g.info.n_cluster_edges = clusterEdges;
296
854
  for (const subg of g.subgraphs.values()) resetGraphRecords(subg);
297
855
  }
298
856
  function resetLayoutRecords(g) {
@@ -300,6 +858,21 @@ function resetLayoutRecords(g) {
300
858
  for (const e of g.edges) e.info = makeEdgeInfo(makePort(), makePort());
301
859
  resetGraphRecords(g);
302
860
  }
861
+ function resetFreedLayouts(g) {
862
+ const visit = (h) => {
863
+ if (layoutWasFreed(h)) resetLayoutRecords(h);
864
+ else for (const subg of h.subgraphs.values()) visit(subg);
865
+ };
866
+ visit(g.root);
867
+ }
868
+ function bindDotRoot(g) {
869
+ const droot = g === g.root ? void 0 : g;
870
+ const visit = (h) => {
871
+ h.info.dotroot = droot;
872
+ for (const subg of h.subgraphs.values()) visit(subg);
873
+ };
874
+ visit(g);
875
+ }
303
876
 
304
877
  // src/common/agerr.ts
305
878
  var PREFIX_ERROR = "Error";
@@ -312,6 +885,7 @@ var OCTAL_WIDTH = 3;
312
885
  var OCTAL_RADIX = 8;
313
886
  var lastLevel = "warning";
314
887
  var pending = { line: null, channel: "warn" };
888
+ var usererrf = null;
315
889
  registerRenderState(() => {
316
890
  flushPending();
317
891
  lastLevel = "warning";
@@ -337,7 +911,9 @@ function flushPending() {
337
911
  writeLine(channel, line);
338
912
  }
339
913
  function writeLine(channel, line) {
340
- if (channel === "warn") console.warn(escapeControl(line));
914
+ if (usererrf !== null) usererrf(`${line}
915
+ `);
916
+ else if (channel === "warn") console.warn(escapeControl(line));
341
917
  else console.error(escapeControl(line));
342
918
  }
343
919
  function assemble(level, msg) {
@@ -345,6 +921,13 @@ function assemble(level, msg) {
345
921
  const prefix = level === "error" ? PREFIX_ERROR : PREFIX_WARNING;
346
922
  return `${prefix}${PREFIX_SEP}${msg}`;
347
923
  }
924
+ function outToUser(errf, level, msg) {
925
+ if (level !== "prev") {
926
+ errf(level === "error" ? PREFIX_ERROR : PREFIX_WARNING);
927
+ errf(PREFIX_SEP);
928
+ }
929
+ errf(msg);
930
+ }
348
931
  function channelOf(level) {
349
932
  const eff = level === "prev" ? lastLevel : level;
350
933
  return eff === "warning" ? "warn" : "error";
@@ -352,6 +935,12 @@ function channelOf(level) {
352
935
  function emit(level, msg, channel, hold) {
353
936
  const target = channel ?? channelOf(level);
354
937
  if (level !== "prev") lastLevel = level;
938
+ if (usererrf !== null) {
939
+ flushPending();
940
+ outToUser(usererrf, level, hold ? msg : `${msg}
941
+ `);
942
+ return;
943
+ }
355
944
  const text = assemble(level, msg);
356
945
  if (pending.line === null) {
357
946
  pending.channel = target;
@@ -1039,7 +1628,12 @@ var GvcContext = class {
1039
1628
  }
1040
1629
  engine = override2;
1041
1630
  }
1042
- if (layoutWasFreed(g)) resetLayoutRecords(g);
1631
+ undoRenderedClusterEdges(g);
1632
+ if (g.root) {
1633
+ resetFreedLayouts(g);
1634
+ bindDotRoot(g);
1635
+ g.root.info.gvc = this;
1636
+ }
1043
1637
  if (g.info) g.info.gvc = this;
1044
1638
  initXdot(g);
1045
1639
  engine.layout(g);
@@ -9116,182 +9710,6 @@ function htmlTextLabel(text, finfo, placed, dim) {
9116
9710
  };
9117
9711
  }
9118
9712
 
9119
- // src/model/lazy-attrs.ts
9120
- var SharedEmptyAttrs = class extends Map {
9121
- set(key, _value) {
9122
- throw new Error(`attrs.set("${key}") on a shared empty map; use ownAttrs()`);
9123
- }
9124
- delete(key) {
9125
- throw new Error(`attrs.delete("${key}") on a shared empty map; use ownAttrs()`);
9126
- }
9127
- clear() {
9128
- throw new Error("attrs.clear() on a shared empty map; use ownAttrs()");
9129
- }
9130
- };
9131
- var EMPTY_ATTRS = new SharedEmptyAttrs();
9132
- function ownAttrs(o) {
9133
- if (o.attrs === EMPTY_ATTRS) o.attrs = /* @__PURE__ */ new Map();
9134
- return o.attrs;
9135
- }
9136
-
9137
- // src/model/node.ts
9138
- var Node = class {
9139
- /**
9140
- * Unique integer ID per root graph; maps to AGID in the C implementation.
9141
- * @see lib/cgraph/cgraph.h:AGID
9142
- */
9143
- id;
9144
- /** Node name; agnameof equivalent. @see lib/cgraph/cgraph.h:agnameof */
9145
- name;
9146
- /**
9147
- * String attributes (agget/agset equivalents).
9148
- * @see lib/cgraph/cgraph.h:Agattr_s
9149
- */
9150
- attrs;
9151
- /**
9152
- * Layout-engine info; replaces ND_* macros via agbindrec (AD-1).
9153
- * @see lib/cgraph/cgraph.h:agbindrec
9154
- */
9155
- info;
9156
- /**
9157
- * Root graph that owns this node.
9158
- * @see lib/cgraph/cgraph.h:Agnode_s
9159
- */
9160
- root;
9161
- /**
9162
- * Frozen snapshot of the node-attribute defaults (`node [...]`) in effect —
9163
- * from the declaring subgraph up through its ancestors — at the moment this
9164
- * node was first created. Captured at creation (not read live at render) so
9165
- * that a `node [...]` declared *after* this node in the same or an ancestor
9166
- * scope does not retroactively apply, matching DOT semantics. Present on
9167
- * parser-built nodes (even when empty); undefined on programmatically created
9168
- * nodes, which fall back to live graph defaults in `nodeAttr`.
9169
- */
9170
- nodeDefaultsSnapshot;
9171
- /** @see lib/cgraph/node.c:agnode */
9172
- constructor(id, name, root, lazyAttrs = false) {
9173
- this.id = id;
9174
- this.name = name;
9175
- this.attrs = lazyAttrs ? EMPTY_ATTRS : /* @__PURE__ */ new Map();
9176
- this.info = makeNodeInfo();
9177
- this.root = root;
9178
- }
9179
- /**
9180
- * Returns out-edges of this node in graph g (where this node is the tail).
9181
- *
9182
- * ORDER: cgraph's per-node out-edge dict sorts by the SEQ of the edge's
9183
- * out-half node — the HEAD — then by edge seq (edge.c:agedgeseqcmpf,
9184
- * Ag_mainedge_seq_disc). Iteration is therefore by (head creation order,
9185
- * edge creation order), NOT by plain edge insertion order. This ordering
9186
- * is load-bearing for emission order and for force-accumulation order in
9187
- * the iterative engines.
9188
- *
9189
- * INVARIANT: In the C cgraph library, the adjacency list for a node begins
9190
- * with the node's own self-loop (index 0), and neighbor traversal MUST start
9191
- * at index 1. This convention originates from lib/cgraph/edge.c and
9192
- * agfstedge/agnxtedge. In this TypeScript implementation, self-loops are
9193
- * included in outEdges() but are excluded from inEdges() — matching the
9194
- * agnxtedge behavior that skips self-loops as in-edges. Callers iterating
9195
- * over neighbors must account for self-loop edges appearing in outEdges().
9196
- *
9197
- * @see lib/cgraph/edge.c:agfstout
9198
- * @see lib/cgraph/edge.c:agnxtout
9199
- * @see lib/cgraph/edge.c:agedgeseqcmpf
9200
- */
9201
- outEdges(g) {
9202
- return g.edges.filter((e) => e.tail === this).sort((a, b) => a.head.id - b.head.id || a.seq - b.seq);
9203
- }
9204
- /**
9205
- * Returns in-edges of this node in graph g (where this node is the head).
9206
- * Self-loops are excluded per C agnxtedge semantics. Ordered by the SEQ
9207
- * of the in-half node — the TAIL — then edge seq (agedgeseqcmpf).
9208
- *
9209
- * @see lib/cgraph/edge.c:agfstin
9210
- * @see lib/cgraph/edge.c:agnxtin
9211
- * @see lib/cgraph/edge.c:agnxtedge (skips self-loops as in-edges)
9212
- * @see lib/cgraph/edge.c:agedgeseqcmpf
9213
- */
9214
- inEdges(g) {
9215
- return g.edges.filter((e) => e.head === this && e.tail !== this).sort((a, b) => a.tail.id - b.tail.id || a.seq - b.seq);
9216
- }
9217
- };
9218
- function buildOutEdgeIndex(g) {
9219
- const m = /* @__PURE__ */ new Map();
9220
- for (const e of g.edges) {
9221
- const l = m.get(e.tail);
9222
- if (l !== void 0) l.push(e);
9223
- else m.set(e.tail, [e]);
9224
- }
9225
- for (const l of m.values()) {
9226
- l.sort((a, b) => a.head.id - b.head.id || a.seq - b.seq);
9227
- }
9228
- return m;
9229
- }
9230
-
9231
- // src/model/edge.ts
9232
- var Edge = class _Edge {
9233
- // Code review: process-wide static seq counter, never reset between renders
9234
- // (C's AGSEQ lives in a per-agopen Agclos_t). Safe today — every reader only
9235
- // compares .seq values within one graph's own edges for relative ordering —
9236
- // and it evades the module-globals fitness scan (a private static field, not
9237
- // a module-scope `let`). Revisit if any consumer serializes an absolute .seq
9238
- // or relies on the counter resetting per parse/createGraph.
9239
- /** @see lib/cgraph/cgraph.h:AGSEQ */
9240
- static _nextSeq = 0;
9241
- /**
9242
- * Monotone sequence number — equivalent to AGSEQ(e) in C.
9243
- * Used by edgeidcmpf for stable sort ordering.
9244
- *
9245
- * Mutable because C's new_virtual_edge overwrites a virtual edge's AGSEQ
9246
- * with AGSEQ(orig) after allocation; copyVirtualEdgeInfo mirrors that.
9247
- * @see lib/cgraph/cgraph.h:AGSEQ, lib/dotgen/fastgr.c:new_virtual_edge
9248
- */
9249
- seq;
9250
- /**
9251
- * Per-graph creation-order index (1-based).
9252
- * Set by the parser after root.edges.push(). Used as the SVG edge id,
9253
- * matching C's AGSEQ-based edge id assignment.
9254
- */
9255
- graphSeq = 0;
9256
- /**
9257
- * Source node (arrow origin).
9258
- * C: AGTAIL(e) = AGMKIN(e)->node = in.node
9259
- * @see lib/cgraph/cgraph.h:AGTAIL
9260
- */
9261
- tail;
9262
- /**
9263
- * Destination node (arrow target).
9264
- * C: AGHEAD(e) = AGMKOUT(e)->node = out.node
9265
- * @see lib/cgraph/cgraph.h:AGHEAD
9266
- */
9267
- head;
9268
- /**
9269
- * Edge key; empty string for anonymous edges.
9270
- * Corresponds to the `name` argument of agedge().
9271
- * @see lib/cgraph/cgraph.h:agedge
9272
- */
9273
- name;
9274
- /**
9275
- * String attributes (agget/agset equivalents).
9276
- * @see lib/cgraph/cgraph.h:Agattr_s
9277
- */
9278
- attrs;
9279
- /**
9280
- * Layout-engine info; replaces ED_* macros via agbindrec (AD-1).
9281
- * @see lib/cgraph/cgraph.h:agbindrec
9282
- */
9283
- info;
9284
- /** @see lib/cgraph/edge.c:agedge */
9285
- constructor(tail, head, name, lazyAttrs = false) {
9286
- this.seq = _Edge._nextSeq++;
9287
- this.tail = tail;
9288
- this.head = head;
9289
- this.name = name;
9290
- this.attrs = lazyAttrs ? EMPTY_ATTRS : /* @__PURE__ */ new Map();
9291
- this.info = makeEdgeInfo(makePort(), makePort());
9292
- }
9293
- };
9294
-
9295
9713
  // src/common/subst.ts
9296
9714
  function labelTextOf(info) {
9297
9715
  const lp = info.label;
@@ -9380,146 +9798,6 @@ function preprocessTooltip(s) {
9380
9798
  return interpretCRNL(htmlEntityUTF8(s));
9381
9799
  }
9382
9800
 
9383
- // src/model/graph.ts
9384
- var Graph = class {
9385
- /** Graph name; agnameof equivalent. @see lib/cgraph/cgraph.h:agnameof */
9386
- name;
9387
- /**
9388
- * True when the graph was declared with NO name (`digraph {`), as opposed to
9389
- * an explicit empty name (`digraph "" {`). Both store `name === ''`, but
9390
- * cgraph gives the truly-anonymous root the internal id `%1` (agnameof) while
9391
- * the empty-named one keeps `""`. Only the imagemap `<map id/name>` reads this
9392
- * (map.ts:mapGraphName); dot/xdot re-serialization keeps `name` so an
9393
- * anonymous root round-trips as `digraph {`, not `digraph %1 {`.
9394
- * @see lib/cgraph/id.c:idmap (anon → `%1`) ; lib/cgraph/agraph.c:agnameof
9395
- */
9396
- anonymous;
9397
- /**
9398
- * Directed/strict classification; mirrors Agdesc_t.directed and
9399
- * Agdesc_t.strict. @see lib/cgraph/cgraph.h:Agdesc_s
9400
- */
9401
- kind;
9402
- /**
9403
- * Node set in insertion order, keyed by name.
9404
- * Mirrors Agraph_t.n_seq (sequence dict) merged with n_id access.
9405
- * @see lib/cgraph/cgraph.h:Agraph_s
9406
- */
9407
- nodes;
9408
- /**
9409
- * All edges owned by this graph (root graph only for ownership; subgraphs
9410
- * reference a subset). Mirrors Agraph_t.e_seq.
9411
- * @see lib/cgraph/cgraph.h:Agraph_s
9412
- */
9413
- edges;
9414
- /**
9415
- * Named subgraphs, keyed by name. Mirrors Agraph_t.g_seq/g_id.
9416
- * @see lib/cgraph/cgraph.h:Agraph_s
9417
- */
9418
- subgraphs;
9419
- /**
9420
- * String attributes (agget/agset equivalents).
9421
- * Replaces the Agattr_t / Agsym_t machinery for simple key-value access.
9422
- * @see lib/cgraph/cgraph.h:Agattr_s
9423
- */
9424
- attrs;
9425
- /** Default attributes applied to all nodes in this graph scope. */
9426
- nodeDefaults;
9427
- /** Default attributes applied to all edges in this graph scope. */
9428
- edgeDefaults;
9429
- /**
9430
- * Snapshot of the enclosing graphs' graph-attribute defaults (this graph ->
9431
- * root, inner wins) captured when this subgraph was OPENED during parsing.
9432
- * Graph attributes set on an ancestor AFTER this subgraph was created are not
9433
- * included — mirroring cgraph's parse-time agsubg defval copy. Used for
9434
- * order-correct label/font inheritance (e.g. a root `label=` declared after a
9435
- * cluster must NOT apply to that cluster). Undefined on the root graph.
9436
- * @see lib/cgraph/graph.c:agsubg (attr defval copy)
9437
- */
9438
- graphDefaultsSnapshot;
9439
- /**
9440
- * Keys in `attrs` the BUILDER seeded from `graphDefaultsSnapshot` rather than
9441
- * the input declaring them in this scope (see builder.ts GRAPH_LABEL_INHERIT_
9442
- * KEYS). cgraph distinguishes these structurally — a seeded value is inherited
9443
- * through the dict view and has no local symbol, while a local declaration
9444
- * creates one even when its value equals the inherited value — so the
9445
- * serializer needs the provenance to decide what write_dict would print.
9446
- * Undefined on the root graph and on any scope that seeded nothing.
9447
- * @see lib/cgraph/write.c:262 write_dict
9448
- */
9449
- seededAttrs;
9450
- /**
9451
- * Graph-attribute keys whose declaration in THIS scope was the first anywhere
9452
- * in the graph. cgraph's `setattr` splits on exactly this: a key with no
9453
- * existing symbol takes the global-declaration branch, which ends up seeding
9454
- * every direct subgraph that already exists with a local empty value (see
9455
- * `eagerEmptyParts`); a key some earlier scope already declared takes the
9456
- * "new local definition" branch and touches no subgraph at all. So an
9457
- * identical `graph [fill=x]` statement makes a child print `fill=""` or print
9458
- * nothing purely according to whether a SIBLING declared `fill` first.
9459
- * Undefined on any scope that declared nothing new.
9460
- * @see lib/cgraph/attr.c:257 setattr (lsym / psym / global branches)
9461
- */
9462
- firstGraphDecl;
9463
- /**
9464
- * Layout-engine info; replaces GD_* macros via agbindrec (AD-1).
9465
- * @see lib/cgraph/cgraph.h:agbindrec
9466
- */
9467
- info;
9468
- /**
9469
- * Immediate parent graph. null for root graphs.
9470
- * @see lib/cgraph/cgraph.h:Agraph_s
9471
- */
9472
- parent;
9473
- /**
9474
- * Root (main) graph. Self-referential for root graphs;
9475
- * points up for subgraphs.
9476
- * @see lib/cgraph/cgraph.h:Agraph_s
9477
- */
9478
- root;
9479
- /**
9480
- * Subgraph sequence number (AGSEQ). A global counter on the root, assigned
9481
- * at creation in source order, counting anonymous subgraphs. The root keeps
9482
- * the default 0 (par == NULL never calls agnextseq). Consumed by getObjId to
9483
- * emit cluster ids `clust<seq>`.
9484
- * @see lib/cgraph/cgraph.h:AGSEQ
9485
- * @see lib/cgraph/graph.c:agopen (AGSEQ(g) = agnextseq(par, AGRAPH))
9486
- */
9487
- seq = 0;
9488
- /**
9489
- * Root-only counter mirroring `clos->seq[AGRAPH]`: the running maximum AGSEQ
9490
- * handed out to subgraphs. Meaningful only on the root graph; `assignSubgSeq`
9491
- * pre-increments it. Other graphs leave it at 0.
9492
- * @see lib/cgraph/graph.c:agnextseq (++clos->seq[AGRAPH])
9493
- */
9494
- subgSeqCounter = 0;
9495
- /**
9496
- * Names of graph attributes (AGRAPH) declared anywhere in this hierarchy —
9497
- * the port's stand-in for cgraph's `Agsym_t` symbol table. Populated on the
9498
- * ROOT only, at parse time, whenever a graph attribute is assigned on any
9499
- * (sub)graph: setting `ordering=out` on a subgraph declares "ordering"
9500
- * graph-wide with an empty default, so `agGraphAttr(root, "ordering")` returns
9501
- * `""` (not undefined) — mirroring `agfindgraphattr`/`late_string`. Read via
9502
- * `agGraphAttr` (model/cgraph-ops.ts); empty on non-root graphs.
9503
- * @see lib/cgraph/attr.c:agattr (graph-wide declaration, "" default)
9504
- */
9505
- declaredGraphAttrs = /* @__PURE__ */ new Set();
9506
- /** @see lib/cgraph/graph.c:agopen */
9507
- constructor(name, kind, anonymous = false) {
9508
- this.name = name;
9509
- this.anonymous = anonymous;
9510
- this.kind = kind;
9511
- this.nodes = /* @__PURE__ */ new Map();
9512
- this.edges = [];
9513
- this.subgraphs = /* @__PURE__ */ new Map();
9514
- this.attrs = /* @__PURE__ */ new Map();
9515
- this.nodeDefaults = /* @__PURE__ */ new Map();
9516
- this.edgeDefaults = /* @__PURE__ */ new Map();
9517
- this.info = makeGraphInfo();
9518
- this.parent = null;
9519
- this.root = this;
9520
- }
9521
- };
9522
-
9523
9801
  // src/common/make-label.ts
9524
9802
  var DEFAULT_FONTSIZE2 = 14;
9525
9803
  var DEFAULT_FONTNAME = "Times-Roman";
@@ -17801,7 +18079,7 @@ function newMatrix(rows, cols) {
17801
18079
  function dotRoot(g) {
17802
18080
  return g.info.dotroot ?? g.root;
17803
18081
  }
17804
- function agContainsNode(g, n) {
18082
+ function agContainsNode2(g, n) {
17805
18083
  return g.nodes.get(n.name) === n;
17806
18084
  }
17807
18085
  function agContainsEdge(g, e) {
@@ -17814,7 +18092,7 @@ function rankSet(rank3, i, n) {
17814
18092
  rank3.v[(rank3.vStart ?? 0) + i] = n;
17815
18093
  }
17816
18094
  function isNormalNodeOf(g, v) {
17817
- return v.info.node_type === NORMAL && agContainsNode(g, v);
18095
+ return v.info.node_type === NORMAL && agContainsNode2(g, v);
17818
18096
  }
17819
18097
  function isVnodeOfEdgeOf(g, v) {
17820
18098
  if (v.info.node_type !== VIRTUAL) return false;
@@ -18211,76 +18489,6 @@ function ncross(ctx) {
18211
18489
  return total;
18212
18490
  }
18213
18491
 
18214
- // src/model/cgraph-ops.ts
18215
- var LOCALNAMEPREFIX = "%";
18216
- var ANONYMOUS_ROOT_ID = 1;
18217
- function agNameOf(g) {
18218
- return g.anonymous ? `${LOCALNAMEPREFIX}${ANONYMOUS_ROOT_ID}` : g.name;
18219
- }
18220
- function freshNodeId(root) {
18221
- let max = -1;
18222
- for (const n of root.nodes.values()) {
18223
- if (n.id > max) max = n.id;
18224
- }
18225
- return max + 1;
18226
- }
18227
- function agnode(g, name, create) {
18228
- const root = g.root;
18229
- if (name !== null && name !== "") {
18230
- const existing = root.nodes.get(name);
18231
- if (existing !== void 0) return existing;
18232
- if (!create) return null;
18233
- const node2 = new Node(freshNodeId(root), name, root);
18234
- root.nodes.set(name, node2);
18235
- return node2;
18236
- }
18237
- if (!create) return null;
18238
- const id = freshNodeId(root);
18239
- const anonName = LOCALNAMEPREFIX + String(id);
18240
- const node = new Node(id, anonName, root);
18241
- root.nodes.set(anonName, node);
18242
- return node;
18243
- }
18244
- function assignSubgSeq(parent2, sg) {
18245
- sg.seq = ++parent2.root.subgSeqCounter;
18246
- }
18247
- function agsubg(parent2, name, create) {
18248
- const existing = parent2.subgraphs.get(name);
18249
- if (existing !== void 0) return existing;
18250
- if (!create) return null;
18251
- const subg = new Graph(name, parent2.kind);
18252
- subg.parent = parent2;
18253
- subg.root = parent2.root;
18254
- assignSubgSeq(parent2, subg);
18255
- parent2.subgraphs.set(name, subg);
18256
- return subg;
18257
- }
18258
- function agsubnode(g, n, create) {
18259
- if (g.root !== n.root) return null;
18260
- const existing = g.nodes.get(n.name);
18261
- if (existing !== void 0) return existing;
18262
- if (!create) return null;
18263
- const par = g.parent;
18264
- if (par !== null) {
18265
- agsubnode(par, n, create);
18266
- }
18267
- g.nodes.set(n.name, n);
18268
- return n;
18269
- }
18270
- function agdelnode(g, n) {
18271
- for (let cur = g; cur !== null; cur = cur.parent) {
18272
- cur.nodes.delete(n.name);
18273
- }
18274
- }
18275
- function agdelsubg(parent2, sg) {
18276
- parent2.subgraphs.delete(sg.name);
18277
- }
18278
- function agGraphAttr(g, name) {
18279
- const own = g.attrs.get(name);
18280
- if (own !== void 0) return own;
18281
- return g.root.declaredGraphAttrs.has(name) ? "" : void 0;
18282
- }
18283
-
18284
18492
  // src/layout/dot/mincross-flat.ts
18285
18493
  function flatRevFindRev(head, tail) {
18286
18494
  const fo = head.info.flat_out;
@@ -18320,7 +18528,7 @@ function flatSearchNormal(g, v, e, M2, hascl) {
18320
18528
  }
18321
18529
  function flatSearchEdge(g, v, e, M2, hascl) {
18322
18530
  if (!M2) return false;
18323
- if (hascl && !(agContainsNode(g, e.tail) && agContainsNode(g, e.head))) return false;
18531
+ if (hascl && !(agContainsNode2(g, e.tail) && agContainsNode2(g, e.head))) return false;
18324
18532
  if ((e.info.weight !== void 0 ? e.info.weight : 0) === 0) return false;
18325
18533
  if (e.head.info.onstack) return flatSearchOstack(g, v, e, M2);
18326
18534
  flatSearchNormal(g, v, e, M2, hascl);
@@ -19550,11 +19758,11 @@ function initSubgraphRankdir(g) {
19550
19758
  var CL_CROSS = 1e3;
19551
19759
  function dotInitNode(n) {
19552
19760
  n.info.UF_size = 1;
19553
- if (!n.info.in) n.info.in = { list: [], size: 0 };
19554
- if (!n.info.out) n.info.out = { list: [], size: 0 };
19555
- if (!n.info.flat_in) n.info.flat_in = { list: [], size: 0 };
19556
- if (!n.info.flat_out) n.info.flat_out = { list: [], size: 0 };
19557
- if (!n.info.other) n.info.other = { list: [], size: 0 };
19761
+ n.info.in = { list: [], size: 0 };
19762
+ n.info.out = { list: [], size: 0 };
19763
+ n.info.flat_in = { list: [], size: 0 };
19764
+ n.info.flat_out = { list: [], size: 0 };
19765
+ n.info.other = { list: [], size: 0 };
19558
19766
  if (n.info.lw === void 0) n.info.lw = 27;
19559
19767
  if (n.info.rw === void 0) n.info.rw = 27;
19560
19768
  if (n.info.ht === void 0) n.info.ht = 36;
@@ -19581,7 +19789,7 @@ function applyNonconstraintZero(e) {
19581
19789
  }
19582
19790
  function dotInitEdge(e) {
19583
19791
  initEdgeConstraint(e);
19584
- e.info.weight = e.attrs.has("weight") ? lateInt(e.attrs.get("weight"), 1, 0) : e.info.weight ?? 1;
19792
+ e.info.weight = lateInt(e.attrs.get("weight"), 1, 0);
19585
19793
  e.info.count = 1;
19586
19794
  e.info.xpenalty = 1;
19587
19795
  applyGroupPenalty(e);
@@ -19611,7 +19819,6 @@ function clearFastGraphLists(n) {
19611
19819
  function dotInitNodeEdge(g) {
19612
19820
  for (const n of nodesInSeq(g)) {
19613
19821
  commonInitNode(n, g);
19614
- clearFastGraphLists(n);
19615
19822
  dotInitNode(n);
19616
19823
  }
19617
19824
  const measurer = g.root.info.gvc?.textMeasurer;
@@ -22079,12 +22286,22 @@ function setGradientFill(obj, color) {
22079
22286
  obj.fill = 2 /* Linear */;
22080
22287
  }
22081
22288
  }
22289
+ var PEN_OF_STYLE = /* @__PURE__ */ new Map([
22290
+ ["solid", 3 /* Solid */],
22291
+ ["dashed", 1 /* Dashed */],
22292
+ ["dotted", 2 /* Dotted */],
22293
+ ["invis", 0 /* None */],
22294
+ ["invisible", 0 /* None */]
22295
+ ]);
22082
22296
  function setStyle(obj, tokens) {
22083
22297
  gvrenderSetStyle(tokens);
22084
22298
  obj.rawStyle = [...tokens];
22085
- const flags = parseStyleFlags(tokens.join(","));
22086
- obj.pen = resolvePenType(flags);
22087
- obj.penWidth = resolvePenWidth(flags, void 0);
22299
+ for (const token of tokens) {
22300
+ const pen = PEN_OF_STYLE.get(styleName(token));
22301
+ if (pen !== void 0) obj.pen = pen;
22302
+ const flags = parseStyleFlags(token);
22303
+ if (flags.bold || flags.setLineWidth !== null) obj.penWidth = resolvePenWidth(flags, void 0);
22304
+ }
22088
22305
  }
22089
22306
  function devicePoints(pts, job) {
22090
22307
  return pts.map((p) => transformPoint({ x: p.x, y: p.y }, job));
@@ -22151,11 +22368,14 @@ function emitXdot(g, renderer, job) {
22151
22368
  for (const op of xd.ops) {
22152
22369
  styled ||= op.kind === "style";
22153
22370
  if (op.kind === "text") continue;
22154
- if (!inClip && isDrawing(op)) continue;
22371
+ if (isDrawing(op) && !drawsNow(obj, inClip)) continue;
22155
22372
  if (!drawOp(op, renderer, job)) stateOp(op, obj, warned2);
22156
22373
  }
22157
22374
  if (styled) setStyle(obj, DEFAULT_LINE_STYLE);
22158
22375
  }
22376
+ function drawsNow(obj, inClip) {
22377
+ return inClip && obj.pen !== 0 /* None */;
22378
+ }
22159
22379
  function isDrawing(op) {
22160
22380
  return op.kind.endsWith("ellipse") || op.kind.endsWith("polygon") || op.kind.endsWith("bezier") || op.kind === "polyline";
22161
22381
  }
@@ -25352,13 +25572,13 @@ function dfsNode(Xg, v, frames) {
25352
25572
  frames.push({ v, edges: v.outEdges(Xg).slice(), i: 0 });
25353
25573
  }
25354
25574
  function dfsStep2(Xg, frames) {
25355
- const fr10 = frames[frames.length - 1];
25356
- if (fr10.i < fr10.edges.length) {
25357
- const e = fr10.edges[fr10.i++];
25575
+ const fr12 = frames[frames.length - 1];
25576
+ if (fr12.i < fr12.edges.length) {
25577
+ const e = fr12.edges[fr12.i++];
25358
25578
  if (e.head.info.onstack) reverseEdge2(Xg, e);
25359
25579
  else if (!e.head.info.mark) dfsNode(Xg, e.head, frames);
25360
25580
  } else {
25361
- fr10.v.info.onstack = 0;
25581
+ fr12.v.info.onstack = 0;
25362
25582
  frames.pop();
25363
25583
  }
25364
25584
  }
@@ -26505,8 +26725,8 @@ function vnodeNotRelatedTo(g, v) {
26505
26725
  let e = v.info.save_out?.list[0];
26506
26726
  while (e?.info.to_orig) e = e.info.to_orig;
26507
26727
  if (!e) return false;
26508
- if (agContainsNode(g, e.tail)) return false;
26509
- if (agContainsNode(g, e.head)) return false;
26728
+ if (agContainsNode2(g, e.tail)) return false;
26729
+ if (agContainsNode2(g, e.head)) return false;
26510
26730
  return true;
26511
26731
  }
26512
26732
  function keepoutLeft(root, g, r, margin) {
@@ -29037,7 +29257,10 @@ function staleBezierCount(e) {
29037
29257
  return staleBeziersByEdge.get(e) ?? 0;
29038
29258
  }
29039
29259
  function staleAdjacent(e) {
29040
- return staleBezierCount(e) > 0 && (e.info.adjacent ?? 0) !== 0;
29260
+ let rep = e;
29261
+ while (rep.info.to_virt !== void 0 && rep.info.to_virt !== rep) rep = rep.info.to_virt;
29262
+ const samePair = rep.tail === e.tail && rep.head === e.head || rep.tail === e.head && rep.head === e.tail;
29263
+ return staleBezierCount(e) > 0 && ((samePair ? rep : e).info.adjacent ?? 0) !== 0;
29041
29264
  }
29042
29265
  function swapStaleBeziers(g) {
29043
29266
  for (const e of g.edges) {
@@ -29047,8 +29270,13 @@ function swapStaleBeziers(g) {
29047
29270
  const old = spl.list.splice(0, stale).reverse();
29048
29271
  for (const bz of old) swapBezier(bz);
29049
29272
  spl.list.push(...old);
29273
+ fillEdgeArrowSlots(e, old);
29050
29274
  }
29051
29275
  }
29276
+ function fillEdgeArrowSlots(e, old) {
29277
+ e.info.tailArrowOps ??= old.find((bz) => bz.sflag !== 0)?.sArrowOps;
29278
+ e.info.headArrowOps ??= old.find((bz) => bz.eflag !== 0)?.eArrowOps;
29279
+ }
29052
29280
  function rankEdgeInfoOf(g, tailNode, headNode) {
29053
29281
  const rankTable = g.info.rank;
29054
29282
  if (rankTable === void 0) return void 0;
@@ -30204,10 +30432,46 @@ function routeChainSegmented(g, beginEdge, endEdge, segs) {
30204
30432
  }
30205
30433
  return finishChain(w, endEdge, segs[ei], segFirst, segs) ? w.pts : null;
30206
30434
  }
30207
- function routeMultiRankEdgeFaithful(g, e) {
30435
+ function copyPort2(p) {
30436
+ return { ...p, p: { ...p.p } };
30437
+ }
30438
+ function hackflagBeginView(e, back, firstVnode) {
30439
+ const tailPort = back ? e.info.head_port : e.info.tail_port;
30440
+ return {
30441
+ ...e,
30442
+ tail: back ? e.head : e.tail,
30443
+ head: firstVnode,
30444
+ info: {
30445
+ ...e.info,
30446
+ tail_port: copyPort2(tailPort),
30447
+ head_port: { ...copyPort2(e.info.head_port), defined: false, p: { x: 0, y: 0 } },
30448
+ edge_type: VIRTUAL,
30449
+ to_orig: e
30450
+ }
30451
+ };
30452
+ }
30453
+ function hackflagEndView(e, back) {
30454
+ if (back) return makeFwdEdge(e);
30455
+ return {
30456
+ ...e,
30457
+ info: { ...e.info, tail_port: copyPort2(e.info.tail_port), head_port: copyPort2(e.info.head_port) }
30458
+ };
30459
+ }
30460
+ function chainEnds(e, segs) {
30461
+ const first = segs[0];
30462
+ const last = segs[segs.length - 1];
30463
+ const orig = resolveOrigEdge(e);
30464
+ if (resolveOrigEdge(first) === orig) return [first, last];
30465
+ const back = (orig.head.info.rank ?? 0) < (orig.tail.info.rank ?? 0);
30466
+ return [hackflagBeginView(orig, back, first.head), hackflagEndView(orig, back)];
30467
+ }
30468
+ function spansRanksForward(g, e) {
30208
30469
  const r = e.tail.info.rank;
30209
30470
  const rh = e.head.info.rank;
30210
- if (g.info.rank === void 0 || r === void 0 || rh === void 0 || rh <= r + 1) return null;
30471
+ return g.info.rank !== void 0 && r !== void 0 && rh !== void 0 && rh > r + 1;
30472
+ }
30473
+ function routeMultiRankEdgeFaithful(g, e) {
30474
+ if (!spansRanksForward(g, e)) return null;
30211
30475
  const et = edgeType(g);
30212
30476
  if (et === EDGETYPE_LINE) {
30213
30477
  const line = makeLineEdge(g, e);
@@ -30215,7 +30479,8 @@ function routeMultiRankEdgeFaithful(g, e) {
30215
30479
  }
30216
30480
  const segs = chainSegments(e);
30217
30481
  if (segs.length === 0 || segs[segs.length - 1].head !== e.head) return null;
30218
- return routeChainSegmented(g, segs[0], segs[segs.length - 1], segs) ?? "lost";
30482
+ const [beginEdge, endEdge] = chainEnds(e, segs);
30483
+ return routeChainSegmented(g, beginEdge, endEdge, segs) ?? "lost";
30219
30484
  }
30220
30485
  function entryRunSegments(e) {
30221
30486
  const segs = [e];
@@ -30286,7 +30551,8 @@ function routeBackEdge(e, _tailBox, _headBox, g) {
30286
30551
  const segs = backChainSegments(e);
30287
30552
  if (segs.length < 2 || segs[segs.length - 1].head !== e.tail) return;
30288
30553
  const fwdEdge = makeFwdEdge(e);
30289
- const fwd = routeChainSegmented(g, segs[0], segs[segs.length - 1], segs);
30554
+ const [beginEdge, endEdge] = chainEnds(e, segs);
30555
+ const fwd = routeChainSegmented(g, beginEdge, endEdge, segs);
30290
30556
  if (fwd === null) {
30291
30557
  e.info.lost = true;
30292
30558
  return;
@@ -30755,7 +31021,7 @@ function cloneNode(g, orign) {
30755
31021
  }
30756
31022
  return n;
30757
31023
  }
30758
- function cloneEdge(g, tn, hn, orig) {
31024
+ function cloneEdge2(g, tn, hn, orig) {
30759
31025
  const e = new Edge(tn, hn, orig.name);
30760
31026
  e.info.tail_port = { ...makePort(), ...orig.info.tail_port };
30761
31027
  e.info.head_port = { ...makePort(), ...orig.info.head_port };
@@ -32346,7 +32612,7 @@ function mapArrowOps(ops) {
32346
32612
  return m;
32347
32613
  });
32348
32614
  }
32349
- function mapEdge(e) {
32615
+ function mapEdge2(e) {
32350
32616
  const spl = e.info.spl;
32351
32617
  if (spl === void 0) return;
32352
32618
  mapSpl(spl);
@@ -32409,7 +32675,7 @@ function translateDrawing(g) {
32409
32675
  }
32410
32676
  continue;
32411
32677
  }
32412
- mapEdge(e);
32678
+ mapEdge2(e);
32413
32679
  }
32414
32680
  }
32415
32681
  translateBb(g, g.info.rankdir & 3);
@@ -32548,7 +32814,7 @@ function isPortless(e) {
32548
32814
  return !e.info.tail_port.defined && !e.info.head_port.defined;
32549
32815
  }
32550
32816
  function cloneFlatEdge(auxg, tn, auxt, auxh, orig) {
32551
- return orig.tail === tn ? cloneEdge(auxg, auxt, auxh, orig) : cloneEdge(auxg, auxh, auxt, orig);
32817
+ return orig.tail === tn ? cloneEdge2(auxg, auxt, auxh, orig) : cloneEdge2(auxg, auxh, auxt, orig);
32552
32818
  }
32553
32819
  function flatLeadPair(edges) {
32554
32820
  const t = edges[0].tail, h = edges[0].head;
@@ -32573,7 +32839,7 @@ function buildFlatAux(g, edges, cnt) {
32573
32839
  hvye = new Edge(auxt, auxh, "");
32574
32840
  auxg.edges.push(hvye);
32575
32841
  }
32576
- hvye.info.weight = 1e4;
32842
+ hvye.attrs.set("weight", "10000");
32577
32843
  return { auxg, auxt, auxh, alg };
32578
32844
  }
32579
32845
  function blocksAdjacency(vn) {
@@ -32601,8 +32867,9 @@ function repositionFlatAux(g, edges, aux) {
32601
32867
  else n.info.coord = { x: n.info.coord.x, y: midx };
32602
32868
  }
32603
32869
  }
32870
+ var transformArrowOps = (ops, del, flip) => ops.map((op) => mapArrowOpPoints(op, (p) => transformf(p, del, flip)));
32604
32871
  function copyFlatArrow(orig, auxe, del, flip) {
32605
- const xf = (ops) => ops.map((op) => mapArrowOpPoints(op, (p) => transformf(p, del, flip)));
32872
+ const xf = (ops) => transformArrowOps(ops, del, flip);
32606
32873
  const eflag = auxe.info.spl?.list[0]?.eflag;
32607
32874
  const head = auxe.info.headArrowOps ?? (eflag ? auxe.info.tailArrowOps : void 0);
32608
32875
  if (head !== void 0) orig.info.headArrowOps = xf(head);
@@ -32627,6 +32894,8 @@ function copyOneFlatSpline(orig, auxe, del, flip, g) {
32627
32894
  bz.eflag = auxbz.eflag;
32628
32895
  bz.sp = transformf(auxbz.sp, del, flip);
32629
32896
  bz.ep = transformf(auxbz.ep, del, flip);
32897
+ if (auxbz.sArrowOps) bz.sArrowOps = transformArrowOps(auxbz.sArrowOps, del, flip);
32898
+ if (auxbz.eArrowOps) bz.eArrowOps = transformArrowOps(auxbz.eArrowOps, del, flip);
32630
32899
  for (let j = 0; j < sz; j++) bz.list[j] = transformf(auxbz.list[j], del, flip);
32631
32900
  const bb = g.info.bb;
32632
32901
  if (bb !== void 0) {
@@ -33278,11 +33547,8 @@ function makeBezierRecord(bezierPts, arrowTip) {
33278
33547
  ep: arrowTip
33279
33548
  };
33280
33549
  }
33281
- function makeSplineRecord(bz) {
33282
- return { list: [bz], size: 1, bb: { ll: { x: 0, y: 0 }, ur: { x: 0, y: 0 } } };
33283
- }
33284
33550
  function installEdgeSpline(e, bezierPts, arrowTip) {
33285
- e.info.spl = makeSplineRecord(makeBezierRecord(bezierPts, arrowTip));
33551
+ Object.assign(newSpline(e, bezierPts.length), makeBezierRecord(bezierPts, arrowTip));
33286
33552
  const bb = e.tail.root.info.bb;
33287
33553
  if (bb != null) {
33288
33554
  for (let i = 0; i + 3 < bezierPts.length; i += 3) {
@@ -34379,7 +34645,7 @@ function makeGraph(n) {
34379
34645
  }
34380
34646
  return { nvs: n, vertices };
34381
34647
  }
34382
- function insertEdge(g, v1, v2) {
34648
+ function insertEdge2(g, v1, v2) {
34383
34649
  if (!edgeExists(g, v1, v2)) {
34384
34650
  g.vertices[v1].adjList.push(v2);
34385
34651
  }
@@ -35306,7 +35572,7 @@ function speFlip(isVert, commCoordMatchesP1, lDirMatchesTarget) {
35306
35572
  }
35307
35573
  function setParallelEdges(seg1, seg2, dir1, dir2, hops, mp) {
35308
35574
  let chan = seg1.isVert ? chanSearch(mp.vchans, seg1.commCoord, seg1.p) : chanSearch(mp.hchans, seg1.commCoord, seg1.p);
35309
- insertEdge(chan.G, seg1.indNo, seg2.indNo);
35575
+ insertEdge2(chan.G, seg1.indNo, seg2.indNo);
35310
35576
  for (let x = 1; x <= hops; x++) {
35311
35577
  const prev1 = nextSeg(seg1, dir1);
35312
35578
  const prev2 = nextSeg(seg2, dir2);
@@ -35316,8 +35582,8 @@ function setParallelEdges(seg1, seg2, dir1, dir2, hops, mp) {
35316
35582
  const target = seg1.isVert ? 2 /* B_LEFT */ : 1 /* B_UP */;
35317
35583
  const flip = speFlip(seg1.isVert, commCoordMatchesP1, lDir === target);
35318
35584
  const edgeSeen = edgeExists(chan.G, seg1.indNo, seg2.indNo);
35319
- if (edgeSeen === flip) insertEdge(nchan.G, prev2.indNo, prev1.indNo);
35320
- else insertEdge(nchan.G, prev1.indNo, prev2.indNo);
35585
+ if (edgeSeen === flip) insertEdge2(nchan.G, prev2.indNo, prev1.indNo);
35586
+ else insertEdge2(nchan.G, prev1.indNo, prev2.indNo);
35321
35587
  chan = nchan;
35322
35588
  seg1 = prev1;
35323
35589
  seg2 = prev2;
@@ -35604,8 +35870,8 @@ function addEdgesInG(cp) {
35604
35870
  for (let y = x + 1; y < size; y++) {
35605
35871
  const cmp = segCmp(cp.segList[x], cp.segList[y]);
35606
35872
  if (cmp === -2) return -1;
35607
- if (cmp > 0) insertEdge(G, x, y);
35608
- else if (cmp === -1) insertEdge(G, y, x);
35873
+ if (cmp > 0) insertEdge2(G, x, y);
35874
+ else if (cmp === -1) insertEdge2(G, y, x);
35609
35875
  }
35610
35876
  }
35611
35877
  return 0;
@@ -36398,7 +36664,7 @@ function orthoDispatch(g) {
36398
36664
  function curvedTop(g) {
36399
36665
  resetRW(g);
36400
36666
  if (((g.root.info.has_labels ?? 0) & EDGE_LABEL) !== 0) {
36401
- agerrLineOn("warn", "edge labels with splines=curved not supported in dot - use xlabels\n");
36667
+ agwarningf("edge labels with splines=curved not supported in dot - use xlabels");
36402
36668
  }
36403
36669
  }
36404
36670
  function finalizeSplines(g, et, normalize) {
@@ -36560,7 +36826,7 @@ function fillClustMap(g, map) {
36560
36826
  fillClustMap(cl, map);
36561
36827
  }
36562
36828
  }
36563
- function mkClustMap(g) {
36829
+ function mkClustMap2(g) {
36564
36830
  const map = /* @__PURE__ */ new Map();
36565
36831
  fillClustMap(g, map);
36566
36832
  return map;
@@ -36715,7 +36981,7 @@ function makeCompoundEdge(e, clustMap) {
36715
36981
  if (tailClipped && bez.sflag) restashArrow(e, bez.sp, bez.list[0], true);
36716
36982
  }
36717
36983
  function dotCompoundEdges(g) {
36718
- const clustMap = mkClustMap(g);
36984
+ const clustMap = mkClustMap2(g);
36719
36985
  for (const e of g.edges) makeCompoundEdge(e, clustMap);
36720
36986
  }
36721
36987
 
@@ -37279,20 +37545,33 @@ function copyParentAttrs(parent2, sg) {
37279
37545
  for (const [k, v] of parent2.attrs) sg.attrs.set(k, v);
37280
37546
  return sg;
37281
37547
  }
37548
+ function componentSubgraph(g, nodes, name, reuse) {
37549
+ const existing = reuse ? g.subgraphs.get(name) : void 0;
37550
+ if (existing === void 0) return copyParentAttrs(g, buildSubgraph(g, nodes, name));
37551
+ const members = /* @__PURE__ */ new Set([...existing.nodes.values(), ...nodes]);
37552
+ existing.nodes.clear();
37553
+ for (const n of [...members].sort((a, b) => a.id - b.id)) existing.nodes.set(n.name, n);
37554
+ const ns = new Set(nodes);
37555
+ const have = new Set(existing.edges);
37556
+ for (const e of g.edges) {
37557
+ if (ns.has(e.tail) && ns.has(e.head) && !have.has(e)) existing.edges.push(e);
37558
+ }
37559
+ return existing;
37560
+ }
37282
37561
  function isLegal(p) {
37283
37562
  return /^[A-Za-z0-9_]*$/.test(p);
37284
37563
  }
37285
37564
  function setPrefix(pfx) {
37286
37565
  return pfx == null || !isLegal(pfx) ? "_cc_" : pfx;
37287
37566
  }
37288
- function ccomps(g, pfx) {
37567
+ function ccomps(g, pfx, reuse = true) {
37289
37568
  const visited = /* @__PURE__ */ new Set();
37290
37569
  const result = [];
37291
37570
  let idx = 0;
37292
37571
  for (const n of g.nodes.values()) {
37293
37572
  if (visited.has(n.name)) continue;
37294
37573
  const comp = dfsCollect(g, n, visited);
37295
- result.push(copyParentAttrs(g, buildSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`)));
37574
+ result.push(componentSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`, reuse));
37296
37575
  }
37297
37576
  return result;
37298
37577
  }
@@ -37308,12 +37587,12 @@ function pccomps(g, pfx) {
37308
37587
  pinned = true;
37309
37588
  }
37310
37589
  if (pinnedNodes.length > 0) {
37311
- result.push(copyParentAttrs(g, buildSubgraph(g, pinnedNodes, `${setPrefix(pfx)}${idx++}`)));
37590
+ result.push(componentSubgraph(g, pinnedNodes, `${setPrefix(pfx)}${idx++}`, true));
37312
37591
  }
37313
37592
  for (const n of g.nodes.values()) {
37314
37593
  if (visited.has(n.name)) continue;
37315
37594
  const comp = dfsCollect(g, n, visited);
37316
- result.push(copyParentAttrs(g, buildSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`)));
37595
+ result.push(componentSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`, true));
37317
37596
  }
37318
37597
  return { graphs: result, pinned };
37319
37598
  }
@@ -37766,8 +38045,15 @@ function setEdgeTypeFromAttr(g, defaultValue) {
37766
38045
  else et = edgeTypeFromString(s, defaultValue);
37767
38046
  setEdgeType(g, et);
37768
38047
  }
38048
+ function resetAbomShift(g) {
38049
+ const shift = g.info.abomShift ?? 0;
38050
+ if (shift !== 0) {
38051
+ for (const n of g.nodes.values()) n.info.rank = (n.info.rank ?? 0) - shift;
38052
+ }
38053
+ g.info.abomShift = 0;
38054
+ }
37769
38055
  function dotPhaseInit(g) {
37770
- for (const e of g.edges) e.info.weight = void 0;
38056
+ resetAbomShift(g);
37771
38057
  dotGraphInit(g);
37772
38058
  setEdgeTypeFromAttr(g, EDGETYPE_SPLINE);
37773
38059
  setAspect(g);
@@ -37848,6 +38134,7 @@ function doDot(g) {
37848
38134
  } else if (ratioIsNone(g)) {
37849
38135
  pinfo.doSplines = true;
37850
38136
  layoutAndPack(g, comps, pinfo, origOf);
38137
+ for (const comp of comps) resetAbomShift(comp);
37851
38138
  } else {
37852
38139
  dotLayoutPipeline(g);
37853
38140
  }
@@ -38575,6 +38862,109 @@ function buildMask(max) {
38575
38862
  return mask >>> 0;
38576
38863
  }
38577
38864
 
38865
+ // src/common/utils-inputscale.ts
38866
+ var POINTS_PER_INCH4 = 72;
38867
+ function getInputscale(g) {
38868
+ const d = lateDouble(g.root.attrs.get("inputscale"), -1, 0);
38869
+ return d === 0 ? POINTS_PER_INCH4 : d;
38870
+ }
38871
+ function inputscaleDivisor(g) {
38872
+ const sc = getInputscale(g);
38873
+ return sc > 0 ? sc : 1;
38874
+ }
38875
+
38876
+ // src/layout/neato/init-dim.ts
38877
+ var DFLT_DIM = 2;
38878
+ var MAXDIM = 10;
38879
+ var POINTS_PER_INCH5 = 72;
38880
+ var NUM = "(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)";
38881
+ var POS3 = new RegExp(`^\\s*${NUM}\\s*,\\s*${NUM}\\s*,\\s*${NUM}(.?)`);
38882
+ var POS2 = new RegExp(`^\\s*${NUM}\\s*,\\s*${NUM}(.?)`);
38883
+ var Z_NUM = new RegExp(`^\\s*${NUM}`);
38884
+ function neatoInitGraphDim(g) {
38885
+ const root = g.root;
38886
+ const outdim = lateInt(root.attrs.get("dimen"), DFLT_DIM, 2);
38887
+ const ndim = Math.min(lateInt(root.attrs.get("dim"), outdim, 2), MAXDIM);
38888
+ root.info.ndim = ndim;
38889
+ root.info.odim = Math.min(outdim, ndim);
38890
+ return ndim;
38891
+ }
38892
+ function ndimOf(g) {
38893
+ return g.root.info.ndim ?? DFLT_DIM;
38894
+ }
38895
+ function jitterD(np, nG, n, ndim) {
38896
+ const pos = np.info.pos;
38897
+ if (pos === void 0) return;
38898
+ for (let k = n; k < ndim; k++) pos[k] = nG * drand48();
38899
+ }
38900
+ function jitter3d(np, nG, ndim) {
38901
+ jitterD(np, nG, 2, ndim);
38902
+ }
38903
+ function nodeAttrDeclared(g, name) {
38904
+ if (g.nodeDefaults.has(name)) return true;
38905
+ for (const n of g.nodes.values()) if (n.attrs.has(name)) return true;
38906
+ for (const sub of g.subgraphs.values()) if (nodeAttrDeclared(sub, name)) return true;
38907
+ return false;
38908
+ }
38909
+ function zDeclared(g) {
38910
+ return nodeAttrDeclared(g.root, "z");
38911
+ }
38912
+ function zValue(np) {
38913
+ return np.attrs.get("z") ?? np.nodeDefaultsSnapshot?.get("z") ?? "";
38914
+ }
38915
+ function scalePos(pvec, ndim, div) {
38916
+ for (let i = 0; i < ndim; i++) pvec[i] = pvec[i] / div;
38917
+ }
38918
+ function userPos3(np, m, nG, ndim) {
38919
+ const pvec = np.info.pos;
38920
+ pvec[0] = Number(m[1]);
38921
+ pvec[1] = Number(m[2]);
38922
+ pvec[2] = Number(m[3]);
38923
+ scalePos(pvec, ndim, inputscaleDivisor(np.root));
38924
+ if (ndim > 3) jitterD(np, nG, 3, ndim);
38925
+ }
38926
+ function userPos2(np, m, nG, ndim) {
38927
+ const pvec = np.info.pos;
38928
+ const div = inputscaleDivisor(np.root);
38929
+ pvec[0] = Number(m[1]);
38930
+ pvec[1] = Number(m[2]);
38931
+ scalePos(pvec, ndim, div);
38932
+ if (ndim <= 2) return;
38933
+ const zm = zDeclared(np.root) ? Z_NUM.exec(zValue(np)) : null;
38934
+ if (zm === null) {
38935
+ jitter3d(np, nG, ndim);
38936
+ return;
38937
+ }
38938
+ pvec[2] = Number(zm[1]) / div;
38939
+ jitterD(np, nG, 3, ndim);
38940
+ }
38941
+ function ensurePos(n, ndim) {
38942
+ if (n.info.pos === void 0 || n.info.pos.length < ndim) n.info.pos = new Array(ndim).fill(0);
38943
+ }
38944
+ function pinRequested(n, c) {
38945
+ const pin = n.attrs.get("pin");
38946
+ return c === "!" || pin !== void 0 && mapbool(pin);
38947
+ }
38948
+ function userPos(n, ndim = DFLT_DIM, nG = n.root.nodes.size) {
38949
+ const p = n.attrs.get("pos");
38950
+ if (p === void 0 || p.length === 0) return false;
38951
+ const m3 = ndim >= 3 ? POS3.exec(p) : null;
38952
+ const m = m3 ?? POS2.exec(p);
38953
+ if (m === null) return false;
38954
+ n.info.posSet = true;
38955
+ ensurePos(n, ndim);
38956
+ if (m3 !== null) userPos3(n, m3, nG, ndim);
38957
+ else userPos2(n, m, nG, ndim);
38958
+ if (pinRequested(n, m[m.length - 1])) n.info.pinned = true;
38959
+ return true;
38960
+ }
38961
+ function addZ(g) {
38962
+ if (ndimOf(g) < 3 || !zDeclared(g)) return;
38963
+ for (const n of g.nodes.values()) {
38964
+ ownAttrs(n).set("z", (POINTS_PER_INCH5 * (n.info.pos?.[2] ?? 0)).toFixed(6));
38965
+ }
38966
+ }
38967
+
38578
38968
  // src/layout/neato/start.ts
38579
38969
  var INIT_SELF = 0;
38580
38970
  var INIT_REGULAR = 1;
@@ -38613,6 +39003,7 @@ function parseStart(p, dflt) {
38613
39003
  return { init, seed };
38614
39004
  }
38615
39005
  function initRegular(g, nG) {
39006
+ const ndim = ndimOf(g);
38616
39007
  let a = 0;
38617
39008
  const da = 2 * Math.PI / nG;
38618
39009
  for (const np of g.nodes.values()) {
@@ -38620,6 +39011,7 @@ function initRegular(g, nG) {
38620
39011
  np.info.posSet = true;
38621
39012
  np.info.pinned = false;
38622
39013
  a += da;
39014
+ if (ndim > 2) jitter3d(np, nG, ndim);
38623
39015
  }
38624
39016
  }
38625
39017
  function checkStart(g, nG = g.nodes.size, dflt = INIT_RANDOM) {
@@ -38789,12 +39181,17 @@ function fisheryatesShuffle(terms, state3) {
38789
39181
  function hasPos(np) {
38790
39182
  return np.info.posSet === true || np.info.pinned === true;
38791
39183
  }
39184
+ function randompos(np, nG, ndim) {
39185
+ np.info.pos = [nG * drand48(), nG * drand48()];
39186
+ if (ndim > 2) jitter3d(np, nG, ndim);
39187
+ }
38792
39188
  function initialPositions(g, nG = g.nodes.size) {
38793
39189
  if (parseStart(g.root.attrs.get("start"), INIT_RANDOM).init === INIT_REGULAR) return;
38794
39190
  checkStart(g, nG, INIT_RANDOM);
39191
+ const ndim = ndimOf(g);
38795
39192
  for (const np of g.nodes.values()) {
38796
39193
  if (hasPos(np)) continue;
38797
- np.info.pos = [drand48(), drand48()];
39194
+ randompos(np, 1, ndim);
38798
39195
  }
38799
39196
  }
38800
39197
  function computeSchedule(terms, maxIter, epsilon = SGD_EPSILON) {
@@ -38860,17 +39257,11 @@ function buildUnfixed(g, n) {
38860
39257
  }
38861
39258
  function resolveModel(model) {
38862
39259
  if (model === MODEL_CIRCUIT) {
38863
- agerrLineOn(
38864
- "warn",
38865
- "circuit model not yet supported in Gmode=sgd, reverting to shortpath model"
38866
- );
39260
+ agwarningf("circuit model not yet supported in Gmode=sgd, reverting to shortpath model");
38867
39261
  return MODEL_SHORTPATH;
38868
39262
  }
38869
39263
  if (model === MODEL_MDS) {
38870
- agerrLineOn(
38871
- "warn",
38872
- "mds model not yet supported in Gmode=sgd, reverting to shortpath model"
38873
- );
39264
+ agwarningf("mds model not yet supported in Gmode=sgd, reverting to shortpath model");
38874
39265
  return MODEL_SHORTPATH;
38875
39266
  }
38876
39267
  return model;
@@ -39702,7 +40093,6 @@ function mdsModel2(dist5, n, edges) {
39702
40093
  }
39703
40094
 
39704
40095
  // src/layout/neato/kk.ts
39705
- var NDIM = 2;
39706
40096
  var DEFAULT_DAMPING = 0.99;
39707
40097
  var EPSILON_PER_NODE = 1e-4;
39708
40098
  var ITERATIONS_PER_NODE = 100;
@@ -39763,13 +40153,15 @@ function scanGraphMode(g, maxIter) {
39763
40153
  const damp = g.root.attrs.get("Damping");
39764
40154
  const { total, lens } = setEdgeLens(g, nodes);
39765
40155
  const ini = initialDist(g, total, epsilon);
40156
+ const ndim = ndimOf(g);
39766
40157
  const st = {
39767
40158
  n,
40159
+ ndim,
39768
40160
  nodes,
39769
40161
  dist: new Float64Array(n * n).fill(ini),
39770
40162
  spring: new Float64Array(n * n).fill(1),
39771
- sumT: new Float64Array(n * NDIM).fill(1),
39772
- t: new Float64Array(n * n * NDIM),
40163
+ sumT: new Float64Array(n * ndim).fill(1),
40164
+ t: new Float64Array(n * n * ndim),
39773
40165
  damping: damp === void 0 ? DEFAULT_DAMPING : parseFloat(damp) || 0,
39774
40166
  epsilon,
39775
40167
  maxIter,
@@ -39777,9 +40169,10 @@ function scanGraphMode(g, maxIter) {
39777
40169
  };
39778
40170
  return { st, adj: neighbours(g, nodes, lens), ini, lens };
39779
40171
  }
39780
- function randompos(np) {
40172
+ function randompos2(np, ndim) {
39781
40173
  np.info.pos[0] = drand48();
39782
40174
  np.info.pos[1] = drand48();
40175
+ if (ndim > 2) jitter3d(np, 1, ndim);
39783
40176
  }
39784
40177
  function initialPositions2(g, st) {
39785
40178
  const init = checkStart(g, st.n, INIT_RANDOM);
@@ -39787,12 +40180,12 @@ function initialPositions2(g, st) {
39787
40180
  if (init === INIT_SELF) warnStartSelfOnce();
39788
40181
  for (const np of st.nodes) {
39789
40182
  if (np.info.posSet === true || np.info.pinned === true) continue;
39790
- randompos(np);
40183
+ randompos2(np, st.ndim);
39791
40184
  }
39792
40185
  }
39793
- function distvec(p0, p1, del) {
40186
+ function distvec(p0, p1, del, ndim) {
39794
40187
  let dist5 = 0;
39795
- for (let k = 0; k < NDIM; k++) {
40188
+ for (let k = 0; k < ndim; k++) {
39796
40189
  del[k] = p0[k] - p1[k];
39797
40190
  dist5 = fma(del[k], del[k], dist5);
39798
40191
  }
@@ -39810,14 +40203,15 @@ function springFactors(g) {
39810
40203
  return (a, b) => byEnds.get(`${a.info.id}:${b.info.id}`) ?? (undirected ? byEnds.get(`${b.info.id}:${a.info.id}`) : void 0);
39811
40204
  }
39812
40205
  function fillRow(st, i, del) {
40206
+ const { ndim } = st;
39813
40207
  const vi = st.nodes[i];
39814
40208
  for (let j = 0; j < st.n; j++) {
39815
40209
  if (i === j) continue;
39816
- const dist5 = distvec(vi.info.pos, st.nodes[j].info.pos, del);
39817
- for (let k = 0; k < NDIM; k++) {
40210
+ const dist5 = distvec(vi.info.pos, st.nodes[j].info.pos, del, ndim);
40211
+ for (let k = 0; k < ndim; k++) {
39818
40212
  const v = st.spring[i * st.n + j] * (del[k] - st.dist[i * st.n + j] * del[k] / dist5);
39819
- st.t[(i * st.n + j) * NDIM + k] = v;
39820
- st.sumT[i * NDIM + k] += v;
40213
+ st.t[(i * st.n + j) * ndim + k] = v;
40214
+ st.sumT[i * ndim + k] += v;
39821
40215
  }
39822
40216
  }
39823
40217
  }
@@ -39834,61 +40228,62 @@ function diffeqModel(g, st) {
39834
40228
  }
39835
40229
  }
39836
40230
  st.sumT.fill(0);
39837
- const del = new Float64Array(NDIM);
40231
+ const del = new Float64Array(st.ndim);
39838
40232
  for (let i = 0; i < n; i++) fillRow(st, i, del);
39839
40233
  }
39840
40234
  function updateArrays(st, i) {
39841
- const { n } = st;
39842
- const del = new Float64Array(NDIM);
40235
+ const { n, ndim } = st;
40236
+ const del = new Float64Array(ndim);
39843
40237
  const vi = st.nodes[i];
39844
- for (let k = 0; k < NDIM; k++) st.sumT[i * NDIM + k] = 0;
40238
+ for (let k = 0; k < ndim; k++) st.sumT[i * ndim + k] = 0;
39845
40239
  for (let j = 0; j < n; j++) {
39846
40240
  if (i === j) continue;
39847
- const dist5 = distvec(vi.info.pos, st.nodes[j].info.pos, del);
39848
- for (let k = 0; k < NDIM; k++) {
40241
+ const dist5 = distvec(vi.info.pos, st.nodes[j].info.pos, del, ndim);
40242
+ for (let k = 0; k < ndim; k++) {
39849
40243
  const tij = st.spring[i * n + j] * (del[k] - st.dist[i * n + j] * del[k] / dist5);
39850
- st.t[(i * n + j) * NDIM + k] = tij;
39851
- st.sumT[i * NDIM + k] += tij;
39852
- const old = st.t[(j * n + i) * NDIM + k];
39853
- st.t[(j * n + i) * NDIM + k] = -tij;
39854
- st.sumT[j * NDIM + k] += -tij - old;
40244
+ st.t[(i * n + j) * ndim + k] = tij;
40245
+ st.sumT[i * ndim + k] += tij;
40246
+ const old = st.t[(j * n + i) * ndim + k];
40247
+ st.t[(j * n + i) * ndim + k] = -tij;
40248
+ st.sumT[j * ndim + k] += -tij - old;
39855
40249
  }
39856
40250
  }
39857
40251
  }
39858
40252
  function d2e(st, m, M2) {
39859
- const { n } = st;
40253
+ const { n, ndim } = st;
39860
40254
  const vn = st.nodes[m];
39861
- const t = new Float64Array(NDIM);
40255
+ const t = new Float64Array(ndim);
39862
40256
  M2.fill(0);
39863
40257
  for (let i = 0; i < n; i++) {
39864
40258
  if (m === i) continue;
39865
40259
  const vi = st.nodes[i];
39866
40260
  let sq = 0;
39867
- for (let k = 0; k < NDIM; k++) {
40261
+ for (let k = 0; k < ndim; k++) {
39868
40262
  t[k] = vn.info.pos[k] - vi.info.pos[k];
39869
40263
  sq = fma(t[k], t[k], sq);
39870
40264
  }
39871
40265
  const scale = 1 / Math.pow(sq, 1.5);
39872
40266
  const K = st.spring[m * n + i];
39873
40267
  const D = st.dist[m * n + i];
39874
- for (let k = 0; k < NDIM; k++) {
39875
- for (let l = 0; l < k; l++) M2[l * NDIM + k] = fma(K * D * t[k] * t[l], scale, M2[l * NDIM + k]);
40268
+ for (let k = 0; k < ndim; k++) {
40269
+ for (let l = 0; l < k; l++) M2[l * ndim + k] = fma(K * D * t[k] * t[l], scale, M2[l * ndim + k]);
39876
40270
  const inner = fms(D * fms(t[k], t[k], sq), scale, 1);
39877
- M2[k * NDIM + k] = fma(K, inner, M2[k * NDIM + k]);
40271
+ M2[k * ndim + k] = fma(K, inner, M2[k * ndim + k]);
39878
40272
  }
39879
40273
  }
39880
- for (let k = 1; k < NDIM; k++) {
39881
- for (let l = 0; l < k; l++) M2[k * NDIM + l] = M2[l * NDIM + k];
40274
+ for (let k = 1; k < ndim; k++) {
40275
+ for (let l = 0; l < k; l++) M2[k * ndim + l] = M2[l * ndim + k];
39882
40276
  }
39883
40277
  }
39884
40278
  function chooseNode(st) {
39885
40279
  if (st.move >= st.maxIter) return -1;
40280
+ const { ndim } = st;
39886
40281
  let max = 0;
39887
40282
  let choice = -1;
39888
40283
  for (let i = 0; i < st.n; i++) {
39889
40284
  if (st.nodes[i].info.pinned === true) continue;
39890
40285
  let m = 0;
39891
- for (let k = 0; k < NDIM; k++) m = fma(st.sumT[i * NDIM + k], st.sumT[i * NDIM + k], m);
40286
+ for (let k = 0; k < ndim; k++) m = fma(st.sumT[i * ndim + k], st.sumT[i * ndim + k], m);
39892
40287
  if (m > max) {
39893
40288
  choice = i;
39894
40289
  max = m;
@@ -39897,14 +40292,15 @@ function chooseNode(st) {
39897
40292
  return max < st.epsilon * st.epsilon ? -1 : choice;
39898
40293
  }
39899
40294
  function moveNode(st, m) {
39900
- const a = new Float64Array(NDIM * NDIM);
39901
- const b = new Float64Array(NDIM);
39902
- const c = new Float64Array(NDIM);
40295
+ const { ndim } = st;
40296
+ const a = new Float64Array(ndim * ndim);
40297
+ const b = new Float64Array(ndim);
40298
+ const c = new Float64Array(ndim);
39903
40299
  d2e(st, m, a);
39904
- for (let i = 0; i < NDIM; i++) c[i] = -st.sumT[m * NDIM + i];
39905
- solve(a, b, c, NDIM);
40300
+ for (let i = 0; i < ndim; i++) c[i] = -st.sumT[m * ndim + i];
40301
+ solve(a, b, c, ndim);
39906
40302
  const pos = st.nodes[m].info.pos;
39907
- for (let i = 0; i < NDIM; i++) {
40303
+ for (let i = 0; i < ndim; i++) {
39908
40304
  b[i] = fma(2 * (1 - st.damping), drand48(), st.damping) * b[i];
39909
40305
  pos[i] += b[i];
39910
40306
  }
@@ -40358,8 +40754,567 @@ function imdsGivenDim(graph, n, givenCoords, newCoords, conjTol) {
40358
40754
  return 0;
40359
40755
  }
40360
40756
 
40361
- // src/layout/neato/stress-kernel.ts
40757
+ // src/layout/neato/embed-graph.ts
40758
+ function saveWeights(graph, n) {
40759
+ return graph[0].ewgts.length === 0 ? null : graph.slice(0, n).map((v) => v.ewgts);
40760
+ }
40761
+ function pivotDistances(node, graph, n, reweightGraph, dist5) {
40762
+ if (reweightGraph) ngdijkstra(node, graph, n, dist5);
40763
+ else bfs(node, graph, n, dist5);
40764
+ }
40765
+ function embedGraph(graph, n, dim, reweightGraph) {
40766
+ const dist5 = new Int32Array(n);
40767
+ const oldWeights = saveWeights(graph, n);
40768
+ const coords = Array.from({ length: dim }, () => new Int32Array(n));
40769
+ if (reweightGraph) computeNewWeights(graph, n);
40770
+ let node = crand() % n;
40771
+ pivotDistances(node, graph, n, reweightGraph, coords[0]);
40772
+ let maxDist = 0;
40773
+ for (let i = 0; i < n; i++) {
40774
+ dist5[i] = coords[0][i];
40775
+ if (dist5[i] > maxDist) {
40776
+ node = i;
40777
+ maxDist = dist5[i];
40778
+ }
40779
+ }
40780
+ for (let i = 1; i < dim; i++) {
40781
+ pivotDistances(node, graph, n, reweightGraph, coords[i]);
40782
+ maxDist = 0;
40783
+ for (let j = 0; j < n; j++) {
40784
+ dist5[j] = Math.min(dist5[j], coords[i][j]);
40785
+ if (dist5[j] > maxDist) {
40786
+ node = j;
40787
+ maxDist = dist5[j];
40788
+ }
40789
+ }
40790
+ }
40791
+ if (reweightGraph) restoreOldWeights(graph, n, oldWeights);
40792
+ return coords;
40793
+ }
40794
+ function centerCoordinate(coords, n, dim) {
40795
+ for (let i = 0; i < dim; i++) {
40796
+ let sum = 0;
40797
+ for (let j = 0; j < n; j++) sum += coords[i][j];
40798
+ const avg = Math.trunc(sum / n);
40799
+ for (let j = 0; j < n; j++) coords[i][j] = coords[i][j] - avg;
40800
+ }
40801
+ }
40802
+
40803
+ // src/layout/neato/matrix-ops-dense.ts
40362
40804
  var fr5 = Math.fround;
40805
+ var P_ITERATION_THRESHOLD = 1e-3;
40806
+ var POWER_LENGTH_FLOOR2 = 1e-10;
40807
+ var GUESS_RANGE = 100;
40808
+ var BLOCK_ROW = 8;
40809
+ function rightMultWithVectorD(matrix, dim1, dim2, vector, result) {
40810
+ const blocked = dim2 - dim2 % BLOCK_ROW;
40811
+ for (let i = 0; i < dim1; i++) {
40812
+ const row = matrix[i];
40813
+ let res = 0;
40814
+ let j = 0;
40815
+ for (; j < blocked; j++) res += row[j] * vector[j];
40816
+ for (; j < dim2; j++) res = fma(row[j], vector[j], res);
40817
+ result[i] = res;
40818
+ }
40819
+ }
40820
+ function rightMultWithVectorTranspose(matrix, dim1, dim2, vector, result) {
40821
+ for (let i = 0; i < dim1; i++) {
40822
+ let res = 0;
40823
+ for (let j = 0; j < dim2; j++) res = fma(matrix[j][i], vector[j], res);
40824
+ result[i] = res;
40825
+ }
40826
+ }
40827
+ function multDenseMat(A3, B2, dim1, dim2, dim3) {
40828
+ const C6 = Array.from({ length: dim1 }, () => new Float32Array(dim3));
40829
+ for (let i = 0; i < dim1; i++) {
40830
+ for (let j = 0; j < dim3; j++) {
40831
+ let sum = 0;
40832
+ for (let k = 0; k < dim2; k++) sum = fma(A3[i][k], B2[k][j], sum);
40833
+ C6[i][j] = sum;
40834
+ }
40835
+ }
40836
+ return C6;
40837
+ }
40838
+ function multDenseMatD(A3, B2, dim1, dim2, dim3) {
40839
+ const C6 = Array.from({ length: dim1 }, () => new Float64Array(dim3));
40840
+ for (let i = 0; i < dim1; i++) {
40841
+ for (let j = 0; j < dim3; j++) {
40842
+ let sum = 0;
40843
+ for (let k = 0; k < dim2; k++) sum = fma(A3[i][k], B2[k][j], sum);
40844
+ C6[i][j] = sum;
40845
+ }
40846
+ }
40847
+ return C6;
40848
+ }
40849
+ function multSparseDenseMatTranspose(A3, B2, dim1, dim2) {
40850
+ const C6 = Array.from({ length: dim1 }, () => new Float32Array(dim2));
40851
+ for (let i = 0; i < dim1; i++) {
40852
+ const { edges, ewgts, nedges } = A3[i];
40853
+ for (let j = 0; j < dim2; j++) {
40854
+ let sum = 0;
40855
+ for (let k = 0; k < nedges; k++) sum = fma(fr5(ewgts[k]), B2[j][edges[k]], sum);
40856
+ C6[i][j] = sum;
40857
+ }
40858
+ }
40859
+ return C6;
40860
+ }
40861
+ function orthogonalize(st, i, vec) {
40862
+ for (let j = 0; j < i; j++) {
40863
+ const alpha = -innerProduct(st.n, st.eigs[j], vec, BLOCK_ROW);
40864
+ scadd(vec, st.n - 1, alpha, st.eigs[j]);
40865
+ }
40866
+ }
40867
+ function guess(st, i) {
40868
+ const curr = st.eigs[i];
40869
+ for (let j = 0; j < st.n; j++) curr[j] = crand() % GUESS_RANGE;
40870
+ orthogonalize(st, i, curr);
40871
+ return norm(curr, st.n - 1, BLOCK_NONE);
40872
+ }
40873
+ function iterate(st, i) {
40874
+ const { n, mat, tmpVec, lastVec } = st;
40875
+ const curr = st.eigs[i];
40876
+ let angle;
40877
+ let len;
40878
+ st.iteration = 0;
40879
+ do {
40880
+ st.iteration++;
40881
+ copyVector(n, curr, lastVec);
40882
+ rightMultWithVectorD(mat, n, n, curr, tmpVec);
40883
+ copyVector(n, tmpVec, curr);
40884
+ orthogonalize(st, i, curr);
40885
+ len = norm(curr, n - 1, BLOCK_NONE);
40886
+ if (len < POWER_LENGTH_FLOOR2 || st.iteration > st.maxIterations) return null;
40887
+ vectorsScalarMult(n, curr, 1 / len, curr);
40888
+ angle = innerProduct(n, curr, lastVec, BLOCK_ROW);
40889
+ } while (Math.abs(angle) < st.tol);
40890
+ return angle * len;
40891
+ }
40892
+ function fillNullSpace(st, from, neigs) {
40893
+ for (let i = from; i < neigs; i++) {
40894
+ const len = guess(st, i);
40895
+ vectorsScalarMult(st.n, st.eigs[i], 1 / len, st.eigs[i]);
40896
+ st.evals[i] = 0;
40897
+ }
40898
+ }
40899
+ function sortByEval(st, neigs) {
40900
+ const { n, eigs, evals, tmpVec } = st;
40901
+ for (let i = 0; i < neigs - 1; i++) {
40902
+ let largestIndex = i;
40903
+ let largestEval = evals[largestIndex];
40904
+ for (let j = i + 1; j < neigs; j++) {
40905
+ if (largestEval < evals[j]) {
40906
+ largestIndex = j;
40907
+ largestEval = evals[largestIndex];
40908
+ }
40909
+ }
40910
+ if (largestIndex !== i) {
40911
+ copyVector(n, eigs[i], tmpVec);
40912
+ copyVector(n, eigs[largestIndex], eigs[i]);
40913
+ copyVector(n, tmpVec, eigs[largestIndex]);
40914
+ evals[largestIndex] = evals[i];
40915
+ evals[i] = largestEval;
40916
+ }
40917
+ }
40918
+ }
40919
+ function powerIteration(mat, n, neigsIn, eigs) {
40920
+ const neigs = neigsIn >= n ? n : neigsIn;
40921
+ const st = {
40922
+ mat,
40923
+ n,
40924
+ eigs,
40925
+ evals: new Float64Array(neigs),
40926
+ tmpVec: new Float64Array(n),
40927
+ lastVec: new Float64Array(n),
40928
+ maxIterations: 30 * n,
40929
+ tol: 1 - P_ITERATION_THRESHOLD,
40930
+ iteration: 0
40931
+ };
40932
+ let i = 0;
40933
+ for (; i < neigs; i++) {
40934
+ let len = guess(st, i);
40935
+ while (len < POWER_LENGTH_FLOOR2) len = guess(st, i);
40936
+ vectorsScalarMult(n, eigs[i], 1 / len, eigs[i]);
40937
+ const rayleigh = iterate(st, i);
40938
+ if (rayleigh === null) break;
40939
+ st.evals[i] = rayleigh;
40940
+ }
40941
+ fillNullSpace(st, i, neigs);
40942
+ sortByEval(st, neigs);
40943
+ return st.iteration <= st.maxIterations;
40944
+ }
40945
+
40946
+ // src/layout/neato/closest.ts
40947
+ function greaterPriority2(h, i, j) {
40948
+ const a = h.data[i].dist;
40949
+ const b = h.data[j].dist;
40950
+ return a < b || a === b && crand() % 2 !== 0;
40951
+ }
40952
+ function swap3(h, i, j) {
40953
+ const t = h.data[i];
40954
+ h.data[i] = h.data[j];
40955
+ h.data[j] = t;
40956
+ }
40957
+ function heapify2(h, start) {
40958
+ let i = start;
40959
+ for (; ; ) {
40960
+ const l = 2 * i;
40961
+ const r = 2 * i + 1;
40962
+ let largest = l < h.heapSize && greaterPriority2(h, l, i) ? l : i;
40963
+ if (r < h.heapSize && greaterPriority2(h, r, largest)) largest = r;
40964
+ if (largest === i) break;
40965
+ swap3(h, largest, i);
40966
+ i = largest;
40967
+ }
40968
+ }
40969
+ function initHeap2(place, ordering, n) {
40970
+ const h = { data: [], heapSize: n - 1 };
40971
+ for (let i = 0; i < n - 1; i++) {
40972
+ const left2 = ordering[i];
40973
+ const right2 = ordering[i + 1];
40974
+ h.data.push({ left: left2, right: right2, dist: place[right2] - place[left2] });
40975
+ }
40976
+ for (let j = Math.trunc((n - 1) / 2); j >= 0; j--) heapify2(h, j);
40977
+ return h;
40978
+ }
40979
+ function extractMax2(h) {
40980
+ if (h.heapSize === 0) return null;
40981
+ const max = h.data[0];
40982
+ h.data[0] = h.data[h.heapSize - 1];
40983
+ h.heapSize--;
40984
+ heapify2(h, 0);
40985
+ return max;
40986
+ }
40987
+ function insert(h, edge) {
40988
+ let i = h.heapSize;
40989
+ h.heapSize++;
40990
+ h.data[i] = edge;
40991
+ while (i > 0 && greaterPriority2(h, i, Math.trunc(i / 2))) {
40992
+ swap3(h, i, Math.trunc(i / 2));
40993
+ i = Math.trunc(i / 2);
40994
+ }
40995
+ }
40996
+ function insertDescendants(s, pair) {
40997
+ const { place, ordering, invOrdering, left: left2, right: right2, heap } = s;
40998
+ const leftIndex = invOrdering[pair.left];
40999
+ const rightIndex = invOrdering[pair.right];
41000
+ if (leftIndex > 0) {
41001
+ const neighbor2 = ordering[leftIndex - 1];
41002
+ if (invOrdering[right2[neighbor2]] < rightIndex) {
41003
+ insert(heap, { left: neighbor2, right: pair.right, dist: place[pair.right] - place[neighbor2] });
41004
+ right2[neighbor2] = pair.right;
41005
+ left2[pair.right] = neighbor2;
41006
+ }
41007
+ }
41008
+ if (rightIndex < s.n - 1) {
41009
+ const neighbor2 = ordering[rightIndex + 1];
41010
+ if (invOrdering[left2[neighbor2]] > leftIndex) {
41011
+ insert(heap, { left: pair.left, right: neighbor2, dist: place[neighbor2] - place[pair.left] });
41012
+ left2[neighbor2] = pair.left;
41013
+ right2[pair.left] = neighbor2;
41014
+ }
41015
+ }
41016
+ }
41017
+ function orderByPlace(place, n) {
41018
+ const ordering = Array.from({ length: n }, (_, i) => i);
41019
+ return gvQsort(ordering, (x, y) => {
41020
+ if (place[x] < place[y]) return -1;
41021
+ if (place[x] > place[y]) return 1;
41022
+ return 0;
41023
+ });
41024
+ }
41025
+ function findClosestPairs(place, n, numPairs) {
41026
+ const ordering = orderByPlace(place, n);
41027
+ const invOrdering = new Int32Array(n);
41028
+ for (let i = 0; i < n; i++) invOrdering[ordering[i]] = i;
41029
+ const left2 = new Int32Array(n);
41030
+ const right2 = new Int32Array(n);
41031
+ const heap = initHeap2(place, ordering, n);
41032
+ for (let i = 1; i < n; i++) left2[ordering[i]] = ordering[i - 1];
41033
+ for (let i = 0; i < n - 1; i++) right2[ordering[i]] = ordering[i + 1];
41034
+ const scan = { place, n, ordering, invOrdering, left: left2, right: right2, heap };
41035
+ const stack = [];
41036
+ for (let i = 0; i < numPairs; i++) {
41037
+ const pair = extractMax2(heap);
41038
+ if (pair === null) break;
41039
+ stack.push(pair);
41040
+ insertDescendants(scan, pair);
41041
+ }
41042
+ return stack;
41043
+ }
41044
+ function addEdge2(graph, u, v) {
41045
+ const gu = graph[u];
41046
+ const gv = graph[v];
41047
+ if (gu.edges.includes(v)) return;
41048
+ gu.edges.push(v);
41049
+ gu.ewgts.push(1);
41050
+ gu.nedges++;
41051
+ gv.edges.push(u);
41052
+ gv.ewgts.push(1);
41053
+ gv.nedges++;
41054
+ gu.ewgts[0]--;
41055
+ gv.ewgts[0]--;
41056
+ }
41057
+ function constructGraph(n, edgesStack) {
41058
+ const graph = Array.from({ length: n }, (_, i) => ({ nedges: 1, edges: [i], ewgts: [0] }));
41059
+ for (let top = edgesStack.length - 1; top >= 0; top--) {
41060
+ addEdge2(graph, edgesStack[top].left, edgesStack[top].right);
41061
+ }
41062
+ return graph;
41063
+ }
41064
+ function closestPairs2Graph(place, n, numPairs) {
41065
+ return constructGraph(n, findClosestPairs(place, n, numPairs));
41066
+ }
41067
+
41068
+ // src/layout/neato/pca.ts
41069
+ var NUM_PAIRS = 4;
41070
+ function pcaAlloc(coords, dim, n, newCoords, newDim) {
41071
+ const eigs = Array.from({ length: newDim }, () => new Float64Array(dim));
41072
+ const DD = Array.from({ length: dim }, () => new Float64Array(dim));
41073
+ for (let i = 0; i < dim; i++) {
41074
+ for (let j = 0; j <= i; j++) {
41075
+ let sum = 0;
41076
+ for (let k = 0; k < n; k++) sum += Math.imul(coords[i][k], coords[j][k]);
41077
+ DD[i][j] = DD[j][i] = sum;
41078
+ }
41079
+ }
41080
+ powerIteration(DD, dim, newDim, eigs);
41081
+ for (let j = 0; j < newDim; j++) {
41082
+ for (let i = 0; i < n; i++) {
41083
+ let sum = 0;
41084
+ for (let k = 0; k < dim; k++) sum = fma(coords[k][i], eigs[j][k], sum);
41085
+ newCoords[j][i] = sum;
41086
+ }
41087
+ }
41088
+ }
41089
+ function iterativePCA1D(coords, dim, n, newDirection) {
41090
+ const laplacian = closestPairs2Graph(coords[0], n, NUM_PAIRS * n);
41091
+ const mat1 = multSparseDenseMatTranspose(laplacian, coords, n, dim);
41092
+ const mat = multDenseMatD(coords, mat1, dim, n, dim);
41093
+ return powerIteration(mat, dim, 1, [newDirection]);
41094
+ }
41095
+
41096
+ // src/layout/neato/stress-subspace.ts
41097
+ var fr6 = Math.fround;
41098
+ var STRESS_PCA_DIM = 50;
41099
+ var MIN_EMBEDDING_PIVOTS = 50;
41100
+ var ZERO_DISTANCE = 1e-30;
41101
+ var STRESS_GUARD = 1e-10;
41102
+ function distanceKD(coords, dim, i, j) {
41103
+ let sum = 0;
41104
+ for (let k = 0; k < dim; k++) {
41105
+ const d = coords[k][i] - coords[k][j];
41106
+ sum = fma(d, d, sum);
41107
+ }
41108
+ return Math.sqrt(sum);
41109
+ }
41110
+ function computeStress1(coords, distances, dim, n, exp) {
41111
+ let sum = 0;
41112
+ for (let i = 0; i < n; i++) {
41113
+ const row = distances[i];
41114
+ for (let j = 0; j < row.nedges; j++) {
41115
+ const node = row.edges[j];
41116
+ if (node <= i) continue;
41117
+ const dist5 = distanceKD(coords, dim, i, node);
41118
+ const Dij = row.edist[j];
41119
+ sum += exp === 2 ? (Dij - dist5) * (Dij - dist5) / (Dij * Dij) : (Dij - dist5) * (Dij - dist5) / Dij;
41120
+ }
41121
+ }
41122
+ return sum;
41123
+ }
41124
+ function nextPivot(dist5, Di, n, from) {
41125
+ let node = from;
41126
+ let maxDist = 0;
41127
+ for (let j = 0; j < n; j++) {
41128
+ dist5[j] = Math.min(dist5[j], Di[j]);
41129
+ if (dist5[j] > maxDist || dist5[j] === maxDist && crand() % (j + 1) === 0) {
41130
+ node = j;
41131
+ maxDist = dist5[j];
41132
+ }
41133
+ }
41134
+ return node;
41135
+ }
41136
+ function selectPivots(graph, n, numCenters, reweightGraph) {
41137
+ const centerIndex = new Int32Array(n).fill(-1);
41138
+ const invCenterIndex = new Int32Array(numCenters);
41139
+ const Dij = Array.from({ length: numCenters }, () => new Int32Array(n));
41140
+ const dist5 = new Int32Array(n);
41141
+ let node = crand() % n;
41142
+ centerIndex[node] = 0;
41143
+ invCenterIndex[0] = node;
41144
+ pivotDistances(node, graph, n, reweightGraph, Dij[0]);
41145
+ let maxDist = 0;
41146
+ for (let i = 0; i < n; i++) {
41147
+ dist5[i] = Dij[0][i];
41148
+ if (dist5[i] > maxDist) {
41149
+ node = i;
41150
+ maxDist = dist5[i];
41151
+ }
41152
+ }
41153
+ for (let i = 1; i < numCenters; i++) {
41154
+ centerIndex[node] = i;
41155
+ invCenterIndex[i] = node;
41156
+ pivotDistances(node, graph, n, reweightGraph, Dij[i]);
41157
+ node = nextPivot(dist5, Dij[i], n, node);
41158
+ }
41159
+ return { centerIndex, invCenterIndex, Dij };
41160
+ }
41161
+ function pivotRow(i, n, Di) {
41162
+ const edges = new Int32Array(n - 1);
41163
+ const edist = new Int32Array(n - 1);
41164
+ for (let j = 0; j < i; j++) {
41165
+ edges[j] = j;
41166
+ edist[j] = Di[j];
41167
+ }
41168
+ for (let j = i + 1; j < n; j++) {
41169
+ edges[j - 1] = j;
41170
+ edist[j - 1] = Di[j];
41171
+ }
41172
+ return { nedges: n - 1, edges, edist };
41173
+ }
41174
+ function nonPivotRow(i, numCenters, p) {
41175
+ const edges = new Int32Array(numCenters);
41176
+ const edist = new Int32Array(numCenters);
41177
+ for (let j = 0; j < numCenters; j++) {
41178
+ edges[j] = p.invCenterIndex[j];
41179
+ edist[j] = p.Dij[j][i];
41180
+ }
41181
+ return { nedges: numCenters, edges, edist };
41182
+ }
41183
+ function buildDistances(n, numCenters, p) {
41184
+ const distances = [];
41185
+ for (let i = 0; i < n; i++) {
41186
+ const index = p.centerIndex[i];
41187
+ distances.push(index >= 0 ? pivotRow(i, n, p.Dij[index]) : nonPivotRow(i, numCenters, p));
41188
+ }
41189
+ return distances;
41190
+ }
41191
+ function buildSparseLaplacian(distances, n, exp) {
41192
+ const lap = [];
41193
+ for (let i = 0; i < n; i++) {
41194
+ const row = distances[i];
41195
+ const edges = [i];
41196
+ const ewgts = [0];
41197
+ let degree = 0;
41198
+ for (let j = 0; j < row.nedges; j++) {
41199
+ const d = fr6(row.edist[j]);
41200
+ const w = exp === 2 ? fr6(-1 / fr6(d * d)) : fr6(-1 / d);
41201
+ edges.push(row.edges[j]);
41202
+ ewgts.push(w);
41203
+ degree -= w;
41204
+ }
41205
+ ewgts[0] = fr6(degree);
41206
+ lap.push({ nedges: row.nedges + 1, edges, ewgts });
41207
+ }
41208
+ return lap;
41209
+ }
41210
+ function initialDirections(subspace, subspaceDim, n, dim) {
41211
+ const storage = new Float64Array(dim * subspaceDim);
41212
+ const directions = Array.from({ length: dim }, (_, k) => storage.subarray(k * subspaceDim, (k + 1) * subspaceDim));
41213
+ if (dim !== 2) {
41214
+ for (let k = 0; k < dim; k++) storage[k * subspaceDim + k] = 1;
41215
+ return directions;
41216
+ }
41217
+ directions[0][0] = 1;
41218
+ if (!iterativePCA1D(subspace, subspaceDim, n, directions[1])) {
41219
+ directions[1].fill(0);
41220
+ directions[1][1] = 1;
41221
+ }
41222
+ return directions;
41223
+ }
41224
+ function computeB(st, k) {
41225
+ const { n, dim, coords, distances, lap, b } = st;
41226
+ const ck = coords[k];
41227
+ for (let i = 0; i < n; i++) {
41228
+ let degree = 0;
41229
+ let bi = 0;
41230
+ const { edges, ewgts, nedges } = lap[i];
41231
+ const edist = distances[i].edist;
41232
+ for (let j = 1; j < nedges; j++) {
41233
+ const node = edges[j];
41234
+ const distIj = distanceKD(coords, dim, i, node);
41235
+ if (distIj > ZERO_DISTANCE) {
41236
+ const Lij = fr6(-ewgts[j] * fr6(edist[j - 1])) / distIj;
41237
+ degree -= Lij;
41238
+ bi = fma(Lij, ck[node], bi);
41239
+ }
41240
+ }
41241
+ b[i] = fma(degree, ck[i], bi);
41242
+ }
41243
+ }
41244
+ function optimizeAxes(st) {
41245
+ const { n, dim, subspaceDim, subspace, matrix, directions, coords, b, bRestricted } = st;
41246
+ for (let k = 0; k < dim; k++) {
41247
+ computeB(st, k);
41248
+ rightMultWithVectorD(subspace, subspaceDim, n, b, bRestricted);
41249
+ const rc = conjugateGradientF(matrix, directions[k], bRestricted, subspaceDim, {
41250
+ tol: TOLERANCE_CG,
41251
+ maxIterations: subspaceDim,
41252
+ ortho1: false
41253
+ });
41254
+ if (rc !== 0) return true;
41255
+ rightMultWithVectorTranspose(subspace, n, subspaceDim, directions[k], coords[k]);
41256
+ }
41257
+ return false;
41258
+ }
41259
+ function optimizeLayout(st, o) {
41260
+ let oldStress = computeStress1(st.coords, st.distances, st.dim, st.n, o.exp);
41261
+ let converged = false;
41262
+ let iterations = 0;
41263
+ for (; iterations < o.nIterations && !converged; iterations++) {
41264
+ if (optimizeAxes(st)) return -1;
41265
+ if (iterations % 2 === 0) {
41266
+ const newStress = computeStress1(st.coords, st.distances, st.dim, st.n, o.exp);
41267
+ converged = Math.abs(newStress - oldStress) / (newStress + STRESS_GUARD) < o.epsilon;
41268
+ oldStress = newStress;
41269
+ }
41270
+ }
41271
+ return iterations;
41272
+ }
41273
+ function computeSubspace(graph, n, subspaceDim, reweightGraph) {
41274
+ const subspace = Array.from({ length: subspaceDim }, () => new Float64Array(n));
41275
+ const numCentersLocal = Math.min(n, Math.max(2 * subspaceDim, MIN_EMBEDDING_PIVOTS));
41276
+ const fullCoords = embedGraph(graph, n, numCentersLocal, reweightGraph);
41277
+ centerCoordinate(fullCoords, n, numCentersLocal);
41278
+ pcaAlloc(fullCoords, numCentersLocal, n, subspace, subspaceDim);
41279
+ return subspace;
41280
+ }
41281
+ function sparseStressSubspaceMajorizationKD(graph, n, coords, o) {
41282
+ const { dim, exp, reweightGraph, numCenters } = o;
41283
+ const subspaceDim = Math.min(STRESS_PCA_DIM, n);
41284
+ const subspace = computeSubspace(graph, n, subspaceDim, reweightGraph);
41285
+ const oldWeights = saveWeights(graph, n);
41286
+ if (reweightGraph) computeNewWeights(graph, n);
41287
+ const pivots = selectPivots(graph, n, numCenters, reweightGraph);
41288
+ const distances = buildDistances(n, numCenters, pivots);
41289
+ const lap = buildSparseLaplacian(distances, n, exp);
41290
+ const directions = initialDirections(subspace, subspaceDim, n, dim);
41291
+ for (let k = 0; k < dim; k++) {
41292
+ rightMultWithVectorTranspose(subspace, n, subspaceDim, directions[k], coords[k]);
41293
+ }
41294
+ const tmpMat = multSparseDenseMatTranspose(lap, subspace, n, subspaceDim);
41295
+ const matrix = multDenseMat(subspace, tmpMat, subspaceDim, n, subspaceDim);
41296
+ const iterations = optimizeLayout({
41297
+ n,
41298
+ dim,
41299
+ subspaceDim,
41300
+ subspace,
41301
+ distances,
41302
+ lap,
41303
+ matrix,
41304
+ directions,
41305
+ coords,
41306
+ b: new Float64Array(n),
41307
+ bRestricted: new Float64Array(subspaceDim)
41308
+ }, o);
41309
+ if (reweightGraph) restoreOldWeights(graph, n, oldWeights);
41310
+ return iterations;
41311
+ }
41312
+
41313
+ // src/layout/neato/stress-kernel.ts
41314
+ var fr7 = Math.fround;
41315
+ var SMART_SUBSPACE_ITERATIONS = 50;
41316
+ var NUM_PIVOTS_STRESS = 40;
41317
+ var SMART_NOISE = 1e-6;
40363
41318
  function computeApspPacked2(graph, n) {
40364
41319
  const Dij = new Float32Array(n * (n + 1) / 2);
40365
41320
  const Di = new Int32Array(n);
@@ -40383,6 +41338,7 @@ function initLayout(n, dim, coords, nodes) {
40383
41338
  if (hasPos2(np)) {
40384
41339
  coords[0][i] = np.info.pos?.[0] ?? 0;
40385
41340
  coords[1][i] = np.info.pos?.[1] ?? 0;
41341
+ for (let d = 2; d < dim; d++) coords[d][i] = np.info.pos?.[d] ?? 0;
40386
41342
  if (isFixed(np)) pinned = true;
40387
41343
  } else {
40388
41344
  coords[0][i] = drand48();
@@ -40432,7 +41388,7 @@ function buildLap1(lap1, lap2, coords, shape) {
40432
41388
  for (let k = 0; k < dim; k++) {
40433
41389
  const ck = coords[k];
40434
41390
  for (let x = 0; x < len; x++) {
40435
- const tmp = fr5(ck[i] + fr5(-1 * ck[i + 1 + x]));
41391
+ const tmp = fr7(ck[i] + fr7(-1 * ck[i + 1 + x]));
40436
41392
  distAccumulator[x] = ops.squareAdd(tmp, distAccumulator[x]);
40437
41393
  }
40438
41394
  }
@@ -40445,7 +41401,7 @@ function buildLap1(lap1, lap2, coords, shape) {
40445
41401
  let degree = 0;
40446
41402
  if (exp === 2) {
40447
41403
  for (let j = 0; j < len; j++, count++) {
40448
- const val2 = lap1[count] = fr5(lap1[count] * distAccumulator[j]);
41404
+ const val2 = lap1[count] = fr7(lap1[count] * distAccumulator[j]);
40449
41405
  degree += val2;
40450
41406
  degrees[i + j + 1] = degrees[i + j + 1] - val2;
40451
41407
  }
@@ -40490,19 +41446,50 @@ function solveAxis(st, k, havePinned, nodes) {
40490
41446
  }
40491
41447
  return 0;
40492
41448
  }
41449
+ function smartLayout(smart, n, dCoords, o) {
41450
+ const { dim } = o;
41451
+ const iterations = sparseStressSubspaceMajorizationKD(smart.graph, n, dCoords, {
41452
+ dim,
41453
+ exp: o.opts & OPT_EXP_FLAG,
41454
+ reweightGraph: smart.reweightGraph,
41455
+ nIterations: SMART_SUBSPACE_ITERATIONS,
41456
+ numCenters: NUM_PIVOTS_STRESS,
41457
+ epsilon: o.epsilon
41458
+ });
41459
+ if (iterations < 0) return -1;
41460
+ for (let i = 0; i < dim; i++) {
41461
+ const c = dCoords[i];
41462
+ let max = 1;
41463
+ for (let j = 0; j < n; j++) {
41464
+ if (Math.abs(c[j]) > max) max = Math.abs(c[j]);
41465
+ }
41466
+ for (let j = 0; j < n; j++) c[j] = c[j] / max;
41467
+ for (let j = 0; j < n; j++) c[j] = fma(drand48() - 0.5, SMART_NOISE, c[j]);
41468
+ orthog1(n, c);
41469
+ }
41470
+ return 0;
41471
+ }
41472
+ function initialLayout(n, dCoords, nodes, o) {
41473
+ if (o.smart !== void 0 && (o.opts & OPT_SMART_INIT) !== 0 && n > 1) {
41474
+ return smartLayout(o.smart, n, dCoords, o);
41475
+ }
41476
+ return initLayout(n, o.dim, dCoords, nodes) ? 1 : 0;
41477
+ }
40493
41478
  function stressMajorizationKDMkernel(Dij, n, dCoords, nodes, o) {
40494
41479
  const { dim, maxi } = o;
40495
41480
  const exp = o.opts & OPT_EXP_FLAG;
40496
41481
  if (maxi < 0) return 0;
40497
- const havePinned = initLayout(n, dim, dCoords, nodes);
41482
+ const layout2 = initialLayout(n, dCoords, nodes, o);
41483
+ if (layout2 < 0) return -1;
41484
+ const havePinned = layout2 === 1;
40498
41485
  if (n === 1 || maxi === 0) return 0;
40499
41486
  const coords = [];
40500
41487
  for (let i = 0; i < dim; i++) {
40501
41488
  const c = new Float32Array(n);
40502
- for (let j = 0; j < n; j++) c[j] = fr5(dCoords[i][j]);
41489
+ for (let j = 0; j < n; j++) c[j] = fr7(dCoords[i][j]);
40503
41490
  coords.push(c);
40504
41491
  }
40505
- const constantTerm = fr5(n * (n - 1) / 2);
41492
+ const constantTerm = fr7(n * (n - 1) / 2);
40506
41493
  const lap2 = Dij;
40507
41494
  buildLap2(lap2, n, exp);
40508
41495
  const lapLength = n * (n + 1) / 2;
@@ -40524,7 +41511,6 @@ function stressMajorizationKDMkernel(Dij, n, dCoords, nodes, o) {
40524
41511
  for (; iterations < maxi && !converged; iterations++) {
40525
41512
  buildLap1(st.lap1, lap2, coords, { n, dim, exp, ops: st.ops });
40526
41513
  const newStress = computeStress(st);
40527
- if (typeof process !== "undefined" && process.env["STRESS_DEBUG"] && iterations % 5 === 0) console.error(newStress.toFixed(3));
40528
41514
  const change = Math.abs(oldStress - newStress);
40529
41515
  converged = change / oldStress < o.epsilon || newStress < o.epsilon;
40530
41516
  oldStress = newStress;
@@ -40642,7 +41628,7 @@ function stressModelDij(graph, n, model) {
40642
41628
  }
40643
41629
 
40644
41630
  // src/layout/neato/constrained-majorization.ts
40645
- var fr6 = Math.fround;
41631
+ var fr8 = Math.fround;
40646
41632
  var LOCAL_CONSTR_MAJOR_ITERATIONS = 15;
40647
41633
  var LEVELS_SEP_TOL = 0.1;
40648
41634
  var ABS_TOL = 0.01;
@@ -40651,18 +41637,15 @@ var FLT_MAX3 = 34028234663852886e22;
40651
41637
  var DBL_MAX = Number.MAX_VALUE;
40652
41638
  var MIN_LEVELS = 1;
40653
41639
  var Y_AXIS = 1;
40654
- function unsupported2(what) {
40655
- throw new RenderError(`hierarchical stress majorization: ${what} is not supported yet`, "UNSUPPORTED_FEATURE");
40656
- }
40657
41640
  function unconstrainedMajorization(graph, n, dCoords, nodes, o) {
40658
41641
  if (o.maxi < 0) return 0;
40659
41642
  const Dij = stressModelDij(graph, n, o.model);
40660
- if ((o.opts & OPT_SMART_INIT) !== 0 && n > 1) unsupported2("the smart initial layout");
40661
41643
  return stressMajorizationKDMkernel(Dij, n, dCoords, nodes, {
40662
41644
  dim: o.dim,
40663
41645
  opts: o.opts,
40664
41646
  maxi: o.maxi,
40665
- epsilon: o.epsilon
41647
+ epsilon: o.epsilon,
41648
+ smart: { graph, reweightGraph: o.model === MODEL_SUBSET2 }
40666
41649
  });
40667
41650
  }
40668
41651
  function hasDirectionality(graph, n) {
@@ -40710,14 +41693,6 @@ function plainInitLayers(graph, n, dCoords, nodes, dim) {
40710
41693
  const h = computeHierarchy(graph, n, ABS_TOL, LEVELS_SEP_TOL, null);
40711
41694
  return h === null ? -1 : h;
40712
41695
  }
40713
- function distanceKD(coords, dim, i, j) {
40714
- let sum = 0;
40715
- for (let k = 0; k < dim; k++) {
40716
- const d = coords[k][i] - coords[k][j];
40717
- sum = fma(d, d, sum);
40718
- }
40719
- return Math.sqrt(sum);
40720
- }
40721
41696
  function scaleDownLayout(dCoords, n, dim) {
40722
41697
  let max = 1;
40723
41698
  for (let i = 0; i < dim; i++) {
@@ -40740,7 +41715,7 @@ function scaleDistances(Dij, dCoords, n, dim) {
40740
41715
  sum2 += distanceKD(dCoords, dim, i, j) / Dij[count];
40741
41716
  }
40742
41717
  }
40743
- const scaleRatio = fr6(sum2 / sum1);
41718
+ const scaleRatio = fr8(sum2 / sum1);
40744
41719
  for (let i = 0; i < length; i++) Dij[i] = Dij[i] * scaleRatio;
40745
41720
  }
40746
41721
  function centerLayout(dCoords, n, dim) {
@@ -40796,7 +41771,7 @@ function buildLap12(st) {
40796
41771
  count++;
40797
41772
  let degree = 0;
40798
41773
  for (let j = 0; j < len; j++, count++) {
40799
- const val2 = fr6(lap1[count] * distAccumulator[j]);
41774
+ const val2 = fr8(lap1[count] * distAccumulator[j]);
40800
41775
  lap1[count] = val2;
40801
41776
  degree += val2;
40802
41777
  degrees[i + j + 1] -= val2;
@@ -42349,8 +43324,8 @@ function genYConstraints(rects, vs) {
42349
43324
  }
42350
43325
 
42351
43326
  // src/layout/neato/quad-prog-vpsc-overlap.ts
42352
- var fr7 = Math.fround;
42353
- var X_GROWTH = fr7(1.0001);
43327
+ var fr9 = Math.fround;
43328
+ var X_GROWTH = fr9(1.0001);
42354
43329
  var BOUNDARY_WIDTH = 1e-4;
42355
43330
  var TMP_CLUSTER_VAR_ID = 123;
42356
43331
  function copyBox(b) {
@@ -42496,7 +43471,7 @@ function generateNonoverlapConstraints(e, a) {
42496
43471
  n -= 2 * a.opt.clusters.nclusters;
42497
43472
  }
42498
43473
  if (a.k === 0) {
42499
- nsizeScale = fr7(nsizeScale * X_GROWTH);
43474
+ nsizeScale = fr9(nsizeScale * X_GROWTH);
42500
43475
  }
42501
43476
  const bb = nodeBoxes(n, nsizeScale, a);
42502
43477
  let csol;
@@ -42559,15 +43534,15 @@ function getNumDigcolaConstraints(levels, numLevels) {
42559
43534
  }
42560
43535
 
42561
43536
  // src/layout/neato/quad-prog-vpsc.ts
42562
- var fr8 = Math.fround;
43537
+ var fr10 = Math.fround;
42563
43538
  var QUAD_PROG_TOL = 1e-4;
42564
43539
  var DUMMY_WEIGHT = 1e-6;
42565
43540
  var VECTOR_BLOCK = 4;
42566
43541
  function rowReduce(row, factor, v, n, acc) {
42567
43542
  const blocked = n - n % VECTOR_BLOCK;
42568
43543
  let j = 0;
42569
- for (; j < blocked; j++) acc = fr8(acc + fr8(fr8(factor * row[j]) * v[j]));
42570
- for (; j < n; j++) acc = fmaf(fr8(factor * row[j]), v[j], acc);
43544
+ for (; j < blocked; j++) acc = fr10(acc + fr10(fr10(factor * row[j]) * v[j]));
43545
+ for (; j < n; j++) acc = fmaf(fr10(factor * row[j]), v[j], acc);
42571
43546
  return acc;
42572
43547
  }
42573
43548
  function project(e, place, n) {
@@ -42585,7 +43560,7 @@ function descentStep(e, b, place, n) {
42585
43560
  const oldPlace = e.fArray2;
42586
43561
  for (let i = 0; i < n; i++) {
42587
43562
  oldPlace[i] = place[i];
42588
- g[i] = rowReduce(A3[i], -2, place, n, fr8(2 * b[i]));
43563
+ g[i] = rowReduce(A3[i], -2, place, n, fr10(2 * b[i]));
42589
43564
  }
42590
43565
  let numerator = 0;
42591
43566
  let denominator = 0;
@@ -42594,7 +43569,7 @@ function descentStep(e, b, place, n) {
42594
43569
  const r = rowReduce(A3[i], 2, g, n, 0);
42595
43570
  denominator = fmaf(-r, g[i], denominator);
42596
43571
  }
42597
- return denominator !== 0 ? -fr8(numerator / denominator) : -1;
43572
+ return denominator !== 0 ? -fr10(numerator / denominator) : -1;
42598
43573
  }
42599
43574
  function lineSearchBeta(e, place, n) {
42600
43575
  const A3 = e.A;
@@ -42602,7 +43577,7 @@ function lineSearchBeta(e, place, n) {
42602
43577
  const oldPlace = e.fArray2;
42603
43578
  const d = e.fArray3;
42604
43579
  for (let i = 0; i < n; i++) {
42605
- d[i] = fr8(place[i] - oldPlace[i]);
43580
+ d[i] = fr10(place[i] - oldPlace[i]);
42606
43581
  }
42607
43582
  let numerator = 0;
42608
43583
  let denominator = 0;
@@ -42611,7 +43586,7 @@ function lineSearchBeta(e, place, n) {
42611
43586
  const r = rowReduce(A3[i], 2, d, n, 0);
42612
43587
  denominator = fmaf(r, d[i], denominator);
42613
43588
  }
42614
- if (!Object.is(denominator, 0) && !Object.is(denominator, -0)) return fr8(numerator / denominator);
43589
+ if (!Object.is(denominator, 0) && !Object.is(denominator, -0)) return fr10(numerator / denominator);
42615
43590
  return 1;
42616
43591
  }
42617
43592
  function applyBeta(e, place, n, beta) {
@@ -42622,7 +43597,7 @@ function applyBeta(e, place, n, beta) {
42622
43597
  if (beta > 0 && beta < 1) {
42623
43598
  place[i] = fmaf(beta, d[i], oldPlace[i]);
42624
43599
  }
42625
- test = fr8(test + fr8(Math.abs(place[i] - oldPlace[i])));
43600
+ test = fr10(test + fr10(Math.abs(place[i] - oldPlace[i])));
42626
43601
  }
42627
43602
  return test;
42628
43603
  }
@@ -42768,11 +43743,11 @@ function deleteCMajEnvVPSC(e) {
42768
43743
  }
42769
43744
 
42770
43745
  // src/layout/neato/stress-cola.ts
42771
- var fr9 = Math.fround;
43746
+ var fr11 = Math.fround;
42772
43747
  var LOCAL_CONSTR_MAJOR_ITERATIONS2 = 1e3;
42773
43748
  var FLT_MAX4 = 34028234663852886e22;
42774
- var CLUSTER_WEIGHT_FLOOR = fr9(0.01);
42775
- var STRESS_GUARD = 1e-10;
43749
+ var CLUSTER_WEIGHT_FLOOR = fr11(0.01);
43750
+ var STRESS_GUARD2 = 1e-10;
42776
43751
  var NSIZE_SCALE_STEP = 0.1;
42777
43752
  var NSIZE_SCALE_LIMIT = 0.999;
42778
43753
  var NSIZE_SCALE_ACTIVE = 1e-3;
@@ -42783,7 +43758,7 @@ function maxEdgeLength(graph, n) {
42783
43758
  let maxEdgeLen = 0;
42784
43759
  for (let i = 0; i < n; i++) {
42785
43760
  for (let j = 1; j < graph[i].nedges; j++) {
42786
- maxEdgeLen = fr9(Math.max(graph[i].ewgts[j], maxEdgeLen));
43761
+ maxEdgeLen = fr11(Math.max(graph[i].ewgts[j], maxEdgeLen));
42787
43762
  }
42788
43763
  }
42789
43764
  return maxEdgeLen;
@@ -42835,8 +43810,8 @@ function clusterLaplacian(lap2, n, nclusters, maxEdgeLen) {
42835
43810
  if (i < n && j < n - i) {
42836
43811
  v = lap2[c0++];
42837
43812
  } else if (j === 1 && i % 2 === 1) {
42838
- v = fr9(maxEdgeLen * maxEdgeLen);
42839
- if (v > CLUSTER_WEIGHT_FLOOR) v = fr9(1 / v);
43813
+ v = fr11(maxEdgeLen * maxEdgeLen);
43814
+ if (v > CLUSTER_WEIGHT_FLOOR) v = fr11(1 / v);
42840
43815
  } else {
42841
43816
  v = 0;
42842
43817
  }
@@ -42894,7 +43869,7 @@ function colaState(Dij, origN, dCoords, o, maxEdgeLen) {
42894
43869
  degrees,
42895
43870
  coords: floatCoords(dCoords, o.dim, n, origN),
42896
43871
  /* compute constant term in stress sum which is \sum_{i<j} w_{ij}d_{ij}^2 */
42897
- constantTerm: fr9(n * (n - 1) / 2),
43872
+ constantTerm: fr11(n * (n - 1) / 2),
42898
43873
  b: Array.from({ length: o.dim }, () => new Float32Array(n)),
42899
43874
  tmpCoords: new Float32Array(n),
42900
43875
  distAccumulator: new Float32Array(n)
@@ -42926,7 +43901,7 @@ function buildLap13(st) {
42926
43901
  count++;
42927
43902
  let degree = 0;
42928
43903
  for (let j = 0; j < len; j++, count++) {
42929
- const val2 = lap1[count] = fr9(lap1[count] * st.distAccumulator[j]);
43904
+ const val2 = lap1[count] = fr11(lap1[count] * st.distAccumulator[j]);
42930
43905
  degree += val2;
42931
43906
  degrees[i + j + 1] = degrees[i + j + 1] - val2;
42932
43907
  }
@@ -42961,7 +43936,7 @@ var overlapDue = (opt, nsizeScale) => opt.noverlap === NOVERLAP_CONSTRAINTS && n
42961
43936
  function solveHorizontal(st, e, nsizeScale, opt) {
42962
43937
  if (overlapDue(opt, nsizeScale)) {
42963
43938
  generateNonoverlapConstraints(e, {
42964
- nsizeScale: fr9(nsizeScale),
43939
+ nsizeScale: fr11(nsizeScale),
42965
43940
  coords: st.coords,
42966
43941
  k: 0,
42967
43942
  transitiveClosure: nsizeScale >= TRANSITIVE_CLOSURE_SCALE,
@@ -42980,7 +43955,7 @@ function solveHorizontal(st, e, nsizeScale, opt) {
42980
43955
  }
42981
43956
  function solveVertical(st, e, nsizeScale, opt) {
42982
43957
  if (overlapDue(opt, nsizeScale)) {
42983
- generateNonoverlapConstraints(e, { nsizeScale: fr9(nsizeScale), coords: st.coords, k: 1, transitiveClosure: false, opt });
43958
+ generateNonoverlapConstraints(e, { nsizeScale: fr11(nsizeScale), coords: st.coords, k: 1, transitiveClosure: false, opt });
42984
43959
  }
42985
43960
  if (e.m > 0) {
42986
43961
  if (constrainedMajorizationVpsc(e, st.b[1], st.coords[1], LOCAL_CONSTR_MAJOR_ITERATIONS2) < 0) return -1;
@@ -42989,13 +43964,13 @@ function solveVertical(st, e, nsizeScale, opt) {
42989
43964
  }
42990
43965
  return 0;
42991
43966
  }
42992
- function iterate(st, envs, o, observe) {
43967
+ function iterate2(st, envs, o, observe) {
42993
43968
  const s = { iterations: 0, converged: false, oldStress: Number.MAX_VALUE, nsizeScale: 0 };
42994
43969
  for (; s.iterations < o.maxi && !s.converged; s.iterations++) {
42995
43970
  buildLap13(st);
42996
43971
  const newStress = computeStress2(st);
42997
43972
  observe?.(newStress);
42998
- s.converged = newStress < s.oldStress && Math.abs(newStress - s.oldStress) / Math.abs(s.oldStress + STRESS_GUARD) < o.epsilon;
43973
+ s.converged = newStress < s.oldStress && Math.abs(newStress - s.oldStress) / Math.abs(s.oldStress + STRESS_GUARD2) < o.epsilon;
42999
43974
  s.oldStress = newStress;
43000
43975
  scaleUpNodes(s, o.maxi, o.opt);
43001
43976
  if (solveHorizontal(st, envs.hor, s.nsizeScale, o.opt) < 0) return -1;
@@ -43009,7 +43984,7 @@ function optimize(st, graph, o, observe) {
43009
43984
  const vrt = initCMajVPSC(st.n, st.lap2, graph, o.opt, o.opt.diredges);
43010
43985
  if (vrt === null) return -1;
43011
43986
  st.lap1 = new Float32Array(st.lapLength);
43012
- const iterations = iterate(st, { hor, vrt }, o, observe);
43987
+ const iterations = iterate2(st, { hor, vrt }, o, observe);
43013
43988
  if (iterations < 0) return iterations;
43014
43989
  deleteCMajEnvVPSC(hor);
43015
43990
  deleteCMajEnvVPSC(vrt);
@@ -43114,7 +44089,7 @@ function realEdges(de) {
43114
44089
  function isNewEdge(de) {
43115
44090
  return de.info.alg === void 0;
43116
44091
  }
43117
- function addEdge2(de, e) {
44092
+ function addEdge3(de, e) {
43118
44093
  const el = de.info.alg;
43119
44094
  if (el === void 0) {
43120
44095
  de.info.alg = [e];
@@ -43662,10 +44637,10 @@ var Cdt = class {
43662
44637
  }
43663
44638
  /** gts_point_locate (guess=NULL): closest_face + barycenter walk. */
43664
44639
  pointLocate(x, y) {
43665
- const guess = this.closestFace(x, y);
43666
- if (guess === null) return null;
43667
- const [bx, by] = this.barycenter(guess);
43668
- return this.pointLocateWalk(bx, by, x, y, guess);
44640
+ const guess2 = this.closestFace(x, y);
44641
+ if (guess2 === null) return null;
44642
+ const [bx, by] = this.barycenter(guess2);
44643
+ return this.pointLocateWalk(bx, by, x, y, guess2);
43669
44644
  }
43670
44645
  // -------------------------------------------------------------------
43671
44646
  // Delaunay insertion (cdt.c: swap_if_in_circle, add_vertex_to_face)
@@ -47542,10 +48517,19 @@ var SMOOTHING_NONE = 0;
47542
48517
  var INT_MAX2 = 2147483647;
47543
48518
  var ELSCHEME_PENALTY2 = 2;
47544
48519
  var EDGE_LABEL_NODE_PREFIX = "|edgelabel|";
48520
+ function sfdpInitDim(g) {
48521
+ const root = g.root;
48522
+ const outdim = lateInt(aggetGraph(g, "dimen"), DFLT_DIM, 2);
48523
+ const ndim = Math.min(lateInt(aggetGraph(g, "dim"), outdim, 2), MAXDIM);
48524
+ root.info.ndim = ndim;
48525
+ root.info.odim = Math.min(outdim, ndim);
48526
+ return ndim;
48527
+ }
47545
48528
  function sfdpInitGraph(g) {
47546
48529
  setEdgeTypeFromAttr(g, EDGETYPE_LINE);
48530
+ const ndim = sfdpInitDim(g);
47547
48531
  commonInitNodeEdge(g);
47548
- for (const n of g.nodes.values()) neatoInitNode(n);
48532
+ for (const n of g.nodes.values()) neatoInitNode(n, ndim);
47549
48533
  const measurer = layoutMeasurer(g);
47550
48534
  if (measurer !== void 0) {
47551
48535
  for (const n of g.nodes.values()) {
@@ -47662,12 +48646,12 @@ function makeMatrix(g) {
47662
48646
  MATRIX_TYPE_REAL
47663
48647
  );
47664
48648
  }
47665
- function getSizes(g, pad) {
47666
- const sizes = new Array(2 * g.nodes.size).fill(0);
48649
+ function getSizes(g, pad, ndim = DFLT_DIM) {
48650
+ const sizes = new Array(ndim * g.nodes.size).fill(0);
47667
48651
  for (const n of g.nodes.values()) {
47668
48652
  const i = n.info.id;
47669
- sizes[i * 2] = (n.info.width ?? 0) * 0.5 + pad.x;
47670
- sizes[i * 2 + 1] = (n.info.height ?? 0) * 0.5 + pad.y;
48653
+ sizes[i * ndim] = (n.info.width ?? 0) * 0.5 + pad.x;
48654
+ sizes[i * ndim + 1] = (n.info.height ?? 0) * 0.5 + pad.y;
47671
48655
  }
47672
48656
  return sizes;
47673
48657
  }
@@ -48599,7 +49583,7 @@ var AM_PORTHOYX = 12;
48599
49583
  var SCALE = 10;
48600
49584
  var SCALE2 = SCALE / 2;
48601
49585
  var INT_MAX3 = 2147483647;
48602
- var POINTS_PER_INCH4 = 72;
49586
+ var POINTS_PER_INCH6 = 72;
48603
49587
  function cmpitem(a, b) {
48604
49588
  if (a < b) return -1;
48605
49589
  if (a > b) return 1;
@@ -48827,18 +49811,18 @@ function overlaps(p) {
48827
49811
  return false;
48828
49812
  }
48829
49813
  function initItem(n, margin) {
48830
- const x = cround(SCALE * (n.info.pos?.[0] ?? 0) * POINTS_PER_INCH4);
48831
- const y = cround(SCALE * (n.info.pos?.[1] ?? 0) * POINTS_PER_INCH4);
49814
+ const x = cround(SCALE * (n.info.pos?.[0] ?? 0) * POINTS_PER_INCH6);
49815
+ const y = cround(SCALE * (n.info.pos?.[1] ?? 0) * POINTS_PER_INCH6);
48832
49816
  const width2 = n.info.width ?? 0;
48833
49817
  const height2 = n.info.height ?? 0;
48834
49818
  let w2;
48835
49819
  let h2;
48836
49820
  if (margin.doAdd) {
48837
- w2 = d2i(SCALE * (cround(width2 / 2 * POINTS_PER_INCH4) + margin.x));
48838
- h2 = d2i(SCALE * (cround(height2 / 2 * POINTS_PER_INCH4) + margin.y));
49821
+ w2 = d2i(SCALE * (cround(width2 / 2 * POINTS_PER_INCH6) + margin.x));
49822
+ h2 = d2i(SCALE * (cround(height2 / 2 * POINTS_PER_INCH6) + margin.y));
48839
49823
  } else {
48840
- w2 = cround(margin.x * SCALE2 * width2 * POINTS_PER_INCH4);
48841
- h2 = cround(margin.y * SCALE2 * height2 * POINTS_PER_INCH4);
49824
+ w2 = cround(margin.x * SCALE2 * width2 * POINTS_PER_INCH6);
49825
+ h2 = cround(margin.y * SCALE2 * height2 * POINTS_PER_INCH6);
48842
49826
  }
48843
49827
  return {
48844
49828
  val: 0,
@@ -48873,8 +49857,8 @@ function cAdjust(g, mode) {
48873
49857
  if (!overlaps(nlist)) return 0;
48874
49858
  runPlan(g, nlist, PLANS.get(mode) ?? PLANS.get(AM_PORTHO));
48875
49859
  for (const p of nlist) {
48876
- const x = p.pos.x / POINTS_PER_INCH4 / SCALE;
48877
- const y = p.pos.y / POINTS_PER_INCH4 / SCALE;
49860
+ const x = p.pos.x / POINTS_PER_INCH6 / SCALE;
49861
+ const y = p.pos.y / POINTS_PER_INCH6 / SCALE;
48878
49862
  if (p.np.info.pos) {
48879
49863
  p.np.info.pos[0] = x;
48880
49864
  p.np.info.pos[1] = y;
@@ -48889,10 +49873,10 @@ function cAdjust(g, mode) {
48889
49873
  var POLY_BOX = 1;
48890
49874
  var POLY_CIRCLE = 2;
48891
49875
  var DFLT_SAMPLE2 = 20;
48892
- var POINTS_PER_INCH5 = 72;
49876
+ var POINTS_PER_INCH7 = 72;
48893
49877
  var MIN_SAMPLES = 3;
48894
49878
  function ps2inch2(a) {
48895
- return a / POINTS_PER_INCH5;
49879
+ return a / POINTS_PER_INCH7;
48896
49880
  }
48897
49881
  function isBoxKind(p) {
48898
49882
  return (p.kind & POLY_BOX) !== 0;
@@ -49185,7 +50169,7 @@ function polyOverlap(p, pp, q, qp) {
49185
50169
  // src/layout/neato/adjust-info.ts
49186
50170
  var DEFAULT_VORO_MARGIN = 0.05;
49187
50171
  var INCR = 0.05;
49188
- var POINTS_PER_INCH6 = 72;
50172
+ var POINTS_PER_INCH8 = 72;
49189
50173
  function newInfoState() {
49190
50174
  return {
49191
50175
  nodeInfo: [],
@@ -49240,8 +50224,8 @@ function chkBoundBox(st, graph) {
49240
50224
  function makeInfo(st, graph) {
49241
50225
  const pmargin = { ...sepFactor(graph) };
49242
50226
  if (pmargin.doAdd) {
49243
- pmargin.x /= POINTS_PER_INCH6;
49244
- pmargin.y /= POINTS_PER_INCH6;
50227
+ pmargin.x /= POINTS_PER_INCH8;
50228
+ pmargin.y /= POINTS_PER_INCH8;
49245
50229
  }
49246
50230
  const polyf = pmargin.doAdd ? makeAddPoly : makePoly;
49247
50231
  const info = [];
@@ -49375,7 +50359,7 @@ function sAdjustGraph(g) {
49375
50359
  }
49376
50360
 
49377
50361
  // src/layout/neato/vpsc-adjust.ts
49378
- var POINTS_PER_INCH7 = 72;
50362
+ var POINTS_PER_INCH9 = 72;
49379
50363
  function noClusters() {
49380
50364
  return {
49381
50365
  nvars: 0,
@@ -49401,21 +50385,30 @@ function vpscAdjust(g) {
49401
50385
  noverlap: 2,
49402
50386
  clusters: noClusters(),
49403
50387
  gap: {
49404
- x: 2 * ((margin.doAdd ? margin.x : DFLT_MARGIN) / POINTS_PER_INCH7),
49405
- y: 2 * ((margin.doAdd ? margin.y : DFLT_MARGIN) / POINTS_PER_INCH7)
50388
+ x: 2 * ((margin.doAdd ? margin.x : DFLT_MARGIN) / POINTS_PER_INCH9),
50389
+ y: 2 * ((margin.doAdd ? margin.y : DFLT_MARGIN) / POINTS_PER_INCH9)
49406
50390
  },
49407
50391
  nsize: nodes.map((n) => ({ x: n.info.width, y: n.info.height }))
49408
50392
  };
49409
50393
  removeoverlaps(nodes.length, coords, opt);
49410
50394
  nodes.forEach((n, j) => {
49411
- n.info.pos = [coords[0][j], coords[1][j]];
50395
+ n.info.pos[0] = coords[0][j];
50396
+ n.info.pos[1] = coords[1][j];
49412
50397
  });
49413
50398
  return 0;
49414
50399
  }
49415
50400
 
49416
50401
  // src/layout/neato/fdp-adjust.ts
49417
50402
  var DFLT_MARGIN2 = 4;
49418
- var NDIM2 = 2;
50403
+ function sizesByNdim(sizes2, ndim) {
50404
+ if (ndim === 2) return sizes2;
50405
+ const sizes = new Array(sizes2.length / 2 * ndim).fill(0);
50406
+ for (let i = 0; i < sizes2.length / 2; i++) {
50407
+ sizes[i * ndim] = sizes2[i * 2];
50408
+ sizes[i * ndim + 1] = sizes2[i * 2 + 1];
50409
+ }
50410
+ return sizes;
50411
+ }
49419
50412
  function mapBoolDflt(p, defaultValue) {
49420
50413
  if (p === void 0 || p === "") return defaultValue;
49421
50414
  const s = p.toLowerCase();
@@ -49457,14 +50450,14 @@ function overlapPrismTries(flag) {
49457
50450
  }
49458
50451
  function fdpAdjust(g, ntry) {
49459
50452
  const A0 = makeMatrix(g);
49460
- const pos = new Array(NDIM2 * g.nodes.size).fill(0);
50453
+ const ndim = ndimOf(g);
50454
+ const pos = new Array(ndim * g.nodes.size).fill(0);
49461
50455
  const sep = sepFactor(g);
49462
50456
  const pad = sep.doAdd ? { x: sep.x / 72, y: sep.y / 72 } : { x: DFLT_MARGIN2 / 72, y: DFLT_MARGIN2 / 72 };
49463
- const sizes = getSizes(g, pad);
50457
+ const sizes = sizesByNdim(getSizes(g, pad), ndim);
49464
50458
  for (const n of g.nodes.values()) {
49465
50459
  const i = n.info.id;
49466
- pos[i * NDIM2] = n.info.pos?.[0] ?? 0;
49467
- pos[i * NDIM2 + 1] = n.info.pos?.[1] ?? 0;
50460
+ for (let k = 0; k < ndim; k++) pos[i * ndim + k] = n.info.pos?.[k] ?? 0;
49468
50461
  }
49469
50462
  const A3 = !smIsSymmetric(A0, false) || A0.type !== MATRIX_TYPE_REAL ? smGetRealAdjacencySymmetrized(A0) : smRemoveDiagonal(A0);
49470
50463
  const scaling = lateDouble(
@@ -49476,12 +50469,11 @@ function fdpAdjust(g, ntry) {
49476
50469
  g.attrs.get("overlap_shrink") ?? g.root.attrs.get("overlap_shrink"),
49477
50470
  true
49478
50471
  );
49479
- removeOverlapPrism(NDIM2, A3, pos, sizes, ntry, scaling, doShrinking);
50472
+ removeOverlapPrism(ndim, A3, pos, sizes, ntry, scaling, doShrinking);
49480
50473
  for (const n of g.nodes.values()) {
49481
50474
  const i = n.info.id;
49482
50475
  if (!n.info.pos) n.info.pos = [0, 0];
49483
- n.info.pos[0] = pos[i * NDIM2];
49484
- n.info.pos[1] = pos[i * NDIM2 + 1];
50476
+ for (let k = 0; k < ndim; k++) n.info.pos[k] = pos[i * ndim + k];
49485
50477
  }
49486
50478
  }
49487
50479
  var AM_NONE = 0;
@@ -49575,9 +50567,9 @@ function graphAdjustMode(g) {
49575
50567
  }
49576
50568
 
49577
50569
  // src/layout/neato/ipsep-opts.ts
49578
- var POINTS_PER_INCH8 = 72;
50570
+ var POINTS_PER_INCH10 = 72;
49579
50571
  var HIER_PREFIX = "hier";
49580
- var ps2inch3 = (points2) => points2 / POINTS_PER_INCH8;
50572
+ var ps2inch3 = (points2) => points2 / POINTS_PER_INCH10;
49581
50573
  var zeroBox = () => ({ ll: { x: 0, y: 0 }, ur: { x: 0, y: 0 } });
49582
50574
  function memberIndices(subg, nodes) {
49583
50575
  const members = nodesInSeq(subg);
@@ -49656,19 +50648,8 @@ function ipsepOptions(mg, g, nodes, am) {
49656
50648
  return { diredges, edgeGap, noverlap, gap, nsize, clusters };
49657
50649
  }
49658
50650
 
49659
- // src/common/utils-inputscale.ts
49660
- var POINTS_PER_INCH9 = 72;
49661
- function getInputscale(g) {
49662
- const d = lateDouble(g.root.attrs.get("inputscale"), -1, 0);
49663
- return d === 0 ? POINTS_PER_INCH9 : d;
49664
- }
49665
- function inputscaleDivisor(g) {
49666
- const sc = getInputscale(g);
49667
- return sc > 0 ? sc : 1;
49668
- }
49669
-
49670
50651
  // src/layout/neato/set-aspect.ts
49671
- var POINTS_PER_INCH10 = 72;
50652
+ var POINTS_PER_INCH11 = 72;
49672
50653
  function neatoRatioKind(g) {
49673
50654
  const p = g.attrs.get("ratio");
49674
50655
  if (p === void 0) return null;
@@ -49716,8 +50697,8 @@ function neatoTranslate(g) {
49716
50697
  const bb = g.info.bb;
49717
50698
  if (!bb) return;
49718
50699
  const ll = bb.ll;
49719
- const ox = ll.x / POINTS_PER_INCH10;
49720
- const oy = ll.y / POINTS_PER_INCH10;
50700
+ const ox = ll.x / POINTS_PER_INCH11;
50701
+ const oy = ll.y / POINTS_PER_INCH11;
49721
50702
  for (const n of g.nodes.values()) {
49722
50703
  if (!n.info.pos) n.info.pos = [0, 0];
49723
50704
  n.info.pos[0] = (n.info.pos[0] ?? 0) - ox;
@@ -49802,8 +50783,7 @@ var MODEL_SHORTPATH2 = 0;
49802
50783
  var MODEL_CIRCUIT2 = 1;
49803
50784
  var MODEL_SUBSET2 = 2;
49804
50785
  var MODEL_MDS2 = 3;
49805
- var DFLT_DIM = 2;
49806
- var POINTS_PER_INCH11 = 72;
50786
+ var POINTS_PER_INCH12 = 72;
49807
50787
  function neatoInitNode(n, dim = DFLT_DIM) {
49808
50788
  if (!n.info.pos || n.info.pos.length < dim) {
49809
50789
  const pos = [];
@@ -49815,19 +50795,6 @@ function neatoInitNode(n, dim = DFLT_DIM) {
49815
50795
  if (!n.info.width && !plainShaped) n.info.width = 0.75;
49816
50796
  if (!n.info.height && !plainShaped) n.info.height = 0.5;
49817
50797
  }
49818
- function userPos(n) {
49819
- const p = n.attrs.get("pos");
49820
- if (p === void 0 || p.length === 0) return false;
49821
- const num2 = "(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)";
49822
- const m = new RegExp(`^\\s*${num2}\\s*,\\s*${num2}(.?)`).exec(p);
49823
- if (m === null) return false;
49824
- const div = inputscaleDivisor(n.root);
49825
- n.info.pos = [Number(m[1]) / div, Number(m[2]) / div];
49826
- n.info.posSet = true;
49827
- const pin = n.attrs.get("pin");
49828
- if (m[3] === "!" || pin !== void 0 && mapbool(pin)) n.info.pinned = true;
49829
- return true;
49830
- }
49831
50798
  function assignNodeIds2(g) {
49832
50799
  const nodeList = [];
49833
50800
  let idx = 0;
@@ -49847,10 +50814,11 @@ function solveStress(c, vtx, dCoords, nodeList) {
49847
50814
  const { g, mode, model, opts } = c;
49848
50815
  const n = nodeList.length;
49849
50816
  const maxi = neatoMaxIter(g.attrs.get("maxiter"), mode, n);
50817
+ const dim = ndimOf(g);
49850
50818
  const epsilon = lateDouble(g.attrs.get("epsilon"), 1e-4, 0);
49851
50819
  if (mode === MODE_HIER) {
49852
50820
  return stressMajorizationWithHierarchy(vtx, n, dCoords, nodeList, {
49853
- dim: DFLT_DIM,
50821
+ dim,
49854
50822
  opts,
49855
50823
  model,
49856
50824
  maxi,
@@ -49861,7 +50829,7 @@ function solveStress(c, vtx, dCoords, nodeList) {
49861
50829
  if (mode === MODE_IPSEP) {
49862
50830
  const opt = ipsepOptions(g.root, g, nodeList, c.am);
49863
50831
  return stressMajorizationCola(vtx, n, dCoords, nodeList, {
49864
- dim: DFLT_DIM,
50832
+ dim,
49865
50833
  model,
49866
50834
  maxi,
49867
50835
  epsilon,
@@ -49870,7 +50838,7 @@ function solveStress(c, vtx, dCoords, nodeList) {
49870
50838
  }
49871
50839
  const Dij = stressModelDij(vtx, n, model);
49872
50840
  return stressMajorizationKDMkernel(Dij, n, dCoords, nodeList, {
49873
- dim: DFLT_DIM,
50841
+ dim,
49874
50842
  opts,
49875
50843
  maxi,
49876
50844
  epsilon
@@ -49885,13 +50853,14 @@ function runMajorization(g, mode, model, am) {
49885
50853
  const opts = checkExp(g) | (init === INIT_SELF ? OPT_SMART_INIT : 0);
49886
50854
  const haveDir = mode === MODE_HIER || mode === MODE_IPSEP;
49887
50855
  const vtx = makeGraphDataC(g, nodeList, haveLen, haveDir, mode);
49888
- const dCoords = [new Float64Array(n), new Float64Array(n)];
50856
+ const ndim = ndimOf(g);
50857
+ const dCoords = Array.from({ length: ndim }, () => new Float64Array(n));
49889
50858
  if (solveStress({ g, mode, model, opts, am }, vtx, dCoords, nodeList) < 0) {
49890
50859
  agerr("prev", "layout aborted");
49891
50860
  return;
49892
50861
  }
49893
50862
  for (let i = 0; i < n; i++) {
49894
- nodeList[i].info.pos = [dCoords[0][i], dCoords[1][i]];
50863
+ nodeList[i].info.pos = dCoords.map((c) => c[i]);
49895
50864
  }
49896
50865
  }
49897
50866
  var NO_ADJUST = { mode: AM_NONE, print: "none", value: 0 };
@@ -49914,8 +50883,8 @@ function neatoSetAspect(g) {
49914
50883
  const pos = n.info.pos;
49915
50884
  if (!pos) continue;
49916
50885
  n.info.coord = {
49917
- x: (pos[0] ?? 0) * POINTS_PER_INCH11,
49918
- y: (pos[1] ?? 0) * POINTS_PER_INCH11
50886
+ x: (pos[0] ?? 0) * POINTS_PER_INCH12,
50887
+ y: (pos[1] ?? 0) * POINTS_PER_INCH12
49919
50888
  };
49920
50889
  }
49921
50890
  }
@@ -49931,7 +50900,7 @@ function neatoCleanup(g) {
49931
50900
  }
49932
50901
 
49933
50902
  // src/layout/twopi/init.ts
49934
- var POINTS_PER_INCH12 = 72;
50903
+ var POINTS_PER_INCH13 = 72;
49935
50904
  function makeRdata(INF) {
49936
50905
  return {
49937
50906
  kind: "twopi",
@@ -49983,8 +50952,8 @@ function finaliseCoords(g) {
49983
50952
  const pos = n.info.pos;
49984
50953
  if (!pos) continue;
49985
50954
  n.info.coord = {
49986
- x: (pos[0] ?? 0) * POINTS_PER_INCH12,
49987
- y: (pos[1] ?? 0) * POINTS_PER_INCH12
50955
+ x: (pos[0] ?? 0) * POINTS_PER_INCH13,
50956
+ y: (pos[1] ?? 0) * POINTS_PER_INCH13
49988
50957
  };
49989
50958
  }
49990
50959
  }
@@ -50220,7 +51189,10 @@ function circleLayout(sg, center) {
50220
51189
  if (center === null) center = findCenterNode(sg);
50221
51190
  if (center === null) return null;
50222
51191
  const maxN = setParentNodes(sg, center);
50223
- if (maxN === Number.MAX_SAFE_INTEGER) return center;
51192
+ if (maxN === Number.MAX_SAFE_INTEGER) {
51193
+ agerrorf("twopi: use of weight=0 creates disconnected component.");
51194
+ return center;
51195
+ }
50224
51196
  setSubtreeSize(sg);
50225
51197
  setSubtreeSpans(sg, center);
50226
51198
  setPositions(sg, center);
@@ -50311,18 +51283,21 @@ function parseModel(g) {
50311
51283
  function maybeRemoveOverlap(g, am) {
50312
51284
  removeOverlapWith(g, am);
50313
51285
  }
50314
- function neatoLayout(g) {
50315
- graphInit(g, false);
50316
- setEdgeTypeFromAttr(g, EDGETYPE_LINE);
50317
- commonInitNodeEdge(g);
51286
+ function neatoInitNodeEdge(g, ndim) {
50318
51287
  for (const [, n] of g.nodes) {
50319
- neatoInitNode(n);
50320
- userPos(n);
51288
+ neatoInitNode(n, ndim);
51289
+ userPos(n, ndim, g.nodes.size);
50321
51290
  }
50322
51291
  const measurer = layoutMeasurer(g);
50323
51292
  if (measurer !== void 0) {
50324
51293
  for (const e of g.edges) initEdgeLabels(e, g, measurer);
50325
51294
  }
51295
+ }
51296
+ function neatoLayout(g) {
51297
+ graphInit(g, false);
51298
+ setEdgeTypeFromAttr(g, EDGETYPE_LINE);
51299
+ commonInitNodeEdge(g);
51300
+ neatoInitNodeEdge(g, neatoInitGraphDim(g));
50326
51301
  const mode = parseMode(g);
50327
51302
  const am = graphAdjustMode(g);
50328
51303
  const model = parseModel(g);
@@ -50334,6 +51309,7 @@ function neatoLayout(g) {
50334
51309
  maybeRemoveOverlap(g, am);
50335
51310
  splineEdgesShifted(g);
50336
51311
  }
51312
+ addZ(g);
50337
51313
  addClusters(g);
50338
51314
  g.info.bb = computeSubgraphBB(g, 0);
50339
51315
  placeGraphLabel(g);
@@ -50525,127 +51501,6 @@ function initParams(g, xpms) {
50525
51501
  return ret;
50526
51502
  }
50527
51503
 
50528
- // src/layout/fdp/cluster-edges.ts
50529
- function fillMap(g, map) {
50530
- const n = g.info.n_cluster ?? 0;
50531
- for (let c = 0; c < n; c++) {
50532
- const cl = g.info.clust[c];
50533
- const s = cl.name;
50534
- if (!map.has(s)) map.set(s, cl);
50535
- fillMap(cl, map);
50536
- }
50537
- }
50538
- function mkClustMap2(g) {
50539
- const map = /* @__PURE__ */ new Map();
50540
- fillMap(g, map);
50541
- return map;
50542
- }
50543
- function mapc(cmap, n) {
50544
- if (n.name.startsWith("cluster")) return cmap.get(n.name) ?? null;
50545
- return null;
50546
- }
50547
- function edgeKey(t, h) {
50548
- return `${t.name}\0${h.name}`;
50549
- }
50550
- function mapEdge2(map, t, h) {
50551
- return map.get(edgeKey(t, h));
50552
- }
50553
- function insertEdge2(map, t, h, ce) {
50554
- map.set(edgeKey(t, h), { t: ce.tail, h: ce.head });
50555
- map.set(edgeKey(h, t), { t: ce.head, h: ce.tail });
50556
- }
50557
- function clustNode(n, cg, root, delSet, idx) {
50558
- const name = `__${idx.v}:${cg.name}`;
50559
- const cn = agnode(root, name, true);
50560
- cn.info.clustnode = true;
50561
- agsubnode(cg, cn, true);
50562
- delSet.add(n);
50563
- cn.attrs.set("label", "");
50564
- cn.attrs.set("style", "invis");
50565
- cn.attrs.set("shape", "box");
50566
- return cn;
50567
- }
50568
- function cloneEdge2(root, e, ct, ch) {
50569
- const ce = new Edge(ct, ch, "");
50570
- for (const [k, v] of e.attrs) ce.attrs.set(k, v);
50571
- ce.info.compound = 1;
50572
- root.edges.push(ce);
50573
- ce.graphSeq = root.edges.length;
50574
- return ce;
50575
- }
50576
- function checkCompound(e, root, cmap, map, delSet, idx) {
50577
- const t = e.tail;
50578
- const h = e.head;
50579
- if (h.info.clustnode) return 0;
50580
- const tg = mapc(cmap, t);
50581
- const hg = mapc(cmap, h);
50582
- if (!tg && !hg) return 0;
50583
- if (tg === hg) return 0;
50584
- const ip = mapEdge2(map, t, h);
50585
- if (ip) {
50586
- cloneEdge2(root, e, ip.t, ip.h);
50587
- return 1;
50588
- }
50589
- let cn;
50590
- let ce;
50591
- if (hg) {
50592
- if (tg) {
50593
- if (agContains(hg, tg) || agContains(tg, hg)) return 0;
50594
- cn = clustNode(t, tg, root, delSet, idx);
50595
- const cn1 = clustNode(h, hg, root, delSet, idx);
50596
- ce = cloneEdge2(root, e, cn, cn1);
50597
- insertEdge2(map, t, h, ce);
50598
- } else {
50599
- if (agContainsNode2(hg, t)) return 0;
50600
- cn = clustNode(h, hg, root, delSet, idx);
50601
- ce = cloneEdge2(root, e, t, cn);
50602
- insertEdge2(map, t, h, ce);
50603
- }
50604
- } else {
50605
- if (agContainsNode2(tg, h)) return 0;
50606
- cn = clustNode(t, tg, root, delSet, idx);
50607
- ce = cloneEdge2(root, e, cn, h);
50608
- insertEdge2(map, t, h, ce);
50609
- }
50610
- return 1;
50611
- }
50612
- function agContains(a, b) {
50613
- for (let g = b; g !== null; g = g.parent) {
50614
- if (g === a) return true;
50615
- }
50616
- return false;
50617
- }
50618
- function agContainsNode2(cg, n) {
50619
- return cg.nodes.has(n.name);
50620
- }
50621
- function deleteNodeAndEdges(root, n) {
50622
- const purge = (gr) => {
50623
- if (gr.edges.length > 0) {
50624
- gr.edges = gr.edges.filter((e) => e.tail !== n && e.head !== n);
50625
- }
50626
- gr.nodes.delete(n.name);
50627
- for (const sg of gr.subgraphs.values()) purge(sg);
50628
- };
50629
- purge(root);
50630
- }
50631
- function processClusterEdges(g) {
50632
- const root = g.root;
50633
- const cmap = mkClustMap2(g);
50634
- if (cmap.size === 0) return;
50635
- const map = /* @__PURE__ */ new Map();
50636
- const delSet = /* @__PURE__ */ new Set();
50637
- const idx = { v: 0 };
50638
- let numClEdges = 0;
50639
- for (const n of [...g.nodes.values()]) {
50640
- if (n.info.clustnode) continue;
50641
- for (const e of n.outEdges(g)) {
50642
- numClEdges += checkCompound(e, root, cmap, map, delSet, idx);
50643
- }
50644
- }
50645
- for (const n of delSet) deleteNodeAndEdges(root, n);
50646
- if (numClEdges > 0) g.info.n_cluster_edges = numClEdges;
50647
- }
50648
-
50649
51504
  // src/layout/fdp/init.ts
50650
51505
  function initialPositions3(g) {
50651
51506
  const div = inputscaleDivisor(g);
@@ -51503,7 +52358,7 @@ function deriveEdges(g, dg, byPair) {
51503
52358
  dndata(hd).deg++;
51504
52359
  dndata(tl).deg++;
51505
52360
  }
51506
- addEdge2(de, e);
52361
+ addEdge3(de, e);
51507
52362
  }
51508
52363
  }
51509
52364
  }
@@ -51525,7 +52380,7 @@ function derivePort(g, dg, byPair, port, m) {
51525
52380
  const de = deriveEdge(dg, byPair, m, dn);
51526
52381
  de.info.dist = port.e.info.dist;
51527
52382
  de.info.factor = port.e.info.factor;
51528
- addEdge2(de, port.e);
52383
+ addEdge3(de, port.e);
51529
52384
  dndata(dn).wdeg++;
51530
52385
  dndata(m).wdeg++;
51531
52386
  dndata(dn).deg++;
@@ -51635,7 +52490,7 @@ function expandCluster2(n, cg) {
51635
52490
  }
51636
52491
 
51637
52492
  // src/layout/fdp/layout.ts
51638
- var POINTS_PER_INCH13 = 72;
52493
+ var POINTS_PER_INCH14 = 72;
51639
52494
  var DEFAULT_NODEWIDTH_PTS = 54;
51640
52495
  var DEFAULT_NODEHEIGHT_PTS = 36;
51641
52496
  function initInfo(g) {
@@ -51730,7 +52585,7 @@ function shiftComponents(cc, pts, pt) {
51730
52585
  } else {
51731
52586
  p = pt;
51732
52587
  }
51733
- const del = { x: p.x / POINTS_PER_INCH13, y: p.y / POINTS_PER_INCH13 };
52588
+ const del = { x: p.x / POINTS_PER_INCH14, y: p.y / POINTS_PER_INCH14 };
51734
52589
  for (const n of cc[i].nodes.values()) {
51735
52590
  n.info.pos[0] += del.x;
51736
52591
  n.info.pos[1] += del.y;
@@ -51746,8 +52601,8 @@ function finalCC(g, cc, pts, rg, infop) {
51746
52601
  const pt = applyMarginAndBorder(rg, bb, margin);
51747
52602
  if (cc.length > 0) shiftComponents(cc, pts, pt);
51748
52603
  gdata(g).bb = {
51749
- ll: { x: bb.ll.x / POINTS_PER_INCH13, y: bb.ll.y / POINTS_PER_INCH13 },
51750
- ur: { x: bb.ur.x / POINTS_PER_INCH13, y: bb.ur.y / POINTS_PER_INCH13 }
52604
+ ll: { x: bb.ll.x / POINTS_PER_INCH14, y: bb.ll.y / POINTS_PER_INCH14 },
52605
+ ur: { x: bb.ur.x / POINTS_PER_INCH14, y: bb.ur.y / POINTS_PER_INCH14 }
51751
52606
  };
51752
52607
  }
51753
52608
  function applyMarginAndBorder(rg, bb, margin) {
@@ -51793,8 +52648,8 @@ function translateOwnNodes(g, bb) {
51793
52648
  function setBB(g) {
51794
52649
  const bb = gdata(g).bb;
51795
52650
  g.info.bb = {
51796
- ll: { x: POINTS_PER_INCH13 * bb.ll.x, y: POINTS_PER_INCH13 * bb.ll.y },
51797
- ur: { x: POINTS_PER_INCH13 * bb.ur.x, y: POINTS_PER_INCH13 * bb.ur.y }
52651
+ ll: { x: POINTS_PER_INCH14 * bb.ll.x, y: POINTS_PER_INCH14 * bb.ll.y },
52652
+ ur: { x: POINTS_PER_INCH14 * bb.ur.x, y: POINTS_PER_INCH14 * bb.ur.y }
51798
52653
  };
51799
52654
  const nClusters = g.info.n_cluster ?? 0;
51800
52655
  for (let i = 0; i < nClusters; i++) {
@@ -51809,8 +52664,8 @@ function setClustNodes(root) {
51809
52664
  const bb = gdata(p).bb;
51810
52665
  const w = bb.ur.x - bb.ll.x;
51811
52666
  const h = bb.ur.y - bb.ll.y;
51812
- const w2 = POINTS_PER_INCH13 * (w / 2);
51813
- const h2 = POINTS_PER_INCH13 * (h / 2);
52667
+ const w2 = POINTS_PER_INCH14 * (w / 2);
52668
+ const h2 = POINTS_PER_INCH14 * (h / 2);
51814
52669
  n.info.pos[0] = w / 2;
51815
52670
  n.info.pos[1] = h / 2;
51816
52671
  n.info.width = w;
@@ -51819,7 +52674,7 @@ function setClustNodes(root) {
51819
52674
  n.info.outline_width = w + penwidth;
51820
52675
  n.info.outline_height = h + penwidth;
51821
52676
  n.info.lw = n.info.rw = w2;
51822
- n.info.ht = POINTS_PER_INCH13 * h;
52677
+ n.info.ht = POINTS_PER_INCH14 * h;
51823
52678
  const poly = n.info.shape_info;
51824
52679
  if (poly && poly.vertices) {
51825
52680
  poly.vertices[0] = { x: w2, y: h2 };
@@ -51832,8 +52687,8 @@ function setClustNodes(root) {
51832
52687
  function syncCoordFromPos(cg) {
51833
52688
  for (const n of cg.nodes.values()) {
51834
52689
  n.info.coord = {
51835
- x: POINTS_PER_INCH13 * n.info.pos[0],
51836
- y: POINTS_PER_INCH13 * n.info.pos[1]
52690
+ x: POINTS_PER_INCH14 * n.info.pos[0],
52691
+ y: POINTS_PER_INCH14 * n.info.pos[1]
51837
52692
  };
51838
52693
  }
51839
52694
  }
@@ -51845,8 +52700,8 @@ function expandComponentClusters(cg, infop, counter) {
51845
52700
  if (r !== 0) return r;
51846
52701
  n.info.width = gdata(sg).bb.ur.x;
51847
52702
  n.info.height = gdata(sg).bb.ur.y;
51848
- const ptx = POINTS_PER_INCH13 * gdata(sg).bb.ur.x;
51849
- const pty = POINTS_PER_INCH13 * gdata(sg).bb.ur.y;
52703
+ const ptx = POINTS_PER_INCH14 * gdata(sg).bb.ur.x;
52704
+ const pty = POINTS_PER_INCH14 * gdata(sg).bb.ur.y;
51850
52705
  n.info.rw = n.info.lw = ptx / 2;
51851
52706
  n.info.ht = pty;
51852
52707
  } else if (isPort(n)) {
@@ -51959,7 +52814,7 @@ function fdpSplines(g) {
51959
52814
  );
51960
52815
  }
51961
52816
  if (g.info.n_cluster_edges) {
51962
- agerrLineOn("warn", CLUSTER_EDGE_WARNING);
52817
+ agwarningf(CLUSTER_EDGE_WARNING);
51963
52818
  et = EDGETYPE_LINE;
51964
52819
  } else {
51965
52820
  splineEdges1(g, et);
@@ -52410,15 +53265,15 @@ function multilevelSpringElectricalEmbedding(dim, A0, ctrl, labelSizes, x) {
52410
53265
  }
52411
53266
 
52412
53267
  // src/layout/sfdp/index.ts
52413
- var DIM = 2;
52414
53268
  function sfdpLayoutComponent(g, ctrl, pad) {
53269
+ const ndim = ndimOf(g);
52415
53270
  const A3 = makeMatrix(g);
52416
- const sizes = ctrl.overlap >= 0 ? getSizes(g, pad) : null;
52417
- const pos = getPos(g, DIM);
52418
- multilevelSpringElectricalEmbedding(DIM, A3, ctrl, sizes, pos);
53271
+ const sizes = ctrl.overlap >= 0 ? getSizes(g, pad, ndim) : null;
53272
+ const pos = getPos(g, ndim);
53273
+ multilevelSpringElectricalEmbedding(ndim, A3, ctrl, sizes, pos);
52419
53274
  for (const n of g.nodes.values()) {
52420
53275
  const i = n.info.id;
52421
- n.info.pos = [pos[i * DIM], pos[i * DIM + 1]];
53276
+ n.info.pos = pos.slice(i * ndim, (i + 1) * ndim);
52422
53277
  }
52423
53278
  }
52424
53279
  function resolveControl(g) {
@@ -52429,7 +53284,8 @@ function resolveControl(g) {
52429
53284
  const flag = overlap5 === void 0 ? "prism0" : overlap5;
52430
53285
  warnUnrecognizedOverlap(flag);
52431
53286
  const ntry = overlapPrismTries(flag);
52432
- if (ntry !== null) {
53287
+ const doAdjust = ndimOf(g) === 2;
53288
+ if (ntry !== null && doAdjust) {
52433
53289
  ctrl.overlap = ntry;
52434
53290
  ctrl.initialScaling = lateDouble(
52435
53291
  g.root.attrs.get("overlap_scaling"),
@@ -52444,7 +53300,7 @@ function resolveControl(g) {
52444
53300
  return { ctrl, pad, doAdjust: false };
52445
53301
  }
52446
53302
  ctrl.overlap = -1;
52447
- return { ctrl, pad, doAdjust: true };
53303
+ return { ctrl, pad, doAdjust };
52448
53304
  }
52449
53305
  function layoutComponents3(g, comps, ctrl, pad, doAdjust) {
52450
53306
  const pinfo = {
@@ -52492,6 +53348,7 @@ function sfdpLayout(g) {
52492
53348
  } else {
52493
53349
  layoutComponents3(g, comps, ctrl, pad, doAdjust);
52494
53350
  }
53351
+ for (const c of comps) agdelsubg(g, c);
52495
53352
  }
52496
53353
  postprocess(g, singleComponent);
52497
53354
  }
@@ -53405,7 +54262,7 @@ function buildDerivedEdges(g, dg) {
53405
54262
  return edges;
53406
54263
  }
53407
54264
  function derivedComponents(g, dg, allEdges3) {
53408
- const comps = ccomps(g);
54265
+ const comps = ccomps(g, null, false);
53409
54266
  return comps.map((sg, i) => {
53410
54267
  const nodes = [];
53411
54268
  for (const n of sg.nodes.values()) {
@@ -53539,6 +54396,7 @@ function twopiLayout(g) {
53539
54396
  } else {
53540
54397
  layoutMulti(g, comps, globalRoot, buildPackInfo(g));
53541
54398
  }
54399
+ for (const c of comps) agdelsubg(g, c);
53542
54400
  normalizeGraphBB(g);
53543
54401
  placeGraphLabel(g);
53544
54402
  gvPostprocess(g);
@@ -54351,8 +55209,8 @@ var forfunc = (cur, total, init) => (1 - cur / total) * init / 2;
54351
55209
  var revfunc = (cur, total, init) => cur / total * init / 2;
54352
55210
  var nonefunc = (_cur, _total, init) => init / 2;
54353
55211
  var bothfunc = (cur, total, init) => {
54354
- const fr10 = cur / total;
54355
- return fr10 <= 0.5 ? fr10 * init : (1 - fr10) * init;
55212
+ const fr12 = cur / total;
55213
+ return fr12 <= 0.5 ? fr12 * init : (1 - fr12) * init;
54356
55214
  };
54357
55215
  function taperfun(dir, directed) {
54358
55216
  if (dir === "forward") return forfunc;
@@ -55214,6 +56072,15 @@ function trimFixed3(v) {
55214
56072
  function edgeAttrsAttached(e) {
55215
56073
  return e.info.edge_type !== IGNORED && e.info.spl != null;
55216
56074
  }
56075
+ function nodePosRaw(n) {
56076
+ const c = n.info.coord;
56077
+ let raw = gfmt5(c.x) + "," + gfmt5(c.y);
56078
+ const odim = n.root.info.odim ?? 2;
56079
+ for (let k = 2; odim >= 3 && k < odim; k++) {
56080
+ raw += "," + gfmt5(POINTS_PER_INCH2 * (n.info.pos?.[k] ?? 0));
56081
+ }
56082
+ return raw;
56083
+ }
55217
56084
  function appendRecordRects(n, f, out) {
55218
56085
  const c = n.info.coord;
55219
56086
  if (f.n_flds === 0) {
@@ -55685,7 +56552,7 @@ var DotWriterBase = class {
55685
56552
  nodeAttrs(n, scope) {
55686
56553
  const info = n.info;
55687
56554
  const defs = effectiveNodeDefaults(scope);
55688
- const posRaw = gfmt5(info.coord.x) + "," + gfmt5(info.coord.y);
56555
+ const posRaw = nodePosRaw(n);
55689
56556
  const widthRaw = gfmt5((info.lw + info.rw) / 72);
55690
56557
  const heightRaw = gfmt5(info.ht / 72);
55691
56558
  const parts = [
@@ -55937,13 +56804,13 @@ var EdgeDrawBase = class extends DotWriterBase {
55937
56804
  };
55938
56805
 
55939
56806
  // src/render/dot/write-back.ts
55940
- var POINTS_PER_INCH14 = 72;
56807
+ var POINTS_PER_INCH15 = 72;
55941
56808
  function attachNode(n) {
55942
56809
  const attrs = ownAttrs(n);
55943
56810
  const info = n.info;
55944
- attrs.set("pos", gfmt5(info.coord.x) + "," + gfmt5(info.coord.y));
55945
- attrs.set("height", gfmt5(info.ht / POINTS_PER_INCH14));
55946
- attrs.set("width", gfmt5((info.lw + info.rw) / POINTS_PER_INCH14));
56811
+ attrs.set("pos", nodePosRaw(n));
56812
+ attrs.set("height", gfmt5(info.ht / POINTS_PER_INCH15));
56813
+ attrs.set("width", gfmt5((info.lw + info.rw) / POINTS_PER_INCH15));
55947
56814
  const xlabel = info.xlabel;
55948
56815
  if (xlabel?.set) attrs.set("xlp", lpStr(xlabel.pos));
55949
56816
  if (info.shape?.name === "record") {
@@ -55973,8 +56840,8 @@ function recAttachBb(g) {
55973
56840
  const label = g.info.label;
55974
56841
  if (label && label.text.length > 0) {
55975
56842
  g.attrs.set("lp", lpStr(label.pos));
55976
- g.attrs.set("lwidth", gfmt2(label.dimen.x / POINTS_PER_INCH14));
55977
- g.attrs.set("lheight", gfmt2(label.dimen.y / POINTS_PER_INCH14));
56843
+ g.attrs.set("lwidth", gfmt2(label.dimen.x / POINTS_PER_INCH15));
56844
+ g.attrs.set("lheight", gfmt2(label.dimen.y / POINTS_PER_INCH15));
55978
56845
  }
55979
56846
  for (const sg of clustersOf(g)) recAttachBb(sg);
55980
56847
  }
@@ -60121,8 +60988,8 @@ var StmtProcessor = class _StmtProcessor {
60121
60988
  * @see lib/cgraph/edge.c:agedge:274-275 (`if (e == NULL && agisundirected(g))`)
60122
60989
  */
60123
60990
  static strictKey(tail, head, undirected) {
60124
- const swap3 = undirected && head.id < tail.id;
60125
- return swap3 ? `${head.id}\0${tail.id}` : `${tail.id}\0${head.id}`;
60991
+ const swap4 = undirected && head.id < tail.id;
60992
+ return swap4 ? `${head.id}\0${tail.id}` : `${tail.id}\0${head.id}`;
60126
60993
  }
60127
60994
  /**
60128
60995
  * Apply the DOT-syntax `:port:compass` endpoints to an edge's attrs.