@knowvah/dot-engine 2.12.0 → 2.12.2

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 (166) 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/edge-in-box.d.ts +6 -20
  6. package/dist/common/edge-in-box.d.ts.map +1 -1
  7. package/dist/common/edge-label-init.d.ts +26 -1
  8. package/dist/common/edge-label-init.d.ts.map +1 -1
  9. package/dist/common/emit-bb.d.ts +36 -0
  10. package/dist/common/emit-bb.d.ts.map +1 -0
  11. package/dist/common/nodeinit.d.ts +16 -2
  12. package/dist/common/nodeinit.d.ts.map +1 -1
  13. package/dist/common/splines-path-begin.d.ts.map +1 -1
  14. package/dist/common/splines-path-end.d.ts.map +1 -1
  15. package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts +10 -0
  16. package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts.map +1 -0
  17. package/dist/gvc/context.d.ts +8 -0
  18. package/dist/gvc/context.d.ts.map +1 -1
  19. package/dist/gvc/device.d.ts.map +1 -1
  20. package/dist/gvc/emit-gates.d.ts +5 -10
  21. package/dist/gvc/emit-gates.d.ts.map +1 -1
  22. package/dist/gvc/emit-xdot.d.ts +10 -0
  23. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  24. package/dist/gvc/job.d.ts +5 -2
  25. package/dist/gvc/job.d.ts.map +1 -1
  26. package/dist/gvc/viewport.d.ts +10 -5
  27. package/dist/gvc/viewport.d.ts.map +1 -1
  28. package/dist/index.js +7617 -7334
  29. package/dist/index.js.map +4 -4
  30. package/dist/layout/dot/decomp.d.ts.map +1 -1
  31. package/dist/layout/dot/edge-route.d.ts +10 -11
  32. package/dist/layout/dot/edge-route.d.ts.map +1 -1
  33. package/dist/layout/dot/fastgr.d.ts +5 -3
  34. package/dist/layout/dot/fastgr.d.ts.map +1 -1
  35. package/dist/layout/dot/flat-adj-record.d.ts +22 -0
  36. package/dist/layout/dot/flat-adj-record.d.ts.map +1 -0
  37. package/dist/layout/dot/init.d.ts +65 -4
  38. package/dist/layout/dot/init.d.ts.map +1 -1
  39. package/dist/layout/dot/mincross-build.d.ts +6 -0
  40. package/dist/layout/dot/mincross-build.d.ts.map +1 -1
  41. package/dist/layout/dot/position-aux.d.ts +7 -1
  42. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  43. package/dist/layout/dot/splines-clone.d.ts +2 -1
  44. package/dist/layout/dot/splines-clone.d.ts.map +1 -1
  45. package/dist/layout/dot/splines-flat-labeled.d.ts.map +1 -1
  46. package/dist/layout/dot/splines-flat.d.ts +18 -0
  47. package/dist/layout/dot/splines-flat.d.ts.map +1 -1
  48. package/dist/layout/dot/splines-groups.d.ts.map +1 -1
  49. package/dist/layout/dot/splines.d.ts +5 -3
  50. package/dist/layout/dot/splines.d.ts.map +1 -1
  51. package/dist/layout/fdp/ports.d.ts.map +1 -1
  52. package/dist/layout/neato/conjgrad-mkernel.d.ts.map +1 -1
  53. package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
  54. package/dist/layout/neato/sgd.d.ts.map +1 -1
  55. package/dist/layout/sfdp/spring-electrical.d.ts.map +1 -1
  56. package/dist/model/cgraph-ops.d.ts +10 -2
  57. package/dist/model/cgraph-ops.d.ts.map +1 -1
  58. package/dist/model/edge.d.ts +7 -2
  59. package/dist/model/edge.d.ts.map +1 -1
  60. package/dist/model/edgeInfo.d.ts +17 -2
  61. package/dist/model/edgeInfo.d.ts.map +1 -1
  62. package/dist/model/graph.d.ts +4 -3
  63. package/dist/model/graph.d.ts.map +1 -1
  64. package/dist/model/lazy-attrs.d.ts.map +1 -1
  65. package/dist/parser/builder.d.ts.map +1 -1
  66. package/dist/render/dot/agwrite-linelength.d.ts +25 -0
  67. package/dist/render/dot/agwrite-linelength.d.ts.map +1 -0
  68. package/dist/render/dot/agwrite.d.ts +9 -8
  69. package/dist/render/dot/agwrite.d.ts.map +1 -1
  70. package/dist/render/dot/attrs.d.ts +15 -4
  71. package/dist/render/dot/attrs.d.ts.map +1 -1
  72. package/dist/render/dot/write-back.d.ts +24 -0
  73. package/dist/render/dot/write-back.d.ts.map +1 -1
  74. package/dist/render/dot/xdot-ops.d.ts +20 -29
  75. package/dist/render/dot/xdot-ops.d.ts.map +1 -1
  76. package/dist/render/dot.d.ts +5 -4
  77. package/dist/render/dot.d.ts.map +1 -1
  78. package/dist/render/json-cluster-edge.d.ts +35 -0
  79. package/dist/render/json-cluster-edge.d.ts.map +1 -0
  80. package/dist/render/json-nonfinite.d.ts +17 -0
  81. package/dist/render/json-nonfinite.d.ts.map +1 -0
  82. package/dist/render/json.d.ts +4 -0
  83. package/dist/render/json.d.ts.map +1 -1
  84. package/dist/render/map.d.ts +3 -0
  85. package/dist/render/map.d.ts.map +1 -1
  86. package/dist/render/svg-graph.d.ts.map +1 -1
  87. package/dist/render/svg-id.d.ts +10 -1
  88. package/dist/render/svg-id.d.ts.map +1 -1
  89. package/dist/render/svg.d.ts +3 -1
  90. package/dist/render/svg.d.ts.map +1 -1
  91. package/dist/render.js +7657 -7374
  92. package/dist/render.js.map +4 -4
  93. package/dist/util/bsd-qsort.d.ts.map +1 -1
  94. package/dist/util/printf-round.d.ts.map +1 -1
  95. package/dist/xdot/parse.d.ts.map +1 -1
  96. package/dist/xdot/strtod.d.ts +23 -0
  97. package/dist/xdot/strtod.d.ts.map +1 -0
  98. package/package.json +1 -1
  99. package/src/api/builder.ts +8 -2
  100. package/src/common/edge-in-box.ts +9 -24
  101. package/src/common/edge-label-init.ts +43 -17
  102. package/src/common/emit-bb.ts +128 -0
  103. package/src/common/nodeinit.ts +28 -8
  104. package/src/common/splines-path-begin.ts +4 -3
  105. package/src/common/splines-path-end.ts +4 -3
  106. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +45 -0
  107. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +45 -0
  108. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +45 -0
  109. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +74 -0
  110. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +74 -0
  111. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +76 -0
  112. package/src/gvc/__fixtures__/rerender/nestedclust.gv +4 -0
  113. package/src/gvc/__fixtures__/rerender/regen.sh +5 -0
  114. package/src/gvc/__fixtures__/subg-renders/subg-renders.ts +48 -0
  115. package/src/gvc/context.ts +8 -0
  116. package/src/gvc/device.ts +28 -29
  117. package/src/gvc/emit-gates.ts +7 -16
  118. package/src/gvc/emit-xdot.ts +10 -12
  119. package/src/gvc/job.ts +5 -2
  120. package/src/gvc/viewport.ts +13 -7
  121. package/src/layout/dot/__fixtures__/flat-adj-aux-syms.native-16.1.json +1210 -0
  122. package/src/layout/dot/decomp.ts +23 -2
  123. package/src/layout/dot/edge-route.ts +52 -86
  124. package/src/layout/dot/fastgr.ts +9 -3
  125. package/src/layout/dot/flat-adj-record.ts +68 -0
  126. package/src/layout/dot/init.ts +84 -13
  127. package/src/layout/dot/mincross-build.ts +14 -1
  128. package/src/layout/dot/position-aux.ts +10 -3
  129. package/src/layout/dot/splines-clone.ts +8 -2
  130. package/src/layout/dot/splines-flat-labeled.ts +3 -2
  131. package/src/layout/dot/splines-flat.ts +11 -21
  132. package/src/layout/dot/splines-groups.ts +7 -5
  133. package/src/layout/dot/splines-route.ts +2 -2
  134. package/src/layout/dot/splines.ts +8 -8
  135. package/src/layout/fdp/ports.ts +6 -2
  136. package/src/layout/neato/conjgrad-mkernel.ts +6 -2
  137. package/src/layout/neato/conjgrad.ts +2 -2
  138. package/src/layout/neato/fdp-adjust.ts +1 -16
  139. package/src/layout/neato/sgd.ts +2 -1
  140. package/src/layout/sfdp/spring-electrical.ts +5 -3
  141. package/src/model/cgraph-ops.ts +4 -3
  142. package/src/model/edge.ts +11 -4
  143. package/src/model/edgeInfo.ts +18 -2
  144. package/src/model/graph.ts +4 -3
  145. package/src/model/lazy-attrs.ts +3 -1
  146. package/src/parser/builder.ts +12 -3
  147. package/src/render/dot/agwrite-linelength.ts +58 -0
  148. package/src/render/dot/agwrite.ts +23 -16
  149. package/src/render/dot/attrs.ts +45 -8
  150. package/src/render/dot/write-back.ts +48 -3
  151. package/src/render/dot/xdot-ops.ts +26 -57
  152. package/src/render/dot.ts +16 -20
  153. package/src/render/json-cluster-edge.ts +87 -0
  154. package/src/render/json-nonfinite.ts +51 -0
  155. package/src/render/json.ts +36 -42
  156. package/src/render/map.ts +6 -7
  157. package/src/render/svg-graph.ts +9 -8
  158. package/src/render/svg-id.ts +11 -2
  159. package/src/render/svg.ts +7 -4
  160. package/src/util/bsd-qsort.ts +2 -1
  161. package/src/util/printf-round.ts +16 -10
  162. package/src/xdot/parse.ts +9 -19
  163. package/src/xdot/strtod.ts +167 -0
  164. package/dist/layout/dot/edge-order.d.ts +0 -27
  165. package/dist/layout/dot/edge-order.d.ts.map +0 -1
  166. package/src/layout/dot/edge-order.ts +0 -62
@@ -140,6 +140,28 @@ export function decompSearch(g: Graph, start: Node, cmark: number): void {
140
140
  const _dc = { cmark: 0 };
141
141
  registerRenderState(() => { _dc.cmark = 0; });
142
142
 
143
+ /**
144
+ * The Cmark each graph's records last met, keyed by the root's record. Cmark is
145
+ * a process static, so a layout with no gvFreeLayout before it continues the
146
+ * count, and the ND_mark the last layout left can never equal the new Cmark.
147
+ * The port starts each layout as a new process (AD-4), so the count is carried
148
+ * with the records it is compared against: a free replaces the root's record
149
+ * (layout-reset.ts), and the next layout starts at the reset value, as the
150
+ * zeroed records of a new process do.
151
+ * @see lib/dotgen/decomp.c:Cmark
152
+ * @see lib/gvc/gvlayout.c:gvFreeLayout
153
+ */
154
+ const cmarkByRecord = new WeakMap<object, number>();
155
+
156
+ /** `++Cmark`, continuing the count `g`'s records last met. @see lib/dotgen/decomp.c:decompose */
157
+ function nextCmark(g: Graph): number {
158
+ const record = g.root.info;
159
+ _dc.cmark = Math.max(_dc.cmark, cmarkByRecord.get(record) ?? 0);
160
+ if (++_dc.cmark === 0) _dc.cmark = 1;
161
+ cmarkByRecord.set(record, _dc.cmark);
162
+ return _dc.cmark;
163
+ }
164
+
143
165
  // ONE private function immediately before decompose — the acyclic.ts pattern.
144
166
  function resolveNode(n: Node, pass: 0 | 1): Node | undefined {
145
167
  if (pass > 0) {
@@ -155,8 +177,7 @@ function resolveNode(n: Node, pass: 0 | 1): Node | undefined {
155
177
  * @see lib/dotgen/decomp.c:decompose
156
178
  */
157
179
  export function decompose(g: Graph, pass: 0 | 1): void {
158
- if (++_dc.cmark === 0) _dc.cmark = 1;
159
- const cmark = _dc.cmark;
180
+ const cmark = nextCmark(g);
160
181
  g.info.comp = [];
161
182
  for (const n of nodesInSeq(g)) {
162
183
  const v = resolveNode(n, pass);
@@ -15,7 +15,6 @@
15
15
 
16
16
  import type { Graph } from '../../model/graph.js';
17
17
  import type { Edge as GraphEdge } from '../../model/edge.js';
18
- import { buildOutEdgeIndex } from '../../model/node.js';
19
18
  import type { Point } from '../../model/geom.js';
20
19
  import type { NodeBox } from './edge-route-geom.js';
21
20
  import type { PortRoute } from './edge-route-routing.js';
@@ -27,9 +26,8 @@ import { arrowDrawOpsForEnd } from './edge-route-arrow.js';
27
26
  import { linearBezier } from './edge-route-poly.js';
28
27
  import { rankEdgeInfoOf, routedThisPass } from './edge-route-rank.js';
29
28
  import { routeRegularEdgeFaithful } from './edge-route-faithful.js';
30
- import { edgeRouteCmp } from './edge-order.js';
31
29
  import { isFlatAdjacent, makeFlatAdjEdges } from './splines-flat.js';
32
- import { ShapeKind, type ShapeDesc } from '../../common/types.js';
30
+ import { lostFlatAdjRecordEdge } from './flat-adj-record.js';
33
31
  import {
34
32
  collectNonAdjacentFlatGroup, routeFlatEdgeGroupFaithful,
35
33
  } from './splines-flat-multi.js';
@@ -138,7 +136,7 @@ export function hasValidCoords(e: GraphEdge): boolean {
138
136
  }
139
137
 
140
138
  // ---------------------------------------------------------------------------
141
- // routeOneEdge / routeDotEdges
139
+ // routeOneEdge / routeLoneEdge
142
140
  // @see lib/dotgen/dotsplines.c:dot_splines_
143
141
  // ---------------------------------------------------------------------------
144
142
 
@@ -176,7 +174,7 @@ function dispatchMultiRankNonForward(
176
174
  * adjacent regular via make_regular_edge. clipAndInstall gates head/tail arrows
177
175
  * by the dir attribute. @see lib/dotgen/dotsplines.c:make_regular_edge
178
176
  */
179
- function routeEdgeNonForward(e: GraphEdge, g: Graph): void {
177
+ function routeEdgeNonForward(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): void {
180
178
  if (routeFaithfulAdjacentBack(e, g)) return; // T1 (AD-1): faithful adjacent back edge
181
179
  const tailBox = nodeBoxOf(e.tail, g);
182
180
  const headBox = nodeBoxOf(e.head, g);
@@ -185,7 +183,7 @@ function routeEdgeNonForward(e: GraphEdge, g: Graph): void {
185
183
  // routers otherwise live only in the forward path, so reach them here too —
186
184
  // e.g. a dir=both flat adjacent side-port edge (2437: AA3:se -> AA4:sw).
187
185
  if (e.tail.info.rank !== undefined && e.tail.info.rank === e.head.info.rank
188
- && routeFlatEdge(e, g)) return;
186
+ && routeFlatEdge(e, g, run)) return;
189
187
  routeFaithfulRegularPlain(e, g);
190
188
  }
191
189
 
@@ -231,10 +229,9 @@ function routeFaithfulRegularPlain(e: GraphEdge, g: Graph): boolean {
231
229
  * the faithful pipeline (AD-1). A back edge is the forward edge with swapped
232
230
  * ends (C `makefwdedge`): route the forward view as a plain adjacent edge, then
233
231
  * `clipAndInstall` installs the forward-geometry spline on the ORIGINAL edge
234
- * (makeFwdEdge sets `to_orig`/`edge_type`). `dotSplines_` runs `edgeNormalize`
235
- * *before* `routeDotEdges`, so the global `swapSpline` pass has already run for
236
- * this edge — apply the back-edge swap here so the spline runs tail→head with
237
- * the arrow at the head. Returns false when `e` is not an adjacent back edge.
232
+ * (makeFwdEdge sets `to_orig`/`edge_type`). Apply the back-edge swap here so
233
+ * the spline runs tail→head with the arrow at the head. Returns false when `e`
234
+ * is not an adjacent back edge.
238
235
  * @see lib/dotgen/dotsplines.c:make_regular_edge (BWDEDGE makefwdedge), edge_normalize
239
236
  */
240
237
  function routeFaithfulAdjacentBack(e: GraphEdge, g: Graph): boolean {
@@ -250,12 +247,12 @@ function routeFaithfulAdjacentBack(e: GraphEdge, g: Graph): boolean {
250
247
  return true;
251
248
  }
252
249
 
253
- /** Route and install spline + arrowhead(s) for a single edge. */
254
- export function routeOneEdge(e: GraphEdge, g: Graph): void {
250
+ /** Route and install spline + arrowhead(s) for a single edge. `run` is the
251
+ * edgecmp run the dispatch loop found `e` in ({@link routeLoneEdge}). */
252
+ export function routeOneEdge(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): void {
255
253
  const dirAttr = e.attrs.get('dir') ?? defaultEdgeDir(g);
256
- const pw = edgeRenderPenwidth(e);
257
254
  if (dirAttr !== 'forward') {
258
- routeEdgeNonForward(e, g);
255
+ routeEdgeNonForward(e, g, run);
259
256
  return;
260
257
  }
261
258
  if (routeFaithfulAdjacentBack(e, g)) return; // T1 (AD-1): faithful adjacent back edge
@@ -269,7 +266,7 @@ export function routeOneEdge(e: GraphEdge, g: Graph): void {
269
266
  routeFaithfulMultiRank(e, g); // T3 (AD-2): faithful chain pipeline
270
267
  return;
271
268
  }
272
- routeForwardEdge(e, g, tailBox, headBox, pw);
269
+ routeForwardEdge(e, g, tailBox, headBox, run);
273
270
  }
274
271
 
275
272
  /**
@@ -322,35 +319,39 @@ function isGroupableFlat(x: GraphEdge, g: Graph): boolean {
322
319
 
323
320
  /** True when a port-less adjacent flat edge shares its group with a ported one:
324
321
  * C's `ports` flag covers the whole group, so it routes via the aux graph. */
325
- function joinsPortedFlatGroup(e: GraphEdge, g: Graph): boolean {
322
+ function joinsPortedFlatGroup(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): boolean {
326
323
  return isAdjFlatCandidate(e) && isGroupableFlat(e, g)
327
- && collectAdjacentFlatGroup(e, g).some(hasDefinedPort);
324
+ && collectAdjacentFlatGroup(e, g, run).some(hasDefinedPort);
328
325
  }
329
326
 
330
327
  /**
331
- * Collect all unrouted adjacent same-rank ported flat edges between e's two
332
- * endpoints (either direction), ordered so group[0].tail is the lower-order
333
- * (left) node. C's dispatch loop sorts edges by edgecmp (equivalent edges
334
- * contiguous) and groups a run while `getmainedge(e0) === getmainedge(e1)`
335
- * (dotsplines.c:343-356); it does NOT re-derive the group from a node-pair
336
- * scan. Gate on getMainEdge equality (not just the unordered node pair) so
337
- * two independent parallel edges that merely share endpoints, but resolve to
338
- * different main edges (e.g. one is itself the main edge of a virtual chain,
339
- * the other belongs to a different original edge), are NOT folded into one
340
- * shared aux solve. C makes one make_flat_adj_edges call PER getmainedge run.
328
+ * The unrouted adjacent same-rank flat edges of `run` between e's two
329
+ * endpoints (either direction), in the run's order. C's dispatch loop sorts
330
+ * edges by edgecmp (equivalent edges contiguous), groups a run while
331
+ * `getmainedge(e0) === getmainedge(e1)` (dotsplines.c:343-356) and hands
332
+ * make_flat_edge that slice of the sorted list; it does NOT re-derive the
333
+ * group from a node-pair scan, and make_flat_adj_edges clones the aux edges
334
+ * in the slice's order (`e = edges[i]`). That order is the aux edges' AGSEQ,
335
+ * which the aux mincross reads (do_ordering_node, the install order), so the
336
+ * group must not be re-sorted here. Gate on getMainEdge equality (not just the
337
+ * unordered node pair) so two independent parallel edges that merely share
338
+ * endpoints, but resolve to different main edges (e.g. one is itself the main
339
+ * edge of a virtual chain, the other belongs to a different original edge),
340
+ * are NOT folded into one shared aux solve. C makes one make_flat_adj_edges
341
+ * call PER getmainedge run.
341
342
  * @see lib/dotgen/dotsplines.c:343-378 (esp. line 356 `if (le0 != le1) break;`)
342
343
  * @see lib/dotgen/dotsplines.c:make_flat_edge (makefwdedge of *edges), dot_splines_
344
+ * @see lib/dotgen/dotsplines.c:make_flat_adj_edges (clone loop over edges[i])
343
345
  */
344
- function collectAdjacentFlatGroup(e: GraphEdge, g: Graph): GraphEdge[] {
346
+ function collectAdjacentFlatGroup(
347
+ e: GraphEdge, g: Graph, run: readonly GraphEdge[],
348
+ ): GraphEdge[] {
345
349
  const u = e.tail, v = e.head;
346
- const lo = (u.info.order ?? 0) <= (v.info.order ?? 0) ? u : v;
347
350
  const me = getMainEdge(e);
348
351
  const sharesPair = (x: GraphEdge): boolean =>
349
352
  (x.tail === u && x.head === v) || (x.tail === v && x.head === u);
350
- const group = g.edges.filter(x =>
353
+ return run.filter(x =>
351
354
  sharesPair(x) && isGroupableFlat(x, g) && getMainEdge(x) === me);
352
- group.sort((a, b) => Number(b.tail === lo) - Number(a.tail === lo) || a.seq - b.seq);
353
- return group;
354
355
  }
355
356
 
356
357
  /**
@@ -363,7 +364,7 @@ function collectAdjacentFlatGroup(e: GraphEdge, g: Graph): GraphEdge[] {
363
364
  * installEdgeSpline/arrowheadPolygon here.
364
365
  * @see lib/dotgen/dotsplines.c:make_flat_edge, make_regular_edge
365
366
  */
366
- function routeFaithfulSidePort(e: GraphEdge, g: Graph): boolean {
367
+ function routeFaithfulSidePort(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): boolean {
367
368
  const sameRank = e.tail.info.rank !== undefined && e.tail.info.rank === e.head.info.rank;
368
369
  // Adjacent flat endpoints route via the rotated-aux pipeline (make_flat_adj_edges),
369
370
  // which installs the spline directly; the box channel handles non-adjacent flats.
@@ -371,7 +372,7 @@ function routeFaithfulSidePort(e: GraphEdge, g: Graph): boolean {
371
372
  // route the whole group so the reversed back edge clones auxh->auxt and curls.
372
373
  // @see lib/dotgen/dotsplines.c:dot_splines_ (ED_adjacent edge-group loop)
373
374
  if (sameRank && isFlatAdjacent(g, e)) {
374
- const group = collectAdjacentFlatGroup(e, g);
375
+ const group = collectAdjacentFlatGroup(e, g, run);
375
376
  return makeFlatAdjEdges(g, group, group.length, edgeType(g)) === 0
376
377
  && routedThisPass(e);
377
378
  }
@@ -391,19 +392,6 @@ function routeFaithfulSidePort(e: GraphEdge, g: Graph): boolean {
391
392
  return true;
392
393
  }
393
394
 
394
- /** graphviz #1323: C make_flat_adj_edges bails on a flat edge between ADJACENT
395
- * nodes with a record-shape endpoint — no spline is built, map_edge "lost"s it,
396
- * and it is never drawn. Detect that case so the router leaves e.info.spl
397
- * undefined (edgeHasDrawableContent then skips it), matching the oracle.
398
- * @see lib/dotgen/dotsplines.c:make_flat_adj_edges */
399
- function isLostFlatAdjRecordEdge(g: Graph, e: GraphEdge): boolean {
400
- const tr = e.tail.info.rank;
401
- if (tr === undefined || tr !== e.head.info.rank) return false;
402
- if (!isFlatAdjacent(g, e)) return false;
403
- const rec = (s: unknown): boolean => (s as ShapeDesc | undefined)?.kind === ShapeKind.SH_RECORD;
404
- return rec(e.tail.info.shape) || rec(e.head.info.shape);
405
- }
406
-
407
395
  /**
408
396
  * Dispatch a same-rank (flat) edge to its faithful router. C routes flat edges
409
397
  * by topology in `dot_splines_` independent of ED_dir (only the arrowheads
@@ -413,16 +401,16 @@ function isLostFlatAdjRecordEdge(g: Graph, e: GraphEdge): boolean {
413
401
  * caller fall through to the regular/fitter path.
414
402
  * @see lib/dotgen/dotsplines.c:dot_splines_ (flat edge group dispatch)
415
403
  */
416
- function routeFlatEdge(e: GraphEdge, g: Graph): boolean {
417
- if (isLostFlatAdjRecordEdge(g, e)) return true; // #1323: lost edge, leave unrouted
404
+ function routeFlatEdge(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): boolean {
405
+ if (lostFlatAdjRecordEdge(g, e)) return true; // #1323: lost edge, leave unrouted
418
406
  // Labeled same-rank edges: non-adjacent routes around the flat label vnode
419
407
  // (make_flat_labeled_edge); adjacent no-port routes straight with the label
420
408
  // above (make_flat_adj_edges → makeSimpleFlatLabels). Both decline for every
421
409
  // other edge, so only labeled flats are diverted. @see dotsplines.c:1527-1533
422
410
  if (makeFlatLabeledEdge(g, e)) return true;
423
- if (joinsPortedFlatGroup(e, g) && routeFaithfulSidePort(e, g)) return true;
411
+ if (joinsPortedFlatGroup(e, g, run) && routeFaithfulSidePort(e, g, run)) return true;
424
412
  if (makeAdjFlatNoPortEdge(g, e)) return true;
425
- if ((hasSidePort(e) || isAdjacentPortFlat(e, g)) && routeFaithfulSidePort(e, g)) return true;
413
+ if ((hasSidePort(e) || isAdjacentPortFlat(e, g)) && routeFaithfulSidePort(e, g, run)) return true;
426
414
  // Non-adjacent unlabeled flat with no side port (e.g. a same-rank cross-cluster
427
415
  // edge with an intervening node): C make_flat_edge routes it UP through the box
428
416
  // corridor, not straight through. @see lib/dotgen/dotsplines.c:make_flat_edge
@@ -438,9 +426,9 @@ function routeFlatEdge(e: GraphEdge, g: Graph): boolean {
438
426
 
439
427
  /** Route + install a plain forward edge, attaching declared ports if any. */
440
428
  function routeForwardEdge(
441
- e: GraphEdge, g: Graph, tailBox: NodeBox, headBox: NodeBox, pw: number,
429
+ e: GraphEdge, g: Graph, tailBox: NodeBox, headBox: NodeBox, run: readonly GraphEdge[],
442
430
  ): void {
443
- if (routeFlatEdge(e, g)) return;
431
+ if (routeFlatEdge(e, g, run)) return;
444
432
  // T2 (AD-1/AD-2): plain adjacent-rank forward edges route through the faithful
445
433
  // pathplan path (make_regular_edge). routeRegularEdgeFaithful declines (null)
446
434
  // for anything not adjacent-rank, so the fitter below only handles declines.
@@ -450,42 +438,24 @@ function routeForwardEdge(
450
438
  tailBox, headBox, rankInfo, edgePenwidthAttr(e), portRouteOf(e),
451
439
  );
452
440
  installEdgeSpline(e, result.bezierPts, result.arrowTip);
453
- e.info.headArrowOps = arrowDrawOpsForEnd(e, 'head', result.arrowTip, result.arrowDir, pw);
454
- }
455
-
456
- /**
457
- * Collect every real out-edge (same set as `g.nodes.values()` × out-edges) in
458
- * C `dot_splines_` routing order: rank-major collection + `edgecmp` sort. Order
459
- * matters because `recover_slack` mutates shared virtual nodes that other edges
460
- * read as `maximal_bbox` neighbours (S1). When the graph is unranked, preserve
461
- * the legacy insertion order (the sort keys are rank-derived).
462
- * @see lib/dotgen/dotsplines.c:dot_splines_ (edges list build + edgecmp sort)
463
- */
464
- function orderedDotEdges(g: Graph): GraphEdge[] {
465
- const outIdx = buildOutEdgeIndex(g);
466
- const edges: GraphEdge[] = [];
467
- for (const n of g.nodes.values()) {
468
- for (const e of outIdx.get(n) ?? []) edges.push(e);
469
- }
470
- if (g.info.rank !== undefined) edges.sort(edgeRouteCmp);
471
- return edges;
441
+ e.info.headArrowOps = arrowDrawOpsForEnd(
442
+ e, 'head', result.arrowTip, result.arrowDir, edgeRenderPenwidth(e));
472
443
  }
473
444
 
474
- /**
475
- * Compute and install edge splines for all unrouted edges in g.
476
- * @see lib/dotgen/dotsplines.c:dot_splines_
477
- */
478
445
  /**
479
446
  * Route one not-yet-routed edge, applying the `dot_splines_` skip guards. No-op
480
447
  * if the edge is already routed or ineligible (FLATORDER/IGNORED, self-loop, or
481
- * lacking valid coords). Used both by the unified `dotSplines_` loop — which
482
- * routes lone edges at their `edgecmp` position, interleaved with groups, as C
483
- * does — and by the `routeDotEdges` backstop sweep below.
448
+ * lacking valid coords). The `dotSplines_` group loop calls it for the edges it
449
+ * collected from the rank arrays, at their `edgecmp` position, as C does; an
450
+ * edge it did not collect keeps the route it had, as `ED_spl` does in C.
451
+ * `run` is the edgecmp run `e` belongs to, in list order: what C passes
452
+ * make_flat_edge as `edges + ind`, `cnt`. A flat-adjacent group is taken from
453
+ * it, so the aux edges are cloned in C's order.
484
454
  * @see lib/dotgen/dotsplines.c:dot_splines_ (per-edge dispatch + 295 skip)
485
455
  */
486
- export function routeLoneEdge(e: GraphEdge, g: Graph): void {
456
+ export function routeLoneEdge(e: GraphEdge, g: Graph, run: readonly GraphEdge[]): void {
487
457
  // A lost edge (routesplines failure, C semantics) is consumed: C routes each
488
- // edge exactly once, so the backstop sweep must not re-attempt it.
458
+ // edge exactly once, so a later group must not re-attempt it.
489
459
  if (routedThisPass(e) || e.info.lost === true) return;
490
460
  // C dot_splines_ skips FLATORDER/IGNORED edges when building the route list;
491
461
  // an IGNORED edge (e.g. a concentrate-merged parallel duplicate) must get no
@@ -505,9 +475,5 @@ export function routeLoneEdge(e: GraphEdge, g: Graph): void {
505
475
  // @see lib/dotgen/dotsplines.c:make_flat_labeled_edge, lib/common/emit.c:edge_in_box
506
476
  if (e.tail === e.head) return;
507
477
  if (!hasValidCoords(e)) return;
508
- routeOneEdge(e, g);
509
- }
510
-
511
- export function routeDotEdges(g: Graph): void {
512
- for (const e of orderedDotEdges(g)) routeLoneEdge(e, g);
478
+ routeOneEdge(e, g, run);
513
479
  }
@@ -236,15 +236,21 @@ export function deleteFlatEdge(e: Edge): void {
236
236
  }
237
237
 
238
238
  /**
239
- * Add `e` to the flat graph (tail.flat_out and head.flat_in) and mark the
240
- * graph as having flat edges.
239
+ * Add `e` to the flat graph (tail.flat_out and head.flat_in) and mark `g` and
240
+ * its dot root as having flat edges. flat_reorder reads the flag of the graph
241
+ * it runs on, so an edge added through a subgraph (ordered_edges recursing
242
+ * into a rank subgraph, e.g. make_flat_adj_edges' `xxx`) must flag the root.
241
243
  * @see lib/dotgen/fastgr.c:flat_edge
242
244
  */
243
- export function flatEdge(g: import('../../model/graph.js').Graph, e: Edge): void {
245
+ export function flatEdge(g: Graph, e: Edge): void {
244
246
  if (!e.tail.info.flat_out) e.tail.info.flat_out = { list: [], size: 0 };
245
247
  if (!e.head.info.flat_in) e.head.info.flat_in = { list: [], size: 0 };
246
248
  elistAppend(e.tail.info.flat_out, e);
247
249
  elistAppend(e.head.info.flat_in, e);
250
+ // C: GD_has_flat_edges(dot_root(g)) = GD_has_flat_edges(g) = true. dot_root
251
+ // is inlined (mincross-utils.ts:dotRoot imports this module).
252
+ // @see lib/dotgen/dotinit.c:dot_root
253
+ (g.info.dotroot ?? g.root).info.has_flat_edges = true;
248
254
  g.info.has_flat_edges = true;
249
255
  }
250
256
 
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * The record exit of C `make_flat_adj_edges`: a flat edge between adjacent
5
+ * nodes one of which has a record shape gets no spline (graphviz #1323), and
6
+ * the first such edge of a process is reported.
7
+ *
8
+ * @see lib/dotgen/dotsplines.c:make_flat_adj_edges (1143-1152)
9
+ */
10
+
11
+ import type { Graph } from '../../model/graph.js';
12
+ import type { Edge } from '../../model/edge.js';
13
+ import type { Node } from '../../model/node.js';
14
+ import { ShapeKind, type ShapeDesc } from '../../common/types.js';
15
+ import { agerr, agwarningf } from '../../common/agerr.js';
16
+ import { registerRenderState } from '../../common/render-state.js';
17
+ import { isFlatAdjacent, flatLeadPair } from './splines-flat.js';
18
+
19
+ /** @see lib/dotgen/dotsplines.c:1145 */
20
+ export const MSG_FLAT_ADJ_RECORD =
21
+ 'flat edge between adjacent nodes one of which has a record shape - replace records with HTML-like labels';
22
+
23
+ const EDGEOP_DIRECTED = '->';
24
+ const EDGEOP_UNDIRECTED = '--';
25
+
26
+ /**
27
+ * C's `static atomic_flag warned`: one warning per process, so one per render
28
+ * here (reset at render entry, AD-4).
29
+ * @see lib/dotgen/dotsplines.c:1141
30
+ */
31
+ const flatAdjRecord = { warned: false };
32
+ registerRenderState(() => {
33
+ flatAdjRecord.warned = false;
34
+ });
35
+
36
+ /** `shapeOf(n) == SH_RECORD`. @see lib/common/shapes.c:shapeOf */
37
+ function isRecord(n: Node): boolean {
38
+ return (n.info.shape as ShapeDesc | undefined)?.kind === ShapeKind.SH_RECORD;
39
+ }
40
+
41
+ /** `agisdirected(g) ? "->" : "--"`. */
42
+ function edgeOp(g: Graph): string {
43
+ const kind = g.root.kind;
44
+ return kind === 'directed' || kind === 'strict-directed' ? EDGEOP_DIRECTED : EDGEOP_UNDIRECTED;
45
+ }
46
+
47
+ /**
48
+ * True when `e` takes the record exit, in which case the caller leaves it
49
+ * unrouted (`map_edge` then reports it lost and it is never drawn). The first
50
+ * call that takes the exit warns, naming C's `e0`: the group's lead edge after
51
+ * `make_flat_edge`'s makefwdedge, i.e. the ends in rank order, by their raw
52
+ * `agnameof` names.
53
+ * @see lib/dotgen/dotsplines.c:make_flat_adj_edges (1143-1152)
54
+ * @see lib/dotgen/dotsplines.c:make_flat_edge (makefwdedge of *edges)
55
+ */
56
+ export function lostFlatAdjRecordEdge(g: Graph, e: Edge): boolean {
57
+ const tr = e.tail.info.rank;
58
+ if (tr === undefined || tr !== e.head.info.rank) return false;
59
+ if (!isFlatAdjacent(g, e)) return false;
60
+ const { tn, hn } = flatLeadPair([e]);
61
+ if (!isRecord(tn) && !isRecord(hn)) return false;
62
+ if (!flatAdjRecord.warned) {
63
+ flatAdjRecord.warned = true;
64
+ agwarningf(MSG_FLAT_ADJ_RECORD);
65
+ agerr('prev', ` Edge ${tn.name} ${edgeOp(g)} ${hn.name}`);
66
+ }
67
+ return true;
68
+ }
@@ -118,6 +118,74 @@ export function dotInitNode(n: Node): void {
118
118
  // dotInitEdge
119
119
  // ---------------------------------------------------------------------------
120
120
 
121
+ /**
122
+ * Which of the attribute symbols make_flat_adj_edges' setState nulls are bound.
123
+ * C reads each attribute through a global (bound per graph by graph_init).
124
+ * setState nulls thirteen of them for the aux layout and cleanupCloneGraph
125
+ * restores them. Seven are modelled here, because a bound read changes what
126
+ * the aux graph holds:
127
+ *
128
+ * - E_constr, E_minlen, N_group (dot_init_edge): an aux edge's copied
129
+ * `constraint=false` or `minlen`, and its clones' `group`, are never read:
130
+ * late_int(e, NULL, 1, 0) is 1 and late_string(n, NULL, "") "".
131
+ * - E_headlabel, E_taillabel, E_xlabel (common_init_edge, utils.c:525-545) and
132
+ * N_xlabel (common_init_node, utils.c:443): the `sym && ...` guards fail, so
133
+ * the aux makes no head, tail or external label and sets none of their
134
+ * GD_has_labels bits. A bound read made each label a second time: a
135
+ * malformed HTML value was reported twice where native reports it once, and
136
+ * the aux postprocess (addXLabels, the aux bounding box) saw labels C never
137
+ * makes.
138
+ *
139
+ * The other six set a field on an aux object that no aux pass reads and that
140
+ * cleanupCloneGraph discards, so they have no gate. Each was probed against
141
+ * native 16.1.0 on flat-adjacent inputs that set it (issue #131: dot, xdot,
142
+ * svg and stderr equal on every input that equals native without it):
143
+ *
144
+ * - E_fontcolor (initFontEdgeAttr, utils.c:460), E_labelfontcolor
145
+ * (initFontLabelEdgeAttr, utils.c:470) and N_fontcolor (common_init_node,
146
+ * utils.c:440): the colour of an aux label. Only the aux edge label's
147
+ * position is copied back.
148
+ * - N_nojustify (poly_init, shapes.c:2133): the aux node label's space.x.
149
+ * - N_showboxes (common_init_node, utils.c:450): not read by the port's init.
150
+ * - N_style (stylenode, shapes.c:471): render only, and the aux is never
151
+ * rendered.
152
+ *
153
+ * _dot_splines' port-label pass tests `E_headlabel || E_taillabel`
154
+ * (dotsplines.c:447). The port's placePortLabels tests whether the attributes
155
+ * are declared, which is true on the aux graph. With no head or tail label on
156
+ * any aux edge its loops do nothing, which is C's result.
157
+ * @see lib/common/input.c:graph_init (E_constr, E_minlen, N_group, ...)
158
+ * @see lib/dotgen/dotsplines.c:setState, cleanupCloneGraph
159
+ */
160
+ export interface InitEdgeSyms {
161
+ /** E_constr. */
162
+ readonly constr: boolean;
163
+ /** E_minlen. */
164
+ readonly minlen: boolean;
165
+ /** N_group. */
166
+ readonly group: boolean;
167
+ /** E_headlabel. */
168
+ readonly headlabel: boolean;
169
+ /** E_taillabel. */
170
+ readonly taillabel: boolean;
171
+ /** E_xlabel. */
172
+ readonly xlabel: boolean;
173
+ /** N_xlabel. */
174
+ readonly nodeXlabel: boolean;
175
+ }
176
+
177
+ /** The main graph's symbols, as graph_init binds them. */
178
+ export const DOT_INIT_SYMS: InitEdgeSyms = {
179
+ constr: true, minlen: true, group: true,
180
+ headlabel: true, taillabel: true, xlabel: true, nodeXlabel: true,
181
+ };
182
+
183
+ /** The flat-adj aux graph's symbols. @see lib/dotgen/dotsplines.c:setState */
184
+ export const AUX_INIT_SYMS: InitEdgeSyms = {
185
+ constr: false, minlen: false, group: false,
186
+ headlabel: false, taillabel: false, xlabel: false, nodeXlabel: false,
187
+ };
188
+
121
189
  /**
122
190
  * True when tail and head carry the same non-empty `group` attribute.
123
191
  * C compares interned refstr pointers (`tailgroup == headgroup`); cgraph's
@@ -125,7 +193,8 @@ export function dotInitNode(n: Node): void {
125
193
  * `tailgroup[0]` guard excludes the shared "" default.
126
194
  * @see lib/dotgen/dotinit.c:dot_init_edge (tailgroup/headgroup check)
127
195
  */
128
- export function sameNonemptyGroup(e: Edge): boolean {
196
+ export function sameNonemptyGroup(e: Edge, syms: InitEdgeSyms = DOT_INIT_SYMS): boolean {
197
+ if (!syms.group) return false;
129
198
  const tailgroup = nodeAttr(e.tail, e.tail.root, 'group') ?? '';
130
199
  const headgroup = nodeAttr(e.head, e.head.root, 'group') ?? '';
131
200
  return tailgroup !== '' && tailgroup === headgroup;
@@ -146,8 +215,8 @@ function initEdgeConstraint(e: Edge): void {
146
215
  * Applies the same-group penalty to xpenalty and weight.
147
216
  * @see lib/dotgen/dotinit.c:dot_init_edge (tailgroup/headgroup block)
148
217
  */
149
- function applyGroupPenalty(e: Edge): void {
150
- if (!sameNonemptyGroup(e)) return;
218
+ function applyGroupPenalty(e: Edge, syms: InitEdgeSyms): void {
219
+ if (!sameNonemptyGroup(e, syms)) return;
151
220
  e.info.xpenalty = CL_CROSS;
152
221
  e.info.weight = (e.info.weight ?? 1) * 100;
153
222
  }
@@ -168,8 +237,8 @@ function applyNonconstraintZero(e: Edge): void {
168
237
  *
169
238
  * @see lib/dotgen/dotinit.c:dot_init_edge
170
239
  */
171
- export function dotInitEdge(e: Edge): void {
172
- initEdgeConstraint(e);
240
+ export function dotInitEdge(e: Edge, syms: InitEdgeSyms = DOT_INIT_SYMS): void {
241
+ if (syms.constr) initEdgeConstraint(e);
173
242
  // C: ED_weight(e) = late_int(e, E_weight, 1, 0), the attribute only, on an aux
174
243
  // edge too: make_flat_adj_edges writes its 10000 with agxset. The group and
175
244
  // nonconstraint adjustments below then apply on top, matching C's order.
@@ -177,11 +246,11 @@ export function dotInitEdge(e: Edge): void {
177
246
  e.info.weight = lateInt(e.attrs.get('weight'), 1, 0);
178
247
  e.info.count = 1;
179
248
  e.info.xpenalty = 1;
180
- applyGroupPenalty(e);
249
+ applyGroupPenalty(e, syms);
181
250
  applyNonconstraintZero(e);
182
- // late_int semantics: default 1, minimum 0.
251
+ // late_int semantics: default 1, minimum 0; an unbound E_minlen gives 1.
183
252
  // @see lib/dotgen/dotinit.c:85 ED_minlen(e) = late_int(e, E_minlen, 1, 0)
184
- e.info.minlen = lateInt(e.attrs.get('minlen'), 1, 0);
253
+ e.info.minlen = lateInt(syms.minlen ? e.attrs.get('minlen') : undefined, 1, 0);
185
254
  // samehead / sametail group ids for shared-port merging. C reads these via
186
255
  // agxget(e, E_samehead/E_sametail) in dot_sameports and treats an empty
187
256
  // string (id[0] == '\0') as "no group". Without populating these, the ported
@@ -233,20 +302,22 @@ function clearFastGraphLists(n: Node): void {
233
302
 
234
303
  /**
235
304
  * Calls commonInitNode (shape-aware, label-driven sizing) then
236
- * dotInitNode for every node, then dotInitEdge for every edge.
305
+ * dotInitNode for every node, then dotInitEdge for every edge. `syms` stands
306
+ * for the global symbol state C's dot_init_edge, common_init_node and
307
+ * common_init_edge read (AUX_INIT_SYMS inside make_flat_adj_edges).
237
308
  *
238
309
  * @see lib/dotgen/dotinit.c:dot_init_node_edge
239
310
  * @see lib/dotgen/dotinit.c:dot_init_node (common_init_node + gv_nodesize)
240
311
  */
241
- export function dotInitNodeEdge(g: Graph): void {
312
+ export function dotInitNodeEdge(g: Graph, syms: InitEdgeSyms = DOT_INIT_SYMS): void {
242
313
  for (const n of nodesInSeq(g)) {
243
- commonInitNode(n, g);
314
+ commonInitNode(n, g, syms);
244
315
  dotInitNode(n);
245
316
  }
246
317
  const measurer = g.root.info.gvc?.textMeasurer;
247
318
  for (const e of g.edges) {
248
- dotInitEdge(e);
249
- if (measurer) initEdgeLabels(e, g, measurer);
319
+ dotInitEdge(e, syms);
320
+ if (measurer) initEdgeLabels(e, g, measurer, syms);
250
321
  }
251
322
  }
252
323
 
@@ -23,6 +23,8 @@ import { CLUSTER, isACluster } from './rank.js';
23
23
  import { installCluster, expandCluster, markLowclusters } from './cluster.js';
24
24
  import { agnode, agsubg, agsubnode, agGraphAttr } from '../../model/cgraph-ops.js';
25
25
  import { nodesInSeq } from './decomp.js';
26
+ import { nodeAttr } from '../../common/attr-get.js';
27
+ import { agerrorf } from '../../common/agerr.js';
26
28
 
27
29
  // betweenclust — @see lib/dotgen/mincross.c:betweenclust
28
30
  export function betweenclust(e: Edge): boolean {
@@ -338,11 +340,20 @@ export function doOrderingNode(ctx: MincrossContext, g: Graph, n: Node, outflag:
338
340
  doOrderingAddFlatEdges(g, sortlist, outflag);
339
341
  }
340
342
 
343
+ /**
344
+ * Order the nodes that carry `ordering`. C reads
345
+ * `late_string(n, N_ordering, NULL)`, which is agxget: the node's own value,
346
+ * else the `node [...]` default the node was created under ({@link nodeAttr}).
347
+ * @see lib/dotgen/mincross.c:do_ordering_for_nodes (489)
348
+ */
341
349
  export function doOrderingForNodes(ctx: MincrossContext, g: Graph): void {
342
350
  for (const n of nodesInSeq(g)) {
343
- const ordering = n.attrs.get('ordering');
351
+ const ordering = nodeAttr(n, g, 'ordering');
344
352
  if (ordering === 'out') doOrderingNode(ctx, g, n, true);
345
353
  else if (ordering === 'in') doOrderingNode(ctx, g, n, false);
354
+ else if (ordering !== undefined && ordering !== '') {
355
+ agerrorf(`ordering '${ordering}' not recognized for node '${n.name}'.`);
356
+ }
346
357
  }
347
358
  }
348
359
 
@@ -359,10 +370,12 @@ export function orderedEdges(ctx: MincrossContext, g: Graph): void {
359
370
  // does NOT recurse into subgraphs. So C silently ignores subgraph-scoped
360
371
  // ordering; only a root-level (or cluster's own) "out"/"in" is applied.
361
372
  // agGraphAttr reproduces the load-bearing "" vs undefined distinction.
373
+ // Any other non-empty value is an error (525), and still does not recurse.
362
374
  const ordering = agGraphAttr(g, 'ordering');
363
375
  if (ordering !== undefined) {
364
376
  if (ordering === 'out') doOrdering(ctx, g, true);
365
377
  else if (ordering === 'in') doOrdering(ctx, g, false);
378
+ else if (ordering !== '') agerrorf(`ordering '${ordering}' not recognized.`);
366
379
  return;
367
380
  }
368
381
  for (const subg of g.subgraphs.values()) {
@@ -99,9 +99,15 @@ export function graphRanksep(g: Graph): number { return g.info.ranksep ?? 0; }
99
99
  // make_aux_edge — @see lib/dotgen/position.c:make_aux_edge
100
100
  // ---------------------------------------------------------------------------
101
101
 
102
- /** @see lib/dotgen/position.c:make_aux_edge */
102
+ /**
103
+ * The edge's two ports are the shared default port: C zeroes them inside the
104
+ * Agedgeinfo_t it allocates here and never writes them. Its attributes are the
105
+ * shared empty map: C binds no attribute record to an aux edge, only the
106
+ * Agedgeinfo_t (issue #145).
107
+ * @see lib/dotgen/position.c:make_aux_edge
108
+ */
103
109
  export function makeAuxEdge(u: Node, v: Node, len: number, wt: number): Edge {
104
- const e = new EdgeClass(u, v, '');
110
+ const e = new EdgeClass(u, v, '', true, true);
105
111
  // C ROUND() is half away from zero. @see lib/dotgen/position.c:195
106
112
  e.info.minlen = cround(Math.min(len, 2147483647));
107
113
  e.info.weight = wt;
@@ -192,7 +198,8 @@ export function applyFlatLabel(
192
198
  const nodesep = graphNodesep(g);
193
199
  const e0 = nodeOrder(e0raw.head) <= nodeOrder(e1raw.head) ? e0raw : e1raw;
194
200
  const e1 = e0 === e0raw ? e1raw : e0raw;
195
- const m0 = edgeMinlen(e) * nodesep / 2;
201
+ // C: int m0 (position.c:222,276), so the half truncates
202
+ const m0 = Math.trunc(edgeMinlen(e) * nodesep / 2);
196
203
  const m1a = m0 + nodeRw(e0.head) + nodeLw(e0.tail);
197
204
  if (!canReach(e0.tail, e0.head)) makeAuxEdge(e0.head, e0.tail, m1a, edgeWeight(e));
198
205
  const m1b = m0 + nodeRw(e1.tail) + nodeLw(e1.head);