@knowvah/dot-engine 2.11.0 → 2.12.1

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 (88) hide show
  1. package/dist/common/agerr.d.ts +12 -0
  2. package/dist/common/agerr.d.ts.map +1 -1
  3. package/dist/common/edge-in-box.d.ts +6 -20
  4. package/dist/common/edge-in-box.d.ts.map +1 -1
  5. package/dist/common/emit-bb.d.ts +36 -0
  6. package/dist/common/emit-bb.d.ts.map +1 -0
  7. package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts +10 -0
  8. package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts.map +1 -0
  9. package/dist/gvc/device.d.ts.map +1 -1
  10. package/dist/gvc/emit-xdot.d.ts +9 -0
  11. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  12. package/dist/index.d.ts +2 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +7357 -7187
  15. package/dist/index.js.map +4 -4
  16. package/dist/layout/dot/decomp.d.ts.map +1 -1
  17. package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
  18. package/dist/layout/dot/edge-route.d.ts +3 -8
  19. package/dist/layout/dot/edge-route.d.ts.map +1 -1
  20. package/dist/layout/dot/init.d.ts +25 -4
  21. package/dist/layout/dot/init.d.ts.map +1 -1
  22. package/dist/layout/dot/splines.d.ts +5 -3
  23. package/dist/layout/dot/splines.d.ts.map +1 -1
  24. package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
  25. package/dist/layout/neato/sgd.d.ts.map +1 -1
  26. package/dist/layout/sfdp/spring-electrical.d.ts.map +1 -1
  27. package/dist/render/dot/agwrite-linelength.d.ts +25 -0
  28. package/dist/render/dot/agwrite-linelength.d.ts.map +1 -0
  29. package/dist/render/dot/agwrite.d.ts +4 -7
  30. package/dist/render/dot/agwrite.d.ts.map +1 -1
  31. package/dist/render/dot/attrs.d.ts.map +1 -1
  32. package/dist/render/dot/write-back.d.ts +10 -0
  33. package/dist/render/dot/write-back.d.ts.map +1 -1
  34. package/dist/render/dot.d.ts +1 -2
  35. package/dist/render/dot.d.ts.map +1 -1
  36. package/dist/render/json-cluster-edge.d.ts +22 -0
  37. package/dist/render/json-cluster-edge.d.ts.map +1 -0
  38. package/dist/render/json.d.ts.map +1 -1
  39. package/dist/render/map.d.ts.map +1 -1
  40. package/dist/render/svg-graph.d.ts.map +1 -1
  41. package/dist/render.js +7360 -7196
  42. package/dist/render.js.map +4 -4
  43. package/dist/util/printf-round.d.ts.map +1 -1
  44. package/package.json +1 -1
  45. package/src/common/agerr.ts +49 -1
  46. package/src/common/edge-in-box.ts +9 -24
  47. package/src/common/emit-bb.ts +128 -0
  48. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +45 -0
  49. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +45 -0
  50. package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +45 -0
  51. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +74 -0
  52. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +74 -0
  53. package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +76 -0
  54. package/src/gvc/__fixtures__/rerender/nestedclust.gv +4 -0
  55. package/src/gvc/__fixtures__/rerender/regen.sh +5 -0
  56. package/src/gvc/__fixtures__/subg-renders/subg-renders.ts +48 -0
  57. package/src/gvc/device.ts +26 -27
  58. package/src/gvc/emit-gates.ts +1 -1
  59. package/src/gvc/emit-xdot.ts +5 -6
  60. package/src/index.ts +4 -0
  61. package/src/layout/dot/decomp.ts +23 -2
  62. package/src/layout/dot/edge-route-chain.ts +79 -7
  63. package/src/layout/dot/edge-route.ts +8 -37
  64. package/src/layout/dot/init.ts +36 -11
  65. package/src/layout/dot/splines-flat.ts +2 -2
  66. package/src/layout/dot/splines-groups.ts +2 -2
  67. package/src/layout/dot/splines-route.ts +2 -2
  68. package/src/layout/dot/splines.ts +10 -10
  69. package/src/layout/fdp/index.ts +2 -2
  70. package/src/layout/neato/conjgrad.ts +2 -2
  71. package/src/layout/neato/fdp-adjust.ts +1 -16
  72. package/src/layout/neato/sgd.ts +3 -9
  73. package/src/layout/sfdp/spring-electrical.ts +5 -3
  74. package/src/render/dot/agwrite-linelength.ts +58 -0
  75. package/src/render/dot/agwrite.ts +13 -13
  76. package/src/render/dot/attrs.ts +27 -1
  77. package/src/render/dot/write-back.ts +21 -0
  78. package/src/render/dot/xdot-ops.ts +1 -1
  79. package/src/render/dot.ts +11 -17
  80. package/src/render/json-cluster-edge.ts +50 -0
  81. package/src/render/json.ts +16 -19
  82. package/src/render/map.ts +3 -7
  83. package/src/render/svg-graph.ts +22 -9
  84. package/src/render/svg.ts +3 -3
  85. package/src/util/printf-round.ts +16 -10
  86. package/dist/layout/dot/edge-order.d.ts +0 -27
  87. package/dist/layout/dot/edge-order.d.ts.map +0 -1
  88. package/src/layout/dot/edge-order.ts +0 -62
@@ -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 { svgGraphId, svgGraphClass } from './svg-id.js';
21
+ import { svgGraphClass } 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,6 +232,18 @@ 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
+
235
247
  /**
236
248
  * Write background polygon element with gradient fill url reference.
237
249
  * Coords identical to emitGraphBackground; only fill changes.
@@ -259,16 +271,17 @@ function writeGradientPolygon(clip: Box, id: string, job: RenderJob): void {
259
271
  * Emit the gradient background for a graph with a two-color bgcolor.
260
272
  * Pushes a temporary ObjState, emits the <defs> gradient, writes the polygon.
261
273
  *
262
- * The gradient id is prefixed "graph0_" to match C's svg_gradstyle behaviour
263
- * when obj->id is set: graph0_l_0 / graph0_r_0.
274
+ * The gradient id is prefixed with the graph's object id to match C's
275
+ * svg_gradstyle behaviour when obj->id is set: graph0_l_0 / graph0_r_0 for a
276
+ * root, graph<AGSEQ>_l_0 for a subgraph render.
264
277
  *
265
278
  * @see lib/common/emit.c:emit_background:1503-1519
266
279
  * @see plugin/core/gvrender_core_svg.c:svg_gradstyle:572
267
280
  * @see plugin/core/gvrender_core_svg.c:svg_rgradstyle:608
268
281
  */
269
- function emitGradientBackground(clip: Box, spec: BgGradientSpec, job: RenderJob): void {
282
+ function emitGradientBackground(g: Graph, clip: Box, spec: BgGradientSpec, job: RenderJob): void {
270
283
  const obj = createObjState(ObjType.RootGraph);
271
- obj.id = 'graph0';
284
+ obj.id = graphObjId(g, job);
272
285
  obj.fillColor = resolveRenderColor(spec.fillColor);
273
286
  obj.stopColor = resolveRenderColor(spec.stopColor);
274
287
  obj.gradientFrac = spec.frac;
@@ -277,10 +290,10 @@ function emitGradientBackground(clip: Box, spec: BgGradientSpec, job: RenderJob)
277
290
  job.pushObj(obj);
278
291
  let gid: string;
279
292
  if (spec.radial) {
280
- gid = gradientId('graph0', 'r', job.radialGradId++);
293
+ gid = gradientId(obj.id, 'r', job.radialGradId++);
281
294
  emitRadialGradient(job, gid);
282
295
  } else {
283
- gid = gradientId('graph0', 'l', job.linearGradId++);
296
+ gid = gradientId(obj.id, 'l', job.linearGradId++);
284
297
  emitLinearGradient(job, bgGradientPts(clip), gid);
285
298
  }
286
299
  job.popObj();
@@ -313,7 +326,7 @@ function emitBgcolorBackground(g: Graph, clip: Box, bgcolorAttr: string | undefi
313
326
  }
314
327
  const spec = resolveBgGradientSpec(g, bgcolorAttr);
315
328
  if (spec !== null) {
316
- emitGradientBackground(clip, spec, job);
329
+ emitGradientBackground(g, clip, spec, job);
317
330
  return;
318
331
  }
319
332
  emitGraphBackground(clip, resolveGraphBgcolor(bgcolorAttr), job);
@@ -408,7 +421,7 @@ export function svgBeginPage(g: Graph, job: RenderJob): void {
408
421
  : -clip.ll.x + job.margin.x / z;
409
422
  const ty = clip.ur.y + job.margin.y / z;
410
423
  emitGraphGroupOpen(
411
- job.idLayerPrefix() + svgGraphId(g, job),
424
+ job.idLayerPrefix() + graphObjId(g, job),
412
425
  svgGraphClass(g),
413
426
  tx, ty, job,
414
427
  );
package/src/render/svg.ts CHANGED
@@ -107,9 +107,9 @@ export class SvgRenderer implements RendererPlugin {
107
107
  beginNode(n: Node, job: RenderJob): void { svgBeginNode(n, job); }
108
108
  endNode(_n: Node, job: RenderJob): void { svgEndNode(job); }
109
109
  beginEdge(e: Edge, job: RenderJob): void {
110
- // job.bb is the final drawing bbox (= GD_bb / job->clip); emit_edge gates
111
- // all edge drawing on edge_in_box(e, job->clip). @see lib/common/emit.c:emit_edge
112
- this.edgeGroupOpen = edgeHasDrawableContent(e, job.bb);
110
+ // emit_edge gates all edge drawing on edge_in_box(e, job->clip).
111
+ // @see lib/common/emit.c:emit_edge
112
+ this.edgeGroupOpen = edgeHasDrawableContent(e, job.clip);
113
113
  if (this.edgeGroupOpen) svgBeginEdge(e, job);
114
114
  }
115
115
 
@@ -80,6 +80,17 @@ function roundHalfEvenDrop(value: bigint, dropCount: number): bigint {
80
80
  return q;
81
81
  }
82
82
 
83
+ /**
84
+ * What C's printf prints for a non-finite double under `%f`, `%g` and `%e`:
85
+ * `inf`, `-inf` or `nan`. The reference libc (macOS) prints no sign on a NaN
86
+ * whose sign bit is set.
87
+ * @see lib/gvc/gvdevice.c:gvprintdouble · lib/common/output.c:71 ("%.5g")
88
+ */
89
+ function printfNonFinite(v: number): string {
90
+ if (Number.isNaN(v)) return 'nan';
91
+ return v > 0 ? 'inf' : '-inf';
92
+ }
93
+
83
94
  /**
84
95
  * Format `v` as C's `%.<decimals>f` would (fixed decimal places, rounded
85
96
  * half-to-even on exact ties). Mirrors `Number.prototype.toFixed(decimals)`
@@ -89,11 +100,8 @@ function roundHalfEvenDrop(value: bigint, dropCount: number): bigint {
89
100
  */
90
101
  export function printfFixed(v: number, decimals: number): string {
91
102
  // Non-finite: the exact-decimal decomposition below reads the IEEE-754
92
- // bit pattern as a finite mantissa, so Infinity/NaN would emit a spurious
93
- // ~309-digit integer. Match the `toFixed` contract this helper replaces:
94
- // it returns "Infinity"/"-Infinity"/"NaN" verbatim (canonicalized to the
95
- // oracle's C printf "inf"/"nan" by the xdot comparator).
96
- if (!Number.isFinite(v)) return v.toFixed(decimals);
103
+ // bit pattern as a finite mantissa, so print C's text instead.
104
+ if (!Number.isFinite(v)) return printfNonFinite(v);
97
105
  if (v === 0) return decimals > 0 ? '0.' + '0'.repeat(decimals) : '0';
98
106
  const sign = v < 0 ? '-' : '';
99
107
  const { digits, exponent10 } = exactDecimalDigits(Math.abs(v));
@@ -124,11 +132,9 @@ export function printfFixed(v: number, decimals: number): string {
124
132
  * @see lib/common/output.c:71 (agxbprint "%.5g")
125
133
  */
126
134
  export function printfSig(v: number, sig: number): string {
127
- // Non-finite: mirror the `toPrecision` contract this helper replaces
128
- // ("Infinity"/"-Infinity"/"NaN"); the bit-decomposition below is only
129
- // valid for finite magnitudes. (gfmt5 already short-circuits non-finite,
130
- // but the contract must hold for every caller.)
131
- if (!Number.isFinite(v)) return v.toPrecision(sig);
135
+ // Non-finite: the bit-decomposition below is only valid for finite
136
+ // magnitudes, so print C's text instead.
137
+ if (!Number.isFinite(v)) return printfNonFinite(v);
132
138
  if (v === 0) return sig > 1 ? '0.' + '0'.repeat(sig - 1) : '0';
133
139
  const sign = v < 0 ? '-' : '';
134
140
  const { digits, exponent10 } = exactDecimalDigits(Math.abs(v));
@@ -1,27 +0,0 @@
1
- /**
2
- * Edge routing order for dot, matching C `dot_splines_`.
3
- *
4
- * C routes edges from a list built rank-major (`GD_rank[i].v[j]` out-edges of
5
- * NORMAL / splineMerge nodes) then `qsort`-ed by `edgecmp`. Because
6
- * `recover_slack` re-centres shared virtual nodes that other edges read as
7
- * `maximal_bbox` neighbours, corridor geometry is routing-order-dependent — so
8
- * the port must route in C's order, not `g.nodes.values()` insertion order.
9
- *
10
- * The port iterates the ORIGINAL edges directly (real tails), so `edgecmp`'s
11
- * `getmainedge` mapping is the identity here and the rank/coord keys read the
12
- * original endpoints. `AGSEQ` (the port's `Edge.seq`) is unique, making the
13
- * comparator a total order — a stable `Array.sort` over any collection order
14
- * reproduces C's `qsort` result (edgecmp-equal originals never occur, and C
15
- * batches genuinely-equivalent edges via the cnt-loop, so their relative
16
- * routing order is immaterial).
17
- *
18
- * @see lib/dotgen/dotsplines.c:dot_splines_ (edges list build + sort)
19
- * @see lib/dotgen/dotsplines.c:edgecmp
20
- */
21
- import type { Edge } from '../../model/edge.js';
22
- /**
23
- * Compare two original edges in C `dot_splines_` routing order via their
24
- * lexicographic `edgecmp` keys. @see lib/dotgen/dotsplines.c:edgecmp
25
- */
26
- export declare function edgeRouteCmp(a: Edge, b: Edge): number;
27
- //# sourceMappingURL=edge-order.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"edge-order.d.ts","sourceRoot":"","sources":["../../../src/layout/dot/edge-order.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AA2BhD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAOrD"}
@@ -1,62 +0,0 @@
1
- // SPDX-License-Identifier: EPL-2.0
2
-
3
- /**
4
- * Edge routing order for dot, matching C `dot_splines_`.
5
- *
6
- * C routes edges from a list built rank-major (`GD_rank[i].v[j]` out-edges of
7
- * NORMAL / splineMerge nodes) then `qsort`-ed by `edgecmp`. Because
8
- * `recover_slack` re-centres shared virtual nodes that other edges read as
9
- * `maximal_bbox` neighbours, corridor geometry is routing-order-dependent — so
10
- * the port must route in C's order, not `g.nodes.values()` insertion order.
11
- *
12
- * The port iterates the ORIGINAL edges directly (real tails), so `edgecmp`'s
13
- * `getmainedge` mapping is the identity here and the rank/coord keys read the
14
- * original endpoints. `AGSEQ` (the port's `Edge.seq`) is unique, making the
15
- * comparator a total order — a stable `Array.sort` over any collection order
16
- * reproduces C's `qsort` result (edgecmp-equal originals never occur, and C
17
- * batches genuinely-equivalent edges via the cnt-loop, so their relative
18
- * routing order is immaterial).
19
- *
20
- * @see lib/dotgen/dotsplines.c:dot_splines_ (edges list build + sort)
21
- * @see lib/dotgen/dotsplines.c:edgecmp
22
- */
23
-
24
- import type { Edge } from '../../model/edge.js';
25
- import { FLATEDGE, REGULAREDGE } from '../../common/splines-constants.js';
26
-
27
- /**
28
- * Edge-type key: same-rank ⇒ FLATEDGE, else REGULAREDGE — mirrors C `setflags`
29
- * (regular out-edges REGULAREDGE, flat_out FLATEDGE).
30
- * @see lib/dotgen/dotsplines.c:dot_splines_ (setflags REGULAREDGE/FLATEDGE)
31
- */
32
- function edgeTypeKey(e: Edge): number {
33
- return e.tail.info.rank === e.head.info.rank ? FLATEDGE : REGULAREDGE;
34
- }
35
-
36
- /**
37
- * Lexicographic sort key for one edge, mirroring `edgecmp`. Each entry is
38
- * compared ascending, so the edge-type term is negated (C orders type
39
- * descending: FLATEDGE before REGULAREDGE). `AGSEQ` (`Edge.seq`) is unique, so
40
- * the key tuple is a total order. @see lib/dotgen/dotsplines.c:edgecmp
41
- */
42
- function edgeRouteKey(e: Edge): number[] {
43
- return [
44
- -edgeTypeKey(e),
45
- Math.abs((e.tail.info.rank ?? 0) - (e.head.info.rank ?? 0)),
46
- Math.abs((e.tail.info.coord?.x ?? 0) - (e.head.info.coord?.x ?? 0)),
47
- e.seq,
48
- ];
49
- }
50
-
51
- /**
52
- * Compare two original edges in C `dot_splines_` routing order via their
53
- * lexicographic `edgecmp` keys. @see lib/dotgen/dotsplines.c:edgecmp
54
- */
55
- export function edgeRouteCmp(a: Edge, b: Edge): number {
56
- const ka = edgeRouteKey(a);
57
- const kb = edgeRouteKey(b);
58
- for (let i = 0; i < ka.length; i++) {
59
- if (ka[i] !== kb[i]) return ka[i] - kb[i];
60
- }
61
- return 0;
62
- }