@knowvah/dot-engine 2.7.1 → 2.8.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 (128) hide show
  1. package/dist/api.js.map +2 -2
  2. package/dist/common/agerr.d.ts +8 -1
  3. package/dist/common/agerr.d.ts.map +1 -1
  4. package/dist/common/fma.d.ts.map +1 -1
  5. package/dist/common/htmltable-emit-fill.d.ts.map +1 -1
  6. package/dist/common/htmltable-emit.d.ts +6 -11
  7. package/dist/common/htmltable-emit.d.ts.map +1 -1
  8. package/dist/common/htmltable-label.d.ts +3 -0
  9. package/dist/common/htmltable-label.d.ts.map +1 -1
  10. package/dist/common/htmltable-lex-attvalue.d.ts.map +1 -1
  11. package/dist/common/htmltable.d.ts +5 -0
  12. package/dist/common/htmltable.d.ts.map +1 -1
  13. package/dist/common/layers.d.ts +12 -0
  14. package/dist/common/layers.d.ts.map +1 -1
  15. package/dist/common/layout-state.d.ts +8 -0
  16. package/dist/common/layout-state.d.ts.map +1 -0
  17. package/dist/common/make-label.d.ts.map +1 -1
  18. package/dist/common/multicolor.d.ts +6 -3
  19. package/dist/common/multicolor.d.ts.map +1 -1
  20. package/dist/common/nodeinit.d.ts.map +1 -1
  21. package/dist/common/poly-gencode.d.ts.map +1 -1
  22. package/dist/common/poly-init.d.ts +21 -0
  23. package/dist/common/poly-init.d.ts.map +1 -1
  24. package/dist/common/poly-sizing.d.ts +1 -0
  25. package/dist/common/poly-sizing.d.ts.map +1 -1
  26. package/dist/common/postproc.d.ts.map +1 -1
  27. package/dist/common/style-resolve.d.ts +11 -9
  28. package/dist/common/style-resolve.d.ts.map +1 -1
  29. package/dist/gvc/device-cluster.d.ts +5 -6
  30. package/dist/gvc/device-cluster.d.ts.map +1 -1
  31. package/dist/gvc/device.d.ts.map +1 -1
  32. package/dist/gvc/first-layer.d.ts +21 -5
  33. package/dist/gvc/first-layer.d.ts.map +1 -1
  34. package/dist/gvc/gvrender-set-style.d.ts.map +1 -1
  35. package/dist/gvc/render-usershape.d.ts +60 -0
  36. package/dist/gvc/render-usershape.d.ts.map +1 -0
  37. package/dist/gvc/usershape.d.ts +20 -0
  38. package/dist/gvc/usershape.d.ts.map +1 -1
  39. package/dist/index.js +8838 -8465
  40. package/dist/index.js.map +4 -4
  41. package/dist/layout/circo/index.d.ts.map +1 -1
  42. package/dist/layout/dot/init.d.ts +10 -0
  43. package/dist/layout/dot/init.d.ts.map +1 -1
  44. package/dist/layout/dot/splines.d.ts.map +1 -1
  45. package/dist/layout/fdp/init.d.ts.map +1 -1
  46. package/dist/layout/neato/conjgrad-mkernel.d.ts.map +1 -1
  47. package/dist/layout/neato/constrained-majorization.d.ts.map +1 -1
  48. package/dist/layout/neato/edge-len.d.ts +6 -2
  49. package/dist/layout/neato/edge-len.d.ts.map +1 -1
  50. package/dist/layout/neato/init.d.ts.map +1 -1
  51. package/dist/layout/neato/kk.d.ts.map +1 -1
  52. package/dist/layout/neato/make-graph-data.d.ts.map +1 -1
  53. package/dist/layout/neato/matrix-ops.d.ts +0 -6
  54. package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
  55. package/dist/layout/neato/smart-ini-x.d.ts.map +1 -1
  56. package/dist/layout/neato/splines.d.ts.map +1 -1
  57. package/dist/layout/neato/start.d.ts.map +1 -1
  58. package/dist/layout/neato/stress-kernel.d.ts +2 -5
  59. package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
  60. package/dist/layout/neato/stress.d.ts +6 -0
  61. package/dist/layout/neato/stress.d.ts.map +1 -1
  62. package/dist/layout/osage/index.d.ts.map +1 -1
  63. package/dist/layout/patchwork/index.d.ts.map +1 -1
  64. package/dist/layout/sfdp/init.d.ts.map +1 -1
  65. package/dist/layout/twopi/init.d.ts +12 -6
  66. package/dist/layout/twopi/init.d.ts.map +1 -1
  67. package/dist/model/cgraph-ops.d.ts +9 -0
  68. package/dist/model/cgraph-ops.d.ts.map +1 -1
  69. package/dist/render/color-resolve.d.ts +7 -0
  70. package/dist/render/color-resolve.d.ts.map +1 -1
  71. package/dist/render/dot.d.ts +8 -1
  72. package/dist/render/dot.d.ts.map +1 -1
  73. package/dist/render/json.d.ts +17 -2
  74. package/dist/render/json.d.ts.map +1 -1
  75. package/dist/render/map.d.ts +3 -5
  76. package/dist/render/map.d.ts.map +1 -1
  77. package/dist/render.js +711 -338
  78. package/dist/render.js.map +4 -4
  79. package/package.json +1 -1
  80. package/src/common/agerr.ts +69 -8
  81. package/src/common/fma.ts +11 -1
  82. package/src/common/htmltable-emit-fill.ts +11 -7
  83. package/src/common/htmltable-emit.ts +11 -46
  84. package/src/common/htmltable-label.ts +6 -3
  85. package/src/common/htmltable-lex-attvalue.ts +17 -1
  86. package/src/common/htmltable.ts +10 -5
  87. package/src/common/layers.ts +31 -2
  88. package/src/common/layout-state.ts +35 -0
  89. package/src/common/make-label.ts +6 -2
  90. package/src/common/multicolor.ts +12 -6
  91. package/src/common/nodeinit.ts +4 -1
  92. package/src/common/poly-gencode.ts +51 -2
  93. package/src/common/poly-init.ts +34 -13
  94. package/src/common/poly-sizing.ts +4 -4
  95. package/src/common/postproc.ts +4 -1
  96. package/src/common/style-resolve.ts +118 -50
  97. package/src/gvc/device-cluster.ts +33 -40
  98. package/src/gvc/device.ts +56 -43
  99. package/src/gvc/first-layer.ts +60 -11
  100. package/src/gvc/gvrender-set-style.ts +1 -6
  101. package/src/gvc/render-usershape.ts +209 -0
  102. package/src/gvc/usershape.ts +40 -0
  103. package/src/layout/circo/index.ts +4 -0
  104. package/src/layout/dot/init.ts +32 -0
  105. package/src/layout/dot/splines.ts +3 -0
  106. package/src/layout/fdp/init.ts +17 -0
  107. package/src/layout/neato/conjgrad-mkernel.ts +2 -3
  108. package/src/layout/neato/constrained-majorization.ts +2 -1
  109. package/src/layout/neato/edge-len.ts +39 -7
  110. package/src/layout/neato/init.ts +8 -3
  111. package/src/layout/neato/kk.ts +2 -1
  112. package/src/layout/neato/make-graph-data.ts +1 -2
  113. package/src/layout/neato/matrix-ops.ts +1 -11
  114. package/src/layout/neato/smart-ini-x.ts +1 -1
  115. package/src/layout/neato/splines.ts +3 -1
  116. package/src/layout/neato/start.ts +3 -2
  117. package/src/layout/neato/stress-kernel.ts +45 -86
  118. package/src/layout/neato/stress.ts +19 -0
  119. package/src/layout/osage/index.ts +8 -1
  120. package/src/layout/patchwork/index.ts +4 -0
  121. package/src/layout/sfdp/init.ts +3 -0
  122. package/src/layout/twopi/init.ts +21 -9
  123. package/src/layout/twopi/pipeline.ts +3 -3
  124. package/src/model/cgraph-ops.ts +19 -0
  125. package/src/render/color-resolve.ts +17 -2
  126. package/src/render/dot.ts +14 -1
  127. package/src/render/json.ts +9 -10
  128. package/src/render/map.ts +5 -6
@@ -10,6 +10,7 @@
10
10
 
11
11
  import type { ShapeDesc } from '../../common/types.js';
12
12
  import type { Graph } from '../../model/graph.js';
13
+ import { gvCleanupEdgeLabels, gvCleanupNodeLabels } from '../dot/init.js';
13
14
  import type { Node } from '../../model/node.js';
14
15
  import type { Edge } from '../../model/edge.js';
15
16
  import type { TwopiAlgData } from '../../model/nodeInfo.js';
@@ -157,23 +158,34 @@ export function adjustNodes(g: Graph): void {
157
158
  }
158
159
 
159
160
  /**
160
- * Release twopi-specific per-node state after layout.
161
+ * Free ND_alg of the first node, as twopi_layout does before spline routing.
161
162
  *
162
- * Mirrors the C twopi_layout cleanup: free(ND_alg(first_node)) / ND_alg = NULL
163
- * on the FIRST node only (the contiguous block was allocated as a single unit).
164
- * Other nodes' ND_alg pointers were interior offsets into that block so they
165
- * do not need to be freed separately.
163
+ * Mirrors the C twopi_layout: free(ND_alg(n)) / ND_alg(n) = NULL on the FIRST
164
+ * node only (the contiguous block was allocated as a single unit). Other
165
+ * nodes' ND_alg pointers were interior offsets into that block so they do
166
+ * not need to be freed separately.
166
167
  *
167
168
  * ORDERING: must be called BEFORE splineEdges because edge routing may
168
169
  * store its own data in n.info.alg.
169
170
  *
170
- * @see lib/twopigen/twopiinit.c:twopi_layout (free(ND_alg) placement note)
171
- * @see lib/twopigen/twopiinit.c:twopi_cleanup
171
+ * @see lib/twopigen/twopiinit.c:twopi_layout (lines 113-115)
172
172
  */
173
- export function twopiCleanup(g: Graph): void {
173
+ export function twopiFreeAlg(g: Graph): void {
174
174
  const first = g.nodes.values().next().value as Node | undefined;
175
175
  if (first !== undefined && first.info.alg?.kind === 'twopi') {
176
176
  first.info.alg = undefined;
177
177
  }
178
- g.info.neato_nlist = undefined;
178
+ }
179
+
180
+ /**
181
+ * Release twopi layout state after rendering (the engine's `cleanup`).
182
+ * ND_alg is freed earlier, in twopi_layout (see twopiFreeAlg).
183
+ *
184
+ * @see lib/twopigen/twopiinit.c:twopi_cleanup
185
+ */
186
+ export function twopiCleanup(g: Graph): void {
187
+ if (g.nodes.size === 0) return; // C: empty graph
188
+ for (const e of g.edges) gvCleanupEdgeLabels(e); // gv_cleanup_edge
189
+ for (const n of g.nodes.values()) gvCleanupNodeLabels(n); // gv_cleanup_node
190
+ g.info.neato_nlist = undefined; // twopi_cleanup_graph
179
191
  }
@@ -11,7 +11,7 @@ import type { Graph } from '../../model/graph.js';
11
11
  import type { Node } from '../../model/node.js';
12
12
  import type { PackInfo } from '../pack/index.js';
13
13
  import {
14
- twopiCleanup,
14
+ twopiFreeAlg,
15
15
  findRootNode,
16
16
  adjustNodes,
17
17
  finaliseCoords,
@@ -71,7 +71,7 @@ export function layoutSingle(g: Graph, comps: Graph[], globalRoot: Center, setRo
71
71
  if (setRoot && globalRoot === null && center !== null) {
72
72
  g.attrs.set('root', center.name);
73
73
  }
74
- twopiCleanup(g); // ORDERING: before spline routing
74
+ twopiFreeAlg(g); // ORDERING: before spline routing
75
75
  // C: spline_edges(g) — shifts pos to the origin, syncs coord, routes.
76
76
  splineEdgesShifted(g);
77
77
  finaliseCoords(g);
@@ -90,7 +90,7 @@ export function layoutMulti(g: Graph, comps: Graph[], globalRoot: Center, pinfo:
90
90
  layoutComponent(g, sg, globalRoot);
91
91
  finaliseCoords(sg);
92
92
  }
93
- twopiCleanup(g); // ORDERING: before spline routing
93
+ twopiFreeAlg(g); // ORDERING: before spline routing
94
94
  packSubgraphs(comps.length, comps, g, pinfo);
95
95
  // C: spline_edges(g) — shifts pos to the origin, syncs coord, routes.
96
96
  splineEdgesShifted(g);
@@ -26,6 +26,25 @@ import { Node } from './node.js';
26
26
  */
27
27
  const LOCALNAMEPREFIX = '%';
28
28
 
29
+ /**
30
+ * cgraph's id for the first anonymous object, which an anonymous root graph is
31
+ * (agopen maps its NULL name first; idmap hands out odd ids from 1).
32
+ * @see lib/cgraph/id.c:idmap
33
+ */
34
+ const ANONYMOUS_ROOT_ID = 1;
35
+
36
+ /**
37
+ * Graph name as `agnameof` returns it: the DOT name, or `%<id>` for an
38
+ * anonymous graph. The port stores `''` for an anonymous root (dot/xdot
39
+ * re-serialization must not print the `%` name), so it is restored here.
40
+ * Anonymous subgraph ids are not tracked; callers pass the root, as C's
41
+ * neato message sites do.
42
+ * @see lib/cgraph/id.c:agnameof
43
+ */
44
+ export function agNameOf(g: Graph): string {
45
+ return g.anonymous ? `${LOCALNAMEPREFIX}${ANONYMOUS_ROOT_ID}` : g.name;
46
+ }
47
+
29
48
  /**
30
49
  * Allocate a fresh node id unique within `root.nodes`. Mirrors C's
31
50
  * agnextseq/agmapnametoid id reservation: at layout time the per-parse
@@ -27,7 +27,7 @@ import type { Edge } from '../model/edge.js';
27
27
  import { registerRenderState } from '../common/render-state.js';
28
28
  import { agerrorf, agwarningf } from '../common/agerr.js';
29
29
  import { parseSegsSilent } from '../common/multicolor.js';
30
- import { findStopColor, styleTokens } from '../common/style-resolve.js';
30
+ import { findStopColor, styleTokensQuiet } from '../common/style-resolve.js';
31
31
  import { emitOnce } from '../common/emit-once.js';
32
32
 
33
33
  /**
@@ -122,6 +122,21 @@ export function firstColor(name: string): string {
122
122
  */
123
123
  export function resolveRenderColor(raw: string, report = true): GVColor {
124
124
  if (raw === '' || raw === 'none') return { type: 'none' };
125
+ return resolveColorName(raw, report);
126
+ }
127
+
128
+ /**
129
+ * {@link resolveRenderColor} without the empty-name shortcut: C hands an empty
130
+ * name (a leading ':' cut at the first colon) to colorxlate, which rejects it
131
+ * (`Warning: is not a known color.`) and leaves opaque black.
132
+ * @see lib/gvc/gvrender.c:456 gvrender_set_fillcolor
133
+ */
134
+ export function resolveFillColorName(raw: string, report = true): GVColor {
135
+ if (raw === 'none') return { type: 'none' };
136
+ return resolveColorName(raw, report);
137
+ }
138
+
139
+ function resolveColorName(raw: string, report: boolean): GVColor {
125
140
  // C keeps a known name verbatim (case preserved); only the compare is
126
141
  // case-insensitive (bsearch over a lowercase table).
127
142
  const known = KNOWN_COLORS.has(raw.toLowerCase());
@@ -338,7 +353,7 @@ export function reportEdgeColors(e: Edge): void {
338
353
  reportColorNames(edgeGraphicsColors({
339
354
  color,
340
355
  fillcolor: e.attrs.get('fillcolor') ?? '',
341
- tapered: styleTokens(e.attrs.get('style')).includes('tapered'),
356
+ tapered: styleTokensQuiet(e.attrs.get('style')).includes('tapered'),
342
357
  arrows: spl.list.map((bz) => ({ sflag: bz.sflag !== 0, eflag: bz.eflag !== 0 })),
343
358
  }));
344
359
  }
package/src/render/dot.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  import type { Graph } from '../model/graph.js';
14
14
  import type { Node } from '../model/node.js';
15
15
  import type { Edge } from '../model/edge.js';
16
- import type { Point } from '../model/geom.js';
16
+ import type { Box, Point } from '../model/geom.js';
17
17
  import type { TextSpan } from '../common/emit-types.js';
18
18
  import type { ArrowDrawOp } from '../common/arrows-types.js';
19
19
  import type { GVColor } from '../common/color.js';
@@ -361,6 +361,17 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
361
361
  buf.push(this.styleOp(job), this.penOp(job), xdotPoints('L', pts));
362
362
  }
363
363
 
364
+ /**
365
+ * The `I` op: `x y w h` of the box, then the image name as an xdot string.
366
+ * @see plugin/core/gvrender_core_dot.c:core_loadimage_xdot
367
+ */
368
+ usershape(src: string, b: Box, job: RenderJob): void {
369
+ this.getBuf(job).push(
370
+ 'I ', xdotPoint(b.ll), xdotNum(b.ur.x - b.ll.x) + ' ' + xdotNum(b.ur.y - b.ll.y) + ' ',
371
+ xdotStrOp('', src),
372
+ );
373
+ }
374
+
364
375
  // --- graphics-state ops ------------------------------------------------
365
376
 
366
377
  /** Pen color op from the resolved graphics state (default black). */
@@ -482,6 +493,8 @@ export class DotRenderer extends XdotRenderer {
482
493
  override polygon(_pts: Point[], _filled: boolean, _job: RenderJob): void { /* no-op */ }
483
494
  override bezier(_pts: Point[], _filled: boolean, _job: RenderJob): void { /* no-op */ }
484
495
  override polyline(_pts: Point[], _job: RenderJob): void { /* no-op */ }
496
+ /** No loadimage engine for "dot" (only "<type>:xdot"). */
497
+ override usershape(_src: string, _b: Box, _job: RenderJob): void { /* no-op */ }
485
498
  }
486
499
 
487
500
  /** @see plugin/core/gvrender_core_dot.c FORMAT_DOT */
@@ -239,12 +239,8 @@ function applyDraws(attrs: Map<string, string> | undefined, d: XdotDraws | undef
239
239
  * hand-built graph with no real layout state) so callers fall back cleanly. */
240
240
  function collectDrawLookup(g: Graph): DrawLookup | undefined {
241
241
  let xg: Graph;
242
- // Inject our own XdotRenderer (last-registered wins bestRenderer) so we can
243
- // read its per-object draw strings AFTER the render: the DOT-text re-parse
244
- // below is faithful for coordinates but LOSSY for draw text containing `"`
245
- // (a DOT quoted string cannot hold `\` before `"`; a cluster label's `\"`
246
- // round-trips to `"`, id 2239). The draws map holds the pre-serialization
247
- // strings C's -Tjson reads directly, so we overlay them onto the re-parse.
242
+ // Our own XdotRenderer (last-registered wins) exposes raw draw strings: the
243
+ // DOT re-parse is LOSSY for draw text containing `"` (id 2239); overlay them.
248
244
  const xr = new XdotRenderer();
249
245
  try {
250
246
  const ctx = createDefaultContext();
@@ -650,8 +646,8 @@ function latin1Reencode(s: string): string {
650
646
  return out;
651
647
  }
652
648
 
653
- export function buildJson(g: Graph, doXDot: boolean): string {
654
- const draws = doXDot ? collectDrawLookup(g) : undefined;
649
+ export function buildJson(g: Graph, doXDot: boolean, preDraws?: DrawLookup): string {
650
+ const draws = doXDot ? (preDraws ?? collectDrawLookup(g)) : undefined;
655
651
  const ctx = assignIds(g, doXDot, draws);
656
652
  const root = buildGraphObject(g, true, ctx);
657
653
  return JSON.stringify(root, null, 2) + '\n';
@@ -702,10 +698,13 @@ export class JsonRenderer implements RendererPlugin {
702
698
  /** @see plugin/core/gvplugin_core.c registration table */
703
699
  readonly quality = 0;
704
700
 
705
- beginGraph(_g: Graph, _job: RenderJob): void { /* no-op */ }
701
+ private draws: DrawLookup | undefined; // set by beginGraph, cleared by endGraph
702
+ /** @see plugin/core/gvrender_core_json.c:json_begin_graph */
703
+ beginGraph(g: Graph, _job: RenderJob): void { this.draws = collectDrawLookup(g); }
706
704
 
707
705
  endGraph(g: Graph, job: RenderJob): void {
708
- job.write(buildJson(g, true));
706
+ job.write(buildJson(g, true, this.draws));
707
+ this.draws = undefined;
709
708
  }
710
709
 
711
710
  beginNode(_n: Node, _job: RenderJob): void { /* no-op */ }
package/src/render/map.ts CHANGED
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import type { Graph } from '../model/graph.js';
14
+ import { agNameOf } from '../model/cgraph-ops.js';
14
15
  import type { Node } from '../model/node.js';
15
16
  import type { Edge } from '../model/edge.js';
16
17
  import type { Point, Box } from '../model/geom.js';
@@ -583,13 +584,11 @@ export class PlainExtRenderer implements RendererPlugin {
583
584
  // Imagemap renderers (cmapx / imap and their no-polygon `_np` variants)
584
585
  // ---------------------------------------------------------------------------
585
586
 
586
- /** Graph name as `agnameof` returns it: the DOT name, or `%1` for an anonymous
587
- * root (cgraph's first anonymous id). The port stores `''` for an anonymous
588
- * root (dot/xdot re-serialization must not print a `%`-name — see dot.ts), so
589
- * the imagemap layer restores the internal name only here.
590
- * @see lib/cgraph/id.c:agnameof ; lib/cgraph/id.c:idmap (anon → `%1`) */
587
+ /** Graph name as `agnameof` returns it (`%1` for an anonymous root; the port
588
+ * stores `''` there so dot/xdot re-serialization stays unchanged).
589
+ * @see lib/cgraph/id.c:agnameof */
591
590
  export function mapGraphName(g: Graph): string {
592
- return g.anonymous ? '%1' : g.name;
591
+ return agNameOf(g);
593
592
  }
594
593
 
595
594
  /** First non-empty attr walking parent scopes (agget inheritance). */