@knowvah/dot-engine 2.10.3 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/dist/gvc/context.d.ts.map +1 -1
  2. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  3. package/dist/gvc/layout-reset.d.ts +38 -1
  4. package/dist/gvc/layout-reset.d.ts.map +1 -1
  5. package/dist/index.js +1191 -372
  6. package/dist/index.js.map +4 -4
  7. package/dist/layout/circo/circular.d.ts.map +1 -1
  8. package/dist/layout/dot/edge-route-helpers.d.ts +6 -1
  9. package/dist/layout/dot/edge-route-helpers.d.ts.map +1 -1
  10. package/dist/layout/dot/edge-route-rank.d.ts +4 -1
  11. package/dist/layout/dot/edge-route-rank.d.ts.map +1 -1
  12. package/dist/layout/dot/index.d.ts.map +1 -1
  13. package/dist/layout/dot/init.d.ts.map +1 -1
  14. package/dist/layout/fdp/cluster-edges.d.ts +11 -0
  15. package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
  16. package/dist/layout/neato/closest.d.ts +20 -0
  17. package/dist/layout/neato/closest.d.ts.map +1 -0
  18. package/dist/layout/neato/constrained-majorization.d.ts +13 -0
  19. package/dist/layout/neato/constrained-majorization.d.ts.map +1 -1
  20. package/dist/layout/neato/embed-graph.d.ts +20 -0
  21. package/dist/layout/neato/embed-graph.d.ts.map +1 -0
  22. package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
  23. package/dist/layout/neato/index.d.ts.map +1 -1
  24. package/dist/layout/neato/init-dim.d.ts +54 -0
  25. package/dist/layout/neato/init-dim.d.ts.map +1 -0
  26. package/dist/layout/neato/init.d.ts +1 -11
  27. package/dist/layout/neato/init.d.ts.map +1 -1
  28. package/dist/layout/neato/kk.d.ts +4 -2
  29. package/dist/layout/neato/kk.d.ts.map +1 -1
  30. package/dist/layout/neato/matrix-ops-dense.d.ts +34 -0
  31. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -0
  32. package/dist/layout/neato/pca.d.ts +14 -0
  33. package/dist/layout/neato/pca.d.ts.map +1 -0
  34. package/dist/layout/neato/sgd.d.ts +2 -3
  35. package/dist/layout/neato/sgd.d.ts.map +1 -1
  36. package/dist/layout/neato/start.d.ts +5 -5
  37. package/dist/layout/neato/start.d.ts.map +1 -1
  38. package/dist/layout/neato/stress-kernel.d.ts +10 -2
  39. package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
  40. package/dist/layout/neato/stress-subspace.d.ts +39 -0
  41. package/dist/layout/neato/stress-subspace.d.ts.map +1 -0
  42. package/dist/layout/neato/vpsc-adjust.d.ts.map +1 -1
  43. package/dist/layout/pack/ccomps.d.ts +4 -2
  44. package/dist/layout/pack/ccomps.d.ts.map +1 -1
  45. package/dist/layout/sfdp/index.d.ts.map +1 -1
  46. package/dist/layout/sfdp/init.d.ts +6 -7
  47. package/dist/layout/sfdp/init.d.ts.map +1 -1
  48. package/dist/layout/twopi/circle.d.ts.map +1 -1
  49. package/dist/layout/twopi/index.d.ts.map +1 -1
  50. package/dist/render/dot/attrs.d.ts +7 -0
  51. package/dist/render/dot/attrs.d.ts.map +1 -1
  52. package/dist/render.js +1574 -755
  53. package/dist/render.js.map +4 -4
  54. package/package.json +4 -4
  55. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +20 -0
  56. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +20 -0
  57. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +20 -0
  58. package/src/gvc/__fixtures__/rerender/abom-shift-pack.gv +1 -0
  59. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.1 +22 -0
  60. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +22 -0
  61. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +22 -0
  62. package/src/gvc/__fixtures__/rerender/abom-shift-parity.gv +1 -0
  63. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.1 +13 -0
  64. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.2 +13 -0
  65. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.3 +13 -0
  66. package/src/gvc/__fixtures__/rerender/abom-shift.gv +1 -0
  67. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.1 +10 -0
  68. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.2 +11 -0
  69. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.gv +9 -0
  70. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.1 +40 -0
  71. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.2 +40 -0
  72. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.1 +15 -0
  73. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.2 +17 -0
  74. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.1 +40 -0
  75. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.2 +15 -0
  76. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.1 +40 -0
  77. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.2 +99 -0
  78. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.1 +489 -0
  79. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.2 +503 -0
  80. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.1 +40 -0
  81. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.2 +109 -0
  82. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.1 +69 -0
  83. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.2 +70 -0
  84. package/src/gvc/__fixtures__/rerender/cluster-edges.gv +15 -0
  85. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.1 +104 -0
  86. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.2 +104 -0
  87. package/src/gvc/__fixtures__/rerender/fdp-1581.gv +26 -0
  88. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +34 -0
  89. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +34 -0
  90. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +34 -0
  91. package/src/gvc/__fixtures__/rerender/flat-rev-stale.gv +33 -0
  92. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +181 -0
  93. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +218 -0
  94. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +255 -0
  95. package/src/gvc/__fixtures__/rerender/regen.sh +25 -0
  96. package/src/gvc/context.ts +7 -2
  97. package/src/gvc/emit-xdot.ts +37 -7
  98. package/src/gvc/layout-reset.ts +59 -1
  99. package/src/layout/circo/circular.ts +3 -1
  100. package/src/layout/dot/edge-route-helpers.ts +8 -2
  101. package/src/layout/dot/edge-route-rank.ts +20 -2
  102. package/src/layout/dot/index.ts +17 -2
  103. package/src/layout/dot/init.ts +9 -17
  104. package/src/layout/dot/splines-flat.ts +12 -12
  105. package/src/layout/fdp/cluster-edges.ts +0 -0
  106. package/src/layout/neato/__fixtures__/dim/circuit-dim3.dot +33 -0
  107. package/src/layout/neato/__fixtures__/dim/circuit-dim3.gv +12 -0
  108. package/src/layout/neato/__fixtures__/dim/circuit-dim3.stderr +0 -0
  109. package/src/layout/neato/__fixtures__/dim/circuit-dim3.xdot +54 -0
  110. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.dot +32 -0
  111. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.gv +11 -0
  112. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.stderr +0 -0
  113. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.xdot +53 -0
  114. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.dot +32 -0
  115. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.gv +11 -0
  116. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  117. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  118. package/src/layout/neato/__fixtures__/dim/dim3.dot +31 -0
  119. package/src/layout/neato/__fixtures__/dim/dim3.gv +10 -0
  120. package/src/layout/neato/__fixtures__/dim/dim3.stderr +0 -0
  121. package/src/layout/neato/__fixtures__/dim/dim3.xdot +52 -0
  122. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.dot +32 -0
  123. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.gv +11 -0
  124. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  125. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  126. package/src/layout/neato/__fixtures__/dim/dimen3.dot +31 -0
  127. package/src/layout/neato/__fixtures__/dim/dimen3.gv +10 -0
  128. package/src/layout/neato/__fixtures__/dim/dimen3.stderr +0 -0
  129. package/src/layout/neato/__fixtures__/dim/dimen3.xdot +52 -0
  130. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +267 -0
  131. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.gv +84 -0
  132. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.stderr +0 -0
  133. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +468 -0
  134. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +267 -0
  135. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.gv +84 -0
  136. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.stderr +0 -0
  137. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +468 -0
  138. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +268 -0
  139. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.gv +85 -0
  140. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.stderr +0 -0
  141. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +469 -0
  142. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +484 -0
  143. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.gv +151 -0
  144. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.stderr +0 -0
  145. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +852 -0
  146. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +34 -0
  147. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.gv +13 -0
  148. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.stderr +0 -0
  149. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +55 -0
  150. package/src/layout/neato/__fixtures__/dim/hier-dim3.dot +33 -0
  151. package/src/layout/neato/__fixtures__/dim/hier-dim3.gv +12 -0
  152. package/src/layout/neato/__fixtures__/dim/hier-dim3.stderr +0 -0
  153. package/src/layout/neato/__fixtures__/dim/hier-dim3.xdot +54 -0
  154. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +33 -0
  155. package/src/layout/neato/__fixtures__/dim/hier-dim4.gv +12 -0
  156. package/src/layout/neato/__fixtures__/dim/hier-dim4.stderr +0 -0
  157. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +54 -0
  158. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.dot +32 -0
  159. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.gv +11 -0
  160. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.stderr +0 -0
  161. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.xdot +53 -0
  162. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.dot +34 -0
  163. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.gv +13 -0
  164. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.stderr +0 -0
  165. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.xdot +55 -0
  166. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +37 -0
  167. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.gv +12 -0
  168. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.stderr +0 -0
  169. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +58 -0
  170. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +141 -0
  171. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.gv +48 -0
  172. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.stderr +1 -0
  173. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +233 -0
  174. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.dot +21 -0
  175. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.gv +8 -0
  176. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.stderr +1 -0
  177. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.xdot +33 -0
  178. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.dot +23 -0
  179. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.gv +10 -0
  180. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.stderr +1 -0
  181. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.xdot +35 -0
  182. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.dot +23 -0
  183. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.gv +10 -0
  184. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.stderr +1 -0
  185. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.xdot +35 -0
  186. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.dot +26 -0
  187. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.gv +7 -0
  188. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.stderr +0 -0
  189. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.xdot +44 -0
  190. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.dot +28 -0
  191. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.gv +9 -0
  192. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.stderr +0 -0
  193. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.xdot +46 -0
  194. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.dot +48 -0
  195. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.gv +15 -0
  196. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.stderr +0 -0
  197. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.xdot +79 -0
  198. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +56 -0
  199. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.gv +17 -0
  200. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.stderr +0 -0
  201. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +94 -0
  202. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +47 -0
  203. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.gv +14 -0
  204. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.stderr +0 -0
  205. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +78 -0
  206. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.dot +34 -0
  207. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.gv +13 -0
  208. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.stderr +0 -0
  209. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.xdot +55 -0
  210. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +34 -0
  211. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.gv +13 -0
  212. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.stderr +0 -0
  213. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +55 -0
  214. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +34 -0
  215. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.gv +13 -0
  216. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.stderr +0 -0
  217. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +55 -0
  218. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.dot +15 -0
  219. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.gv +6 -0
  220. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.stderr +0 -0
  221. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.xdot +22 -0
  222. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.dot +33 -0
  223. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.gv +12 -0
  224. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.stderr +0 -0
  225. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.xdot +54 -0
  226. package/src/layout/neato/__fixtures__/dim/kk-dim3.dot +33 -0
  227. package/src/layout/neato/__fixtures__/dim/kk-dim3.gv +12 -0
  228. package/src/layout/neato/__fixtures__/dim/kk-dim3.stderr +0 -0
  229. package/src/layout/neato/__fixtures__/dim/kk-dim3.xdot +54 -0
  230. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.dot +33 -0
  231. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.gv +12 -0
  232. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.stderr +0 -0
  233. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.xdot +54 -0
  234. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.dot +39 -0
  235. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.gv +15 -0
  236. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.stderr +0 -0
  237. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.xdot +60 -0
  238. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.dot +33 -0
  239. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.gv +12 -0
  240. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.stderr +0 -0
  241. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.xdot +54 -0
  242. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.dot +33 -0
  243. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.gv +12 -0
  244. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.stderr +0 -0
  245. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.xdot +54 -0
  246. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.dot +33 -0
  247. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.gv +12 -0
  248. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.stderr +0 -0
  249. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.xdot +54 -0
  250. package/src/layout/neato/__fixtures__/dim/pack-dim3.dot +47 -0
  251. package/src/layout/neato/__fixtures__/dim/pack-dim3.gv +14 -0
  252. package/src/layout/neato/__fixtures__/dim/pack-dim3.stderr +0 -0
  253. package/src/layout/neato/__fixtures__/dim/pack-dim3.xdot +78 -0
  254. package/src/layout/neato/__fixtures__/dim/pins-dim3.dot +38 -0
  255. package/src/layout/neato/__fixtures__/dim/pins-dim3.gv +14 -0
  256. package/src/layout/neato/__fixtures__/dim/pins-dim3.stderr +0 -0
  257. package/src/layout/neato/__fixtures__/dim/pins-dim3.xdot +59 -0
  258. package/src/layout/neato/__fixtures__/dim/regen.sh +24 -0
  259. package/src/layout/neato/__fixtures__/dim/regular-dim3.dot +33 -0
  260. package/src/layout/neato/__fixtures__/dim/regular-dim3.gv +12 -0
  261. package/src/layout/neato/__fixtures__/dim/regular-dim3.stderr +0 -0
  262. package/src/layout/neato/__fixtures__/dim/regular-dim3.xdot +54 -0
  263. package/src/layout/neato/__fixtures__/dim/sgd-dim3.dot +33 -0
  264. package/src/layout/neato/__fixtures__/dim/sgd-dim3.gv +12 -0
  265. package/src/layout/neato/__fixtures__/dim/sgd-dim3.stderr +0 -0
  266. package/src/layout/neato/__fixtures__/dim/sgd-dim3.xdot +54 -0
  267. package/src/layout/neato/__fixtures__/dim/smart-units.json +16 -0
  268. package/src/layout/neato/__fixtures__/dim/subset-dim3.dot +33 -0
  269. package/src/layout/neato/__fixtures__/dim/subset-dim3.gv +12 -0
  270. package/src/layout/neato/__fixtures__/dim/subset-dim3.stderr +0 -0
  271. package/src/layout/neato/__fixtures__/dim/subset-dim3.xdot +54 -0
  272. package/src/layout/neato/closest.ts +206 -0
  273. package/src/layout/neato/constrained-majorization.ts +4 -23
  274. package/src/layout/neato/embed-graph.ts +81 -0
  275. package/src/layout/neato/fdp-adjust.ts +22 -8
  276. package/src/layout/neato/index.ts +26 -17
  277. package/src/layout/neato/init-dim.ts +165 -0
  278. package/src/layout/neato/init.ts +9 -35
  279. package/src/layout/neato/kk.ts +47 -41
  280. package/src/layout/neato/matrix-ops-dense.ts +232 -0
  281. package/src/layout/neato/pca.ts +60 -0
  282. package/src/layout/neato/sgd.ts +11 -4
  283. package/src/layout/neato/start.ts +8 -5
  284. package/src/layout/neato/stress-kernel.ts +65 -5
  285. package/src/layout/neato/stress-subspace.ts +371 -0
  286. package/src/layout/neato/vpsc-adjust.ts +3 -1
  287. package/src/layout/pack/__fixtures__/cc-reuse/circo.dot +23 -0
  288. package/src/layout/pack/__fixtures__/cc-reuse/circo.gv +1 -0
  289. package/src/layout/pack/__fixtures__/cc-reuse/circo.stderr +0 -0
  290. package/src/layout/pack/__fixtures__/cc-reuse/circo.xdot +38 -0
  291. package/src/layout/pack/__fixtures__/cc-reuse/neato.dot +23 -0
  292. package/src/layout/pack/__fixtures__/cc-reuse/neato.gv +1 -0
  293. package/src/layout/pack/__fixtures__/cc-reuse/neato.stderr +0 -0
  294. package/src/layout/pack/__fixtures__/cc-reuse/neato.xdot +38 -0
  295. package/src/layout/pack/__fixtures__/cc-reuse/osage.dot +23 -0
  296. package/src/layout/pack/__fixtures__/cc-reuse/osage.gv +1 -0
  297. package/src/layout/pack/__fixtures__/cc-reuse/osage.stderr +0 -0
  298. package/src/layout/pack/__fixtures__/cc-reuse/osage.xdot +38 -0
  299. package/src/layout/pack/__fixtures__/cc-reuse/regen.sh +24 -0
  300. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.dot +21 -0
  301. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.gv +1 -0
  302. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.stderr +0 -0
  303. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.xdot +36 -0
  304. package/src/layout/pack/__fixtures__/cc-reuse/twopi.dot +21 -0
  305. package/src/layout/pack/__fixtures__/cc-reuse/twopi.gv +1 -0
  306. package/src/layout/pack/__fixtures__/cc-reuse/twopi.stderr +1 -0
  307. package/src/layout/pack/__fixtures__/cc-reuse/twopi.xdot +36 -0
  308. package/src/layout/pack/ccomps.ts +34 -6
  309. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +32 -0
  310. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.gv +11 -0
  311. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  312. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  313. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +31 -0
  314. package/src/layout/sfdp/__fixtures__/dim/dim3.gv +10 -0
  315. package/src/layout/sfdp/__fixtures__/dim/dim3.stderr +0 -0
  316. package/src/layout/sfdp/__fixtures__/dim/dim3.xdot +52 -0
  317. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +32 -0
  318. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.gv +11 -0
  319. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  320. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  321. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +33 -0
  322. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.gv +12 -0
  323. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.stderr +0 -0
  324. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.xdot +54 -0
  325. package/src/layout/sfdp/__fixtures__/dim/regen.sh +24 -0
  326. package/src/layout/sfdp/index.ts +15 -10
  327. package/src/layout/sfdp/init.ts +26 -11
  328. package/src/layout/twopi/circle.ts +5 -1
  329. package/src/layout/twopi/index.ts +3 -0
  330. package/src/render/dot/agwrite.ts +2 -2
  331. package/src/render/dot/attrs.ts +16 -0
  332. package/src/render/dot/write-back.ts +2 -2
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";
@@ -1039,7 +1612,12 @@ var GvcContext = class {
1039
1612
  }
1040
1613
  engine = override2;
1041
1614
  }
1042
- if (layoutWasFreed(g)) resetLayoutRecords(g);
1615
+ undoRenderedClusterEdges(g);
1616
+ if (g.root) {
1617
+ resetFreedLayouts(g);
1618
+ bindDotRoot(g);
1619
+ g.root.info.gvc = this;
1620
+ }
1043
1621
  if (g.info) g.info.gvc = this;
1044
1622
  initXdot(g);
1045
1623
  engine.layout(g);
@@ -9116,182 +9694,6 @@ function htmlTextLabel(text, finfo, placed, dim) {
9116
9694
  };
9117
9695
  }
9118
9696
 
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
9697
  // src/common/subst.ts
9296
9698
  function labelTextOf(info) {
9297
9699
  const lp = info.label;
@@ -9380,146 +9782,6 @@ function preprocessTooltip(s) {
9380
9782
  return interpretCRNL(htmlEntityUTF8(s));
9381
9783
  }
9382
9784
 
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
9785
  // src/common/make-label.ts
9524
9786
  var DEFAULT_FONTSIZE2 = 14;
9525
9787
  var DEFAULT_FONTNAME = "Times-Roman";
@@ -17801,7 +18063,7 @@ function newMatrix(rows, cols) {
17801
18063
  function dotRoot(g) {
17802
18064
  return g.info.dotroot ?? g.root;
17803
18065
  }
17804
- function agContainsNode(g, n) {
18066
+ function agContainsNode2(g, n) {
17805
18067
  return g.nodes.get(n.name) === n;
17806
18068
  }
17807
18069
  function agContainsEdge(g, e) {
@@ -17814,7 +18076,7 @@ function rankSet(rank3, i, n) {
17814
18076
  rank3.v[(rank3.vStart ?? 0) + i] = n;
17815
18077
  }
17816
18078
  function isNormalNodeOf(g, v) {
17817
- return v.info.node_type === NORMAL && agContainsNode(g, v);
18079
+ return v.info.node_type === NORMAL && agContainsNode2(g, v);
17818
18080
  }
17819
18081
  function isVnodeOfEdgeOf(g, v) {
17820
18082
  if (v.info.node_type !== VIRTUAL) return false;
@@ -18211,76 +18473,6 @@ function ncross(ctx) {
18211
18473
  return total;
18212
18474
  }
18213
18475
 
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
18476
  // src/layout/dot/mincross-flat.ts
18285
18477
  function flatRevFindRev(head, tail) {
18286
18478
  const fo = head.info.flat_out;
@@ -18320,7 +18512,7 @@ function flatSearchNormal(g, v, e, M2, hascl) {
18320
18512
  }
18321
18513
  function flatSearchEdge(g, v, e, M2, hascl) {
18322
18514
  if (!M2) return false;
18323
- if (hascl && !(agContainsNode(g, e.tail) && agContainsNode(g, e.head))) return false;
18515
+ if (hascl && !(agContainsNode2(g, e.tail) && agContainsNode2(g, e.head))) return false;
18324
18516
  if ((e.info.weight !== void 0 ? e.info.weight : 0) === 0) return false;
18325
18517
  if (e.head.info.onstack) return flatSearchOstack(g, v, e, M2);
18326
18518
  flatSearchNormal(g, v, e, M2, hascl);
@@ -19550,11 +19742,11 @@ function initSubgraphRankdir(g) {
19550
19742
  var CL_CROSS = 1e3;
19551
19743
  function dotInitNode(n) {
19552
19744
  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 };
19745
+ n.info.in = { list: [], size: 0 };
19746
+ n.info.out = { list: [], size: 0 };
19747
+ n.info.flat_in = { list: [], size: 0 };
19748
+ n.info.flat_out = { list: [], size: 0 };
19749
+ n.info.other = { list: [], size: 0 };
19558
19750
  if (n.info.lw === void 0) n.info.lw = 27;
19559
19751
  if (n.info.rw === void 0) n.info.rw = 27;
19560
19752
  if (n.info.ht === void 0) n.info.ht = 36;
@@ -19581,7 +19773,7 @@ function applyNonconstraintZero(e) {
19581
19773
  }
19582
19774
  function dotInitEdge(e) {
19583
19775
  initEdgeConstraint(e);
19584
- e.info.weight = e.attrs.has("weight") ? lateInt(e.attrs.get("weight"), 1, 0) : e.info.weight ?? 1;
19776
+ e.info.weight = lateInt(e.attrs.get("weight"), 1, 0);
19585
19777
  e.info.count = 1;
19586
19778
  e.info.xpenalty = 1;
19587
19779
  applyGroupPenalty(e);
@@ -19611,7 +19803,6 @@ function clearFastGraphLists(n) {
19611
19803
  function dotInitNodeEdge(g) {
19612
19804
  for (const n of nodesInSeq(g)) {
19613
19805
  commonInitNode(n, g);
19614
- clearFastGraphLists(n);
19615
19806
  dotInitNode(n);
19616
19807
  }
19617
19808
  const measurer = g.root.info.gvc?.textMeasurer;
@@ -22079,12 +22270,22 @@ function setGradientFill(obj, color) {
22079
22270
  obj.fill = 2 /* Linear */;
22080
22271
  }
22081
22272
  }
22273
+ var PEN_OF_STYLE = /* @__PURE__ */ new Map([
22274
+ ["solid", 3 /* Solid */],
22275
+ ["dashed", 1 /* Dashed */],
22276
+ ["dotted", 2 /* Dotted */],
22277
+ ["invis", 0 /* None */],
22278
+ ["invisible", 0 /* None */]
22279
+ ]);
22082
22280
  function setStyle(obj, tokens) {
22083
22281
  gvrenderSetStyle(tokens);
22084
22282
  obj.rawStyle = [...tokens];
22085
- const flags = parseStyleFlags(tokens.join(","));
22086
- obj.pen = resolvePenType(flags);
22087
- obj.penWidth = resolvePenWidth(flags, void 0);
22283
+ for (const token of tokens) {
22284
+ const pen = PEN_OF_STYLE.get(styleName(token));
22285
+ if (pen !== void 0) obj.pen = pen;
22286
+ const flags = parseStyleFlags(token);
22287
+ if (flags.bold || flags.setLineWidth !== null) obj.penWidth = resolvePenWidth(flags, void 0);
22288
+ }
22088
22289
  }
22089
22290
  function devicePoints(pts, job) {
22090
22291
  return pts.map((p) => transformPoint({ x: p.x, y: p.y }, job));
@@ -22151,11 +22352,14 @@ function emitXdot(g, renderer, job) {
22151
22352
  for (const op of xd.ops) {
22152
22353
  styled ||= op.kind === "style";
22153
22354
  if (op.kind === "text") continue;
22154
- if (!inClip && isDrawing(op)) continue;
22355
+ if (isDrawing(op) && !drawsNow(obj, inClip)) continue;
22155
22356
  if (!drawOp(op, renderer, job)) stateOp(op, obj, warned2);
22156
22357
  }
22157
22358
  if (styled) setStyle(obj, DEFAULT_LINE_STYLE);
22158
22359
  }
22360
+ function drawsNow(obj, inClip) {
22361
+ return inClip && obj.pen !== 0 /* None */;
22362
+ }
22159
22363
  function isDrawing(op) {
22160
22364
  return op.kind.endsWith("ellipse") || op.kind.endsWith("polygon") || op.kind.endsWith("bezier") || op.kind === "polyline";
22161
22365
  }
@@ -25352,13 +25556,13 @@ function dfsNode(Xg, v, frames) {
25352
25556
  frames.push({ v, edges: v.outEdges(Xg).slice(), i: 0 });
25353
25557
  }
25354
25558
  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++];
25559
+ const fr12 = frames[frames.length - 1];
25560
+ if (fr12.i < fr12.edges.length) {
25561
+ const e = fr12.edges[fr12.i++];
25358
25562
  if (e.head.info.onstack) reverseEdge2(Xg, e);
25359
25563
  else if (!e.head.info.mark) dfsNode(Xg, e.head, frames);
25360
25564
  } else {
25361
- fr10.v.info.onstack = 0;
25565
+ fr12.v.info.onstack = 0;
25362
25566
  frames.pop();
25363
25567
  }
25364
25568
  }
@@ -26505,8 +26709,8 @@ function vnodeNotRelatedTo(g, v) {
26505
26709
  let e = v.info.save_out?.list[0];
26506
26710
  while (e?.info.to_orig) e = e.info.to_orig;
26507
26711
  if (!e) return false;
26508
- if (agContainsNode(g, e.tail)) return false;
26509
- if (agContainsNode(g, e.head)) return false;
26712
+ if (agContainsNode2(g, e.tail)) return false;
26713
+ if (agContainsNode2(g, e.head)) return false;
26510
26714
  return true;
26511
26715
  }
26512
26716
  function keepoutLeft(root, g, r, margin) {
@@ -29037,7 +29241,10 @@ function staleBezierCount(e) {
29037
29241
  return staleBeziersByEdge.get(e) ?? 0;
29038
29242
  }
29039
29243
  function staleAdjacent(e) {
29040
- return staleBezierCount(e) > 0 && (e.info.adjacent ?? 0) !== 0;
29244
+ let rep = e;
29245
+ while (rep.info.to_virt !== void 0 && rep.info.to_virt !== rep) rep = rep.info.to_virt;
29246
+ const samePair = rep.tail === e.tail && rep.head === e.head || rep.tail === e.head && rep.head === e.tail;
29247
+ return staleBezierCount(e) > 0 && ((samePair ? rep : e).info.adjacent ?? 0) !== 0;
29041
29248
  }
29042
29249
  function swapStaleBeziers(g) {
29043
29250
  for (const e of g.edges) {
@@ -29047,8 +29254,13 @@ function swapStaleBeziers(g) {
29047
29254
  const old = spl.list.splice(0, stale).reverse();
29048
29255
  for (const bz of old) swapBezier(bz);
29049
29256
  spl.list.push(...old);
29257
+ fillEdgeArrowSlots(e, old);
29050
29258
  }
29051
29259
  }
29260
+ function fillEdgeArrowSlots(e, old) {
29261
+ e.info.tailArrowOps ??= old.find((bz) => bz.sflag !== 0)?.sArrowOps;
29262
+ e.info.headArrowOps ??= old.find((bz) => bz.eflag !== 0)?.eArrowOps;
29263
+ }
29052
29264
  function rankEdgeInfoOf(g, tailNode, headNode) {
29053
29265
  const rankTable = g.info.rank;
29054
29266
  if (rankTable === void 0) return void 0;
@@ -30755,7 +30967,7 @@ function cloneNode(g, orign) {
30755
30967
  }
30756
30968
  return n;
30757
30969
  }
30758
- function cloneEdge(g, tn, hn, orig) {
30970
+ function cloneEdge2(g, tn, hn, orig) {
30759
30971
  const e = new Edge(tn, hn, orig.name);
30760
30972
  e.info.tail_port = { ...makePort(), ...orig.info.tail_port };
30761
30973
  e.info.head_port = { ...makePort(), ...orig.info.head_port };
@@ -32346,7 +32558,7 @@ function mapArrowOps(ops) {
32346
32558
  return m;
32347
32559
  });
32348
32560
  }
32349
- function mapEdge(e) {
32561
+ function mapEdge2(e) {
32350
32562
  const spl = e.info.spl;
32351
32563
  if (spl === void 0) return;
32352
32564
  mapSpl(spl);
@@ -32409,7 +32621,7 @@ function translateDrawing(g) {
32409
32621
  }
32410
32622
  continue;
32411
32623
  }
32412
- mapEdge(e);
32624
+ mapEdge2(e);
32413
32625
  }
32414
32626
  }
32415
32627
  translateBb(g, g.info.rankdir & 3);
@@ -32548,7 +32760,7 @@ function isPortless(e) {
32548
32760
  return !e.info.tail_port.defined && !e.info.head_port.defined;
32549
32761
  }
32550
32762
  function cloneFlatEdge(auxg, tn, auxt, auxh, orig) {
32551
- return orig.tail === tn ? cloneEdge(auxg, auxt, auxh, orig) : cloneEdge(auxg, auxh, auxt, orig);
32763
+ return orig.tail === tn ? cloneEdge2(auxg, auxt, auxh, orig) : cloneEdge2(auxg, auxh, auxt, orig);
32552
32764
  }
32553
32765
  function flatLeadPair(edges) {
32554
32766
  const t = edges[0].tail, h = edges[0].head;
@@ -32573,7 +32785,7 @@ function buildFlatAux(g, edges, cnt) {
32573
32785
  hvye = new Edge(auxt, auxh, "");
32574
32786
  auxg.edges.push(hvye);
32575
32787
  }
32576
- hvye.info.weight = 1e4;
32788
+ hvye.attrs.set("weight", "10000");
32577
32789
  return { auxg, auxt, auxh, alg };
32578
32790
  }
32579
32791
  function blocksAdjacency(vn) {
@@ -32601,8 +32813,9 @@ function repositionFlatAux(g, edges, aux) {
32601
32813
  else n.info.coord = { x: n.info.coord.x, y: midx };
32602
32814
  }
32603
32815
  }
32816
+ var transformArrowOps = (ops, del, flip) => ops.map((op) => mapArrowOpPoints(op, (p) => transformf(p, del, flip)));
32604
32817
  function copyFlatArrow(orig, auxe, del, flip) {
32605
- const xf = (ops) => ops.map((op) => mapArrowOpPoints(op, (p) => transformf(p, del, flip)));
32818
+ const xf = (ops) => transformArrowOps(ops, del, flip);
32606
32819
  const eflag = auxe.info.spl?.list[0]?.eflag;
32607
32820
  const head = auxe.info.headArrowOps ?? (eflag ? auxe.info.tailArrowOps : void 0);
32608
32821
  if (head !== void 0) orig.info.headArrowOps = xf(head);
@@ -32627,6 +32840,8 @@ function copyOneFlatSpline(orig, auxe, del, flip, g) {
32627
32840
  bz.eflag = auxbz.eflag;
32628
32841
  bz.sp = transformf(auxbz.sp, del, flip);
32629
32842
  bz.ep = transformf(auxbz.ep, del, flip);
32843
+ if (auxbz.sArrowOps) bz.sArrowOps = transformArrowOps(auxbz.sArrowOps, del, flip);
32844
+ if (auxbz.eArrowOps) bz.eArrowOps = transformArrowOps(auxbz.eArrowOps, del, flip);
32630
32845
  for (let j = 0; j < sz; j++) bz.list[j] = transformf(auxbz.list[j], del, flip);
32631
32846
  const bb = g.info.bb;
32632
32847
  if (bb !== void 0) {
@@ -33278,11 +33493,8 @@ function makeBezierRecord(bezierPts, arrowTip) {
33278
33493
  ep: arrowTip
33279
33494
  };
33280
33495
  }
33281
- function makeSplineRecord(bz) {
33282
- return { list: [bz], size: 1, bb: { ll: { x: 0, y: 0 }, ur: { x: 0, y: 0 } } };
33283
- }
33284
33496
  function installEdgeSpline(e, bezierPts, arrowTip) {
33285
- e.info.spl = makeSplineRecord(makeBezierRecord(bezierPts, arrowTip));
33497
+ Object.assign(newSpline(e, bezierPts.length), makeBezierRecord(bezierPts, arrowTip));
33286
33498
  const bb = e.tail.root.info.bb;
33287
33499
  if (bb != null) {
33288
33500
  for (let i = 0; i + 3 < bezierPts.length; i += 3) {
@@ -34379,7 +34591,7 @@ function makeGraph(n) {
34379
34591
  }
34380
34592
  return { nvs: n, vertices };
34381
34593
  }
34382
- function insertEdge(g, v1, v2) {
34594
+ function insertEdge2(g, v1, v2) {
34383
34595
  if (!edgeExists(g, v1, v2)) {
34384
34596
  g.vertices[v1].adjList.push(v2);
34385
34597
  }
@@ -35306,7 +35518,7 @@ function speFlip(isVert, commCoordMatchesP1, lDirMatchesTarget) {
35306
35518
  }
35307
35519
  function setParallelEdges(seg1, seg2, dir1, dir2, hops, mp) {
35308
35520
  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);
35521
+ insertEdge2(chan.G, seg1.indNo, seg2.indNo);
35310
35522
  for (let x = 1; x <= hops; x++) {
35311
35523
  const prev1 = nextSeg(seg1, dir1);
35312
35524
  const prev2 = nextSeg(seg2, dir2);
@@ -35316,8 +35528,8 @@ function setParallelEdges(seg1, seg2, dir1, dir2, hops, mp) {
35316
35528
  const target = seg1.isVert ? 2 /* B_LEFT */ : 1 /* B_UP */;
35317
35529
  const flip = speFlip(seg1.isVert, commCoordMatchesP1, lDir === target);
35318
35530
  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);
35531
+ if (edgeSeen === flip) insertEdge2(nchan.G, prev2.indNo, prev1.indNo);
35532
+ else insertEdge2(nchan.G, prev1.indNo, prev2.indNo);
35321
35533
  chan = nchan;
35322
35534
  seg1 = prev1;
35323
35535
  seg2 = prev2;
@@ -35604,8 +35816,8 @@ function addEdgesInG(cp) {
35604
35816
  for (let y = x + 1; y < size; y++) {
35605
35817
  const cmp = segCmp(cp.segList[x], cp.segList[y]);
35606
35818
  if (cmp === -2) return -1;
35607
- if (cmp > 0) insertEdge(G, x, y);
35608
- else if (cmp === -1) insertEdge(G, y, x);
35819
+ if (cmp > 0) insertEdge2(G, x, y);
35820
+ else if (cmp === -1) insertEdge2(G, y, x);
35609
35821
  }
35610
35822
  }
35611
35823
  return 0;
@@ -36560,7 +36772,7 @@ function fillClustMap(g, map) {
36560
36772
  fillClustMap(cl, map);
36561
36773
  }
36562
36774
  }
36563
- function mkClustMap(g) {
36775
+ function mkClustMap2(g) {
36564
36776
  const map = /* @__PURE__ */ new Map();
36565
36777
  fillClustMap(g, map);
36566
36778
  return map;
@@ -36715,7 +36927,7 @@ function makeCompoundEdge(e, clustMap) {
36715
36927
  if (tailClipped && bez.sflag) restashArrow(e, bez.sp, bez.list[0], true);
36716
36928
  }
36717
36929
  function dotCompoundEdges(g) {
36718
- const clustMap = mkClustMap(g);
36930
+ const clustMap = mkClustMap2(g);
36719
36931
  for (const e of g.edges) makeCompoundEdge(e, clustMap);
36720
36932
  }
36721
36933
 
@@ -37279,20 +37491,33 @@ function copyParentAttrs(parent2, sg) {
37279
37491
  for (const [k, v] of parent2.attrs) sg.attrs.set(k, v);
37280
37492
  return sg;
37281
37493
  }
37494
+ function componentSubgraph(g, nodes, name, reuse) {
37495
+ const existing = reuse ? g.subgraphs.get(name) : void 0;
37496
+ if (existing === void 0) return copyParentAttrs(g, buildSubgraph(g, nodes, name));
37497
+ const members = /* @__PURE__ */ new Set([...existing.nodes.values(), ...nodes]);
37498
+ existing.nodes.clear();
37499
+ for (const n of [...members].sort((a, b) => a.id - b.id)) existing.nodes.set(n.name, n);
37500
+ const ns = new Set(nodes);
37501
+ const have = new Set(existing.edges);
37502
+ for (const e of g.edges) {
37503
+ if (ns.has(e.tail) && ns.has(e.head) && !have.has(e)) existing.edges.push(e);
37504
+ }
37505
+ return existing;
37506
+ }
37282
37507
  function isLegal(p) {
37283
37508
  return /^[A-Za-z0-9_]*$/.test(p);
37284
37509
  }
37285
37510
  function setPrefix(pfx) {
37286
37511
  return pfx == null || !isLegal(pfx) ? "_cc_" : pfx;
37287
37512
  }
37288
- function ccomps(g, pfx) {
37513
+ function ccomps(g, pfx, reuse = true) {
37289
37514
  const visited = /* @__PURE__ */ new Set();
37290
37515
  const result = [];
37291
37516
  let idx = 0;
37292
37517
  for (const n of g.nodes.values()) {
37293
37518
  if (visited.has(n.name)) continue;
37294
37519
  const comp = dfsCollect(g, n, visited);
37295
- result.push(copyParentAttrs(g, buildSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`)));
37520
+ result.push(componentSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`, reuse));
37296
37521
  }
37297
37522
  return result;
37298
37523
  }
@@ -37308,12 +37533,12 @@ function pccomps(g, pfx) {
37308
37533
  pinned = true;
37309
37534
  }
37310
37535
  if (pinnedNodes.length > 0) {
37311
- result.push(copyParentAttrs(g, buildSubgraph(g, pinnedNodes, `${setPrefix(pfx)}${idx++}`)));
37536
+ result.push(componentSubgraph(g, pinnedNodes, `${setPrefix(pfx)}${idx++}`, true));
37312
37537
  }
37313
37538
  for (const n of g.nodes.values()) {
37314
37539
  if (visited.has(n.name)) continue;
37315
37540
  const comp = dfsCollect(g, n, visited);
37316
- result.push(copyParentAttrs(g, buildSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`)));
37541
+ result.push(componentSubgraph(g, comp, `${setPrefix(pfx)}${idx++}`, true));
37317
37542
  }
37318
37543
  return { graphs: result, pinned };
37319
37544
  }
@@ -37766,8 +37991,15 @@ function setEdgeTypeFromAttr(g, defaultValue) {
37766
37991
  else et = edgeTypeFromString(s, defaultValue);
37767
37992
  setEdgeType(g, et);
37768
37993
  }
37994
+ function resetAbomShift(g) {
37995
+ const shift = g.info.abomShift ?? 0;
37996
+ if (shift !== 0) {
37997
+ for (const n of g.nodes.values()) n.info.rank = (n.info.rank ?? 0) - shift;
37998
+ }
37999
+ g.info.abomShift = 0;
38000
+ }
37769
38001
  function dotPhaseInit(g) {
37770
- for (const e of g.edges) e.info.weight = void 0;
38002
+ resetAbomShift(g);
37771
38003
  dotGraphInit(g);
37772
38004
  setEdgeTypeFromAttr(g, EDGETYPE_SPLINE);
37773
38005
  setAspect(g);
@@ -37848,6 +38080,7 @@ function doDot(g) {
37848
38080
  } else if (ratioIsNone(g)) {
37849
38081
  pinfo.doSplines = true;
37850
38082
  layoutAndPack(g, comps, pinfo, origOf);
38083
+ for (const comp of comps) resetAbomShift(comp);
37851
38084
  } else {
37852
38085
  dotLayoutPipeline(g);
37853
38086
  }
@@ -38575,6 +38808,109 @@ function buildMask(max) {
38575
38808
  return mask >>> 0;
38576
38809
  }
38577
38810
 
38811
+ // src/common/utils-inputscale.ts
38812
+ var POINTS_PER_INCH4 = 72;
38813
+ function getInputscale(g) {
38814
+ const d = lateDouble(g.root.attrs.get("inputscale"), -1, 0);
38815
+ return d === 0 ? POINTS_PER_INCH4 : d;
38816
+ }
38817
+ function inputscaleDivisor(g) {
38818
+ const sc = getInputscale(g);
38819
+ return sc > 0 ? sc : 1;
38820
+ }
38821
+
38822
+ // src/layout/neato/init-dim.ts
38823
+ var DFLT_DIM = 2;
38824
+ var MAXDIM = 10;
38825
+ var POINTS_PER_INCH5 = 72;
38826
+ var NUM = "(-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?)";
38827
+ var POS3 = new RegExp(`^\\s*${NUM}\\s*,\\s*${NUM}\\s*,\\s*${NUM}(.?)`);
38828
+ var POS2 = new RegExp(`^\\s*${NUM}\\s*,\\s*${NUM}(.?)`);
38829
+ var Z_NUM = new RegExp(`^\\s*${NUM}`);
38830
+ function neatoInitGraphDim(g) {
38831
+ const root = g.root;
38832
+ const outdim = lateInt(root.attrs.get("dimen"), DFLT_DIM, 2);
38833
+ const ndim = Math.min(lateInt(root.attrs.get("dim"), outdim, 2), MAXDIM);
38834
+ root.info.ndim = ndim;
38835
+ root.info.odim = Math.min(outdim, ndim);
38836
+ return ndim;
38837
+ }
38838
+ function ndimOf(g) {
38839
+ return g.root.info.ndim ?? DFLT_DIM;
38840
+ }
38841
+ function jitterD(np, nG, n, ndim) {
38842
+ const pos = np.info.pos;
38843
+ if (pos === void 0) return;
38844
+ for (let k = n; k < ndim; k++) pos[k] = nG * drand48();
38845
+ }
38846
+ function jitter3d(np, nG, ndim) {
38847
+ jitterD(np, nG, 2, ndim);
38848
+ }
38849
+ function nodeAttrDeclared(g, name) {
38850
+ if (g.nodeDefaults.has(name)) return true;
38851
+ for (const n of g.nodes.values()) if (n.attrs.has(name)) return true;
38852
+ for (const sub of g.subgraphs.values()) if (nodeAttrDeclared(sub, name)) return true;
38853
+ return false;
38854
+ }
38855
+ function zDeclared(g) {
38856
+ return nodeAttrDeclared(g.root, "z");
38857
+ }
38858
+ function zValue(np) {
38859
+ return np.attrs.get("z") ?? np.nodeDefaultsSnapshot?.get("z") ?? "";
38860
+ }
38861
+ function scalePos(pvec, ndim, div) {
38862
+ for (let i = 0; i < ndim; i++) pvec[i] = pvec[i] / div;
38863
+ }
38864
+ function userPos3(np, m, nG, ndim) {
38865
+ const pvec = np.info.pos;
38866
+ pvec[0] = Number(m[1]);
38867
+ pvec[1] = Number(m[2]);
38868
+ pvec[2] = Number(m[3]);
38869
+ scalePos(pvec, ndim, inputscaleDivisor(np.root));
38870
+ if (ndim > 3) jitterD(np, nG, 3, ndim);
38871
+ }
38872
+ function userPos2(np, m, nG, ndim) {
38873
+ const pvec = np.info.pos;
38874
+ const div = inputscaleDivisor(np.root);
38875
+ pvec[0] = Number(m[1]);
38876
+ pvec[1] = Number(m[2]);
38877
+ scalePos(pvec, ndim, div);
38878
+ if (ndim <= 2) return;
38879
+ const zm = zDeclared(np.root) ? Z_NUM.exec(zValue(np)) : null;
38880
+ if (zm === null) {
38881
+ jitter3d(np, nG, ndim);
38882
+ return;
38883
+ }
38884
+ pvec[2] = Number(zm[1]) / div;
38885
+ jitterD(np, nG, 3, ndim);
38886
+ }
38887
+ function ensurePos(n, ndim) {
38888
+ if (n.info.pos === void 0 || n.info.pos.length < ndim) n.info.pos = new Array(ndim).fill(0);
38889
+ }
38890
+ function pinRequested(n, c) {
38891
+ const pin = n.attrs.get("pin");
38892
+ return c === "!" || pin !== void 0 && mapbool(pin);
38893
+ }
38894
+ function userPos(n, ndim = DFLT_DIM, nG = n.root.nodes.size) {
38895
+ const p = n.attrs.get("pos");
38896
+ if (p === void 0 || p.length === 0) return false;
38897
+ const m3 = ndim >= 3 ? POS3.exec(p) : null;
38898
+ const m = m3 ?? POS2.exec(p);
38899
+ if (m === null) return false;
38900
+ n.info.posSet = true;
38901
+ ensurePos(n, ndim);
38902
+ if (m3 !== null) userPos3(n, m3, nG, ndim);
38903
+ else userPos2(n, m, nG, ndim);
38904
+ if (pinRequested(n, m[m.length - 1])) n.info.pinned = true;
38905
+ return true;
38906
+ }
38907
+ function addZ(g) {
38908
+ if (ndimOf(g) < 3 || !zDeclared(g)) return;
38909
+ for (const n of g.nodes.values()) {
38910
+ ownAttrs(n).set("z", (POINTS_PER_INCH5 * (n.info.pos?.[2] ?? 0)).toFixed(6));
38911
+ }
38912
+ }
38913
+
38578
38914
  // src/layout/neato/start.ts
38579
38915
  var INIT_SELF = 0;
38580
38916
  var INIT_REGULAR = 1;
@@ -38613,6 +38949,7 @@ function parseStart(p, dflt) {
38613
38949
  return { init, seed };
38614
38950
  }
38615
38951
  function initRegular(g, nG) {
38952
+ const ndim = ndimOf(g);
38616
38953
  let a = 0;
38617
38954
  const da = 2 * Math.PI / nG;
38618
38955
  for (const np of g.nodes.values()) {
@@ -38620,6 +38957,7 @@ function initRegular(g, nG) {
38620
38957
  np.info.posSet = true;
38621
38958
  np.info.pinned = false;
38622
38959
  a += da;
38960
+ if (ndim > 2) jitter3d(np, nG, ndim);
38623
38961
  }
38624
38962
  }
38625
38963
  function checkStart(g, nG = g.nodes.size, dflt = INIT_RANDOM) {
@@ -38789,12 +39127,17 @@ function fisheryatesShuffle(terms, state3) {
38789
39127
  function hasPos(np) {
38790
39128
  return np.info.posSet === true || np.info.pinned === true;
38791
39129
  }
39130
+ function randompos(np, nG, ndim) {
39131
+ np.info.pos = [nG * drand48(), nG * drand48()];
39132
+ if (ndim > 2) jitter3d(np, nG, ndim);
39133
+ }
38792
39134
  function initialPositions(g, nG = g.nodes.size) {
38793
39135
  if (parseStart(g.root.attrs.get("start"), INIT_RANDOM).init === INIT_REGULAR) return;
38794
39136
  checkStart(g, nG, INIT_RANDOM);
39137
+ const ndim = ndimOf(g);
38795
39138
  for (const np of g.nodes.values()) {
38796
39139
  if (hasPos(np)) continue;
38797
- np.info.pos = [drand48(), drand48()];
39140
+ randompos(np, 1, ndim);
38798
39141
  }
38799
39142
  }
38800
39143
  function computeSchedule(terms, maxIter, epsilon = SGD_EPSILON) {
@@ -39702,7 +40045,6 @@ function mdsModel2(dist5, n, edges) {
39702
40045
  }
39703
40046
 
39704
40047
  // src/layout/neato/kk.ts
39705
- var NDIM = 2;
39706
40048
  var DEFAULT_DAMPING = 0.99;
39707
40049
  var EPSILON_PER_NODE = 1e-4;
39708
40050
  var ITERATIONS_PER_NODE = 100;
@@ -39763,13 +40105,15 @@ function scanGraphMode(g, maxIter) {
39763
40105
  const damp = g.root.attrs.get("Damping");
39764
40106
  const { total, lens } = setEdgeLens(g, nodes);
39765
40107
  const ini = initialDist(g, total, epsilon);
40108
+ const ndim = ndimOf(g);
39766
40109
  const st = {
39767
40110
  n,
40111
+ ndim,
39768
40112
  nodes,
39769
40113
  dist: new Float64Array(n * n).fill(ini),
39770
40114
  spring: new Float64Array(n * n).fill(1),
39771
- sumT: new Float64Array(n * NDIM).fill(1),
39772
- t: new Float64Array(n * n * NDIM),
40115
+ sumT: new Float64Array(n * ndim).fill(1),
40116
+ t: new Float64Array(n * n * ndim),
39773
40117
  damping: damp === void 0 ? DEFAULT_DAMPING : parseFloat(damp) || 0,
39774
40118
  epsilon,
39775
40119
  maxIter,
@@ -39777,9 +40121,10 @@ function scanGraphMode(g, maxIter) {
39777
40121
  };
39778
40122
  return { st, adj: neighbours(g, nodes, lens), ini, lens };
39779
40123
  }
39780
- function randompos(np) {
40124
+ function randompos2(np, ndim) {
39781
40125
  np.info.pos[0] = drand48();
39782
40126
  np.info.pos[1] = drand48();
40127
+ if (ndim > 2) jitter3d(np, 1, ndim);
39783
40128
  }
39784
40129
  function initialPositions2(g, st) {
39785
40130
  const init = checkStart(g, st.n, INIT_RANDOM);
@@ -39787,12 +40132,12 @@ function initialPositions2(g, st) {
39787
40132
  if (init === INIT_SELF) warnStartSelfOnce();
39788
40133
  for (const np of st.nodes) {
39789
40134
  if (np.info.posSet === true || np.info.pinned === true) continue;
39790
- randompos(np);
40135
+ randompos2(np, st.ndim);
39791
40136
  }
39792
40137
  }
39793
- function distvec(p0, p1, del) {
40138
+ function distvec(p0, p1, del, ndim) {
39794
40139
  let dist5 = 0;
39795
- for (let k = 0; k < NDIM; k++) {
40140
+ for (let k = 0; k < ndim; k++) {
39796
40141
  del[k] = p0[k] - p1[k];
39797
40142
  dist5 = fma(del[k], del[k], dist5);
39798
40143
  }
@@ -39810,14 +40155,15 @@ function springFactors(g) {
39810
40155
  return (a, b) => byEnds.get(`${a.info.id}:${b.info.id}`) ?? (undirected ? byEnds.get(`${b.info.id}:${a.info.id}`) : void 0);
39811
40156
  }
39812
40157
  function fillRow(st, i, del) {
40158
+ const { ndim } = st;
39813
40159
  const vi = st.nodes[i];
39814
40160
  for (let j = 0; j < st.n; j++) {
39815
40161
  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++) {
40162
+ const dist5 = distvec(vi.info.pos, st.nodes[j].info.pos, del, ndim);
40163
+ for (let k = 0; k < ndim; k++) {
39818
40164
  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;
40165
+ st.t[(i * st.n + j) * ndim + k] = v;
40166
+ st.sumT[i * ndim + k] += v;
39821
40167
  }
39822
40168
  }
39823
40169
  }
@@ -39834,61 +40180,62 @@ function diffeqModel(g, st) {
39834
40180
  }
39835
40181
  }
39836
40182
  st.sumT.fill(0);
39837
- const del = new Float64Array(NDIM);
40183
+ const del = new Float64Array(st.ndim);
39838
40184
  for (let i = 0; i < n; i++) fillRow(st, i, del);
39839
40185
  }
39840
40186
  function updateArrays(st, i) {
39841
- const { n } = st;
39842
- const del = new Float64Array(NDIM);
40187
+ const { n, ndim } = st;
40188
+ const del = new Float64Array(ndim);
39843
40189
  const vi = st.nodes[i];
39844
- for (let k = 0; k < NDIM; k++) st.sumT[i * NDIM + k] = 0;
40190
+ for (let k = 0; k < ndim; k++) st.sumT[i * ndim + k] = 0;
39845
40191
  for (let j = 0; j < n; j++) {
39846
40192
  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++) {
40193
+ const dist5 = distvec(vi.info.pos, st.nodes[j].info.pos, del, ndim);
40194
+ for (let k = 0; k < ndim; k++) {
39849
40195
  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;
40196
+ st.t[(i * n + j) * ndim + k] = tij;
40197
+ st.sumT[i * ndim + k] += tij;
40198
+ const old = st.t[(j * n + i) * ndim + k];
40199
+ st.t[(j * n + i) * ndim + k] = -tij;
40200
+ st.sumT[j * ndim + k] += -tij - old;
39855
40201
  }
39856
40202
  }
39857
40203
  }
39858
40204
  function d2e(st, m, M2) {
39859
- const { n } = st;
40205
+ const { n, ndim } = st;
39860
40206
  const vn = st.nodes[m];
39861
- const t = new Float64Array(NDIM);
40207
+ const t = new Float64Array(ndim);
39862
40208
  M2.fill(0);
39863
40209
  for (let i = 0; i < n; i++) {
39864
40210
  if (m === i) continue;
39865
40211
  const vi = st.nodes[i];
39866
40212
  let sq = 0;
39867
- for (let k = 0; k < NDIM; k++) {
40213
+ for (let k = 0; k < ndim; k++) {
39868
40214
  t[k] = vn.info.pos[k] - vi.info.pos[k];
39869
40215
  sq = fma(t[k], t[k], sq);
39870
40216
  }
39871
40217
  const scale = 1 / Math.pow(sq, 1.5);
39872
40218
  const K = st.spring[m * n + i];
39873
40219
  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]);
40220
+ for (let k = 0; k < ndim; k++) {
40221
+ for (let l = 0; l < k; l++) M2[l * ndim + k] = fma(K * D * t[k] * t[l], scale, M2[l * ndim + k]);
39876
40222
  const inner = fms(D * fms(t[k], t[k], sq), scale, 1);
39877
- M2[k * NDIM + k] = fma(K, inner, M2[k * NDIM + k]);
40223
+ M2[k * ndim + k] = fma(K, inner, M2[k * ndim + k]);
39878
40224
  }
39879
40225
  }
39880
- for (let k = 1; k < NDIM; k++) {
39881
- for (let l = 0; l < k; l++) M2[k * NDIM + l] = M2[l * NDIM + k];
40226
+ for (let k = 1; k < ndim; k++) {
40227
+ for (let l = 0; l < k; l++) M2[k * ndim + l] = M2[l * ndim + k];
39882
40228
  }
39883
40229
  }
39884
40230
  function chooseNode(st) {
39885
40231
  if (st.move >= st.maxIter) return -1;
40232
+ const { ndim } = st;
39886
40233
  let max = 0;
39887
40234
  let choice = -1;
39888
40235
  for (let i = 0; i < st.n; i++) {
39889
40236
  if (st.nodes[i].info.pinned === true) continue;
39890
40237
  let m = 0;
39891
- for (let k = 0; k < NDIM; k++) m = fma(st.sumT[i * NDIM + k], st.sumT[i * NDIM + k], m);
40238
+ for (let k = 0; k < ndim; k++) m = fma(st.sumT[i * ndim + k], st.sumT[i * ndim + k], m);
39892
40239
  if (m > max) {
39893
40240
  choice = i;
39894
40241
  max = m;
@@ -39897,14 +40244,15 @@ function chooseNode(st) {
39897
40244
  return max < st.epsilon * st.epsilon ? -1 : choice;
39898
40245
  }
39899
40246
  function moveNode(st, m) {
39900
- const a = new Float64Array(NDIM * NDIM);
39901
- const b = new Float64Array(NDIM);
39902
- const c = new Float64Array(NDIM);
40247
+ const { ndim } = st;
40248
+ const a = new Float64Array(ndim * ndim);
40249
+ const b = new Float64Array(ndim);
40250
+ const c = new Float64Array(ndim);
39903
40251
  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);
40252
+ for (let i = 0; i < ndim; i++) c[i] = -st.sumT[m * ndim + i];
40253
+ solve(a, b, c, ndim);
39906
40254
  const pos = st.nodes[m].info.pos;
39907
- for (let i = 0; i < NDIM; i++) {
40255
+ for (let i = 0; i < ndim; i++) {
39908
40256
  b[i] = fma(2 * (1 - st.damping), drand48(), st.damping) * b[i];
39909
40257
  pos[i] += b[i];
39910
40258
  }
@@ -40358,8 +40706,567 @@ function imdsGivenDim(graph, n, givenCoords, newCoords, conjTol) {
40358
40706
  return 0;
40359
40707
  }
40360
40708
 
40361
- // src/layout/neato/stress-kernel.ts
40709
+ // src/layout/neato/embed-graph.ts
40710
+ function saveWeights(graph, n) {
40711
+ return graph[0].ewgts.length === 0 ? null : graph.slice(0, n).map((v) => v.ewgts);
40712
+ }
40713
+ function pivotDistances(node, graph, n, reweightGraph, dist5) {
40714
+ if (reweightGraph) ngdijkstra(node, graph, n, dist5);
40715
+ else bfs(node, graph, n, dist5);
40716
+ }
40717
+ function embedGraph(graph, n, dim, reweightGraph) {
40718
+ const dist5 = new Int32Array(n);
40719
+ const oldWeights = saveWeights(graph, n);
40720
+ const coords = Array.from({ length: dim }, () => new Int32Array(n));
40721
+ if (reweightGraph) computeNewWeights(graph, n);
40722
+ let node = crand() % n;
40723
+ pivotDistances(node, graph, n, reweightGraph, coords[0]);
40724
+ let maxDist = 0;
40725
+ for (let i = 0; i < n; i++) {
40726
+ dist5[i] = coords[0][i];
40727
+ if (dist5[i] > maxDist) {
40728
+ node = i;
40729
+ maxDist = dist5[i];
40730
+ }
40731
+ }
40732
+ for (let i = 1; i < dim; i++) {
40733
+ pivotDistances(node, graph, n, reweightGraph, coords[i]);
40734
+ maxDist = 0;
40735
+ for (let j = 0; j < n; j++) {
40736
+ dist5[j] = Math.min(dist5[j], coords[i][j]);
40737
+ if (dist5[j] > maxDist) {
40738
+ node = j;
40739
+ maxDist = dist5[j];
40740
+ }
40741
+ }
40742
+ }
40743
+ if (reweightGraph) restoreOldWeights(graph, n, oldWeights);
40744
+ return coords;
40745
+ }
40746
+ function centerCoordinate(coords, n, dim) {
40747
+ for (let i = 0; i < dim; i++) {
40748
+ let sum = 0;
40749
+ for (let j = 0; j < n; j++) sum += coords[i][j];
40750
+ const avg = Math.trunc(sum / n);
40751
+ for (let j = 0; j < n; j++) coords[i][j] = coords[i][j] - avg;
40752
+ }
40753
+ }
40754
+
40755
+ // src/layout/neato/matrix-ops-dense.ts
40362
40756
  var fr5 = Math.fround;
40757
+ var P_ITERATION_THRESHOLD = 1e-3;
40758
+ var POWER_LENGTH_FLOOR2 = 1e-10;
40759
+ var GUESS_RANGE = 100;
40760
+ var BLOCK_ROW = 8;
40761
+ function rightMultWithVectorD(matrix, dim1, dim2, vector, result) {
40762
+ const blocked = dim2 - dim2 % BLOCK_ROW;
40763
+ for (let i = 0; i < dim1; i++) {
40764
+ const row = matrix[i];
40765
+ let res = 0;
40766
+ let j = 0;
40767
+ for (; j < blocked; j++) res += row[j] * vector[j];
40768
+ for (; j < dim2; j++) res = fma(row[j], vector[j], res);
40769
+ result[i] = res;
40770
+ }
40771
+ }
40772
+ function rightMultWithVectorTranspose(matrix, dim1, dim2, vector, result) {
40773
+ for (let i = 0; i < dim1; i++) {
40774
+ let res = 0;
40775
+ for (let j = 0; j < dim2; j++) res = fma(matrix[j][i], vector[j], res);
40776
+ result[i] = res;
40777
+ }
40778
+ }
40779
+ function multDenseMat(A3, B2, dim1, dim2, dim3) {
40780
+ const C6 = Array.from({ length: dim1 }, () => new Float32Array(dim3));
40781
+ for (let i = 0; i < dim1; i++) {
40782
+ for (let j = 0; j < dim3; j++) {
40783
+ let sum = 0;
40784
+ for (let k = 0; k < dim2; k++) sum = fma(A3[i][k], B2[k][j], sum);
40785
+ C6[i][j] = sum;
40786
+ }
40787
+ }
40788
+ return C6;
40789
+ }
40790
+ function multDenseMatD(A3, B2, dim1, dim2, dim3) {
40791
+ const C6 = Array.from({ length: dim1 }, () => new Float64Array(dim3));
40792
+ for (let i = 0; i < dim1; i++) {
40793
+ for (let j = 0; j < dim3; j++) {
40794
+ let sum = 0;
40795
+ for (let k = 0; k < dim2; k++) sum = fma(A3[i][k], B2[k][j], sum);
40796
+ C6[i][j] = sum;
40797
+ }
40798
+ }
40799
+ return C6;
40800
+ }
40801
+ function multSparseDenseMatTranspose(A3, B2, dim1, dim2) {
40802
+ const C6 = Array.from({ length: dim1 }, () => new Float32Array(dim2));
40803
+ for (let i = 0; i < dim1; i++) {
40804
+ const { edges, ewgts, nedges } = A3[i];
40805
+ for (let j = 0; j < dim2; j++) {
40806
+ let sum = 0;
40807
+ for (let k = 0; k < nedges; k++) sum = fma(fr5(ewgts[k]), B2[j][edges[k]], sum);
40808
+ C6[i][j] = sum;
40809
+ }
40810
+ }
40811
+ return C6;
40812
+ }
40813
+ function orthogonalize(st, i, vec) {
40814
+ for (let j = 0; j < i; j++) {
40815
+ const alpha = -innerProduct(st.n, st.eigs[j], vec, BLOCK_ROW);
40816
+ scadd(vec, st.n - 1, alpha, st.eigs[j]);
40817
+ }
40818
+ }
40819
+ function guess(st, i) {
40820
+ const curr = st.eigs[i];
40821
+ for (let j = 0; j < st.n; j++) curr[j] = crand() % GUESS_RANGE;
40822
+ orthogonalize(st, i, curr);
40823
+ return norm(curr, st.n - 1, BLOCK_NONE);
40824
+ }
40825
+ function iterate(st, i) {
40826
+ const { n, mat, tmpVec, lastVec } = st;
40827
+ const curr = st.eigs[i];
40828
+ let angle;
40829
+ let len;
40830
+ st.iteration = 0;
40831
+ do {
40832
+ st.iteration++;
40833
+ copyVector(n, curr, lastVec);
40834
+ rightMultWithVectorD(mat, n, n, curr, tmpVec);
40835
+ copyVector(n, tmpVec, curr);
40836
+ orthogonalize(st, i, curr);
40837
+ len = norm(curr, n - 1, BLOCK_NONE);
40838
+ if (len < POWER_LENGTH_FLOOR2 || st.iteration > st.maxIterations) return null;
40839
+ vectorsScalarMult(n, curr, 1 / len, curr);
40840
+ angle = innerProduct(n, curr, lastVec, BLOCK_ROW);
40841
+ } while (Math.abs(angle) < st.tol);
40842
+ return angle * len;
40843
+ }
40844
+ function fillNullSpace(st, from, neigs) {
40845
+ for (let i = from; i < neigs; i++) {
40846
+ const len = guess(st, i);
40847
+ vectorsScalarMult(st.n, st.eigs[i], 1 / len, st.eigs[i]);
40848
+ st.evals[i] = 0;
40849
+ }
40850
+ }
40851
+ function sortByEval(st, neigs) {
40852
+ const { n, eigs, evals, tmpVec } = st;
40853
+ for (let i = 0; i < neigs - 1; i++) {
40854
+ let largestIndex = i;
40855
+ let largestEval = evals[largestIndex];
40856
+ for (let j = i + 1; j < neigs; j++) {
40857
+ if (largestEval < evals[j]) {
40858
+ largestIndex = j;
40859
+ largestEval = evals[largestIndex];
40860
+ }
40861
+ }
40862
+ if (largestIndex !== i) {
40863
+ copyVector(n, eigs[i], tmpVec);
40864
+ copyVector(n, eigs[largestIndex], eigs[i]);
40865
+ copyVector(n, tmpVec, eigs[largestIndex]);
40866
+ evals[largestIndex] = evals[i];
40867
+ evals[i] = largestEval;
40868
+ }
40869
+ }
40870
+ }
40871
+ function powerIteration(mat, n, neigsIn, eigs) {
40872
+ const neigs = neigsIn >= n ? n : neigsIn;
40873
+ const st = {
40874
+ mat,
40875
+ n,
40876
+ eigs,
40877
+ evals: new Float64Array(neigs),
40878
+ tmpVec: new Float64Array(n),
40879
+ lastVec: new Float64Array(n),
40880
+ maxIterations: 30 * n,
40881
+ tol: 1 - P_ITERATION_THRESHOLD,
40882
+ iteration: 0
40883
+ };
40884
+ let i = 0;
40885
+ for (; i < neigs; i++) {
40886
+ let len = guess(st, i);
40887
+ while (len < POWER_LENGTH_FLOOR2) len = guess(st, i);
40888
+ vectorsScalarMult(n, eigs[i], 1 / len, eigs[i]);
40889
+ const rayleigh = iterate(st, i);
40890
+ if (rayleigh === null) break;
40891
+ st.evals[i] = rayleigh;
40892
+ }
40893
+ fillNullSpace(st, i, neigs);
40894
+ sortByEval(st, neigs);
40895
+ return st.iteration <= st.maxIterations;
40896
+ }
40897
+
40898
+ // src/layout/neato/closest.ts
40899
+ function greaterPriority2(h, i, j) {
40900
+ const a = h.data[i].dist;
40901
+ const b = h.data[j].dist;
40902
+ return a < b || a === b && crand() % 2 !== 0;
40903
+ }
40904
+ function swap3(h, i, j) {
40905
+ const t = h.data[i];
40906
+ h.data[i] = h.data[j];
40907
+ h.data[j] = t;
40908
+ }
40909
+ function heapify2(h, start) {
40910
+ let i = start;
40911
+ for (; ; ) {
40912
+ const l = 2 * i;
40913
+ const r = 2 * i + 1;
40914
+ let largest = l < h.heapSize && greaterPriority2(h, l, i) ? l : i;
40915
+ if (r < h.heapSize && greaterPriority2(h, r, largest)) largest = r;
40916
+ if (largest === i) break;
40917
+ swap3(h, largest, i);
40918
+ i = largest;
40919
+ }
40920
+ }
40921
+ function initHeap2(place, ordering, n) {
40922
+ const h = { data: [], heapSize: n - 1 };
40923
+ for (let i = 0; i < n - 1; i++) {
40924
+ const left2 = ordering[i];
40925
+ const right2 = ordering[i + 1];
40926
+ h.data.push({ left: left2, right: right2, dist: place[right2] - place[left2] });
40927
+ }
40928
+ for (let j = Math.trunc((n - 1) / 2); j >= 0; j--) heapify2(h, j);
40929
+ return h;
40930
+ }
40931
+ function extractMax2(h) {
40932
+ if (h.heapSize === 0) return null;
40933
+ const max = h.data[0];
40934
+ h.data[0] = h.data[h.heapSize - 1];
40935
+ h.heapSize--;
40936
+ heapify2(h, 0);
40937
+ return max;
40938
+ }
40939
+ function insert(h, edge) {
40940
+ let i = h.heapSize;
40941
+ h.heapSize++;
40942
+ h.data[i] = edge;
40943
+ while (i > 0 && greaterPriority2(h, i, Math.trunc(i / 2))) {
40944
+ swap3(h, i, Math.trunc(i / 2));
40945
+ i = Math.trunc(i / 2);
40946
+ }
40947
+ }
40948
+ function insertDescendants(s, pair) {
40949
+ const { place, ordering, invOrdering, left: left2, right: right2, heap } = s;
40950
+ const leftIndex = invOrdering[pair.left];
40951
+ const rightIndex = invOrdering[pair.right];
40952
+ if (leftIndex > 0) {
40953
+ const neighbor2 = ordering[leftIndex - 1];
40954
+ if (invOrdering[right2[neighbor2]] < rightIndex) {
40955
+ insert(heap, { left: neighbor2, right: pair.right, dist: place[pair.right] - place[neighbor2] });
40956
+ right2[neighbor2] = pair.right;
40957
+ left2[pair.right] = neighbor2;
40958
+ }
40959
+ }
40960
+ if (rightIndex < s.n - 1) {
40961
+ const neighbor2 = ordering[rightIndex + 1];
40962
+ if (invOrdering[left2[neighbor2]] > leftIndex) {
40963
+ insert(heap, { left: pair.left, right: neighbor2, dist: place[neighbor2] - place[pair.left] });
40964
+ left2[neighbor2] = pair.left;
40965
+ right2[pair.left] = neighbor2;
40966
+ }
40967
+ }
40968
+ }
40969
+ function orderByPlace(place, n) {
40970
+ const ordering = Array.from({ length: n }, (_, i) => i);
40971
+ return gvQsort(ordering, (x, y) => {
40972
+ if (place[x] < place[y]) return -1;
40973
+ if (place[x] > place[y]) return 1;
40974
+ return 0;
40975
+ });
40976
+ }
40977
+ function findClosestPairs(place, n, numPairs) {
40978
+ const ordering = orderByPlace(place, n);
40979
+ const invOrdering = new Int32Array(n);
40980
+ for (let i = 0; i < n; i++) invOrdering[ordering[i]] = i;
40981
+ const left2 = new Int32Array(n);
40982
+ const right2 = new Int32Array(n);
40983
+ const heap = initHeap2(place, ordering, n);
40984
+ for (let i = 1; i < n; i++) left2[ordering[i]] = ordering[i - 1];
40985
+ for (let i = 0; i < n - 1; i++) right2[ordering[i]] = ordering[i + 1];
40986
+ const scan = { place, n, ordering, invOrdering, left: left2, right: right2, heap };
40987
+ const stack = [];
40988
+ for (let i = 0; i < numPairs; i++) {
40989
+ const pair = extractMax2(heap);
40990
+ if (pair === null) break;
40991
+ stack.push(pair);
40992
+ insertDescendants(scan, pair);
40993
+ }
40994
+ return stack;
40995
+ }
40996
+ function addEdge2(graph, u, v) {
40997
+ const gu = graph[u];
40998
+ const gv = graph[v];
40999
+ if (gu.edges.includes(v)) return;
41000
+ gu.edges.push(v);
41001
+ gu.ewgts.push(1);
41002
+ gu.nedges++;
41003
+ gv.edges.push(u);
41004
+ gv.ewgts.push(1);
41005
+ gv.nedges++;
41006
+ gu.ewgts[0]--;
41007
+ gv.ewgts[0]--;
41008
+ }
41009
+ function constructGraph(n, edgesStack) {
41010
+ const graph = Array.from({ length: n }, (_, i) => ({ nedges: 1, edges: [i], ewgts: [0] }));
41011
+ for (let top = edgesStack.length - 1; top >= 0; top--) {
41012
+ addEdge2(graph, edgesStack[top].left, edgesStack[top].right);
41013
+ }
41014
+ return graph;
41015
+ }
41016
+ function closestPairs2Graph(place, n, numPairs) {
41017
+ return constructGraph(n, findClosestPairs(place, n, numPairs));
41018
+ }
41019
+
41020
+ // src/layout/neato/pca.ts
41021
+ var NUM_PAIRS = 4;
41022
+ function pcaAlloc(coords, dim, n, newCoords, newDim) {
41023
+ const eigs = Array.from({ length: newDim }, () => new Float64Array(dim));
41024
+ const DD = Array.from({ length: dim }, () => new Float64Array(dim));
41025
+ for (let i = 0; i < dim; i++) {
41026
+ for (let j = 0; j <= i; j++) {
41027
+ let sum = 0;
41028
+ for (let k = 0; k < n; k++) sum += Math.imul(coords[i][k], coords[j][k]);
41029
+ DD[i][j] = DD[j][i] = sum;
41030
+ }
41031
+ }
41032
+ powerIteration(DD, dim, newDim, eigs);
41033
+ for (let j = 0; j < newDim; j++) {
41034
+ for (let i = 0; i < n; i++) {
41035
+ let sum = 0;
41036
+ for (let k = 0; k < dim; k++) sum = fma(coords[k][i], eigs[j][k], sum);
41037
+ newCoords[j][i] = sum;
41038
+ }
41039
+ }
41040
+ }
41041
+ function iterativePCA1D(coords, dim, n, newDirection) {
41042
+ const laplacian = closestPairs2Graph(coords[0], n, NUM_PAIRS * n);
41043
+ const mat1 = multSparseDenseMatTranspose(laplacian, coords, n, dim);
41044
+ const mat = multDenseMatD(coords, mat1, dim, n, dim);
41045
+ return powerIteration(mat, dim, 1, [newDirection]);
41046
+ }
41047
+
41048
+ // src/layout/neato/stress-subspace.ts
41049
+ var fr6 = Math.fround;
41050
+ var STRESS_PCA_DIM = 50;
41051
+ var MIN_EMBEDDING_PIVOTS = 50;
41052
+ var ZERO_DISTANCE = 1e-30;
41053
+ var STRESS_GUARD = 1e-10;
41054
+ function distanceKD(coords, dim, i, j) {
41055
+ let sum = 0;
41056
+ for (let k = 0; k < dim; k++) {
41057
+ const d = coords[k][i] - coords[k][j];
41058
+ sum = fma(d, d, sum);
41059
+ }
41060
+ return Math.sqrt(sum);
41061
+ }
41062
+ function computeStress1(coords, distances, dim, n, exp) {
41063
+ let sum = 0;
41064
+ for (let i = 0; i < n; i++) {
41065
+ const row = distances[i];
41066
+ for (let j = 0; j < row.nedges; j++) {
41067
+ const node = row.edges[j];
41068
+ if (node <= i) continue;
41069
+ const dist5 = distanceKD(coords, dim, i, node);
41070
+ const Dij = row.edist[j];
41071
+ sum += exp === 2 ? (Dij - dist5) * (Dij - dist5) / (Dij * Dij) : (Dij - dist5) * (Dij - dist5) / Dij;
41072
+ }
41073
+ }
41074
+ return sum;
41075
+ }
41076
+ function nextPivot(dist5, Di, n, from) {
41077
+ let node = from;
41078
+ let maxDist = 0;
41079
+ for (let j = 0; j < n; j++) {
41080
+ dist5[j] = Math.min(dist5[j], Di[j]);
41081
+ if (dist5[j] > maxDist || dist5[j] === maxDist && crand() % (j + 1) === 0) {
41082
+ node = j;
41083
+ maxDist = dist5[j];
41084
+ }
41085
+ }
41086
+ return node;
41087
+ }
41088
+ function selectPivots(graph, n, numCenters, reweightGraph) {
41089
+ const centerIndex = new Int32Array(n).fill(-1);
41090
+ const invCenterIndex = new Int32Array(numCenters);
41091
+ const Dij = Array.from({ length: numCenters }, () => new Int32Array(n));
41092
+ const dist5 = new Int32Array(n);
41093
+ let node = crand() % n;
41094
+ centerIndex[node] = 0;
41095
+ invCenterIndex[0] = node;
41096
+ pivotDistances(node, graph, n, reweightGraph, Dij[0]);
41097
+ let maxDist = 0;
41098
+ for (let i = 0; i < n; i++) {
41099
+ dist5[i] = Dij[0][i];
41100
+ if (dist5[i] > maxDist) {
41101
+ node = i;
41102
+ maxDist = dist5[i];
41103
+ }
41104
+ }
41105
+ for (let i = 1; i < numCenters; i++) {
41106
+ centerIndex[node] = i;
41107
+ invCenterIndex[i] = node;
41108
+ pivotDistances(node, graph, n, reweightGraph, Dij[i]);
41109
+ node = nextPivot(dist5, Dij[i], n, node);
41110
+ }
41111
+ return { centerIndex, invCenterIndex, Dij };
41112
+ }
41113
+ function pivotRow(i, n, Di) {
41114
+ const edges = new Int32Array(n - 1);
41115
+ const edist = new Int32Array(n - 1);
41116
+ for (let j = 0; j < i; j++) {
41117
+ edges[j] = j;
41118
+ edist[j] = Di[j];
41119
+ }
41120
+ for (let j = i + 1; j < n; j++) {
41121
+ edges[j - 1] = j;
41122
+ edist[j - 1] = Di[j];
41123
+ }
41124
+ return { nedges: n - 1, edges, edist };
41125
+ }
41126
+ function nonPivotRow(i, numCenters, p) {
41127
+ const edges = new Int32Array(numCenters);
41128
+ const edist = new Int32Array(numCenters);
41129
+ for (let j = 0; j < numCenters; j++) {
41130
+ edges[j] = p.invCenterIndex[j];
41131
+ edist[j] = p.Dij[j][i];
41132
+ }
41133
+ return { nedges: numCenters, edges, edist };
41134
+ }
41135
+ function buildDistances(n, numCenters, p) {
41136
+ const distances = [];
41137
+ for (let i = 0; i < n; i++) {
41138
+ const index = p.centerIndex[i];
41139
+ distances.push(index >= 0 ? pivotRow(i, n, p.Dij[index]) : nonPivotRow(i, numCenters, p));
41140
+ }
41141
+ return distances;
41142
+ }
41143
+ function buildSparseLaplacian(distances, n, exp) {
41144
+ const lap = [];
41145
+ for (let i = 0; i < n; i++) {
41146
+ const row = distances[i];
41147
+ const edges = [i];
41148
+ const ewgts = [0];
41149
+ let degree = 0;
41150
+ for (let j = 0; j < row.nedges; j++) {
41151
+ const d = fr6(row.edist[j]);
41152
+ const w = exp === 2 ? fr6(-1 / fr6(d * d)) : fr6(-1 / d);
41153
+ edges.push(row.edges[j]);
41154
+ ewgts.push(w);
41155
+ degree -= w;
41156
+ }
41157
+ ewgts[0] = fr6(degree);
41158
+ lap.push({ nedges: row.nedges + 1, edges, ewgts });
41159
+ }
41160
+ return lap;
41161
+ }
41162
+ function initialDirections(subspace, subspaceDim, n, dim) {
41163
+ const storage = new Float64Array(dim * subspaceDim);
41164
+ const directions = Array.from({ length: dim }, (_, k) => storage.subarray(k * subspaceDim, (k + 1) * subspaceDim));
41165
+ if (dim !== 2) {
41166
+ for (let k = 0; k < dim; k++) storage[k * subspaceDim + k] = 1;
41167
+ return directions;
41168
+ }
41169
+ directions[0][0] = 1;
41170
+ if (!iterativePCA1D(subspace, subspaceDim, n, directions[1])) {
41171
+ directions[1].fill(0);
41172
+ directions[1][1] = 1;
41173
+ }
41174
+ return directions;
41175
+ }
41176
+ function computeB(st, k) {
41177
+ const { n, dim, coords, distances, lap, b } = st;
41178
+ const ck = coords[k];
41179
+ for (let i = 0; i < n; i++) {
41180
+ let degree = 0;
41181
+ let bi = 0;
41182
+ const { edges, ewgts, nedges } = lap[i];
41183
+ const edist = distances[i].edist;
41184
+ for (let j = 1; j < nedges; j++) {
41185
+ const node = edges[j];
41186
+ const distIj = distanceKD(coords, dim, i, node);
41187
+ if (distIj > ZERO_DISTANCE) {
41188
+ const Lij = fr6(-ewgts[j] * fr6(edist[j - 1])) / distIj;
41189
+ degree -= Lij;
41190
+ bi = fma(Lij, ck[node], bi);
41191
+ }
41192
+ }
41193
+ b[i] = fma(degree, ck[i], bi);
41194
+ }
41195
+ }
41196
+ function optimizeAxes(st) {
41197
+ const { n, dim, subspaceDim, subspace, matrix, directions, coords, b, bRestricted } = st;
41198
+ for (let k = 0; k < dim; k++) {
41199
+ computeB(st, k);
41200
+ rightMultWithVectorD(subspace, subspaceDim, n, b, bRestricted);
41201
+ const rc = conjugateGradientF(matrix, directions[k], bRestricted, subspaceDim, {
41202
+ tol: TOLERANCE_CG,
41203
+ maxIterations: subspaceDim,
41204
+ ortho1: false
41205
+ });
41206
+ if (rc !== 0) return true;
41207
+ rightMultWithVectorTranspose(subspace, n, subspaceDim, directions[k], coords[k]);
41208
+ }
41209
+ return false;
41210
+ }
41211
+ function optimizeLayout(st, o) {
41212
+ let oldStress = computeStress1(st.coords, st.distances, st.dim, st.n, o.exp);
41213
+ let converged = false;
41214
+ let iterations = 0;
41215
+ for (; iterations < o.nIterations && !converged; iterations++) {
41216
+ if (optimizeAxes(st)) return -1;
41217
+ if (iterations % 2 === 0) {
41218
+ const newStress = computeStress1(st.coords, st.distances, st.dim, st.n, o.exp);
41219
+ converged = Math.abs(newStress - oldStress) / (newStress + STRESS_GUARD) < o.epsilon;
41220
+ oldStress = newStress;
41221
+ }
41222
+ }
41223
+ return iterations;
41224
+ }
41225
+ function computeSubspace(graph, n, subspaceDim, reweightGraph) {
41226
+ const subspace = Array.from({ length: subspaceDim }, () => new Float64Array(n));
41227
+ const numCentersLocal = Math.min(n, Math.max(2 * subspaceDim, MIN_EMBEDDING_PIVOTS));
41228
+ const fullCoords = embedGraph(graph, n, numCentersLocal, reweightGraph);
41229
+ centerCoordinate(fullCoords, n, numCentersLocal);
41230
+ pcaAlloc(fullCoords, numCentersLocal, n, subspace, subspaceDim);
41231
+ return subspace;
41232
+ }
41233
+ function sparseStressSubspaceMajorizationKD(graph, n, coords, o) {
41234
+ const { dim, exp, reweightGraph, numCenters } = o;
41235
+ const subspaceDim = Math.min(STRESS_PCA_DIM, n);
41236
+ const subspace = computeSubspace(graph, n, subspaceDim, reweightGraph);
41237
+ const oldWeights = saveWeights(graph, n);
41238
+ if (reweightGraph) computeNewWeights(graph, n);
41239
+ const pivots = selectPivots(graph, n, numCenters, reweightGraph);
41240
+ const distances = buildDistances(n, numCenters, pivots);
41241
+ const lap = buildSparseLaplacian(distances, n, exp);
41242
+ const directions = initialDirections(subspace, subspaceDim, n, dim);
41243
+ for (let k = 0; k < dim; k++) {
41244
+ rightMultWithVectorTranspose(subspace, n, subspaceDim, directions[k], coords[k]);
41245
+ }
41246
+ const tmpMat = multSparseDenseMatTranspose(lap, subspace, n, subspaceDim);
41247
+ const matrix = multDenseMat(subspace, tmpMat, subspaceDim, n, subspaceDim);
41248
+ const iterations = optimizeLayout({
41249
+ n,
41250
+ dim,
41251
+ subspaceDim,
41252
+ subspace,
41253
+ distances,
41254
+ lap,
41255
+ matrix,
41256
+ directions,
41257
+ coords,
41258
+ b: new Float64Array(n),
41259
+ bRestricted: new Float64Array(subspaceDim)
41260
+ }, o);
41261
+ if (reweightGraph) restoreOldWeights(graph, n, oldWeights);
41262
+ return iterations;
41263
+ }
41264
+
41265
+ // src/layout/neato/stress-kernel.ts
41266
+ var fr7 = Math.fround;
41267
+ var SMART_SUBSPACE_ITERATIONS = 50;
41268
+ var NUM_PIVOTS_STRESS = 40;
41269
+ var SMART_NOISE = 1e-6;
40363
41270
  function computeApspPacked2(graph, n) {
40364
41271
  const Dij = new Float32Array(n * (n + 1) / 2);
40365
41272
  const Di = new Int32Array(n);
@@ -40383,6 +41290,7 @@ function initLayout(n, dim, coords, nodes) {
40383
41290
  if (hasPos2(np)) {
40384
41291
  coords[0][i] = np.info.pos?.[0] ?? 0;
40385
41292
  coords[1][i] = np.info.pos?.[1] ?? 0;
41293
+ for (let d = 2; d < dim; d++) coords[d][i] = np.info.pos?.[d] ?? 0;
40386
41294
  if (isFixed(np)) pinned = true;
40387
41295
  } else {
40388
41296
  coords[0][i] = drand48();
@@ -40432,7 +41340,7 @@ function buildLap1(lap1, lap2, coords, shape) {
40432
41340
  for (let k = 0; k < dim; k++) {
40433
41341
  const ck = coords[k];
40434
41342
  for (let x = 0; x < len; x++) {
40435
- const tmp = fr5(ck[i] + fr5(-1 * ck[i + 1 + x]));
41343
+ const tmp = fr7(ck[i] + fr7(-1 * ck[i + 1 + x]));
40436
41344
  distAccumulator[x] = ops.squareAdd(tmp, distAccumulator[x]);
40437
41345
  }
40438
41346
  }
@@ -40445,7 +41353,7 @@ function buildLap1(lap1, lap2, coords, shape) {
40445
41353
  let degree = 0;
40446
41354
  if (exp === 2) {
40447
41355
  for (let j = 0; j < len; j++, count++) {
40448
- const val2 = lap1[count] = fr5(lap1[count] * distAccumulator[j]);
41356
+ const val2 = lap1[count] = fr7(lap1[count] * distAccumulator[j]);
40449
41357
  degree += val2;
40450
41358
  degrees[i + j + 1] = degrees[i + j + 1] - val2;
40451
41359
  }
@@ -40490,19 +41398,50 @@ function solveAxis(st, k, havePinned, nodes) {
40490
41398
  }
40491
41399
  return 0;
40492
41400
  }
41401
+ function smartLayout(smart, n, dCoords, o) {
41402
+ const { dim } = o;
41403
+ const iterations = sparseStressSubspaceMajorizationKD(smart.graph, n, dCoords, {
41404
+ dim,
41405
+ exp: o.opts & OPT_EXP_FLAG,
41406
+ reweightGraph: smart.reweightGraph,
41407
+ nIterations: SMART_SUBSPACE_ITERATIONS,
41408
+ numCenters: NUM_PIVOTS_STRESS,
41409
+ epsilon: o.epsilon
41410
+ });
41411
+ if (iterations < 0) return -1;
41412
+ for (let i = 0; i < dim; i++) {
41413
+ const c = dCoords[i];
41414
+ let max = 1;
41415
+ for (let j = 0; j < n; j++) {
41416
+ if (Math.abs(c[j]) > max) max = Math.abs(c[j]);
41417
+ }
41418
+ for (let j = 0; j < n; j++) c[j] = c[j] / max;
41419
+ for (let j = 0; j < n; j++) c[j] = fma(drand48() - 0.5, SMART_NOISE, c[j]);
41420
+ orthog1(n, c);
41421
+ }
41422
+ return 0;
41423
+ }
41424
+ function initialLayout(n, dCoords, nodes, o) {
41425
+ if (o.smart !== void 0 && (o.opts & OPT_SMART_INIT) !== 0 && n > 1) {
41426
+ return smartLayout(o.smart, n, dCoords, o);
41427
+ }
41428
+ return initLayout(n, o.dim, dCoords, nodes) ? 1 : 0;
41429
+ }
40493
41430
  function stressMajorizationKDMkernel(Dij, n, dCoords, nodes, o) {
40494
41431
  const { dim, maxi } = o;
40495
41432
  const exp = o.opts & OPT_EXP_FLAG;
40496
41433
  if (maxi < 0) return 0;
40497
- const havePinned = initLayout(n, dim, dCoords, nodes);
41434
+ const layout2 = initialLayout(n, dCoords, nodes, o);
41435
+ if (layout2 < 0) return -1;
41436
+ const havePinned = layout2 === 1;
40498
41437
  if (n === 1 || maxi === 0) return 0;
40499
41438
  const coords = [];
40500
41439
  for (let i = 0; i < dim; i++) {
40501
41440
  const c = new Float32Array(n);
40502
- for (let j = 0; j < n; j++) c[j] = fr5(dCoords[i][j]);
41441
+ for (let j = 0; j < n; j++) c[j] = fr7(dCoords[i][j]);
40503
41442
  coords.push(c);
40504
41443
  }
40505
- const constantTerm = fr5(n * (n - 1) / 2);
41444
+ const constantTerm = fr7(n * (n - 1) / 2);
40506
41445
  const lap2 = Dij;
40507
41446
  buildLap2(lap2, n, exp);
40508
41447
  const lapLength = n * (n + 1) / 2;
@@ -40524,7 +41463,6 @@ function stressMajorizationKDMkernel(Dij, n, dCoords, nodes, o) {
40524
41463
  for (; iterations < maxi && !converged; iterations++) {
40525
41464
  buildLap1(st.lap1, lap2, coords, { n, dim, exp, ops: st.ops });
40526
41465
  const newStress = computeStress(st);
40527
- if (typeof process !== "undefined" && process.env["STRESS_DEBUG"] && iterations % 5 === 0) console.error(newStress.toFixed(3));
40528
41466
  const change = Math.abs(oldStress - newStress);
40529
41467
  converged = change / oldStress < o.epsilon || newStress < o.epsilon;
40530
41468
  oldStress = newStress;
@@ -40642,7 +41580,7 @@ function stressModelDij(graph, n, model) {
40642
41580
  }
40643
41581
 
40644
41582
  // src/layout/neato/constrained-majorization.ts
40645
- var fr6 = Math.fround;
41583
+ var fr8 = Math.fround;
40646
41584
  var LOCAL_CONSTR_MAJOR_ITERATIONS = 15;
40647
41585
  var LEVELS_SEP_TOL = 0.1;
40648
41586
  var ABS_TOL = 0.01;
@@ -40651,18 +41589,15 @@ var FLT_MAX3 = 34028234663852886e22;
40651
41589
  var DBL_MAX = Number.MAX_VALUE;
40652
41590
  var MIN_LEVELS = 1;
40653
41591
  var Y_AXIS = 1;
40654
- function unsupported2(what) {
40655
- throw new RenderError(`hierarchical stress majorization: ${what} is not supported yet`, "UNSUPPORTED_FEATURE");
40656
- }
40657
41592
  function unconstrainedMajorization(graph, n, dCoords, nodes, o) {
40658
41593
  if (o.maxi < 0) return 0;
40659
41594
  const Dij = stressModelDij(graph, n, o.model);
40660
- if ((o.opts & OPT_SMART_INIT) !== 0 && n > 1) unsupported2("the smart initial layout");
40661
41595
  return stressMajorizationKDMkernel(Dij, n, dCoords, nodes, {
40662
41596
  dim: o.dim,
40663
41597
  opts: o.opts,
40664
41598
  maxi: o.maxi,
40665
- epsilon: o.epsilon
41599
+ epsilon: o.epsilon,
41600
+ smart: { graph, reweightGraph: o.model === MODEL_SUBSET2 }
40666
41601
  });
40667
41602
  }
40668
41603
  function hasDirectionality(graph, n) {
@@ -40710,14 +41645,6 @@ function plainInitLayers(graph, n, dCoords, nodes, dim) {
40710
41645
  const h = computeHierarchy(graph, n, ABS_TOL, LEVELS_SEP_TOL, null);
40711
41646
  return h === null ? -1 : h;
40712
41647
  }
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
41648
  function scaleDownLayout(dCoords, n, dim) {
40722
41649
  let max = 1;
40723
41650
  for (let i = 0; i < dim; i++) {
@@ -40740,7 +41667,7 @@ function scaleDistances(Dij, dCoords, n, dim) {
40740
41667
  sum2 += distanceKD(dCoords, dim, i, j) / Dij[count];
40741
41668
  }
40742
41669
  }
40743
- const scaleRatio = fr6(sum2 / sum1);
41670
+ const scaleRatio = fr8(sum2 / sum1);
40744
41671
  for (let i = 0; i < length; i++) Dij[i] = Dij[i] * scaleRatio;
40745
41672
  }
40746
41673
  function centerLayout(dCoords, n, dim) {
@@ -40796,7 +41723,7 @@ function buildLap12(st) {
40796
41723
  count++;
40797
41724
  let degree = 0;
40798
41725
  for (let j = 0; j < len; j++, count++) {
40799
- const val2 = fr6(lap1[count] * distAccumulator[j]);
41726
+ const val2 = fr8(lap1[count] * distAccumulator[j]);
40800
41727
  lap1[count] = val2;
40801
41728
  degree += val2;
40802
41729
  degrees[i + j + 1] -= val2;
@@ -42349,8 +43276,8 @@ function genYConstraints(rects, vs) {
42349
43276
  }
42350
43277
 
42351
43278
  // src/layout/neato/quad-prog-vpsc-overlap.ts
42352
- var fr7 = Math.fround;
42353
- var X_GROWTH = fr7(1.0001);
43279
+ var fr9 = Math.fround;
43280
+ var X_GROWTH = fr9(1.0001);
42354
43281
  var BOUNDARY_WIDTH = 1e-4;
42355
43282
  var TMP_CLUSTER_VAR_ID = 123;
42356
43283
  function copyBox(b) {
@@ -42496,7 +43423,7 @@ function generateNonoverlapConstraints(e, a) {
42496
43423
  n -= 2 * a.opt.clusters.nclusters;
42497
43424
  }
42498
43425
  if (a.k === 0) {
42499
- nsizeScale = fr7(nsizeScale * X_GROWTH);
43426
+ nsizeScale = fr9(nsizeScale * X_GROWTH);
42500
43427
  }
42501
43428
  const bb = nodeBoxes(n, nsizeScale, a);
42502
43429
  let csol;
@@ -42559,15 +43486,15 @@ function getNumDigcolaConstraints(levels, numLevels) {
42559
43486
  }
42560
43487
 
42561
43488
  // src/layout/neato/quad-prog-vpsc.ts
42562
- var fr8 = Math.fround;
43489
+ var fr10 = Math.fround;
42563
43490
  var QUAD_PROG_TOL = 1e-4;
42564
43491
  var DUMMY_WEIGHT = 1e-6;
42565
43492
  var VECTOR_BLOCK = 4;
42566
43493
  function rowReduce(row, factor, v, n, acc) {
42567
43494
  const blocked = n - n % VECTOR_BLOCK;
42568
43495
  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);
43496
+ for (; j < blocked; j++) acc = fr10(acc + fr10(fr10(factor * row[j]) * v[j]));
43497
+ for (; j < n; j++) acc = fmaf(fr10(factor * row[j]), v[j], acc);
42571
43498
  return acc;
42572
43499
  }
42573
43500
  function project(e, place, n) {
@@ -42585,7 +43512,7 @@ function descentStep(e, b, place, n) {
42585
43512
  const oldPlace = e.fArray2;
42586
43513
  for (let i = 0; i < n; i++) {
42587
43514
  oldPlace[i] = place[i];
42588
- g[i] = rowReduce(A3[i], -2, place, n, fr8(2 * b[i]));
43515
+ g[i] = rowReduce(A3[i], -2, place, n, fr10(2 * b[i]));
42589
43516
  }
42590
43517
  let numerator = 0;
42591
43518
  let denominator = 0;
@@ -42594,7 +43521,7 @@ function descentStep(e, b, place, n) {
42594
43521
  const r = rowReduce(A3[i], 2, g, n, 0);
42595
43522
  denominator = fmaf(-r, g[i], denominator);
42596
43523
  }
42597
- return denominator !== 0 ? -fr8(numerator / denominator) : -1;
43524
+ return denominator !== 0 ? -fr10(numerator / denominator) : -1;
42598
43525
  }
42599
43526
  function lineSearchBeta(e, place, n) {
42600
43527
  const A3 = e.A;
@@ -42602,7 +43529,7 @@ function lineSearchBeta(e, place, n) {
42602
43529
  const oldPlace = e.fArray2;
42603
43530
  const d = e.fArray3;
42604
43531
  for (let i = 0; i < n; i++) {
42605
- d[i] = fr8(place[i] - oldPlace[i]);
43532
+ d[i] = fr10(place[i] - oldPlace[i]);
42606
43533
  }
42607
43534
  let numerator = 0;
42608
43535
  let denominator = 0;
@@ -42611,7 +43538,7 @@ function lineSearchBeta(e, place, n) {
42611
43538
  const r = rowReduce(A3[i], 2, d, n, 0);
42612
43539
  denominator = fmaf(r, d[i], denominator);
42613
43540
  }
42614
- if (!Object.is(denominator, 0) && !Object.is(denominator, -0)) return fr8(numerator / denominator);
43541
+ if (!Object.is(denominator, 0) && !Object.is(denominator, -0)) return fr10(numerator / denominator);
42615
43542
  return 1;
42616
43543
  }
42617
43544
  function applyBeta(e, place, n, beta) {
@@ -42622,7 +43549,7 @@ function applyBeta(e, place, n, beta) {
42622
43549
  if (beta > 0 && beta < 1) {
42623
43550
  place[i] = fmaf(beta, d[i], oldPlace[i]);
42624
43551
  }
42625
- test = fr8(test + fr8(Math.abs(place[i] - oldPlace[i])));
43552
+ test = fr10(test + fr10(Math.abs(place[i] - oldPlace[i])));
42626
43553
  }
42627
43554
  return test;
42628
43555
  }
@@ -42768,11 +43695,11 @@ function deleteCMajEnvVPSC(e) {
42768
43695
  }
42769
43696
 
42770
43697
  // src/layout/neato/stress-cola.ts
42771
- var fr9 = Math.fround;
43698
+ var fr11 = Math.fround;
42772
43699
  var LOCAL_CONSTR_MAJOR_ITERATIONS2 = 1e3;
42773
43700
  var FLT_MAX4 = 34028234663852886e22;
42774
- var CLUSTER_WEIGHT_FLOOR = fr9(0.01);
42775
- var STRESS_GUARD = 1e-10;
43701
+ var CLUSTER_WEIGHT_FLOOR = fr11(0.01);
43702
+ var STRESS_GUARD2 = 1e-10;
42776
43703
  var NSIZE_SCALE_STEP = 0.1;
42777
43704
  var NSIZE_SCALE_LIMIT = 0.999;
42778
43705
  var NSIZE_SCALE_ACTIVE = 1e-3;
@@ -42783,7 +43710,7 @@ function maxEdgeLength(graph, n) {
42783
43710
  let maxEdgeLen = 0;
42784
43711
  for (let i = 0; i < n; i++) {
42785
43712
  for (let j = 1; j < graph[i].nedges; j++) {
42786
- maxEdgeLen = fr9(Math.max(graph[i].ewgts[j], maxEdgeLen));
43713
+ maxEdgeLen = fr11(Math.max(graph[i].ewgts[j], maxEdgeLen));
42787
43714
  }
42788
43715
  }
42789
43716
  return maxEdgeLen;
@@ -42835,8 +43762,8 @@ function clusterLaplacian(lap2, n, nclusters, maxEdgeLen) {
42835
43762
  if (i < n && j < n - i) {
42836
43763
  v = lap2[c0++];
42837
43764
  } else if (j === 1 && i % 2 === 1) {
42838
- v = fr9(maxEdgeLen * maxEdgeLen);
42839
- if (v > CLUSTER_WEIGHT_FLOOR) v = fr9(1 / v);
43765
+ v = fr11(maxEdgeLen * maxEdgeLen);
43766
+ if (v > CLUSTER_WEIGHT_FLOOR) v = fr11(1 / v);
42840
43767
  } else {
42841
43768
  v = 0;
42842
43769
  }
@@ -42894,7 +43821,7 @@ function colaState(Dij, origN, dCoords, o, maxEdgeLen) {
42894
43821
  degrees,
42895
43822
  coords: floatCoords(dCoords, o.dim, n, origN),
42896
43823
  /* compute constant term in stress sum which is \sum_{i<j} w_{ij}d_{ij}^2 */
42897
- constantTerm: fr9(n * (n - 1) / 2),
43824
+ constantTerm: fr11(n * (n - 1) / 2),
42898
43825
  b: Array.from({ length: o.dim }, () => new Float32Array(n)),
42899
43826
  tmpCoords: new Float32Array(n),
42900
43827
  distAccumulator: new Float32Array(n)
@@ -42926,7 +43853,7 @@ function buildLap13(st) {
42926
43853
  count++;
42927
43854
  let degree = 0;
42928
43855
  for (let j = 0; j < len; j++, count++) {
42929
- const val2 = lap1[count] = fr9(lap1[count] * st.distAccumulator[j]);
43856
+ const val2 = lap1[count] = fr11(lap1[count] * st.distAccumulator[j]);
42930
43857
  degree += val2;
42931
43858
  degrees[i + j + 1] = degrees[i + j + 1] - val2;
42932
43859
  }
@@ -42961,7 +43888,7 @@ var overlapDue = (opt, nsizeScale) => opt.noverlap === NOVERLAP_CONSTRAINTS && n
42961
43888
  function solveHorizontal(st, e, nsizeScale, opt) {
42962
43889
  if (overlapDue(opt, nsizeScale)) {
42963
43890
  generateNonoverlapConstraints(e, {
42964
- nsizeScale: fr9(nsizeScale),
43891
+ nsizeScale: fr11(nsizeScale),
42965
43892
  coords: st.coords,
42966
43893
  k: 0,
42967
43894
  transitiveClosure: nsizeScale >= TRANSITIVE_CLOSURE_SCALE,
@@ -42980,7 +43907,7 @@ function solveHorizontal(st, e, nsizeScale, opt) {
42980
43907
  }
42981
43908
  function solveVertical(st, e, nsizeScale, opt) {
42982
43909
  if (overlapDue(opt, nsizeScale)) {
42983
- generateNonoverlapConstraints(e, { nsizeScale: fr9(nsizeScale), coords: st.coords, k: 1, transitiveClosure: false, opt });
43910
+ generateNonoverlapConstraints(e, { nsizeScale: fr11(nsizeScale), coords: st.coords, k: 1, transitiveClosure: false, opt });
42984
43911
  }
42985
43912
  if (e.m > 0) {
42986
43913
  if (constrainedMajorizationVpsc(e, st.b[1], st.coords[1], LOCAL_CONSTR_MAJOR_ITERATIONS2) < 0) return -1;
@@ -42989,13 +43916,13 @@ function solveVertical(st, e, nsizeScale, opt) {
42989
43916
  }
42990
43917
  return 0;
42991
43918
  }
42992
- function iterate(st, envs, o, observe) {
43919
+ function iterate2(st, envs, o, observe) {
42993
43920
  const s = { iterations: 0, converged: false, oldStress: Number.MAX_VALUE, nsizeScale: 0 };
42994
43921
  for (; s.iterations < o.maxi && !s.converged; s.iterations++) {
42995
43922
  buildLap13(st);
42996
43923
  const newStress = computeStress2(st);
42997
43924
  observe?.(newStress);
42998
- s.converged = newStress < s.oldStress && Math.abs(newStress - s.oldStress) / Math.abs(s.oldStress + STRESS_GUARD) < o.epsilon;
43925
+ s.converged = newStress < s.oldStress && Math.abs(newStress - s.oldStress) / Math.abs(s.oldStress + STRESS_GUARD2) < o.epsilon;
42999
43926
  s.oldStress = newStress;
43000
43927
  scaleUpNodes(s, o.maxi, o.opt);
43001
43928
  if (solveHorizontal(st, envs.hor, s.nsizeScale, o.opt) < 0) return -1;
@@ -43009,7 +43936,7 @@ function optimize(st, graph, o, observe) {
43009
43936
  const vrt = initCMajVPSC(st.n, st.lap2, graph, o.opt, o.opt.diredges);
43010
43937
  if (vrt === null) return -1;
43011
43938
  st.lap1 = new Float32Array(st.lapLength);
43012
- const iterations = iterate(st, { hor, vrt }, o, observe);
43939
+ const iterations = iterate2(st, { hor, vrt }, o, observe);
43013
43940
  if (iterations < 0) return iterations;
43014
43941
  deleteCMajEnvVPSC(hor);
43015
43942
  deleteCMajEnvVPSC(vrt);
@@ -43114,7 +44041,7 @@ function realEdges(de) {
43114
44041
  function isNewEdge(de) {
43115
44042
  return de.info.alg === void 0;
43116
44043
  }
43117
- function addEdge2(de, e) {
44044
+ function addEdge3(de, e) {
43118
44045
  const el = de.info.alg;
43119
44046
  if (el === void 0) {
43120
44047
  de.info.alg = [e];
@@ -43662,10 +44589,10 @@ var Cdt = class {
43662
44589
  }
43663
44590
  /** gts_point_locate (guess=NULL): closest_face + barycenter walk. */
43664
44591
  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);
44592
+ const guess2 = this.closestFace(x, y);
44593
+ if (guess2 === null) return null;
44594
+ const [bx, by] = this.barycenter(guess2);
44595
+ return this.pointLocateWalk(bx, by, x, y, guess2);
43669
44596
  }
43670
44597
  // -------------------------------------------------------------------
43671
44598
  // Delaunay insertion (cdt.c: swap_if_in_circle, add_vertex_to_face)
@@ -47542,10 +48469,19 @@ var SMOOTHING_NONE = 0;
47542
48469
  var INT_MAX2 = 2147483647;
47543
48470
  var ELSCHEME_PENALTY2 = 2;
47544
48471
  var EDGE_LABEL_NODE_PREFIX = "|edgelabel|";
48472
+ function sfdpInitDim(g) {
48473
+ const root = g.root;
48474
+ const outdim = lateInt(aggetGraph(g, "dimen"), DFLT_DIM, 2);
48475
+ const ndim = Math.min(lateInt(aggetGraph(g, "dim"), outdim, 2), MAXDIM);
48476
+ root.info.ndim = ndim;
48477
+ root.info.odim = Math.min(outdim, ndim);
48478
+ return ndim;
48479
+ }
47545
48480
  function sfdpInitGraph(g) {
47546
48481
  setEdgeTypeFromAttr(g, EDGETYPE_LINE);
48482
+ const ndim = sfdpInitDim(g);
47547
48483
  commonInitNodeEdge(g);
47548
- for (const n of g.nodes.values()) neatoInitNode(n);
48484
+ for (const n of g.nodes.values()) neatoInitNode(n, ndim);
47549
48485
  const measurer = layoutMeasurer(g);
47550
48486
  if (measurer !== void 0) {
47551
48487
  for (const n of g.nodes.values()) {
@@ -47662,12 +48598,12 @@ function makeMatrix(g) {
47662
48598
  MATRIX_TYPE_REAL
47663
48599
  );
47664
48600
  }
47665
- function getSizes(g, pad) {
47666
- const sizes = new Array(2 * g.nodes.size).fill(0);
48601
+ function getSizes(g, pad, ndim = DFLT_DIM) {
48602
+ const sizes = new Array(ndim * g.nodes.size).fill(0);
47667
48603
  for (const n of g.nodes.values()) {
47668
48604
  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;
48605
+ sizes[i * ndim] = (n.info.width ?? 0) * 0.5 + pad.x;
48606
+ sizes[i * ndim + 1] = (n.info.height ?? 0) * 0.5 + pad.y;
47671
48607
  }
47672
48608
  return sizes;
47673
48609
  }
@@ -48599,7 +49535,7 @@ var AM_PORTHOYX = 12;
48599
49535
  var SCALE = 10;
48600
49536
  var SCALE2 = SCALE / 2;
48601
49537
  var INT_MAX3 = 2147483647;
48602
- var POINTS_PER_INCH4 = 72;
49538
+ var POINTS_PER_INCH6 = 72;
48603
49539
  function cmpitem(a, b) {
48604
49540
  if (a < b) return -1;
48605
49541
  if (a > b) return 1;
@@ -48827,18 +49763,18 @@ function overlaps(p) {
48827
49763
  return false;
48828
49764
  }
48829
49765
  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);
49766
+ const x = cround(SCALE * (n.info.pos?.[0] ?? 0) * POINTS_PER_INCH6);
49767
+ const y = cround(SCALE * (n.info.pos?.[1] ?? 0) * POINTS_PER_INCH6);
48832
49768
  const width2 = n.info.width ?? 0;
48833
49769
  const height2 = n.info.height ?? 0;
48834
49770
  let w2;
48835
49771
  let h2;
48836
49772
  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));
49773
+ w2 = d2i(SCALE * (cround(width2 / 2 * POINTS_PER_INCH6) + margin.x));
49774
+ h2 = d2i(SCALE * (cround(height2 / 2 * POINTS_PER_INCH6) + margin.y));
48839
49775
  } else {
48840
- w2 = cround(margin.x * SCALE2 * width2 * POINTS_PER_INCH4);
48841
- h2 = cround(margin.y * SCALE2 * height2 * POINTS_PER_INCH4);
49776
+ w2 = cround(margin.x * SCALE2 * width2 * POINTS_PER_INCH6);
49777
+ h2 = cround(margin.y * SCALE2 * height2 * POINTS_PER_INCH6);
48842
49778
  }
48843
49779
  return {
48844
49780
  val: 0,
@@ -48873,8 +49809,8 @@ function cAdjust(g, mode) {
48873
49809
  if (!overlaps(nlist)) return 0;
48874
49810
  runPlan(g, nlist, PLANS.get(mode) ?? PLANS.get(AM_PORTHO));
48875
49811
  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;
49812
+ const x = p.pos.x / POINTS_PER_INCH6 / SCALE;
49813
+ const y = p.pos.y / POINTS_PER_INCH6 / SCALE;
48878
49814
  if (p.np.info.pos) {
48879
49815
  p.np.info.pos[0] = x;
48880
49816
  p.np.info.pos[1] = y;
@@ -48889,10 +49825,10 @@ function cAdjust(g, mode) {
48889
49825
  var POLY_BOX = 1;
48890
49826
  var POLY_CIRCLE = 2;
48891
49827
  var DFLT_SAMPLE2 = 20;
48892
- var POINTS_PER_INCH5 = 72;
49828
+ var POINTS_PER_INCH7 = 72;
48893
49829
  var MIN_SAMPLES = 3;
48894
49830
  function ps2inch2(a) {
48895
- return a / POINTS_PER_INCH5;
49831
+ return a / POINTS_PER_INCH7;
48896
49832
  }
48897
49833
  function isBoxKind(p) {
48898
49834
  return (p.kind & POLY_BOX) !== 0;
@@ -49185,7 +50121,7 @@ function polyOverlap(p, pp, q, qp) {
49185
50121
  // src/layout/neato/adjust-info.ts
49186
50122
  var DEFAULT_VORO_MARGIN = 0.05;
49187
50123
  var INCR = 0.05;
49188
- var POINTS_PER_INCH6 = 72;
50124
+ var POINTS_PER_INCH8 = 72;
49189
50125
  function newInfoState() {
49190
50126
  return {
49191
50127
  nodeInfo: [],
@@ -49240,8 +50176,8 @@ function chkBoundBox(st, graph) {
49240
50176
  function makeInfo(st, graph) {
49241
50177
  const pmargin = { ...sepFactor(graph) };
49242
50178
  if (pmargin.doAdd) {
49243
- pmargin.x /= POINTS_PER_INCH6;
49244
- pmargin.y /= POINTS_PER_INCH6;
50179
+ pmargin.x /= POINTS_PER_INCH8;
50180
+ pmargin.y /= POINTS_PER_INCH8;
49245
50181
  }
49246
50182
  const polyf = pmargin.doAdd ? makeAddPoly : makePoly;
49247
50183
  const info = [];
@@ -49375,7 +50311,7 @@ function sAdjustGraph(g) {
49375
50311
  }
49376
50312
 
49377
50313
  // src/layout/neato/vpsc-adjust.ts
49378
- var POINTS_PER_INCH7 = 72;
50314
+ var POINTS_PER_INCH9 = 72;
49379
50315
  function noClusters() {
49380
50316
  return {
49381
50317
  nvars: 0,
@@ -49401,21 +50337,30 @@ function vpscAdjust(g) {
49401
50337
  noverlap: 2,
49402
50338
  clusters: noClusters(),
49403
50339
  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)
50340
+ x: 2 * ((margin.doAdd ? margin.x : DFLT_MARGIN) / POINTS_PER_INCH9),
50341
+ y: 2 * ((margin.doAdd ? margin.y : DFLT_MARGIN) / POINTS_PER_INCH9)
49406
50342
  },
49407
50343
  nsize: nodes.map((n) => ({ x: n.info.width, y: n.info.height }))
49408
50344
  };
49409
50345
  removeoverlaps(nodes.length, coords, opt);
49410
50346
  nodes.forEach((n, j) => {
49411
- n.info.pos = [coords[0][j], coords[1][j]];
50347
+ n.info.pos[0] = coords[0][j];
50348
+ n.info.pos[1] = coords[1][j];
49412
50349
  });
49413
50350
  return 0;
49414
50351
  }
49415
50352
 
49416
50353
  // src/layout/neato/fdp-adjust.ts
49417
50354
  var DFLT_MARGIN2 = 4;
49418
- var NDIM2 = 2;
50355
+ function sizesByNdim(sizes2, ndim) {
50356
+ if (ndim === 2) return sizes2;
50357
+ const sizes = new Array(sizes2.length / 2 * ndim).fill(0);
50358
+ for (let i = 0; i < sizes2.length / 2; i++) {
50359
+ sizes[i * ndim] = sizes2[i * 2];
50360
+ sizes[i * ndim + 1] = sizes2[i * 2 + 1];
50361
+ }
50362
+ return sizes;
50363
+ }
49419
50364
  function mapBoolDflt(p, defaultValue) {
49420
50365
  if (p === void 0 || p === "") return defaultValue;
49421
50366
  const s = p.toLowerCase();
@@ -49457,14 +50402,14 @@ function overlapPrismTries(flag) {
49457
50402
  }
49458
50403
  function fdpAdjust(g, ntry) {
49459
50404
  const A0 = makeMatrix(g);
49460
- const pos = new Array(NDIM2 * g.nodes.size).fill(0);
50405
+ const ndim = ndimOf(g);
50406
+ const pos = new Array(ndim * g.nodes.size).fill(0);
49461
50407
  const sep = sepFactor(g);
49462
50408
  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);
50409
+ const sizes = sizesByNdim(getSizes(g, pad), ndim);
49464
50410
  for (const n of g.nodes.values()) {
49465
50411
  const i = n.info.id;
49466
- pos[i * NDIM2] = n.info.pos?.[0] ?? 0;
49467
- pos[i * NDIM2 + 1] = n.info.pos?.[1] ?? 0;
50412
+ for (let k = 0; k < ndim; k++) pos[i * ndim + k] = n.info.pos?.[k] ?? 0;
49468
50413
  }
49469
50414
  const A3 = !smIsSymmetric(A0, false) || A0.type !== MATRIX_TYPE_REAL ? smGetRealAdjacencySymmetrized(A0) : smRemoveDiagonal(A0);
49470
50415
  const scaling = lateDouble(
@@ -49476,12 +50421,11 @@ function fdpAdjust(g, ntry) {
49476
50421
  g.attrs.get("overlap_shrink") ?? g.root.attrs.get("overlap_shrink"),
49477
50422
  true
49478
50423
  );
49479
- removeOverlapPrism(NDIM2, A3, pos, sizes, ntry, scaling, doShrinking);
50424
+ removeOverlapPrism(ndim, A3, pos, sizes, ntry, scaling, doShrinking);
49480
50425
  for (const n of g.nodes.values()) {
49481
50426
  const i = n.info.id;
49482
50427
  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];
50428
+ for (let k = 0; k < ndim; k++) n.info.pos[k] = pos[i * ndim + k];
49485
50429
  }
49486
50430
  }
49487
50431
  var AM_NONE = 0;
@@ -49575,9 +50519,9 @@ function graphAdjustMode(g) {
49575
50519
  }
49576
50520
 
49577
50521
  // src/layout/neato/ipsep-opts.ts
49578
- var POINTS_PER_INCH8 = 72;
50522
+ var POINTS_PER_INCH10 = 72;
49579
50523
  var HIER_PREFIX = "hier";
49580
- var ps2inch3 = (points2) => points2 / POINTS_PER_INCH8;
50524
+ var ps2inch3 = (points2) => points2 / POINTS_PER_INCH10;
49581
50525
  var zeroBox = () => ({ ll: { x: 0, y: 0 }, ur: { x: 0, y: 0 } });
49582
50526
  function memberIndices(subg, nodes) {
49583
50527
  const members = nodesInSeq(subg);
@@ -49656,19 +50600,8 @@ function ipsepOptions(mg, g, nodes, am) {
49656
50600
  return { diredges, edgeGap, noverlap, gap, nsize, clusters };
49657
50601
  }
49658
50602
 
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
50603
  // src/layout/neato/set-aspect.ts
49671
- var POINTS_PER_INCH10 = 72;
50604
+ var POINTS_PER_INCH11 = 72;
49672
50605
  function neatoRatioKind(g) {
49673
50606
  const p = g.attrs.get("ratio");
49674
50607
  if (p === void 0) return null;
@@ -49716,8 +50649,8 @@ function neatoTranslate(g) {
49716
50649
  const bb = g.info.bb;
49717
50650
  if (!bb) return;
49718
50651
  const ll = bb.ll;
49719
- const ox = ll.x / POINTS_PER_INCH10;
49720
- const oy = ll.y / POINTS_PER_INCH10;
50652
+ const ox = ll.x / POINTS_PER_INCH11;
50653
+ const oy = ll.y / POINTS_PER_INCH11;
49721
50654
  for (const n of g.nodes.values()) {
49722
50655
  if (!n.info.pos) n.info.pos = [0, 0];
49723
50656
  n.info.pos[0] = (n.info.pos[0] ?? 0) - ox;
@@ -49802,8 +50735,7 @@ var MODEL_SHORTPATH2 = 0;
49802
50735
  var MODEL_CIRCUIT2 = 1;
49803
50736
  var MODEL_SUBSET2 = 2;
49804
50737
  var MODEL_MDS2 = 3;
49805
- var DFLT_DIM = 2;
49806
- var POINTS_PER_INCH11 = 72;
50738
+ var POINTS_PER_INCH12 = 72;
49807
50739
  function neatoInitNode(n, dim = DFLT_DIM) {
49808
50740
  if (!n.info.pos || n.info.pos.length < dim) {
49809
50741
  const pos = [];
@@ -49815,19 +50747,6 @@ function neatoInitNode(n, dim = DFLT_DIM) {
49815
50747
  if (!n.info.width && !plainShaped) n.info.width = 0.75;
49816
50748
  if (!n.info.height && !plainShaped) n.info.height = 0.5;
49817
50749
  }
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
50750
  function assignNodeIds2(g) {
49832
50751
  const nodeList = [];
49833
50752
  let idx = 0;
@@ -49847,10 +50766,11 @@ function solveStress(c, vtx, dCoords, nodeList) {
49847
50766
  const { g, mode, model, opts } = c;
49848
50767
  const n = nodeList.length;
49849
50768
  const maxi = neatoMaxIter(g.attrs.get("maxiter"), mode, n);
50769
+ const dim = ndimOf(g);
49850
50770
  const epsilon = lateDouble(g.attrs.get("epsilon"), 1e-4, 0);
49851
50771
  if (mode === MODE_HIER) {
49852
50772
  return stressMajorizationWithHierarchy(vtx, n, dCoords, nodeList, {
49853
- dim: DFLT_DIM,
50773
+ dim,
49854
50774
  opts,
49855
50775
  model,
49856
50776
  maxi,
@@ -49861,7 +50781,7 @@ function solveStress(c, vtx, dCoords, nodeList) {
49861
50781
  if (mode === MODE_IPSEP) {
49862
50782
  const opt = ipsepOptions(g.root, g, nodeList, c.am);
49863
50783
  return stressMajorizationCola(vtx, n, dCoords, nodeList, {
49864
- dim: DFLT_DIM,
50784
+ dim,
49865
50785
  model,
49866
50786
  maxi,
49867
50787
  epsilon,
@@ -49870,7 +50790,7 @@ function solveStress(c, vtx, dCoords, nodeList) {
49870
50790
  }
49871
50791
  const Dij = stressModelDij(vtx, n, model);
49872
50792
  return stressMajorizationKDMkernel(Dij, n, dCoords, nodeList, {
49873
- dim: DFLT_DIM,
50793
+ dim,
49874
50794
  opts,
49875
50795
  maxi,
49876
50796
  epsilon
@@ -49885,13 +50805,14 @@ function runMajorization(g, mode, model, am) {
49885
50805
  const opts = checkExp(g) | (init === INIT_SELF ? OPT_SMART_INIT : 0);
49886
50806
  const haveDir = mode === MODE_HIER || mode === MODE_IPSEP;
49887
50807
  const vtx = makeGraphDataC(g, nodeList, haveLen, haveDir, mode);
49888
- const dCoords = [new Float64Array(n), new Float64Array(n)];
50808
+ const ndim = ndimOf(g);
50809
+ const dCoords = Array.from({ length: ndim }, () => new Float64Array(n));
49889
50810
  if (solveStress({ g, mode, model, opts, am }, vtx, dCoords, nodeList) < 0) {
49890
50811
  agerr("prev", "layout aborted");
49891
50812
  return;
49892
50813
  }
49893
50814
  for (let i = 0; i < n; i++) {
49894
- nodeList[i].info.pos = [dCoords[0][i], dCoords[1][i]];
50815
+ nodeList[i].info.pos = dCoords.map((c) => c[i]);
49895
50816
  }
49896
50817
  }
49897
50818
  var NO_ADJUST = { mode: AM_NONE, print: "none", value: 0 };
@@ -49914,8 +50835,8 @@ function neatoSetAspect(g) {
49914
50835
  const pos = n.info.pos;
49915
50836
  if (!pos) continue;
49916
50837
  n.info.coord = {
49917
- x: (pos[0] ?? 0) * POINTS_PER_INCH11,
49918
- y: (pos[1] ?? 0) * POINTS_PER_INCH11
50838
+ x: (pos[0] ?? 0) * POINTS_PER_INCH12,
50839
+ y: (pos[1] ?? 0) * POINTS_PER_INCH12
49919
50840
  };
49920
50841
  }
49921
50842
  }
@@ -49931,7 +50852,7 @@ function neatoCleanup(g) {
49931
50852
  }
49932
50853
 
49933
50854
  // src/layout/twopi/init.ts
49934
- var POINTS_PER_INCH12 = 72;
50855
+ var POINTS_PER_INCH13 = 72;
49935
50856
  function makeRdata(INF) {
49936
50857
  return {
49937
50858
  kind: "twopi",
@@ -49983,8 +50904,8 @@ function finaliseCoords(g) {
49983
50904
  const pos = n.info.pos;
49984
50905
  if (!pos) continue;
49985
50906
  n.info.coord = {
49986
- x: (pos[0] ?? 0) * POINTS_PER_INCH12,
49987
- y: (pos[1] ?? 0) * POINTS_PER_INCH12
50907
+ x: (pos[0] ?? 0) * POINTS_PER_INCH13,
50908
+ y: (pos[1] ?? 0) * POINTS_PER_INCH13
49988
50909
  };
49989
50910
  }
49990
50911
  }
@@ -50220,7 +51141,10 @@ function circleLayout(sg, center) {
50220
51141
  if (center === null) center = findCenterNode(sg);
50221
51142
  if (center === null) return null;
50222
51143
  const maxN = setParentNodes(sg, center);
50223
- if (maxN === Number.MAX_SAFE_INTEGER) return center;
51144
+ if (maxN === Number.MAX_SAFE_INTEGER) {
51145
+ agerrorf("twopi: use of weight=0 creates disconnected component.");
51146
+ return center;
51147
+ }
50224
51148
  setSubtreeSize(sg);
50225
51149
  setSubtreeSpans(sg, center);
50226
51150
  setPositions(sg, center);
@@ -50311,18 +51235,21 @@ function parseModel(g) {
50311
51235
  function maybeRemoveOverlap(g, am) {
50312
51236
  removeOverlapWith(g, am);
50313
51237
  }
50314
- function neatoLayout(g) {
50315
- graphInit(g, false);
50316
- setEdgeTypeFromAttr(g, EDGETYPE_LINE);
50317
- commonInitNodeEdge(g);
51238
+ function neatoInitNodeEdge(g, ndim) {
50318
51239
  for (const [, n] of g.nodes) {
50319
- neatoInitNode(n);
50320
- userPos(n);
51240
+ neatoInitNode(n, ndim);
51241
+ userPos(n, ndim, g.nodes.size);
50321
51242
  }
50322
51243
  const measurer = layoutMeasurer(g);
50323
51244
  if (measurer !== void 0) {
50324
51245
  for (const e of g.edges) initEdgeLabels(e, g, measurer);
50325
51246
  }
51247
+ }
51248
+ function neatoLayout(g) {
51249
+ graphInit(g, false);
51250
+ setEdgeTypeFromAttr(g, EDGETYPE_LINE);
51251
+ commonInitNodeEdge(g);
51252
+ neatoInitNodeEdge(g, neatoInitGraphDim(g));
50326
51253
  const mode = parseMode(g);
50327
51254
  const am = graphAdjustMode(g);
50328
51255
  const model = parseModel(g);
@@ -50334,6 +51261,7 @@ function neatoLayout(g) {
50334
51261
  maybeRemoveOverlap(g, am);
50335
51262
  splineEdgesShifted(g);
50336
51263
  }
51264
+ addZ(g);
50337
51265
  addClusters(g);
50338
51266
  g.info.bb = computeSubgraphBB(g, 0);
50339
51267
  placeGraphLabel(g);
@@ -50525,127 +51453,6 @@ function initParams(g, xpms) {
50525
51453
  return ret;
50526
51454
  }
50527
51455
 
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
51456
  // src/layout/fdp/init.ts
50650
51457
  function initialPositions3(g) {
50651
51458
  const div = inputscaleDivisor(g);
@@ -51503,7 +52310,7 @@ function deriveEdges(g, dg, byPair) {
51503
52310
  dndata(hd).deg++;
51504
52311
  dndata(tl).deg++;
51505
52312
  }
51506
- addEdge2(de, e);
52313
+ addEdge3(de, e);
51507
52314
  }
51508
52315
  }
51509
52316
  }
@@ -51525,7 +52332,7 @@ function derivePort(g, dg, byPair, port, m) {
51525
52332
  const de = deriveEdge(dg, byPair, m, dn);
51526
52333
  de.info.dist = port.e.info.dist;
51527
52334
  de.info.factor = port.e.info.factor;
51528
- addEdge2(de, port.e);
52335
+ addEdge3(de, port.e);
51529
52336
  dndata(dn).wdeg++;
51530
52337
  dndata(m).wdeg++;
51531
52338
  dndata(dn).deg++;
@@ -51635,7 +52442,7 @@ function expandCluster2(n, cg) {
51635
52442
  }
51636
52443
 
51637
52444
  // src/layout/fdp/layout.ts
51638
- var POINTS_PER_INCH13 = 72;
52445
+ var POINTS_PER_INCH14 = 72;
51639
52446
  var DEFAULT_NODEWIDTH_PTS = 54;
51640
52447
  var DEFAULT_NODEHEIGHT_PTS = 36;
51641
52448
  function initInfo(g) {
@@ -51730,7 +52537,7 @@ function shiftComponents(cc, pts, pt) {
51730
52537
  } else {
51731
52538
  p = pt;
51732
52539
  }
51733
- const del = { x: p.x / POINTS_PER_INCH13, y: p.y / POINTS_PER_INCH13 };
52540
+ const del = { x: p.x / POINTS_PER_INCH14, y: p.y / POINTS_PER_INCH14 };
51734
52541
  for (const n of cc[i].nodes.values()) {
51735
52542
  n.info.pos[0] += del.x;
51736
52543
  n.info.pos[1] += del.y;
@@ -51746,8 +52553,8 @@ function finalCC(g, cc, pts, rg, infop) {
51746
52553
  const pt = applyMarginAndBorder(rg, bb, margin);
51747
52554
  if (cc.length > 0) shiftComponents(cc, pts, pt);
51748
52555
  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 }
52556
+ ll: { x: bb.ll.x / POINTS_PER_INCH14, y: bb.ll.y / POINTS_PER_INCH14 },
52557
+ ur: { x: bb.ur.x / POINTS_PER_INCH14, y: bb.ur.y / POINTS_PER_INCH14 }
51751
52558
  };
51752
52559
  }
51753
52560
  function applyMarginAndBorder(rg, bb, margin) {
@@ -51793,8 +52600,8 @@ function translateOwnNodes(g, bb) {
51793
52600
  function setBB(g) {
51794
52601
  const bb = gdata(g).bb;
51795
52602
  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 }
52603
+ ll: { x: POINTS_PER_INCH14 * bb.ll.x, y: POINTS_PER_INCH14 * bb.ll.y },
52604
+ ur: { x: POINTS_PER_INCH14 * bb.ur.x, y: POINTS_PER_INCH14 * bb.ur.y }
51798
52605
  };
51799
52606
  const nClusters = g.info.n_cluster ?? 0;
51800
52607
  for (let i = 0; i < nClusters; i++) {
@@ -51809,8 +52616,8 @@ function setClustNodes(root) {
51809
52616
  const bb = gdata(p).bb;
51810
52617
  const w = bb.ur.x - bb.ll.x;
51811
52618
  const h = bb.ur.y - bb.ll.y;
51812
- const w2 = POINTS_PER_INCH13 * (w / 2);
51813
- const h2 = POINTS_PER_INCH13 * (h / 2);
52619
+ const w2 = POINTS_PER_INCH14 * (w / 2);
52620
+ const h2 = POINTS_PER_INCH14 * (h / 2);
51814
52621
  n.info.pos[0] = w / 2;
51815
52622
  n.info.pos[1] = h / 2;
51816
52623
  n.info.width = w;
@@ -51819,7 +52626,7 @@ function setClustNodes(root) {
51819
52626
  n.info.outline_width = w + penwidth;
51820
52627
  n.info.outline_height = h + penwidth;
51821
52628
  n.info.lw = n.info.rw = w2;
51822
- n.info.ht = POINTS_PER_INCH13 * h;
52629
+ n.info.ht = POINTS_PER_INCH14 * h;
51823
52630
  const poly = n.info.shape_info;
51824
52631
  if (poly && poly.vertices) {
51825
52632
  poly.vertices[0] = { x: w2, y: h2 };
@@ -51832,8 +52639,8 @@ function setClustNodes(root) {
51832
52639
  function syncCoordFromPos(cg) {
51833
52640
  for (const n of cg.nodes.values()) {
51834
52641
  n.info.coord = {
51835
- x: POINTS_PER_INCH13 * n.info.pos[0],
51836
- y: POINTS_PER_INCH13 * n.info.pos[1]
52642
+ x: POINTS_PER_INCH14 * n.info.pos[0],
52643
+ y: POINTS_PER_INCH14 * n.info.pos[1]
51837
52644
  };
51838
52645
  }
51839
52646
  }
@@ -51845,8 +52652,8 @@ function expandComponentClusters(cg, infop, counter) {
51845
52652
  if (r !== 0) return r;
51846
52653
  n.info.width = gdata(sg).bb.ur.x;
51847
52654
  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;
52655
+ const ptx = POINTS_PER_INCH14 * gdata(sg).bb.ur.x;
52656
+ const pty = POINTS_PER_INCH14 * gdata(sg).bb.ur.y;
51850
52657
  n.info.rw = n.info.lw = ptx / 2;
51851
52658
  n.info.ht = pty;
51852
52659
  } else if (isPort(n)) {
@@ -52410,15 +53217,15 @@ function multilevelSpringElectricalEmbedding(dim, A0, ctrl, labelSizes, x) {
52410
53217
  }
52411
53218
 
52412
53219
  // src/layout/sfdp/index.ts
52413
- var DIM = 2;
52414
53220
  function sfdpLayoutComponent(g, ctrl, pad) {
53221
+ const ndim = ndimOf(g);
52415
53222
  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);
53223
+ const sizes = ctrl.overlap >= 0 ? getSizes(g, pad, ndim) : null;
53224
+ const pos = getPos(g, ndim);
53225
+ multilevelSpringElectricalEmbedding(ndim, A3, ctrl, sizes, pos);
52419
53226
  for (const n of g.nodes.values()) {
52420
53227
  const i = n.info.id;
52421
- n.info.pos = [pos[i * DIM], pos[i * DIM + 1]];
53228
+ n.info.pos = pos.slice(i * ndim, (i + 1) * ndim);
52422
53229
  }
52423
53230
  }
52424
53231
  function resolveControl(g) {
@@ -52429,7 +53236,8 @@ function resolveControl(g) {
52429
53236
  const flag = overlap5 === void 0 ? "prism0" : overlap5;
52430
53237
  warnUnrecognizedOverlap(flag);
52431
53238
  const ntry = overlapPrismTries(flag);
52432
- if (ntry !== null) {
53239
+ const doAdjust = ndimOf(g) === 2;
53240
+ if (ntry !== null && doAdjust) {
52433
53241
  ctrl.overlap = ntry;
52434
53242
  ctrl.initialScaling = lateDouble(
52435
53243
  g.root.attrs.get("overlap_scaling"),
@@ -52444,7 +53252,7 @@ function resolveControl(g) {
52444
53252
  return { ctrl, pad, doAdjust: false };
52445
53253
  }
52446
53254
  ctrl.overlap = -1;
52447
- return { ctrl, pad, doAdjust: true };
53255
+ return { ctrl, pad, doAdjust };
52448
53256
  }
52449
53257
  function layoutComponents3(g, comps, ctrl, pad, doAdjust) {
52450
53258
  const pinfo = {
@@ -52492,6 +53300,7 @@ function sfdpLayout(g) {
52492
53300
  } else {
52493
53301
  layoutComponents3(g, comps, ctrl, pad, doAdjust);
52494
53302
  }
53303
+ for (const c of comps) agdelsubg(g, c);
52495
53304
  }
52496
53305
  postprocess(g, singleComponent);
52497
53306
  }
@@ -53405,7 +54214,7 @@ function buildDerivedEdges(g, dg) {
53405
54214
  return edges;
53406
54215
  }
53407
54216
  function derivedComponents(g, dg, allEdges3) {
53408
- const comps = ccomps(g);
54217
+ const comps = ccomps(g, null, false);
53409
54218
  return comps.map((sg, i) => {
53410
54219
  const nodes = [];
53411
54220
  for (const n of sg.nodes.values()) {
@@ -53539,6 +54348,7 @@ function twopiLayout(g) {
53539
54348
  } else {
53540
54349
  layoutMulti(g, comps, globalRoot, buildPackInfo(g));
53541
54350
  }
54351
+ for (const c of comps) agdelsubg(g, c);
53542
54352
  normalizeGraphBB(g);
53543
54353
  placeGraphLabel(g);
53544
54354
  gvPostprocess(g);
@@ -54351,8 +55161,8 @@ var forfunc = (cur, total, init) => (1 - cur / total) * init / 2;
54351
55161
  var revfunc = (cur, total, init) => cur / total * init / 2;
54352
55162
  var nonefunc = (_cur, _total, init) => init / 2;
54353
55163
  var bothfunc = (cur, total, init) => {
54354
- const fr10 = cur / total;
54355
- return fr10 <= 0.5 ? fr10 * init : (1 - fr10) * init;
55164
+ const fr12 = cur / total;
55165
+ return fr12 <= 0.5 ? fr12 * init : (1 - fr12) * init;
54356
55166
  };
54357
55167
  function taperfun(dir, directed) {
54358
55168
  if (dir === "forward") return forfunc;
@@ -55214,6 +56024,15 @@ function trimFixed3(v) {
55214
56024
  function edgeAttrsAttached(e) {
55215
56025
  return e.info.edge_type !== IGNORED && e.info.spl != null;
55216
56026
  }
56027
+ function nodePosRaw(n) {
56028
+ const c = n.info.coord;
56029
+ let raw = gfmt5(c.x) + "," + gfmt5(c.y);
56030
+ const odim = n.root.info.odim ?? 2;
56031
+ for (let k = 2; odim >= 3 && k < odim; k++) {
56032
+ raw += "," + gfmt5(POINTS_PER_INCH2 * (n.info.pos?.[k] ?? 0));
56033
+ }
56034
+ return raw;
56035
+ }
55217
56036
  function appendRecordRects(n, f, out) {
55218
56037
  const c = n.info.coord;
55219
56038
  if (f.n_flds === 0) {
@@ -55685,7 +56504,7 @@ var DotWriterBase = class {
55685
56504
  nodeAttrs(n, scope) {
55686
56505
  const info = n.info;
55687
56506
  const defs = effectiveNodeDefaults(scope);
55688
- const posRaw = gfmt5(info.coord.x) + "," + gfmt5(info.coord.y);
56507
+ const posRaw = nodePosRaw(n);
55689
56508
  const widthRaw = gfmt5((info.lw + info.rw) / 72);
55690
56509
  const heightRaw = gfmt5(info.ht / 72);
55691
56510
  const parts = [
@@ -55937,13 +56756,13 @@ var EdgeDrawBase = class extends DotWriterBase {
55937
56756
  };
55938
56757
 
55939
56758
  // src/render/dot/write-back.ts
55940
- var POINTS_PER_INCH14 = 72;
56759
+ var POINTS_PER_INCH15 = 72;
55941
56760
  function attachNode(n) {
55942
56761
  const attrs = ownAttrs(n);
55943
56762
  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));
56763
+ attrs.set("pos", nodePosRaw(n));
56764
+ attrs.set("height", gfmt5(info.ht / POINTS_PER_INCH15));
56765
+ attrs.set("width", gfmt5((info.lw + info.rw) / POINTS_PER_INCH15));
55947
56766
  const xlabel = info.xlabel;
55948
56767
  if (xlabel?.set) attrs.set("xlp", lpStr(xlabel.pos));
55949
56768
  if (info.shape?.name === "record") {
@@ -55973,8 +56792,8 @@ function recAttachBb(g) {
55973
56792
  const label = g.info.label;
55974
56793
  if (label && label.text.length > 0) {
55975
56794
  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));
56795
+ g.attrs.set("lwidth", gfmt2(label.dimen.x / POINTS_PER_INCH15));
56796
+ g.attrs.set("lheight", gfmt2(label.dimen.y / POINTS_PER_INCH15));
55978
56797
  }
55979
56798
  for (const sg of clustersOf(g)) recAttachBb(sg);
55980
56799
  }
@@ -60121,8 +60940,8 @@ var StmtProcessor = class _StmtProcessor {
60121
60940
  * @see lib/cgraph/edge.c:agedge:274-275 (`if (e == NULL && agisundirected(g))`)
60122
60941
  */
60123
60942
  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}`;
60943
+ const swap4 = undirected && head.id < tail.id;
60944
+ return swap4 ? `${head.id}\0${tail.id}` : `${tail.id}\0${head.id}`;
60126
60945
  }
60127
60946
  /**
60128
60947
  * Apply the DOT-syntax `:port:compass` endpoints to an edge's attrs.