@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
@@ -13,6 +13,8 @@ import { colorxlate } from '../../common/color.js';
13
13
  import { getGradientPoints } from '../svg-gradient.js';
14
14
  import { EmitState, toFixed2HalfEven } from '../../gvc/job.js';
15
15
  import { printfSig, printfFixed } from '../../util/printf-round.js';
16
+ import { isHtmlValue } from '../../common/html-string.js';
17
+ import { agstrcanon } from '../map.js';
16
18
 
17
19
  // ---------------------------------------------------------------------------
18
20
  // Constants
@@ -296,31 +298,34 @@ export function xdotStrOp(prefix: string, s: string): string {
296
298
  }
297
299
 
298
300
  /**
299
- * Quote a DOT identifier unless it is a bare id or numeral, mirroring agwrite's
300
- * agcanonStr so the serialized graph reparses (the comparator reparses both
301
- * sides). Only `"` is escaped (→ `\"`); a `\` is left as-is — it is already the
302
- * start of a stored escape like `\n`/`\l` that agcanonStr keeps verbatim, so
303
- * doubling it (`\\n`) would change the name (`a\n(b\n"c")` must stay `a\n…`, not
304
- * `a\\n…`). Over-quoting a value native leaves bare is harmless: both parse to
305
- * the same name. @see lib/cgraph/write.c:_agstrcanon (escapes '"', keeps '\')
301
+ * Canonicalize a node, edge-endpoint or graph/subgraph name for `-Tdot`/`-Txdot`
302
+ * as agwrite does: `write_nodename` and `write_hdr` both print the name through
303
+ * `write_canonstr`, i.e. `agstrcanon` with the html check on. So a name is bare
304
+ * when it is an id or numeral, quoted when it is a keyword or holds any other
305
+ * byte, wrapped at `Max_outputline`, and angle-bracketed when it is html-like.
306
+ * A `\` is copied verbatim: it is already the start of a stored escape like
307
+ * `\n`/`\l`, so doubling it would change the name.
308
+ * @see lib/cgraph/write.c:write_nodename
309
+ * @see lib/cgraph/write.c:write_hdr
310
+ * @see lib/cgraph/write.c:write_canonstr
306
311
  *
307
- * ONE DELIBERATE DIVERGENCE from _agstrcanon: an ODD trailing backslash run is
308
- * padded to even. C copies it verbatim and appends the closing quote, so a name
309
- * ending in a single `\` serializes as `"a\"` — the backslash escapes the quote
310
- * and the output does not reparse. The DOT lexer cannot produce such a name
311
- * (source `"a\"` never terminates), so this is unreachable from any file and no
312
- * corpus id changes; it is reachable only through the programmatic API, where a
313
- * caller supplies the string directly. Padding costs a name that round-trips to
314
- * `a\\` instead of `a\`, which beats emitting a document that cannot be parsed.
312
+ * ONE DELIBERATE DIVERGENCE from _agstrcanon: an ODD trailing backslash run on
313
+ * a non-html name is padded to even. C copies it verbatim and appends the
314
+ * closing quote, so a name ending in a single `\` serializes as `"a\"` — the
315
+ * backslash escapes the quote and the output does not reparse. The DOT lexer
316
+ * cannot produce such a name (source `"a\"` never terminates), so this is
317
+ * unreachable from any file and no corpus id changes; it is reachable only
318
+ * through the programmatic API, where a caller supplies the string directly.
319
+ * Padding costs a name that round-trips to `a\\` instead of `a\`, which beats
320
+ * emitting a document that cannot be parsed. An html name is never padded: C
321
+ * prints `<a\>` and that reparses.
315
322
  * @see CodeQL "Incomplete string escaping or encoding" — the alert's own remedy
316
323
  * (escape every `\`) is wrong here and breaks `\n`/`\l` parity.
317
324
  */
318
325
  export function xdotId(s: string): string {
319
- if (/^[A-Za-z_][A-Za-z_0-9]*$/.test(s)) return s;
320
- if (/^-?(\.[0-9]+|[0-9]+(\.[0-9]*)?)$/.test(s)) return s;
321
- const body = s.replace(/"/g, '\\"');
322
- const trailingBackslashes = /\\*$/.exec(body)![0].length;
323
- return '"' + body + (trailingBackslashes % 2 === 1 ? '\\' : '') + '"';
326
+ if (isHtmlValue(s)) return agstrcanon(s);
327
+ const oddTrailingRun = /\\*$/.exec(s)![0].length % 2 === 1;
328
+ return agstrcanon(oddTrailingRun ? `${s}\\` : s);
324
329
  }
325
330
 
326
331
  /**
@@ -385,42 +390,6 @@ export function escBackslash(s: string): string {
385
390
  return s.replace(/\\/g, '\\\\');
386
391
  }
387
392
 
388
- /** True if s[i..] starts an escape sequence agcanonStr keeps verbatim: a `\`
389
- * followed by one of E G H L N T l n r \ ". @see lib/cgraph/write.c:is_escape */
390
- export function isEscapeSeq(s: string, i: number): boolean {
391
- if (s[i] !== '\\') return false;
392
- const n = s[i + 1];
393
- return n === 'E' || n === 'G' || n === 'H' || n === 'L' || n === 'N' || n === 'T'
394
- || n === 'l' || n === 'n' || n === 'r' || n === '\\' || n === '"';
395
- }
396
-
397
- /**
398
- * Escape a value for a DOT attribute exactly as agwrite's agcanonStr does: a `"`
399
- * becomes `\"` ONLY when it is not already part of an escape sequence, so an
400
- * existing `\"` or `\\` in the value is passed through verbatim rather than
401
- * double-escaped. For an already-backslash-doubled value (node/edge/graph labels,
402
- * post put_escaping_backslashes) this is identical to a naive `"`→`\"` — every
403
- * `"` follows a doubled `\\`, so none are ever part_of_escape. For raw cluster
404
- * labels (agset, no put_escaping) it preserves the source `\"`/`\\` unchanged.
405
- * @see lib/cgraph/write.c:_agstrcanon (135-167)
406
- */
407
- export function agcanonEscape(s: string): string {
408
- let out = '';
409
- let partOfEscape = false;
410
- for (let i = 0; i < s.length; i++) {
411
- const c = s[i]!;
412
- if (c === '"' && !partOfEscape) {
413
- out += '\\';
414
- } else if (!partOfEscape && isEscapeSeq(s, i)) {
415
- partOfEscape = true;
416
- } else {
417
- partOfEscape = false;
418
- }
419
- out += c;
420
- }
421
- return out;
422
- }
423
-
424
393
  /** Trim a "%.3f" fixed string like C's agxbuf_trim_zeros (trailing 0s + dot). */
425
394
  export function trimFixed3(v: number): string {
426
395
  let s = v.toFixed(3);
package/src/render/dot.ts CHANGED
@@ -68,6 +68,8 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
68
68
  readonly type: string = 'xdot';
69
69
  /** @see plugin/core/gvplugin_core.c registration table */
70
70
  readonly quality = 0;
71
+ /** `-Tdot` too (`:734`). @see plugin/core/gvrender_core_dot.c:745 render_features_xdot */
72
+ readonly defaultPad = 0;
71
73
 
72
74
  /**
73
75
  * Whether this format attaches the xdot draw attributes before agwrite.
@@ -104,8 +106,8 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
104
106
  this.clusters = [];
105
107
  }
106
108
 
107
- /** The last render's draw strings by ORIGINAL object: what `-Tjson` reads via agxget.
108
- * The DOT-text round-trip cannot represent draw text containing `"` (id 2239). */
109
+ /** This render's draw strings by ORIGINAL object. `-Tjson` lays them over the re-parsed xdot text,
110
+ * which cannot represent draw text containing `"` (id 2239); stored strings reach it by that text. */
109
111
  drawStringsByObject(): ReadonlyMap<Node | Edge | Graph, XdotDraws> {
110
112
  return this.draws;
111
113
  }
@@ -139,8 +141,8 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
139
141
  if (fillSpec === 'transparent') fillSpec = 'white';
140
142
  // The canvas fill covers job->clip, which setup_page derives from the focus
141
143
  // and page size: bb ± pad (xdot's default pad is 0), and nan for an infinite
142
- // bb. @see emit.c:1559-1562 setup_page · gvrender_core_dot.c:739 (default_pad)
143
- const c = deviceClip(g, this, job);
144
+ // bb. @see emit.c:1559-1562 setup_page · gvrender_core_dot.c:745 (default_pad)
145
+ const c = deviceClip(g, job);
144
146
  const corners: Point[] = [
145
147
  { x: c.ll.x, y: c.ll.y }, { x: c.ll.x, y: c.ur.y }, { x: c.ur.x, y: c.ur.y }, { x: c.ur.x, y: c.ll.y },
146
148
  ];
@@ -301,7 +303,7 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
301
303
  if (draw) set.draw = draw;
302
304
  // Cluster labels are stored via plain agxset (xdot_end_cluster:286), NOT
303
305
  // put_escaping_backslashes like node/edge/graph labels — so NO escBackslash.
304
- // The source `\"`/`\\` in the label survive as-is through agcanonEscape on
306
+ // The source `\"`/`\\` in the label survive as-is through agstrcanonText on
305
307
  // serialize (drawAttr). @see gvrender_core_dot.c:286
306
308
  if (ldraw) set.ldraw = ldraw;
307
309
  }
@@ -9,10 +9,17 @@
9
9
  * the same helper. A graph with no cluster edges keeps the usual order (attach
10
10
  * after the write): nothing there can differ.
11
11
  *
12
+ * Also the json cluster map: write_graph's top pass numbers the subgraphs and
13
+ * maps each cluster's name to its gid (label_subgs, insert), which is where a
14
+ * cluster node's gid comes from (lookup) and where a repeated cluster name is
15
+ * warned about.
16
+ *
12
17
  * @see plugin/core/gvrender_core_json.c:json_begin_graph
18
+ * @see plugin/core/gvrender_core_json.c:write_graph
13
19
  * @see lib/common/output.c:403 (if (HAS_CLUST_EDGE(g)) undoClusterEdges(g))
14
20
  */
15
21
 
22
+ import { agwarningf } from '../common/agerr.js';
16
23
  import { undoRenderedClusterEdges } from '../gvc/layout-reset.js';
17
24
  import { isACluster } from '../layout/dot/rank.js';
18
25
  import type { Graph } from '../model/graph.js';
@@ -41,10 +48,40 @@ export function jsonNodes(g: Graph): Node[] {
41
48
  }
42
49
 
43
50
  /**
44
- * A cluster node's `_gvid`: that of the first cluster of its name, as write_graph's
45
- * `lookup(map, agnameof(np))` finds it, or -1 when there is none.
46
- * @see plugin/core/gvrender_core_json.c:658 lookup, label_subgs
51
+ * The gid mapped to cluster `name`, or -1 when there is none.
52
+ * @see plugin/core/gvrender_core_json.c:lookup
53
+ */
54
+ export function lookupCluster(map: ReadonlyMap<string, number>, name: string): number {
55
+ return map.get(name) ?? -1;
56
+ }
57
+
58
+ /**
59
+ * Maps cluster `name` to gid `v`. The first entry of a name is kept; a later
60
+ * one with another value is warned about and dropped.
61
+ * @see plugin/core/gvrender_core_json.c:insert
62
+ */
63
+ export function insertCluster(map: Map<string, number>, name: string, v: number): void {
64
+ const ip = map.get(name);
65
+ if (ip !== undefined) {
66
+ if (ip !== v) agwarningf(`Duplicate cluster name "${name}"`);
67
+ return;
68
+ }
69
+ map.set(name, v);
70
+ }
71
+
72
+ /**
73
+ * Numbers `g`'s subgraphs in DFS preorder from `lbl` (C's `GD_gid(g) = lbl++`;
74
+ * here a subgraph's gid is its index in `out`) and maps each cluster's name to
75
+ * its gid. Returns the next label: the subgraph count when called on the root
76
+ * with 0.
77
+ * @see plugin/core/gvrender_core_json.c:label_subgs
47
78
  */
48
- export function clusterNodeGid(n: Node, dfsSubs: readonly Graph[]): number {
49
- return dfsSubs.findIndex((sg) => sg.name === n.name && isACluster(sg));
79
+ export function labelSubgs(g: Graph, lbl: number, map: Map<string, number>, out: Graph[]): number {
80
+ if (g !== g.root) {
81
+ const gid = lbl++;
82
+ out.push(g);
83
+ if (isACluster(g)) insertCluster(map, g.name, gid);
84
+ }
85
+ for (const [, sg] of g.subgraphs) lbl = labelSubgs(sg, lbl, map, out);
86
+ return lbl;
50
87
  }
@@ -0,0 +1,51 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+ /**
3
+ * The json writers' serialization step. C prints every draw-op number with
4
+ * `%.03f`, and on the oracle platform (macOS libc) that prints a non-finite
5
+ * double as the bare token `inf`, `-inf` or `nan` (a negative NaN prints
6
+ * `nan` too). `JSON.stringify` would print `null`, so the tree is serialized
7
+ * with those tokens instead. A document that holds one is not valid JSON,
8
+ * exactly as native's is not; a tree with no non-finite number serializes
9
+ * byte for byte as `JSON.stringify(tree, null, 2)`.
10
+ * @see plugin/core/gvrender_core_json.c:write_polyline (%.03f)
11
+ */
12
+
13
+ const JSON_INDENT = 2;
14
+
15
+ const INF_TOKEN = 'inf';
16
+ const NEG_INF_TOKEN = '-inf';
17
+ const NAN_TOKEN = 'nan';
18
+
19
+ /**
20
+ * Brackets a token while it travels through JSON.stringify as a string. A C
21
+ * string cannot hold NUL, so no attribute value cgraph could store spells a
22
+ * bracketed token.
23
+ */
24
+ const MARK = '\u0000';
25
+ /** MARK as JSON.stringify escapes it. */
26
+ const ESCAPED_MARK = JSON.stringify(MARK).slice(1, -1).replace(/\\/g, '\\\\');
27
+ /** A whole string value that is one bracketed token. */
28
+ const QUOTED_TOKEN = new RegExp(
29
+ `"${ESCAPED_MARK}(${INF_TOKEN}|${NEG_INF_TOKEN}|${NAN_TOKEN})${ESCAPED_MARK}"`, 'g',
30
+ );
31
+
32
+ /** What C's `%.03f` prints for a non-finite double. */
33
+ function nonFiniteToken(v: number): string {
34
+ if (Number.isNaN(v)) return NAN_TOKEN;
35
+ return v > 0 ? INF_TOKEN : NEG_INF_TOKEN;
36
+ }
37
+
38
+ /**
39
+ * `JSON.stringify(tree, null, 2)`, except that a non-finite number prints as
40
+ * C's `%.03f` token.
41
+ * @see plugin/core/gvrender_core_json.c:write_polyline (%.03f)
42
+ */
43
+ export function stringifyJsonTree(tree: unknown): string {
44
+ let sawNonFinite = false;
45
+ const text = JSON.stringify(tree, (_key, v: unknown) => {
46
+ if (typeof v !== 'number' || Number.isFinite(v)) return v;
47
+ sawNonFinite = true;
48
+ return `${MARK}${nonFiniteToken(v)}${MARK}`;
49
+ }, JSON_INDENT);
50
+ return sawNonFinite ? text.replace(QUOTED_TOKEN, '$1') : text;
51
+ }
@@ -28,6 +28,8 @@
28
28
  * conformance bar is the semantic `compare-json` comparator (±0.01, colors /
29
29
  * fonts canonicalized). `stoj`/`ind` are retained as the C-faithful string
30
30
  * helpers referenced by the unit tests.
31
+ * A non-finite draw coordinate prints as C's `%.03f` token (`inf`, `-inf`,
32
+ * `nan`), so such a document is not valid JSON, exactly as native's is not.
31
33
  *
32
34
  * @see plugin/core/gvrender_core_json.c
33
35
  */
@@ -41,15 +43,16 @@ import type { RendererPlugin } from '../gvc/context.js';
41
43
  import type { RenderJob } from '../gvc/job.js';
42
44
  import type { XdotOp, XdotColor } from '../xdot/types.js';
43
45
  import type { TextlabelT, FieldT } from '../common/types.js';
44
- import { printNum, gfmt5, XdotRenderer, type XdotDraws } from './dot.js';
45
- import { attachAttrs } from './dot/write-back.js';
46
- import { attachBeforeWriteWithClusterEdges as attachFirst, clusterNodeGid, jsonNodes } from './json-cluster-edge.js';
46
+ import { gfmt5, XdotRenderer, type XdotDraws } from './dot.js';
47
+ import { attachAttrs, nodeLayoutAttrs } from './dot/write-back.js';
48
+ import { attachBeforeWriteWithClusterEdges as attachFirst, jsonNodes, labelSubgs, lookupCluster } from './json-cluster-edge.js';
47
49
  import { attrsWithoutLayoutBb } from '../gvc/layout-bb.js';
48
50
  import { CHAR_LATIN1 } from '../common/graph-init.js';
49
51
  import { parse } from '../parser/index.js';
50
52
  import { render as deviceRender } from '../gvc/device.js';
51
53
  import { createDefaultContext } from '../gvc/default-context.js';
52
54
  import { parseXDot } from '../xdot/index.js';
55
+ import { stringifyJsonTree } from './json-nonfinite.js';
53
56
  import { isHtmlValue, htmlValueContent } from '../common/html-string.js';
54
57
 
55
58
  // ---------------------------------------------------------------------------
@@ -219,10 +222,10 @@ function canonicalRootEdges(g: Graph): Array<{ e: Edge; key: string }> {
219
222
  const counter = new Map<string, number>();
220
223
  for (const [, n] of g.nodes) {
221
224
  for (const e of n.outEdges(g)) {
222
- const base = e.tail.name + '' + e.head.name;
225
+ const base = e.tail.name + '\0' + e.head.name;
223
226
  const occ = counter.get(base) ?? 0;
224
227
  counter.set(base, occ + 1);
225
- out.push({ e, key: base + '' + occ });
228
+ out.push({ e, key: base + '\0' + occ });
226
229
  }
227
230
  }
228
231
  return out;
@@ -310,7 +313,7 @@ interface BuildCtx {
310
313
  subgGid: Map<Graph, number>;
311
314
  nodeGid: Map<Node, number>;
312
315
  edgeGid: Map<Edge, number>;
313
- /** All subgraphs in DFS preorder (the flat top-level "objects" ordering). */
316
+ /** The subgraphs below the rendered graph in DFS preorder (the flat top-level "objects" ordering). */
314
317
  dfsSubs: Graph[];
315
318
  /** True once any edge (or edge default) declares `label`: cgraph then carries
316
319
  * a global `label` edge symbol, and write_attrs emits `label` (its value or
@@ -358,26 +361,19 @@ function isEdgeLabelDeclared(g: Graph): boolean {
358
361
  return walk(g);
359
362
  }
360
363
 
361
- /** DFS preorder over the subgraph tree. @see label_subgs recursion order */
362
- function dfsSubgraphs(g: Graph, out: Graph[]): void {
363
- for (const [, sg] of g.subgraphs) {
364
- out.push(sg);
365
- dfsSubgraphs(sg, out);
366
- }
367
- }
368
-
369
364
  /** Assign every object its `_gvid`, mirroring write_graph's top-level pass:
370
365
  * subgraphs DFS-preorder 0..sgcnt-1, then nodes sgcnt.., then edges 0.. in
371
366
  * agfstnode/agfstout order. @see plugin/core/gvrender_core_json.c:write_graph */
372
367
  function assignIds(g: Graph, doXDot: boolean, draws?: DrawLookup): BuildCtx {
373
368
  const dfsSubs: Graph[] = [];
374
- dfsSubgraphs(g, dfsSubs);
369
+ const clusters = new Map<string, number>();
370
+ const sgcnt = labelSubgs(g, 0, clusters, dfsSubs);
375
371
  const subgGid = new Map<Graph, number>();
376
372
  dfsSubs.forEach((sg, i) => subgGid.set(sg, i));
377
- const sgcnt = dfsSubs.length;
373
+ if (dfsSubs[0] === g) dfsSubs.shift(); // a subgraph render: label_subgs numbers g, write_subgs lists below it
378
374
  const nodeGid = new Map<Node, number>();
379
375
  let ncnt = 0;
380
- for (const [, n] of g.nodes) nodeGid.set(n, n.info.clustnode ? clusterNodeGid(n, dfsSubs) : sgcnt + ncnt++);
376
+ for (const [, n] of g.nodes) nodeGid.set(n, n.info.clustnode ? lookupCluster(clusters, n.name) : sgcnt + ncnt++);
381
377
  const edgeGid = new Map<Edge, number>();
382
378
  let ecnt = 0;
383
379
  for (const { e } of canonicalRootEdges(g)) edgeGid.set(e, ecnt++);
@@ -397,9 +393,9 @@ function assignIds(g: Graph, doXDot: boolean, draws?: DrawLookup): BuildCtx {
397
393
  * Emit an object's attributes into `o`, mirroring C's write_attrs: `agxget`
398
394
  * returns HTML-string content with the marker stripped, empty non-`label`
399
395
  * values are skipped, and xdot draw attrs are re-serialized as op arrays.
400
- * `base` carries user/inherited attrs; `overlay` (from the xdot re-render)
401
- * supplies the post-layout `pos`/`width`/`height`/`bb`/draw strings and wins
402
- * on conflict.
396
+ * `base` is the object's own attrs: user/inherited values and the draw strings the input or an
397
+ * earlier render stored, which an object this render does not draw prints as agxget would.
398
+ * `overlay` (the xdot re-render: `pos`/`width`/`height`/`bb`/draw strings) wins on conflict.
403
399
  */
404
400
  function emitAttrs(
405
401
  o: JObj,
@@ -522,11 +518,10 @@ function buildNodeObject(n: Node, ctx: BuildCtx): JObj {
522
518
  const eff = nodeEffectiveAttrs(n);
523
519
  const xd = ctx.draws?.node.get(n.name);
524
520
  if (xd === undefined) {
525
- // Fallback (json0 / hand-built graph): synthesize the layout attrs the
526
- // xdot render would otherwise supply, from the laid-out node.
527
- eff.set('pos', printNum(n.info.coord.x) + ',' + printNum(n.info.coord.y));
528
- eff.set('width', printNum(n.info.width));
529
- eff.set('height', printNum(n.info.height));
521
+ // Fallback (json0 / hand-built graph): no xdot render supplies the layout
522
+ // attrs, so take the strings attach_attrs writes (output.c:296-309).
523
+ const layout = nodeLayoutAttrs(n);
524
+ eff.set('pos', layout.pos).set('width', layout.width).set('height', layout.height);
530
525
  }
531
526
  emitAttrs(o, eff, xd, ctx);
532
527
  attachNodeRects(o, n);
@@ -653,13 +648,15 @@ function latin1Reencode(s: string): string {
653
648
  export function buildJson(g: Graph, doXDot: boolean, preDraws?: DrawLookup): string {
654
649
  const draws = doXDot ? (preDraws ?? collectDrawLookup(g)) : undefined;
655
650
  const ctx = assignIds(g, doXDot, draws);
656
- return JSON.stringify(buildGraphObject(g, true, ctx), null, 2) + '\n';
651
+ return stringifyJsonTree(buildGraphObject(g, true, ctx)) + '\n';
657
652
  }
658
653
 
659
654
  /** Everything the JSON writers leave to the graph walk: they write once, at the end. */
660
655
  abstract class JsonRendererBase {
661
656
  /** @see plugin/core/gvplugin_core.c registration table */
662
657
  readonly quality = 0;
658
+ /** @see plugin/core/gvrender_core_json.c:745 render_features_json (default pad) */
659
+ readonly defaultPad = 0;
663
660
  beginNode(_n: Node, _job: RenderJob): void { /* no-op */ }
664
661
  endNode(_n: Node, _job: RenderJob): void { /* no-op */ }
665
662
  beginEdge(_e: Edge, _job: RenderJob): void { /* no-op */ }
package/src/render/map.ts CHANGED
@@ -540,6 +540,7 @@ export function mapOutputImap(
540
540
  export class PlainRenderer implements RendererPlugin {
541
541
  readonly type = 'plain';
542
542
  readonly quality = 0;
543
+ readonly defaultPad = 0; // @see plugin/core/gvrender_core_dot.c:734 render_features_dot
543
544
 
544
545
  beginGraph(_g: Graph, _job: RenderJob): void { /* no-op */ }
545
546
  endGraph(g: Graph, job: RenderJob): void { writePlain(g, job, false); }
@@ -562,6 +563,7 @@ export class PlainRenderer implements RendererPlugin {
562
563
  export class PlainExtRenderer implements RendererPlugin {
563
564
  readonly type = 'plain-ext';
564
565
  readonly quality = 0;
566
+ readonly defaultPad = 0; // @see plugin/core/gvrender_core_dot.c:734 render_features_dot
565
567
 
566
568
  beginGraph(_g: Graph, _job: RenderJob): void { /* no-op */ }
567
569
  endGraph(g: Graph, job: RenderJob): void { writePlain(g, job, true); }
@@ -637,6 +639,7 @@ function anchorOf(url: string | null, tooltip: string | null, target: string | n
637
639
  abstract class MapRendererBase implements RendererPlugin {
638
640
  abstract readonly type: string;
639
641
  readonly quality = 0;
642
+ readonly defaultPad = 4; // @see plugin/core/gvrender_core_map.c:244 render_features_map
640
643
  protected abstract readonly isCmapx: boolean;
641
644
  protected abstract readonly mapPolygon: boolean;
642
645
  private mapCtx: MapCtx | null = null;
@@ -18,7 +18,7 @@ import { createObjState, ObjType } from '../gvc/job.js';
18
18
  import { FillType } from '../gvc/context.js';
19
19
  import { escapeXml, escapeXmlTitle, svgComment } from './svg-helpers.js';
20
20
  import { resolveRenderColor, colorPaint } from './color-resolve.js';
21
- import { svgGraphClass } from './svg-id.js';
21
+ import { svgGraphClass, svgGraphId } from './svg-id.js';
22
22
  import { parseGradientSpec } from '../common/htmltable-emit-fill.js';
23
23
  import { findStopColor, parseStyleFlags } from '../common/style-resolve.js';
24
24
  import { croundNarrow32 } from '../common/arith.js';
@@ -232,18 +232,6 @@ function bgGradientPts(clip: Box): Point[] {
232
232
  ];
233
233
  }
234
234
 
235
- /**
236
- * Object id of the graph being emitted, as getObjId builds it for an AGRAPH:
237
- * the DOT `id` attr wins; else "graph" + AGSEQ. The graph being emitted is
238
- * job->gvc->g, i.e. `root == obj`, so neither the `<gid>_` prefix nor the
239
- * "clust" prefix applies. The root's AGSEQ is 0; a subgraph rendered after
240
- * its own layout carries its creation sequence among subgraphs.
241
- * @see lib/common/emit.c:getObjId
242
- */
243
- function graphObjId(g: Graph, job: RenderJob): string {
244
- return job.objId(g.attrs.get('id'), 'graph' + g.seq, true);
245
- }
246
-
247
235
  /**
248
236
  * Write background polygon element with gradient fill url reference.
249
237
  * Coords identical to emitGraphBackground; only fill changes.
@@ -281,7 +269,7 @@ function writeGradientPolygon(clip: Box, id: string, job: RenderJob): void {
281
269
  */
282
270
  function emitGradientBackground(g: Graph, clip: Box, spec: BgGradientSpec, job: RenderJob): void {
283
271
  const obj = createObjState(ObjType.RootGraph);
284
- obj.id = graphObjId(g, job);
272
+ obj.id = svgGraphId(g, job);
285
273
  obj.fillColor = resolveRenderColor(spec.fillColor);
286
274
  obj.stopColor = resolveRenderColor(spec.stopColor);
287
275
  obj.gradientFrac = spec.frac;
@@ -421,7 +409,7 @@ export function svgBeginPage(g: Graph, job: RenderJob): void {
421
409
  : -clip.ll.x + job.margin.x / z;
422
410
  const ty = clip.ur.y + job.margin.y / z;
423
411
  emitGraphGroupOpen(
424
- job.idLayerPrefix() + graphObjId(g, job),
412
+ job.idLayerPrefix() + svgGraphId(g, job),
425
413
  svgGraphClass(g),
426
414
  tx, ty, job,
427
415
  );
@@ -50,9 +50,18 @@ export function svgClusterId(sg: Graph, job: RenderJob): string {
50
50
  return job.objId(sg.attrs.get('id'), 'clust' + sg.seq);
51
51
  }
52
52
 
53
- /** SVG id for the root graph group: DOT `id` attr, else `graph0` (no prefix). */
53
+ /**
54
+ * Object id of the graph being emitted, as getObjId builds it for an AGRAPH:
55
+ * the DOT `id` attr wins; else `graph<AGSEQ>`. The graph being emitted is
56
+ * job->gvc->g, i.e. `root == obj`, so neither the `<gid>_` prefix nor the
57
+ * "clust" prefix applies. The root's AGSEQ is 0; a subgraph rendered after
58
+ * its own layout carries its creation sequence among subgraphs. It names the
59
+ * top group, the gradients, the graph anchor and map area (obj->id) and the
60
+ * base of the graph label's HTML anchor ids.
61
+ * @see lib/common/emit.c:getObjId
62
+ */
54
63
  export function svgGraphId(g: Graph, job: RenderJob): string {
55
- return job.objId(g.attrs.get('id'), 'graph0', true);
64
+ return job.objId(g.attrs.get('id'), 'graph' + g.seq, true);
56
65
  }
57
66
 
58
67
  /** `class="node[ <class>]"`, reading the inherited DOT `class` attribute. */
package/src/render/svg.ts CHANGED
@@ -53,6 +53,7 @@ import {
53
53
  emitParallelEdgePaths,
54
54
  escapeXml,
55
55
  emitPoints,
56
+ SVG_PAD,
56
57
  } from './svg-helpers.js';
57
58
  import { emitArrowOps } from './svg-arrow-ops.js';
58
59
  import { resolveRenderColor, colorOpacity, colorPaint } from './color-resolve.js';
@@ -93,6 +94,8 @@ export class SvgRenderer implements RendererPlugin {
93
94
  readonly type = 'svg';
94
95
  /** @see plugin/core/gvplugin_core.c registration table */
95
96
  readonly quality = 0;
97
+ /** @see plugin/core/gvrender_core_svg.c:810 render_features_svg (default pad) */
98
+ readonly defaultPad = SVG_PAD;
96
99
  /** Whether the current edge's <g> group was opened (deferred-emit state). */
97
100
  private edgeGroupOpen = false;
98
101
 
@@ -116,7 +119,7 @@ export class SvgRenderer implements RendererPlugin {
116
119
  /**
117
120
  * Close the edge group. Edge graphics (path + arrowhead) are emitted here
118
121
  * because the full spline is available on e.info.spl only after layout has
119
- * run routeDotEdges.
122
+ * routed the edges.
120
123
  *
121
124
  * For multi-color edges (color="c1:c2:…"), emits parallel offset Béziers
122
125
  * (one per color, SEP=2.0 apart) then arrows in headcolor/tailcolor.
@@ -8,7 +8,8 @@
8
8
  * (`lib/util/list.c:gv_list_sort_`). libc `qsort` is **not stable**: it reorders
9
9
  * comparator-equal elements in an implementation-defined permutation. Most port
10
10
  * sort sites can use JS's stable `Array.prototype.sort` because their comparator
11
- * never reports a tie (e.g. `edge-order.ts`). Where ties DO occur AND the
11
+ * never reports a tie (e.g. `routeCurvedGroup`'s sort of distinct originals by
12
+ * creation seq, `splines-groups.ts`). Where ties DO occur AND the
12
13
  * downstream result depends on their order, a stable sort diverges from the C
13
14
  * oracle.
14
15
  *
@@ -0,0 +1,74 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+ /**
3
+ * Overflow-checked arithmetic helpers.
4
+ *
5
+ * @see lib/util/overflow.h
6
+ */
7
+
8
+ // C's INT_MAX / INT_MIN for a 32-bit int.
9
+ const INT_MAX = 2_147_483_647;
10
+ const INT_MIN = -2_147_483_648;
11
+
12
+ /**
13
+ * Add two integers, clamping to lower and upper type bounds.
14
+ *
15
+ * Returns the sum `a + b`, or `INT_MAX`/`INT_MIN` on overflow/underflow. C's
16
+ * operands are `int`; the port applies the same three branches to its numbers
17
+ * as they are, with no int32 wrap of the inputs.
18
+ * @see lib/util/overflow.h:sadd_saturate
19
+ */
20
+ export function saddSaturate(a: number, b: number): number {
21
+ // overflow?
22
+ if (b > 0 && INT_MAX - b < a) {
23
+ return INT_MAX;
24
+ }
25
+
26
+ // underflow?
27
+ if (b < 0 && INT_MIN - b > a) {
28
+ return INT_MIN;
29
+ }
30
+
31
+ return a + b;
32
+ }
33
+
34
+ /**
35
+ * Divide two double floating-point values, checking for overflow.
36
+ *
37
+ * Returns the quotient `n / d`, or `null` where C returns `true` and leaves
38
+ * `*res` as it was: the quotient is not finite (a zero or subnormal divisor,
39
+ * a non-finite operand, or a result past `DBL_MAX`). A call site writes C's
40
+ * "assign the fallback, then overwrite on success" as `fdivOverflow(n, d) ??
41
+ * fallback`; a zero quotient is a result, and `??` keeps it.
42
+ * @see lib/util/overflow.h:fdiv_overflow
43
+ */
44
+ export function fdivOverflow(n: number, d: number): number | null {
45
+ const r = n / d;
46
+
47
+ // did we overflow?
48
+ if (!Number.isFinite(r)) {
49
+ return null;
50
+ }
51
+
52
+ return r;
53
+ }
54
+
55
+ /**
56
+ * Divide two floating-point values, checking for overflow.
57
+ *
58
+ * The `float` twin of {@link fdivOverflow}. C's parameters and quotient are
59
+ * `float`, so the operands and the quotient are rounded to float32: a
60
+ * quotient past `FLT_MAX` is an overflow here though it is finite as a
61
+ * double. Dividing two float32 values in double and rounding once gives
62
+ * IEEE single division's result (53 >= 2 * 24 + 2 bits).
63
+ * @see lib/util/overflow.h:fdivf_overflow
64
+ */
65
+ export function fdivfOverflow(n: number, d: number): number | null {
66
+ const r = Math.fround(Math.fround(n) / Math.fround(d));
67
+
68
+ // did we overflow?
69
+ if (!Number.isFinite(r)) {
70
+ return null;
71
+ }
72
+
73
+ return r;
74
+ }
package/src/xdot/parse.ts CHANGED
@@ -12,6 +12,7 @@ import type {
12
12
  XdotRadialGrad, XdotColorStop, OpFunctions,
13
13
  } from "./types.js";
14
14
  import { XDOT_PARSE_ERROR } from "./types.js";
15
+ import { isSpace, scanStrtod } from "./strtod.js";
15
16
 
16
17
  /** ULONG_MAX on an LP64 target: strtoul saturation value. */
17
18
  const ULONG_MAX = 0xffff_ffff_ffff_ffffn;
@@ -21,8 +22,9 @@ type OpResult = { op: XdotOp; pos: number } | "error";
21
22
  type OpMaybeResult = OpResult | null;
22
23
 
23
24
  class XdotParser {
25
+ /** @see lib/util/gv_ctype.h:gv_isspace */
24
26
  static isWs(c: string): boolean {
25
- return c === " " || c === "\t" || c === "\n" || c === "\r";
27
+ return isSpace(c);
26
28
  }
27
29
 
28
30
  static skipWs(s: string, pos: number): number {
@@ -35,25 +37,13 @@ class XdotParser {
35
37
  return i;
36
38
  }
37
39
 
38
- static consumeExponent(s: string, i: number): number {
39
- if (i < s.length && (s[i] === "e" || s[i] === "E")) {
40
- i++;
41
- if (i < s.length && (s[i] === "+" || s[i] === "-")) i++;
42
- i = XdotParser.consumeDigits(s, i);
43
- }
44
- return i;
45
- }
46
-
40
+ /**
41
+ * C reads every xdot double with strtod, so a number may be a decimal, a
42
+ * hex float, inf/infinity or nan/nan(...); null is C's `p == s`.
43
+ * @see lib/xdot/xdot.c:parseReal
44
+ */
47
45
  static parseReal(s: string, pos: number): PR<number> {
48
- let i = XdotParser.skipWs(s, pos);
49
- const start = i;
50
- if (i < s.length && (s[i] === "-" || s[i] === "+")) i++;
51
- const digStart = i;
52
- i = XdotParser.consumeDigits(s, i);
53
- if (i < s.length && s[i] === ".") { i++; i = XdotParser.consumeDigits(s, i); }
54
- i = XdotParser.consumeExponent(s, i);
55
- if (i === start || i === digStart) return null;
56
- return { val: parseFloat(s.slice(start, i)), pos: i };
46
+ return scanStrtod(s, pos);
57
47
  }
58
48
 
59
49
  static parseInt_(s: string, pos: number): PR<number> {