@knowvah/dot-engine 2.12.1 → 2.12.3

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 (308) hide show
  1. package/dist/api/builder.d.ts +7 -1
  2. package/dist/api/builder.d.ts.map +1 -1
  3. package/dist/api.js +14 -7
  4. package/dist/api.js.map +2 -2
  5. package/dist/common/compass-port.d.ts.map +1 -1
  6. package/dist/common/edge-label-init.d.ts +26 -1
  7. package/dist/common/edge-label-init.d.ts.map +1 -1
  8. package/dist/common/graph-init.d.ts.map +1 -1
  9. package/dist/common/htmltable-label.d.ts.map +1 -1
  10. package/dist/common/htmltable-lex.d.ts +3 -1
  11. package/dist/common/htmltable-lex.d.ts.map +1 -1
  12. package/dist/common/htmltable-parse-image.d.ts +23 -0
  13. package/dist/common/htmltable-parse-image.d.ts.map +1 -0
  14. package/dist/common/htmltable-parse-state.d.ts +4 -0
  15. package/dist/common/htmltable-parse-state.d.ts.map +1 -1
  16. package/dist/common/htmltable-parse.d.ts +33 -2
  17. package/dist/common/htmltable-parse.d.ts.map +1 -1
  18. package/dist/common/nodeinit.d.ts +16 -2
  19. package/dist/common/nodeinit.d.ts.map +1 -1
  20. package/dist/common/poly-inside.d.ts.map +1 -1
  21. package/dist/common/splines-geom.d.ts +2 -1
  22. package/dist/common/splines-geom.d.ts.map +1 -1
  23. package/dist/common/splines-path-begin.d.ts.map +1 -1
  24. package/dist/common/splines-path-end.d.ts.map +1 -1
  25. package/dist/common/splines-routespl.d.ts +3 -0
  26. package/dist/common/splines-routespl.d.ts.map +1 -1
  27. package/dist/gvc/context.d.ts +8 -0
  28. package/dist/gvc/context.d.ts.map +1 -1
  29. package/dist/gvc/emit-gates.d.ts +5 -10
  30. package/dist/gvc/emit-gates.d.ts.map +1 -1
  31. package/dist/gvc/emit-xdot.d.ts +7 -6
  32. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  33. package/dist/gvc/job.d.ts +5 -2
  34. package/dist/gvc/job.d.ts.map +1 -1
  35. package/dist/gvc/viewport.d.ts +10 -5
  36. package/dist/gvc/viewport.d.ts.map +1 -1
  37. package/dist/index.js +21565 -21326
  38. package/dist/index.js.map +4 -4
  39. package/dist/layout/dot/classify.d.ts.map +1 -1
  40. package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
  41. package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
  42. package/dist/layout/dot/edge-route-chain.d.ts +20 -16
  43. package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
  44. package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
  45. package/dist/layout/dot/edge-route.d.ts +7 -3
  46. package/dist/layout/dot/edge-route.d.ts.map +1 -1
  47. package/dist/layout/dot/fastgr.d.ts +5 -3
  48. package/dist/layout/dot/fastgr.d.ts.map +1 -1
  49. package/dist/layout/dot/flat-adj-record.d.ts +22 -0
  50. package/dist/layout/dot/flat-adj-record.d.ts.map +1 -0
  51. package/dist/layout/dot/flat.d.ts +22 -7
  52. package/dist/layout/dot/flat.d.ts.map +1 -1
  53. package/dist/layout/dot/init.d.ts +49 -9
  54. package/dist/layout/dot/init.d.ts.map +1 -1
  55. package/dist/layout/dot/mincross-build.d.ts +6 -0
  56. package/dist/layout/dot/mincross-build.d.ts.map +1 -1
  57. package/dist/layout/dot/mincross-flat.d.ts +10 -1
  58. package/dist/layout/dot/mincross-flat.d.ts.map +1 -1
  59. package/dist/layout/dot/mincross.d.ts +6 -1
  60. package/dist/layout/dot/mincross.d.ts.map +1 -1
  61. package/dist/layout/dot/ns-subtree.d.ts +9 -6
  62. package/dist/layout/dot/ns-subtree.d.ts.map +1 -1
  63. package/dist/layout/dot/pack-components.d.ts +4 -3
  64. package/dist/layout/dot/pack-components.d.ts.map +1 -1
  65. package/dist/layout/dot/position-aux.d.ts +69 -21
  66. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  67. package/dist/layout/dot/position-bbox.d.ts.map +1 -1
  68. package/dist/layout/dot/position-ycoords.d.ts.map +1 -1
  69. package/dist/layout/dot/position.d.ts.map +1 -1
  70. package/dist/layout/dot/rank-dot2.d.ts +7 -25
  71. package/dist/layout/dot/rank-dot2.d.ts.map +1 -1
  72. package/dist/layout/dot/self-loop.d.ts +11 -4
  73. package/dist/layout/dot/self-loop.d.ts.map +1 -1
  74. package/dist/layout/dot/splines-clone.d.ts +2 -1
  75. package/dist/layout/dot/splines-clone.d.ts.map +1 -1
  76. package/dist/layout/dot/splines-flat-labeled.d.ts.map +1 -1
  77. package/dist/layout/dot/splines-flat-multi.d.ts +11 -3
  78. package/dist/layout/dot/splines-flat-multi.d.ts.map +1 -1
  79. package/dist/layout/dot/splines-flat.d.ts +18 -0
  80. package/dist/layout/dot/splines-flat.d.ts.map +1 -1
  81. package/dist/layout/dot/splines-groups.d.ts.map +1 -1
  82. package/dist/layout/dot/splines-route.d.ts +6 -3
  83. package/dist/layout/dot/splines-route.d.ts.map +1 -1
  84. package/dist/layout/dot/straight-edges.d.ts.map +1 -1
  85. package/dist/layout/fdp/ports.d.ts.map +1 -1
  86. package/dist/layout/fdp/tlayout.d.ts +3 -0
  87. package/dist/layout/fdp/tlayout.d.ts.map +1 -1
  88. package/dist/layout/neato/__fixtures__/hier-imds.d.ts +5 -4
  89. package/dist/layout/neato/__fixtures__/hier-imds.d.ts.map +1 -1
  90. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts +6 -5
  91. package/dist/layout/neato/__fixtures__/hier-majorization.d.ts.map +1 -1
  92. package/dist/layout/neato/conjgrad-mkernel.d.ts.map +1 -1
  93. package/dist/layout/neato/conjgrad.d.ts +7 -6
  94. package/dist/layout/neato/conjgrad.d.ts.map +1 -1
  95. package/dist/layout/neato/matrix-ops-dense.d.ts +1 -6
  96. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -1
  97. package/dist/layout/neato/matrix-ops.d.ts +0 -6
  98. package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
  99. package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -1
  100. package/dist/layout/neato/sgd.d.ts.map +1 -1
  101. package/dist/model/cgraph-ops.d.ts +10 -2
  102. package/dist/model/cgraph-ops.d.ts.map +1 -1
  103. package/dist/model/edge.d.ts +7 -2
  104. package/dist/model/edge.d.ts.map +1 -1
  105. package/dist/model/edgeInfo.d.ts +17 -2
  106. package/dist/model/edgeInfo.d.ts.map +1 -1
  107. package/dist/model/graph.d.ts +4 -3
  108. package/dist/model/graph.d.ts.map +1 -1
  109. package/dist/model/lazy-attrs.d.ts.map +1 -1
  110. package/dist/model/rankEntry.d.ts +3 -1
  111. package/dist/model/rankEntry.d.ts.map +1 -1
  112. package/dist/ortho/index.d.ts +0 -1
  113. package/dist/ortho/index.d.ts.map +1 -1
  114. package/dist/ortho/partition.d.ts +2 -4
  115. package/dist/ortho/partition.d.ts.map +1 -1
  116. package/dist/parser/builder.d.ts.map +1 -1
  117. package/dist/pathplan/route.d.ts +93 -0
  118. package/dist/pathplan/route.d.ts.map +1 -1
  119. package/dist/render/dot/agwrite.d.ts +26 -10
  120. package/dist/render/dot/agwrite.d.ts.map +1 -1
  121. package/dist/render/dot/attrs.d.ts +15 -4
  122. package/dist/render/dot/attrs.d.ts.map +1 -1
  123. package/dist/render/dot/types.d.ts +7 -2
  124. package/dist/render/dot/types.d.ts.map +1 -1
  125. package/dist/render/dot/write-back.d.ts +14 -0
  126. package/dist/render/dot/write-back.d.ts.map +1 -1
  127. package/dist/render/dot/xdot-ops.d.ts +20 -29
  128. package/dist/render/dot/xdot-ops.d.ts.map +1 -1
  129. package/dist/render/dot.d.ts +4 -2
  130. package/dist/render/dot.d.ts.map +1 -1
  131. package/dist/render/json-cluster-edge.d.ts +17 -4
  132. package/dist/render/json-cluster-edge.d.ts.map +1 -1
  133. package/dist/render/json-nonfinite.d.ts +17 -0
  134. package/dist/render/json-nonfinite.d.ts.map +1 -0
  135. package/dist/render/json.d.ts +4 -0
  136. package/dist/render/json.d.ts.map +1 -1
  137. package/dist/render/map.d.ts +3 -0
  138. package/dist/render/map.d.ts.map +1 -1
  139. package/dist/render/svg-graph.d.ts.map +1 -1
  140. package/dist/render/svg-id.d.ts +10 -1
  141. package/dist/render/svg-id.d.ts.map +1 -1
  142. package/dist/render/svg.d.ts +3 -1
  143. package/dist/render/svg.d.ts.map +1 -1
  144. package/dist/render.js +21517 -21278
  145. package/dist/render.js.map +4 -4
  146. package/dist/util/bsd-qsort.d.ts.map +1 -1
  147. package/dist/util/overflow.d.ts +37 -0
  148. package/dist/util/overflow.d.ts.map +1 -0
  149. package/dist/xdot/parse.d.ts.map +1 -1
  150. package/dist/xdot/strtod.d.ts +23 -0
  151. package/dist/xdot/strtod.d.ts.map +1 -0
  152. package/package.json +3 -2
  153. package/src/api/builder.ts +8 -2
  154. package/src/common/compass-port.ts +36 -20
  155. package/src/common/edge-label-init.ts +43 -17
  156. package/src/common/graph-init.ts +11 -1
  157. package/src/common/htmltable-label.ts +9 -4
  158. package/src/common/htmltable-lex.ts +5 -2
  159. package/src/common/htmltable-parse-image.ts +69 -0
  160. package/src/common/htmltable-parse-state.ts +6 -0
  161. package/src/common/htmltable-parse.ts +34 -44
  162. package/src/common/nodeinit.ts +28 -8
  163. package/src/common/poly-inside.ts +11 -5
  164. package/src/common/splines-geom.ts +24 -6
  165. package/src/common/splines-path-begin.ts +4 -3
  166. package/src/common/splines-path-end.ts +4 -3
  167. package/src/common/splines-routespl.ts +32 -0
  168. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
  169. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
  170. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
  171. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
  172. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
  173. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
  174. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
  175. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
  176. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
  177. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
  178. package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
  179. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
  180. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
  181. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
  182. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
  183. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
  184. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
  185. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
  186. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
  187. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
  188. package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
  189. package/src/gvc/context.ts +8 -0
  190. package/src/gvc/device.ts +6 -6
  191. package/src/gvc/emit-gates.ts +6 -15
  192. package/src/gvc/emit-xdot.ts +10 -11
  193. package/src/gvc/job.ts +5 -2
  194. package/src/gvc/viewport.ts +13 -7
  195. package/src/layout/dot/__fixtures__/flat-adj-aux-syms.native-16.1.json +1210 -0
  196. package/src/layout/dot/classify.ts +5 -2
  197. package/src/layout/dot/edge-route-chain-views.ts +120 -0
  198. package/src/layout/dot/edge-route-chain.ts +103 -117
  199. package/src/layout/dot/edge-route-faithful.ts +20 -5
  200. package/src/layout/dot/edge-route.ts +44 -49
  201. package/src/layout/dot/fastgr.ts +9 -3
  202. package/src/layout/dot/flat-adj-record.ts +68 -0
  203. package/src/layout/dot/flat.ts +38 -17
  204. package/src/layout/dot/init.ts +59 -13
  205. package/src/layout/dot/mincross-build.ts +14 -1
  206. package/src/layout/dot/mincross-flat.ts +15 -5
  207. package/src/layout/dot/mincross.ts +6 -2
  208. package/src/layout/dot/ns-subtree.ts +11 -7
  209. package/src/layout/dot/pack-components.ts +6 -4
  210. package/src/layout/dot/position-aux.ts +122 -42
  211. package/src/layout/dot/position-bbox.ts +14 -1
  212. package/src/layout/dot/position-ycoords.ts +7 -1
  213. package/src/layout/dot/position.ts +4 -1
  214. package/src/layout/dot/rank-dot2.ts +13 -94
  215. package/src/layout/dot/self-loop.ts +29 -11
  216. package/src/layout/dot/splines-clone.ts +8 -2
  217. package/src/layout/dot/splines-flat-labeled.ts +3 -2
  218. package/src/layout/dot/splines-flat-multi.ts +12 -4
  219. package/src/layout/dot/splines-flat.ts +9 -19
  220. package/src/layout/dot/splines-groups.ts +5 -3
  221. package/src/layout/dot/splines-route.ts +10 -11
  222. package/src/layout/dot/straight-edges.ts +5 -3
  223. package/src/layout/fdp/ports.ts +6 -2
  224. package/src/layout/fdp/tlayout.ts +6 -5
  225. package/src/layout/neato/__fixtures__/conjgrad-d.json +1 -0
  226. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +141 -141
  227. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +339 -339
  228. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +140 -140
  229. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +323 -323
  230. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +141 -141
  231. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +339 -339
  232. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +251 -251
  233. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +535 -535
  234. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +14 -14
  235. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +32 -32
  236. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +8 -8
  237. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +14 -14
  238. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +17 -17
  239. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +35 -35
  240. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +2 -2
  241. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +2 -2
  242. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +11 -11
  243. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +21 -21
  244. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +14 -14
  245. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +26 -26
  246. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +13 -13
  247. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +30 -30
  248. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +10 -10
  249. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +19 -19
  250. package/src/layout/neato/__fixtures__/dim/smart-units.json +1 -1
  251. package/src/layout/neato/__fixtures__/hier/cases/dirnone.plain +10 -10
  252. package/src/layout/neato/__fixtures__/hier/cases/tdist.plain +12 -12
  253. package/src/layout/neato/__fixtures__/hier/hier-probe.plain +1 -1
  254. package/src/layout/neato/__fixtures__/hier/hier-probe.xdot +19 -19
  255. package/src/layout/neato/__fixtures__/hier-imds.ts +14 -13
  256. package/src/layout/neato/__fixtures__/hier-majorization.ts +24 -23
  257. package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +20 -20
  258. package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +8 -8
  259. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +34 -34
  260. package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +32 -32
  261. package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +18 -18
  262. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +13 -13
  263. package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +12 -12
  264. package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +33 -33
  265. package/src/layout/neato/__fixtures__/models/hier-default.xdot +30 -30
  266. package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +30 -30
  267. package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +35 -35
  268. package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +30 -30
  269. package/src/layout/neato/conjgrad-mkernel.ts +6 -2
  270. package/src/layout/neato/conjgrad.ts +38 -35
  271. package/src/layout/neato/matrix-ops-dense.ts +2 -20
  272. package/src/layout/neato/matrix-ops.ts +0 -20
  273. package/src/layout/neato/quad-prog-vpsc.ts +7 -5
  274. package/src/layout/neato/sgd.ts +2 -1
  275. package/src/layout/neato/smart-ini-x.ts +15 -15
  276. package/src/layout/neato/stress-subspace.ts +5 -5
  277. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +6 -6
  278. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +6 -6
  279. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +6 -6
  280. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +6 -6
  281. package/src/layout/sfdp/__fixtures__/dim/regen.sh +2 -0
  282. package/src/model/cgraph-ops.ts +4 -3
  283. package/src/model/edge.ts +11 -4
  284. package/src/model/edgeInfo.ts +18 -2
  285. package/src/model/graph.ts +4 -3
  286. package/src/model/lazy-attrs.ts +3 -1
  287. package/src/model/rankEntry.ts +3 -1
  288. package/src/ortho/index.ts +0 -1
  289. package/src/ortho/partition.ts +10 -22
  290. package/src/parser/builder.ts +12 -3
  291. package/src/pathplan/route.ts +14 -4
  292. package/src/render/dot/agwrite.ts +45 -18
  293. package/src/render/dot/attrs.ts +18 -7
  294. package/src/render/dot/types.ts +7 -2
  295. package/src/render/dot/write-back.ts +27 -3
  296. package/src/render/dot/xdot-ops.ts +25 -56
  297. package/src/render/dot.ts +7 -5
  298. package/src/render/json-cluster-edge.ts +42 -5
  299. package/src/render/json-nonfinite.ts +51 -0
  300. package/src/render/json.ts +23 -26
  301. package/src/render/map.ts +3 -0
  302. package/src/render/svg-graph.ts +3 -15
  303. package/src/render/svg-id.ts +11 -2
  304. package/src/render/svg.ts +4 -1
  305. package/src/util/bsd-qsort.ts +2 -1
  306. package/src/util/overflow.ts +74 -0
  307. package/src/xdot/parse.ts +9 -19
  308. package/src/xdot/strtod.ts +167 -0
@@ -24,7 +24,7 @@ import { Node } from './node.js';
24
24
  * @see lib/cgraph/cghdr.h:LOCALNAMEPREFIX
25
25
  * @see lib/cgraph/id.c:aginternalmapprint
26
26
  */
27
- const LOCALNAMEPREFIX = '%';
27
+ export const LOCALNAMEPREFIX = '%';
28
28
 
29
29
  /**
30
30
  * cgraph's id for the first anonymous object, which an anonymous root graph is
@@ -37,8 +37,9 @@ const ANONYMOUS_ROOT_ID = 1;
37
37
  * Graph name as `agnameof` returns it: the DOT name, or `%<id>` for an
38
38
  * anonymous graph. The port stores `''` for an anonymous root (dot/xdot
39
39
  * re-serialization must not print the `%` name), so it is restored here.
40
- * Anonymous subgraph ids are not tracked; callers pass the root, as C's
41
- * neato message sites do.
40
+ * An anonymous subgraph already carries its `%N` name (the parser allocates
41
+ * it), so only the root needs restoring; the dot writer passes either, and
42
+ * the neato message sites pass the root, as C's do.
42
43
  * @see lib/cgraph/id.c:agnameof
43
44
  */
44
45
  export function agNameOf(g: Graph): string {
package/src/model/edge.ts CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type { Node } from './node.js';
11
11
  import { EMPTY_ATTRS } from './lazy-attrs.js';
12
- import { type EdgeInfo, makeEdgeInfo, makePort } from './edgeInfo.js';
12
+ import { type EdgeInfo, AUX_EDGE_PORT, makeEdgeInfo, makePort } from './edgeInfo.js';
13
13
 
14
14
  /**
15
15
  * Represents an abstract edge in the graph, corresponding to Agedgepair_t.
@@ -93,13 +93,20 @@ export class Edge {
93
93
  */
94
94
  info: EdgeInfo;
95
95
 
96
- /** @see lib/cgraph/edge.c:agedge */
97
- constructor(tail: Node, head: Node, name: string, lazyAttrs = false) {
96
+ /**
97
+ * `auxPorts` is for dot's auxiliary edges only: both ends take the shared
98
+ * {@link AUX_EDGE_PORT} in place of a private port each.
99
+ * @see lib/cgraph/edge.c:agedge
100
+ * @see lib/dotgen/position.c:make_aux_edge
101
+ */
102
+ constructor(tail: Node, head: Node, name: string, lazyAttrs = false, auxPorts = false) {
98
103
  this.seq = Edge._nextSeq++;
99
104
  this.tail = tail;
100
105
  this.head = head;
101
106
  this.name = name;
102
107
  this.attrs = lazyAttrs ? EMPTY_ATTRS : new Map();
103
- this.info = makeEdgeInfo(makePort(), makePort());
108
+ this.info = auxPorts
109
+ ? makeEdgeInfo(AUX_EDGE_PORT, AUX_EDGE_PORT)
110
+ : makeEdgeInfo(makePort(), makePort());
104
111
  }
105
112
  }
@@ -173,8 +173,9 @@ export interface EdgeInfo {
173
173
 
174
174
  /**
175
175
  * Routing attempted and routesplines failed: the edge is LOST exactly as in
176
- * C (no spline installed, map_edge warns, emit skips). Port-only bookkeeping
177
- * so the routeDotEdges backstop does not re-attempt an edge C routes once.
176
+ * C (no spline installed, map_edge warns, emit skips). Port-only bookkeeping:
177
+ * routeLoneEdge skips a lost edge, so a later call in the same routing pass
178
+ * does not re-attempt an edge C routes once; beginRoutingPass clears it.
178
179
  * @see lib/common/routespl.c:routesplines (NULL), lib/common/postproc.c:map_edge
179
180
  */
180
181
  lost?: boolean;
@@ -391,6 +392,21 @@ export function makePort(): Port {
391
392
  };
392
393
  }
393
394
 
395
+ /**
396
+ * The default port both ends of every auxiliary edge share.
397
+ *
398
+ * C's make_aux_edge zero-allocates one Agedgeinfo_t, so an aux edge's
399
+ * ED_tail_port and ED_head_port are two structs inside that block, and nothing
400
+ * writes them before remove_aux_edges frees the edge. A makePort() pair per aux
401
+ * edge stood for those 96 inline bytes with 352 B of separate objects (two
402
+ * ports, two points, four boxed doubles), on a structure separate_subclust
403
+ * builds once per pair of sibling clusters (16.3 M on tests/2475_1.dot). It
404
+ * carries makePort()'s values and is frozen with its point, so a write throws
405
+ * rather than reaching every aux edge.
406
+ * @see lib/dotgen/position.c:make_aux_edge
407
+ */
408
+ export const AUX_EDGE_PORT: Port = Object.freeze({ ...makePort(), p: Object.freeze({ x: 0, y: 0 }) });
409
+
394
410
  /**
395
411
  * Constructs a minimal EdgeInfo with required port fields initialized.
396
412
  *
@@ -48,9 +48,10 @@ export class Graph {
48
48
  * True when the graph was declared with NO name (`digraph {`), as opposed to
49
49
  * an explicit empty name (`digraph "" {`). Both store `name === ''`, but
50
50
  * cgraph gives the truly-anonymous root the internal id `%1` (agnameof) while
51
- * the empty-named one keeps `""`. Only the imagemap `<map id/name>` reads this
52
- * (map.ts:mapGraphName); dot/xdot re-serialization keeps `name` so an
53
- * anonymous root round-trips as `digraph {`, not `digraph %1 {`.
51
+ * the empty-named one keeps `""`. Read through `agNameOf` by the imagemap
52
+ * `<map id/name>`, the neato messages and the dot/xdot writer's header,
53
+ * which prints `digraph {` for an anonymous root and `digraph "" {` for the
54
+ * empty-named one. `name` stays `''` for both.
54
55
  * @see lib/cgraph/id.c:idmap (anon → `%1`) ; lib/cgraph/agraph.c:agnameof
55
56
  */
56
57
  readonly anonymous: boolean;
@@ -1,7 +1,8 @@
1
1
  // SPDX-License-Identifier: EPL-2.0
2
2
 
3
3
  /**
4
- * Shared empty attribute map for dot virtual nodes/edges (AD-12).
4
+ * Shared empty attribute map for dot virtual nodes/edges (AD-12) and for
5
+ * auxiliary edges (make_aux_edge, issue #145).
5
6
  *
6
7
  * C virtual nodes/edges carry no attribute record; allocating an empty `Map`
7
8
  * per object cost ~372 B per virtual pair. Virtual objects start with this
@@ -9,6 +10,7 @@
9
10
  * through {@link ownAttrs}, which materialises a private `Map`. A direct
10
11
  * mutation of the shared map throws rather than leaking into every virtual.
11
12
  * @see lib/dotgen/fastgr.c:virtual_node
13
+ * @see lib/dotgen/position.c:make_aux_edge
12
14
  */
13
15
 
14
16
  class SharedEmptyAttrs extends Map<string, string> {
@@ -73,8 +73,10 @@ export interface RankEntry {
73
73
 
74
74
  /**
75
75
  * Flat-edge adjacency matrix for cycle-breaking. Allocated per-rank by
76
- * flatBreakcycles when any flat edges exist; freed in cleanup2.
76
+ * flatBreakcycles when any flat edges exist. Left set after cleanup2, as
77
+ * C's free_matrix leaves the pointer: flat_edges reads it as a flag.
77
78
  * @see lib/dotgen/mincross.c:GD_rank(g)[r].flat
79
+ * @see lib/dotgen/flat.c:flat_edges (16.1.1) 274
78
80
  */
79
81
  flat?: AdjMatrix;
80
82
 
@@ -23,7 +23,6 @@ import { gvQsort } from "../util/bsd-qsort.js";
23
23
  import { agwarningf } from '../common/agerr.js';
24
24
 
25
25
  export type { OrthoGraph, OrthoEdge, OrthoNode, OrthoPoint, ClipAndInstallFn };
26
- export { SEED } from "./partition.js";
27
26
 
28
27
  // ─── Edge length / sorting ────────────────────────────────────────────────────
29
28
 
@@ -7,23 +7,19 @@
7
7
  * (via perp()). Intersection of the two decompositions yields cells
8
8
  * bounded on all four sides.
9
9
  *
10
- * SEED is fixed at 173 — matches lib/ortho/partition.c:srand48(173).
10
+ * The segment permutation draws from the process-global libc rand() stream
11
+ * (graphviz 16.1.1, b99490ece): partition no longer seeds srand48(173).
11
12
  *
12
13
  * @see lib/ortho/partition.c
13
14
  */
14
15
 
15
- import { srand48, drand48 } from "../common/random.js";
16
+ import { gvPermutation } from "../common/crand.js";
16
17
  import type { OrthoBox, OrthoPoint, Cell } from "./types.js";
17
18
  import {
18
19
  constructTrapezoids, fpEqual, greaterThan, isValidTrap, C_EPS, equalTo,
19
20
  } from "./trapezoid.js";
20
21
  import type { SegmentT, TrapT } from "./trapezoid.js";
21
22
 
22
- /** Fixed RNG seed — matches lib/ortho/partition.c:srand48(173) */
23
- const SEED = 173;
24
-
25
- export { SEED };
26
-
27
23
  const NPOINTS = 4;
28
24
 
29
25
  /** @see lib/ortho/partition.c:#define TR_FROM_UP/TR_FROM_DN */
@@ -86,20 +82,14 @@ class PartitionHelper {
86
82
  }
87
83
 
88
84
  /**
89
- * Generate a random permutation of the segments 1..n, drawing from the
90
- * process-global POSIX drand48 stream (seeded by partition's srand48).
85
+ * Generate a random permutation of the segments 1..n: gv_permutation's
86
+ * Fisher-Yates shuffle over the global libc rand() stream, made 1-based.
91
87
  * @see lib/ortho/partition.c:generateRandomOrdering
92
88
  */
93
89
  static generateRandomOrdering(n: number): number[] {
94
- const permute: number[] = [];
95
- for (let i = 0; i < n; i++) permute.push(i + 1);
96
- for (let i = 0; i < n; i++) {
97
- // C: j = (size_t)((double)i + drand48() * (double)(n - i));
98
- const j = Math.floor(i + drand48() * (n - i));
99
- if (j !== i) {
100
- const tmp = permute[i]; permute[i] = permute[j]; permute[j] = tmp;
101
- }
102
- }
90
+ const permute = gvPermutation(n);
91
+ // make indexing 1-based
92
+ for (let i = 0; i < n; i++) permute[i]!++;
103
93
  return permute;
104
94
  }
105
95
 
@@ -271,10 +261,8 @@ export function partition(cells: Cell[], bb: OrthoBox): OrthoBox[] | null {
271
261
  const h = PartitionHelper;
272
262
  const nsegs = 4 * (cells.length + 1);
273
263
 
274
- // C: srand48(173) once, then two generateRandomOrdering calls share the
275
- // continuing drand48 stream (partition.c:737-763).
276
- srand48(SEED);
277
-
264
+ // C: the two generateRandomOrdering calls share the continuing rand()
265
+ // stream (partition.c:677, :693).
278
266
  const hSeg = h.genSegments(cells, bb, false);
279
267
  const hPerm = h.generateRandomOrdering(nsegs);
280
268
  const hTr = constructTrapezoids(nsegs, hSeg, hPerm);
@@ -10,6 +10,7 @@ import { Graph, type GraphKind } from '../model/graph.js';
10
10
  import { Node } from '../model/node.js';
11
11
  import { Edge } from '../model/edge.js';
12
12
  import { assignSubgSeq } from '../model/cgraph-ops.js';
13
+ import { htmlValueContent, isHtmlValue } from '../common/html-string.js';
13
14
  import type {
14
15
  AttrPair,
15
16
  NodeId,
@@ -475,12 +476,20 @@ export function buildFromAst(ast: ParsedGraph): Graph {
475
476
  else kind = 'undirected';
476
477
  // ast.id is null for a nameless root (`digraph {`) and '' for an explicit
477
478
  // empty name (`digraph "" {`); only the former is anonymous in cgraph (→ `%1`).
478
- const graph = new Graph(ast.id ?? '', kind, ast.id == null);
479
+ // An html-like root name (`digraph <h g> {`) is plain text: the lexer interns
480
+ // it with agstrdup_html before the graph exists, so agopen's idmap finds no
481
+ // html ref in the new graph's dictionary and copies it as text. Node and
482
+ // subgraph names are interned in the graph and keep the flag.
483
+ // @see lib/cgraph/scan.l:233, lib/cgraph/id.c:52, lib/cgraph/refstr.c:agstrdup
484
+ const id = ast.id ?? '';
485
+ const graph = new Graph(isHtmlValue(id) ? htmlValueContent(id) : id, kind, ast.id == null);
479
486
  // An unnamed root graph is itself anonymous in cgraph (agopen with no name),
480
487
  // consuming anon id 1 before any statement — so the first anonymous subgraph is
481
- // %3, not %1 (a named root leaves the counter at 0 → first subgraph %1).
488
+ // %3, not %1 (a named root leaves the counter at 0 → first subgraph %1). A root
489
+ // named `""` is named: idmap maps the string and leaves the counter alone, so
490
+ // the test is for null, not for a falsy id.
482
491
  // @see lib/cgraph/graph.c:agopen, lib/cgraph/id.c:idmap
483
- if (!ast.id) processor.advanceAnonId();
492
+ if (ast.id == null) processor.advanceAnonId();
484
493
  buildGraph(ast.stmts, graph, graph, ast.directed, processor);
485
494
  return graph;
486
495
  }
@@ -15,7 +15,8 @@ interface LineCoeff { xc0: number; xc1: number; yc0: number; yc1: number; }
15
15
  interface RootAccum { roots: number[]; n: number; }
16
16
  interface RouteState { ops: Point[]; barriers: Edge[]; }
17
17
 
18
- class RouteHelper {
18
+ /** @internal — exported for route.branch.test.ts */
19
+ export class RouteHelper {
19
20
  static B0(t: number): number { const u = 1-t; return u*u*u; }
20
21
  static B1(t: number): number { const u = 1-t; return 3*t*u*u; }
21
22
  static B2(t: number): number { const u = 1-t; return 3*t*t*u; }
@@ -71,6 +72,15 @@ class RouteHelper {
71
72
  c[0] = v0;
72
73
  }
73
74
 
75
+ /**
76
+ * `a == b` within a tolerance (16.1.1 `d3ab9ba47`; the same 1e-7 as solve3).
77
+ * @see lib/pathplan/route.c:eq
78
+ */
79
+ static eq(a: number, b: number): boolean {
80
+ const EPS = 1e-7;
81
+ return Math.abs(a - b) < EPS;
82
+ }
83
+
74
84
  static addRoot(root: number, acc: RootAccum): void {
75
85
  if (root >= 0 && root <= 1) { acc.roots[acc.n] = root; acc.n++; }
76
86
  }
@@ -91,7 +101,7 @@ class RouteHelper {
91
101
  } else {
92
102
  for (let i = 0; i < xn; i++)
93
103
  for (let j = 0; j < yn; j++)
94
- if (xr[i] === yr[j]) RouteHelper.addRoot(xr[i], acc);
104
+ if (RouteHelper.eq(xr[i], yr[j])) RouteHelper.addRoot(xr[i], acc);
95
105
  }
96
106
  return acc.n;
97
107
  }
@@ -144,8 +154,8 @@ class RouteHelper {
144
154
  yc0: lps[0].y, yc1: lps[1].y - lps[0].y,
145
155
  };
146
156
  const acc: RootAccum = { roots, n: 0 };
147
- if (lc.xc1 === 0) {
148
- if (lc.yc1 === 0) return RouteHelper.silBothZero(sps, lc, acc);
157
+ if (RouteHelper.eq(lc.xc1, 0)) {
158
+ if (RouteHelper.eq(lc.yc1, 0)) return RouteHelper.silBothZero(sps, lc, acc);
149
159
  return RouteHelper.silXzeroYnonzero(sps, lc, acc);
150
160
  }
151
161
  return RouteHelper.silGeneral(sps, lc, acc);
@@ -17,6 +17,7 @@
17
17
  import type { Graph } from '../../model/graph.js';
18
18
  import type { Node } from '../../model/node.js';
19
19
  import type { Edge } from '../../model/edge.js';
20
+ import { LOCALNAMEPREFIX, agNameOf } from '../../model/cgraph-ops.js';
20
21
  import type { TextlabelT, FieldT, ShapeDesc } from '../../common/types.js';
21
22
  import { agstrcanon, agstrcanonText } from '../map.js';
22
23
  import { isHtmlValue } from '../../common/html-string.js';
@@ -60,19 +61,22 @@ export abstract class DotWriterBase {
60
61
  /**
61
62
  * Serialize the whole laid-out graph to xdot DOT text — a faithful port of
62
63
  * cgraph's agwrite (lib/cgraph/write.c). Recurses the subgraph tree
63
- * (write_subgs/write_body), scoping each node/edge to the subgraph(s) it
64
- * belongs to via preorder numbers (write_node_test/write_edge_test), and
65
- * re-emits an object bare (no attrs) on any scope after the first
66
- * (attrs_written). This reproduces native's per-subgraph edge re-declarations
67
- * — e.g. an edge in a rank=same subgraph is drawn once, then re-declared bare.
64
+ * (write_subgs/write_body). A node is scoped to the subgraph(s) it belongs
65
+ * to via preorder numbers (write_node_test), and is re-emitted bare (no
66
+ * attrs) on any scope after the first (attrs_written). An edge is written
67
+ * once: each body pends its out-edges during the node walk and writes them
68
+ * after it in creation order (write_edges), and an edge already written is
69
+ * never pended again, so no later scope re-declares it (graphviz 16.1.1).
68
70
  * @see lib/cgraph/write.c:agwrite
71
+ * @see lib/cgraph/write.c:before_write
69
72
  */
70
73
  protected serialize(g: Graph): string {
71
74
  const ctx: SerCtx = {
72
75
  out: [],
73
76
  preorder: new Map<Graph, number>(),
74
77
  nodeLW: new Map<Node, number>(),
75
- edgeLW: new Map<Edge, number>(),
78
+ edgesTodo: new Map<number, Edge>(),
79
+ edgesDone: new Set<number>(),
76
80
  attrsWritten: new Set<Node | Edge>(),
77
81
  level: 0,
78
82
  };
@@ -93,9 +97,13 @@ export abstract class DotWriterBase {
93
97
  return ix0 + 1;
94
98
  }
95
99
 
96
- /** A subgraph is anonymous when its name is empty or a `%N` local name. */
100
+ /** A graph is anonymous when `agnameof` gives a `%` local name: a nameless
101
+ * root (`%1`), a nameless subgraph (the parser names it `%N`), or a name
102
+ * that itself starts with `%`. A graph named `""` is named: cgraph maps `""`
103
+ * as a name, so it keeps its header and is never inlined.
104
+ * @see write.c:is_anonymous ; write.c:write_hdr ; lib/cgraph/id.c:idmap */
97
105
  private isAnonymous(g: Graph): boolean {
98
- return g.name.length === 0 || g.name.charCodeAt(0) === 0x25 /* % */;
106
+ return agNameOf(g).startsWith(LOCALNAMEPREFIX);
99
107
  }
100
108
 
101
109
  /** A graph carries a `bb` attribute when it is the root or has a layout bb
@@ -155,7 +163,9 @@ export abstract class DotWriterBase {
155
163
  if (top) {
156
164
  const strict = g.kind === 'strict-directed' || g.kind === 'strict-undirected' ? 'strict ' : '';
157
165
  const kw = isDirected(g) ? 'digraph' : 'graph';
158
- const nm = g.name.length > 0 && !this.isAnonymous(g) ? xdotId(g.name) + ' ' : '';
166
+ // The root's name is '' both when it has none (agnameof: `%1`, not
167
+ // printed) and when it is named `""` (printed as `""`).
168
+ const nm = this.isAnonymous(g) ? '' : xdotId(g.name) + ' ';
159
169
  ctx.out.push(strict + kw + ' ' + nm + '{\n');
160
170
  ctx.level++;
161
171
  } else {
@@ -253,7 +263,10 @@ export abstract class DotWriterBase {
253
263
  }
254
264
  }
255
265
 
256
- /** @see write.c:write_body — subgraphs, then this scope's nodes and edges. */
266
+ /** Subgraphs, then this scope's nodes, then the edges the node walk pended.
267
+ * The walk still writes an out-edge's head node right after its tail, but
268
+ * the edge itself waits for writeEdges unless an earlier body wrote it.
269
+ * @see lib/cgraph/write.c:write_body */
257
270
  private writeBody(g: Graph, ctx: SerCtx): void {
258
271
  this.writeSubgs(g, ctx);
259
272
  // agfstnode/agnxtnode walk a subgraph's node set in AGSEQ (root creation)
@@ -268,9 +281,24 @@ export abstract class DotWriterBase {
268
281
  this.writeNode(g, e.head, ctx);
269
282
  prev = e.head;
270
283
  }
271
- if (this.writeEdgeTest(g, e, ctx)) this.writeEdge(g, e, ctx);
284
+ // pend this edge to be emitted later
285
+ if (!ctx.edgesDone.has(e.seq)) ctx.edgesTodo.set(e.seq, e);
272
286
  }
273
287
  }
288
+ // flush pending edges to the output
289
+ this.writeEdges(g, ctx);
290
+ }
291
+
292
+ /** Write the pending edges in ascending `Edge.seq` (the C walks a Dtoset
293
+ * keyed on AGSEQ), mark each done, and empty the set for the next body.
294
+ * @see lib/cgraph/write.c:write_edges */
295
+ private writeEdges(g: Graph, ctx: SerCtx): void {
296
+ const seqs = [...ctx.edgesTodo.keys()].sort((a, b) => a - b);
297
+ for (const seq of seqs) {
298
+ this.writeEdge(g, ctx.edgesTodo.get(seq)!, ctx);
299
+ ctx.edgesDone.add(seq);
300
+ }
301
+ ctx.edgesTodo.clear();
274
302
  }
275
303
 
276
304
  /** @see write.c:write_node_test — every xdot node carries pos/size, so it is
@@ -292,11 +320,6 @@ export abstract class DotWriterBase {
292
320
  return n.name;
293
321
  }
294
322
 
295
- /** @see write.c:write_edge_test */
296
- private writeEdgeTest(g: Graph, e: Edge, ctx: SerCtx): boolean {
297
- return (ctx.edgeLW.get(e) ?? 0) < ctx.preorder.get(g)!;
298
- }
299
-
300
323
  /** @see write.c:write_node */
301
324
  private writeNode(g: Graph, n: Node, ctx: SerCtx): void {
302
325
  let s = this.indent(ctx) + xdotId(this.emitNodeName(n));
@@ -308,7 +331,6 @@ export abstract class DotWriterBase {
308
331
  ctx.nodeLW.set(n, ctx.preorder.get(g)!);
309
332
  }
310
333
 
311
- /** @see write.c:write_edge — attrs only on first emission, bare thereafter. */
312
334
  /**
313
335
  * The `:port` / `:port:compass` suffix C writes after an endpoint name.
314
336
  *
@@ -334,6 +356,12 @@ export abstract class DotWriterBase {
334
356
  return ':' + agstrcanonText(val.slice(0, i)) + ':' + agstrcanonText(val.slice(i + 1));
335
357
  }
336
358
 
359
+ /** One edge statement. The C's `else` arm (write_edge_name: a bare `[key=…]`
360
+ * for an edge whose attributes were already written) is not ported: since
361
+ * 16.1.1 edges_done makes write_body write each edge once per agwrite, and
362
+ * before_write's set_attrwf clears every flag first, so the arm cannot run.
363
+ * The attrsWritten gate stays, as the C's `if (!attrs_written(e))` does.
364
+ * @see lib/cgraph/write.c:write_edge */
337
365
  private writeEdge(g: Graph, e: Edge, ctx: SerCtx): void {
338
366
  const conn = edgeConnector(isDirected(g));
339
367
  let s = this.indent(ctx) + xdotId(this.emitNodeName(e.tail)) +
@@ -344,7 +372,6 @@ export abstract class DotWriterBase {
344
372
  ctx.attrsWritten.add(e);
345
373
  }
346
374
  ctx.out.push(s + ';\n');
347
- ctx.edgeLW.set(e, ctx.preorder.get(g)!);
348
375
  }
349
376
 
350
377
  /** Root-graph attribute block: `_draw_`, `_ldraw_`, `bb`, `xdotversion`. */
@@ -16,7 +16,7 @@ import { IGNORED } from '../../layout/dot/rank.js';
16
16
  import { agstrcanon } from '../map.js';
17
17
  import { POINTS_PER_INCH } from '../../model/geom.js';
18
18
  import type { TextlabelT, FieldT } from '../../common/types.js';
19
- import { agcanonEscape, gfmt2, gfmt5, lpStr } from './xdot-ops.js';
19
+ import { gfmt2, gfmt5, lpStr } from './xdot-ops.js';
20
20
 
21
21
  /**
22
22
  * C's `attach_attrs` edge loop skips IGNORED edges and edges with no spline
@@ -356,10 +356,19 @@ export function nodeDictParts(g: Graph, top: boolean): string[] {
356
356
  return dictParts(defs);
357
357
  }
358
358
 
359
+ /**
360
+ * A node or edge attribute the layout did not overwrite: the input's own value,
361
+ * written as agwrite writes every value, `name=` + `agstrcanon(value)` — an
362
+ * html value as `<...>`, a plain one quoted only when it needs it and broken
363
+ * with backslash-newline at `Max_outputline`. An absent or empty value prints
364
+ * nothing.
365
+ * @see lib/cgraph/write.c:write_nondefault_attrs (502-504)
366
+ * @see lib/cgraph/write.c:_write_canonstr
367
+ */
359
368
  export function echoAttr(attrs: Map<string, string>, key: string): string[] {
360
369
  const v = attrs.get(key);
361
370
  if (v === undefined || v.length === 0) return [];
362
- return [key + '="' + agcanonEscape(v) + '"'];
371
+ return [`${key}=${agstrcanon(v)}`];
363
372
  }
364
373
 
365
374
  /**
@@ -385,16 +394,18 @@ export function writeDictSkips(v: string, inherited: string | undefined): boolea
385
394
 
386
395
  /**
387
396
  * `echoAttr` for a GRAPH attribute the layout did not overwrite — same as
388
- * echoAttr except an EMPTY value can still be emitted, per `writeDictSkips`.
389
- * So a re-fed dot output whose `{rank=same}` block carries `bb=""`/`lp=""`
390
- * under a boxed, labelled cluster echoes both back verbatim
391
- * (tests/share/KW91.gv).
397
+ * echoAttr (the value goes through `agstrcanon`, as write_dict's does) except
398
+ * an EMPTY value can still be emitted, per `writeDictSkips`. So a re-fed dot
399
+ * output whose `{rank=same}` block carries `bb=""`/`lp=""` under a boxed,
400
+ * labelled cluster echoes both back verbatim (tests/share/KW91.gv).
401
+ * @see lib/cgraph/write.c:write_dict (290-292)
402
+ * @see lib/cgraph/write.c:_write_canonstr
392
403
  */
393
404
  export function echoGraphAttr(g: Graph, key: string): string[] {
394
405
  const v = g.attrs.get(key);
395
406
  if (v === undefined) return [];
396
407
  if (writeDictSkips(v, g.graphDefaultsSnapshot?.get(key))) return [];
397
- return [key + '="' + agcanonEscape(v) + '"'];
408
+ return [`${key}=${agstrcanon(v)}`];
398
409
  }
399
410
 
400
411
  /**
@@ -23,8 +23,13 @@ export interface SerCtx {
23
23
  preorder: Map<Graph, number>;
24
24
  /** node → preorder of the subgraph it was last written in (node_last_written). */
25
25
  nodeLW: Map<Node, number>;
26
- /** edge → preorder of the subgraph it was last written in (edge_last_written). */
27
- edgeLW: Map<Edge, number>;
26
+ /** Edges the current body has pended, keyed on `Edge.seq` (AGSEQ), which dedupes as the C's
27
+ * ordered dictionary does. Empty at the start of every body's node walk.
28
+ * @see lib/cgraph/write.c:info_t (edges_todo) */
29
+ edgesTodo: Map<number, Edge>;
30
+ /** `Edge.seq` of every edge already written in this agwrite.
31
+ * @see lib/cgraph/write.c:info_t (edges_done) */
32
+ edgesDone: Set<number>;
28
33
  /** objects whose attributes have already been emitted (AGATTRWF/attrs_written). */
29
34
  attrsWritten: Set<Node | Edge>;
30
35
  /** current indentation depth. */
@@ -29,13 +29,37 @@ const POINTS_PER_INCH = 72;
29
29
  /** The draw strings of one object, or undefined for an object drawn with none. */
30
30
  type DrawsOf = (obj: Node | Edge | Graph) => XdotDraws | undefined;
31
31
 
32
+ /** The three strings attach_attrs writes on every node. */
33
+ export interface NodeLayoutAttrs {
34
+ readonly pos: string;
35
+ readonly height: string;
36
+ readonly width: string;
37
+ }
38
+
39
+ /**
40
+ * A laid-out node's `pos`, `height` and `width` as attach_attrs prints them:
41
+ * `%.5g` of ND_coord (every coordinate when `odim >= 3`), PS2INCH(ND_ht) and
42
+ * PS2INCH(ND_lw + ND_rw). Pure: the write-back and json0, which has no xdot
43
+ * render to read them from, both take their values here.
44
+ * @see lib/common/output.c:296-309
45
+ */
46
+ export function nodeLayoutAttrs(n: Node): NodeLayoutAttrs {
47
+ const info = n.info;
48
+ return {
49
+ pos: nodePosRaw(n),
50
+ height: gfmt5(info.ht / POINTS_PER_INCH),
51
+ width: gfmt5((info.lw + info.rw) / POINTS_PER_INCH),
52
+ };
53
+ }
54
+
32
55
  /** @see lib/common/output.c:296-317 */
33
56
  function attachNode(n: Node): void {
34
57
  const attrs = ownAttrs(n);
35
58
  const info = n.info;
36
- attrs.set('pos', nodePosRaw(n));
37
- attrs.set('height', gfmt5(info.ht / POINTS_PER_INCH));
38
- attrs.set('width', gfmt5((info.lw + info.rw) / POINTS_PER_INCH));
59
+ const layout = nodeLayoutAttrs(n);
60
+ attrs.set('pos', layout.pos);
61
+ attrs.set('height', layout.height);
62
+ attrs.set('width', layout.width);
39
63
  const xlabel = info.xlabel as TextlabelT | undefined;
40
64
  if (xlabel?.set) attrs.set('xlp', lpStr(xlabel.pos));
41
65
  if ((info.shape as ShapeDesc | undefined)?.name === 'record') {