@knowvah/dot-engine 2.12.1 → 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 (129) 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-label-init.d.ts +26 -1
  6. package/dist/common/edge-label-init.d.ts.map +1 -1
  7. package/dist/common/nodeinit.d.ts +16 -2
  8. package/dist/common/nodeinit.d.ts.map +1 -1
  9. package/dist/common/splines-path-begin.d.ts.map +1 -1
  10. package/dist/common/splines-path-end.d.ts.map +1 -1
  11. package/dist/gvc/context.d.ts +8 -0
  12. package/dist/gvc/context.d.ts.map +1 -1
  13. package/dist/gvc/emit-gates.d.ts +5 -10
  14. package/dist/gvc/emit-gates.d.ts.map +1 -1
  15. package/dist/gvc/emit-xdot.d.ts +7 -6
  16. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  17. package/dist/gvc/job.d.ts +5 -2
  18. package/dist/gvc/job.d.ts.map +1 -1
  19. package/dist/gvc/viewport.d.ts +10 -5
  20. package/dist/gvc/viewport.d.ts.map +1 -1
  21. package/dist/index.js +361 -194
  22. package/dist/index.js.map +4 -4
  23. package/dist/layout/dot/edge-route.d.ts +7 -3
  24. package/dist/layout/dot/edge-route.d.ts.map +1 -1
  25. package/dist/layout/dot/fastgr.d.ts +5 -3
  26. package/dist/layout/dot/fastgr.d.ts.map +1 -1
  27. package/dist/layout/dot/flat-adj-record.d.ts +22 -0
  28. package/dist/layout/dot/flat-adj-record.d.ts.map +1 -0
  29. package/dist/layout/dot/init.d.ts +49 -9
  30. package/dist/layout/dot/init.d.ts.map +1 -1
  31. package/dist/layout/dot/mincross-build.d.ts +6 -0
  32. package/dist/layout/dot/mincross-build.d.ts.map +1 -1
  33. package/dist/layout/dot/position-aux.d.ts +7 -1
  34. package/dist/layout/dot/position-aux.d.ts.map +1 -1
  35. package/dist/layout/dot/splines-clone.d.ts +2 -1
  36. package/dist/layout/dot/splines-clone.d.ts.map +1 -1
  37. package/dist/layout/dot/splines-flat-labeled.d.ts.map +1 -1
  38. package/dist/layout/dot/splines-flat.d.ts +18 -0
  39. package/dist/layout/dot/splines-flat.d.ts.map +1 -1
  40. package/dist/layout/dot/splines-groups.d.ts.map +1 -1
  41. package/dist/layout/fdp/ports.d.ts.map +1 -1
  42. package/dist/layout/neato/conjgrad-mkernel.d.ts.map +1 -1
  43. package/dist/layout/neato/sgd.d.ts.map +1 -1
  44. package/dist/model/cgraph-ops.d.ts +10 -2
  45. package/dist/model/cgraph-ops.d.ts.map +1 -1
  46. package/dist/model/edge.d.ts +7 -2
  47. package/dist/model/edge.d.ts.map +1 -1
  48. package/dist/model/edgeInfo.d.ts +17 -2
  49. package/dist/model/edgeInfo.d.ts.map +1 -1
  50. package/dist/model/graph.d.ts +4 -3
  51. package/dist/model/graph.d.ts.map +1 -1
  52. package/dist/model/lazy-attrs.d.ts.map +1 -1
  53. package/dist/parser/builder.d.ts.map +1 -1
  54. package/dist/render/dot/agwrite.d.ts +5 -1
  55. package/dist/render/dot/agwrite.d.ts.map +1 -1
  56. package/dist/render/dot/attrs.d.ts +15 -4
  57. package/dist/render/dot/attrs.d.ts.map +1 -1
  58. package/dist/render/dot/write-back.d.ts +14 -0
  59. package/dist/render/dot/write-back.d.ts.map +1 -1
  60. package/dist/render/dot/xdot-ops.d.ts +20 -29
  61. package/dist/render/dot/xdot-ops.d.ts.map +1 -1
  62. package/dist/render/dot.d.ts +4 -2
  63. package/dist/render/dot.d.ts.map +1 -1
  64. package/dist/render/json-cluster-edge.d.ts +17 -4
  65. package/dist/render/json-cluster-edge.d.ts.map +1 -1
  66. package/dist/render/json-nonfinite.d.ts +17 -0
  67. package/dist/render/json-nonfinite.d.ts.map +1 -0
  68. package/dist/render/json.d.ts +4 -0
  69. package/dist/render/json.d.ts.map +1 -1
  70. package/dist/render/map.d.ts +3 -0
  71. package/dist/render/map.d.ts.map +1 -1
  72. package/dist/render/svg-graph.d.ts.map +1 -1
  73. package/dist/render/svg-id.d.ts +10 -1
  74. package/dist/render/svg-id.d.ts.map +1 -1
  75. package/dist/render/svg.d.ts +3 -1
  76. package/dist/render/svg.d.ts.map +1 -1
  77. package/dist/render.js +360 -193
  78. package/dist/render.js.map +4 -4
  79. package/dist/util/bsd-qsort.d.ts.map +1 -1
  80. package/dist/xdot/parse.d.ts.map +1 -1
  81. package/dist/xdot/strtod.d.ts +23 -0
  82. package/dist/xdot/strtod.d.ts.map +1 -0
  83. package/package.json +1 -1
  84. package/src/api/builder.ts +8 -2
  85. package/src/common/edge-label-init.ts +43 -17
  86. package/src/common/nodeinit.ts +28 -8
  87. package/src/common/splines-path-begin.ts +4 -3
  88. package/src/common/splines-path-end.ts +4 -3
  89. package/src/gvc/context.ts +8 -0
  90. package/src/gvc/device.ts +6 -6
  91. package/src/gvc/emit-gates.ts +6 -15
  92. package/src/gvc/emit-xdot.ts +10 -11
  93. package/src/gvc/job.ts +5 -2
  94. package/src/gvc/viewport.ts +13 -7
  95. package/src/layout/dot/__fixtures__/flat-adj-aux-syms.native-16.1.json +1210 -0
  96. package/src/layout/dot/edge-route.ts +44 -49
  97. package/src/layout/dot/fastgr.ts +9 -3
  98. package/src/layout/dot/flat-adj-record.ts +68 -0
  99. package/src/layout/dot/init.ts +59 -13
  100. package/src/layout/dot/mincross-build.ts +14 -1
  101. package/src/layout/dot/position-aux.ts +10 -3
  102. package/src/layout/dot/splines-clone.ts +8 -2
  103. package/src/layout/dot/splines-flat-labeled.ts +3 -2
  104. package/src/layout/dot/splines-flat.ts +9 -19
  105. package/src/layout/dot/splines-groups.ts +5 -3
  106. package/src/layout/fdp/ports.ts +6 -2
  107. package/src/layout/neato/conjgrad-mkernel.ts +6 -2
  108. package/src/layout/neato/sgd.ts +2 -1
  109. package/src/model/cgraph-ops.ts +4 -3
  110. package/src/model/edge.ts +11 -4
  111. package/src/model/edgeInfo.ts +18 -2
  112. package/src/model/graph.ts +4 -3
  113. package/src/model/lazy-attrs.ts +3 -1
  114. package/src/parser/builder.ts +12 -3
  115. package/src/render/dot/agwrite.ts +10 -3
  116. package/src/render/dot/attrs.ts +18 -7
  117. package/src/render/dot/write-back.ts +27 -3
  118. package/src/render/dot/xdot-ops.ts +25 -56
  119. package/src/render/dot.ts +7 -5
  120. package/src/render/json-cluster-edge.ts +42 -5
  121. package/src/render/json-nonfinite.ts +51 -0
  122. package/src/render/json.ts +23 -26
  123. package/src/render/map.ts +3 -0
  124. package/src/render/svg-graph.ts +3 -15
  125. package/src/render/svg-id.ts +11 -2
  126. package/src/render/svg.ts +4 -1
  127. package/src/util/bsd-qsort.ts +2 -1
  128. package/src/xdot/parse.ts +9 -19
  129. package/src/xdot/strtod.ts +167 -0
@@ -1 +1 @@
1
- {"version":3,"file":"bsd-qsort.d.ts","sourceRoot":"","sources":["../../src/util/bsd-qsort.ts"],"names":[],"mappings":"AA+KA;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAQ9F;AAyCD;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,GAAG,CAAC,EAAE,CAOrE"}
1
+ {"version":3,"file":"bsd-qsort.d.ts","sourceRoot":"","sources":["../../src/util/bsd-qsort.ts"],"names":[],"mappings":"AAgLA;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,M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,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAE1F;AACD,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAoC;AACrF,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAyC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * The number scan C's xdot parser gets from libc strtod. parseReal, parseRect
3
+ * and parsePolyline all read their doubles with strtod, so an xdot string may
4
+ * hold anything strtod accepts: a decimal, a hexadecimal float, `inf` or
5
+ * `infinity`, and `nan` or `nan(...)`. The grammar is the oracle platform's
6
+ * (macOS libc), which takes any characters between `nan(` and the first `)`.
7
+ * @see lib/xdot/xdot.c:parseReal
8
+ */
9
+ /** A scanned number and the offset just past it, or null when none starts here. */
10
+ export type Scan = {
11
+ val: number;
12
+ pos: number;
13
+ } | null;
14
+ /** @see lib/util/gv_ctype.h:gv_isspace */
15
+ export declare function isSpace(c: string): boolean;
16
+ /**
17
+ * strtod(s + pos, &end): skips whitespace, takes an optional sign, then the
18
+ * longest number strtod accepts. Null when no conversion is possible, which
19
+ * is C's `end == s`.
20
+ * @see lib/xdot/xdot.c:parseReal
21
+ */
22
+ export declare function scanStrtod(s: string, pos: number): Scan;
23
+ //# sourceMappingURL=strtod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strtod.d.ts","sourceRoot":"","sources":["../../src/xdot/strtod.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,mFAAmF;AACnF,MAAM,MAAM,IAAI,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC;AAgBvD,0CAA0C;AAC1C,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE1C;AA2HD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAOvD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knowvah/dot-engine",
3
- "version": "2.12.1",
3
+ "version": "2.12.2",
4
4
  "description": "Faithful TypeScript port of Graphviz (dot, neato, fdp, sfdp, circo, twopi, osage, patchwork) — no C: no native binary, no WASM. Oracle-verified against the C implementation, runs in the browser.",
5
5
  "keywords": [
6
6
  "graphviz",
@@ -26,6 +26,8 @@ import { HTML_STRING_MARK } from '../common/html-string.js';
26
26
  export interface CreateGraphOptions {
27
27
  directed?: boolean;
28
28
  strict?: boolean;
29
+ /** The graph's name. Omitted: the graph is anonymous, as `agopen(NULL)` is
30
+ * (written `digraph {`). An explicit `''` is a name (written `digraph "" {`). */
29
31
  name?: string;
30
32
  }
31
33
 
@@ -331,15 +333,19 @@ function resolveKind(opts: CreateGraphOptions | undefined): GraphKind {
331
333
  * Create a new programmatic graph builder.
332
334
  *
333
335
  * The builder's `.graph` is a fresh Graph ready for handoff to layout/render.
334
- * Defaults: directed=true, strict=false, name=''.
336
+ * Defaults: directed=true, strict=false, no name. A graph created without a
337
+ * `name` is anonymous, as `agopen(NULL)` is: `graph.name` reads `''` and dot
338
+ * output starts `digraph {`. An explicit `name: ''` is a name, as `agopen("")`
339
+ * is, and prints `digraph "" {`.
335
340
  *
336
341
  * @throws TypeError `ERR_INVALID_ARG_TYPE` if `opts` or one of its fields has
337
342
  * the wrong type. Builder and handle methods throw the same for wrong
338
343
  * argument types, and `InternalError` if node/subgraph creation fails.
339
344
  * @see lib/cgraph/graph.c:agopen
345
+ * @see lib/cgraph/id.c:agmapnametoid
340
346
  */
341
347
  export function createGraph(opts?: CreateGraphOptions): GvGraphBuilder {
342
348
  requireGraphOptions(opts);
343
- const g = new Graph(opts?.name ?? '', resolveKind(opts));
349
+ const g = new Graph(opts?.name ?? '', resolveKind(opts), opts?.name === undefined);
344
350
  return new GraphBuilder(g, g);
345
351
  }
@@ -220,12 +220,32 @@ function applyTailLabel(e: Edge, g: Graph, lfi: FontInfo, measurer: TextMeasurer
220
220
  // @see lib/common/utils.c:509-545
221
221
  // ---------------------------------------------------------------------------
222
222
 
223
+ /**
224
+ * Which of common_init_edge's guarded label symbols are bound. C tests each
225
+ * global before reading it (`E_xlabel && (str = agxget(e, E_xlabel)) && str[0]`),
226
+ * and make_flat_adj_edges' setState nulls these three for the aux layout, so an
227
+ * aux edge's copied `xlabel`, `headlabel` and `taillabel` are never read: no
228
+ * label is made and no GD_has_labels bit is set. E_label is rebound from the
229
+ * aux graph instead, so it has no entry here.
230
+ * @see lib/common/utils.c:common_init_edge (525, 533, 539)
231
+ * @see lib/dotgen/dotsplines.c:setState
232
+ */
233
+ export interface EdgeLabelSyms {
234
+ readonly headlabel: boolean;
235
+ readonly taillabel: boolean;
236
+ readonly xlabel: boolean;
237
+ }
238
+
239
+ /** Every symbol bound, as graph_init leaves them. @see lib/common/input.c:graph_init */
240
+ export const BOUND_EDGE_LABEL_SYMS: EdgeLabelSyms = { headlabel: true, taillabel: true, xlabel: true };
241
+
223
242
  /**
224
243
  * Apply label and xlabel with lazy fi init mirroring C's NULL-guard pattern.
225
- * fi is initialized at most once and reused for xlabel.
244
+ * fi is initialized at most once and reused for xlabel. An unbound E_xlabel
245
+ * fails C's guard before the attribute is read.
226
246
  * @see lib/common/utils.c:common_init_edge (lines 515-531)
227
247
  */
228
- function applyMainLabels(e: Edge, g: Graph, measurer: TextMeasurer): void {
248
+ function applyMainLabels(e: Edge, g: Graph, measurer: TextMeasurer, syms: EdgeLabelSyms): void {
229
249
  // C: fi.fontname = NULL; init on first need, reuse for xlabel.
230
250
  let fi: FontInfo | null = null;
231
251
  const labelStr = e.attrs.get('label');
@@ -233,29 +253,25 @@ function applyMainLabels(e: Edge, g: Graph, measurer: TextMeasurer): void {
233
253
  fi = initFontEdgeAttr(e);
234
254
  applyLabel(e, g, fi, measurer);
235
255
  }
236
- const xlabelStr = e.attrs.get('xlabel');
256
+ // utils.c:525 — E_xlabel && (str = agxget(e, E_xlabel)) && str[0]
257
+ const xlabelStr = syms.xlabel ? e.attrs.get('xlabel') : undefined;
237
258
  if (xlabelStr) {
238
259
  applyXLabel(e, g, fi ?? initFontEdgeAttr(e), measurer);
239
260
  }
240
261
  }
241
262
 
242
263
  /**
243
- * Apply headlabel and taillabel using the labelfont* chain.
264
+ * Apply headlabel and taillabel using the labelfont* chain. An unbound
265
+ * E_headlabel or E_taillabel fails C's guard before the attribute is read.
244
266
  * @see lib/common/utils.c:common_init_edge (lines 533-545)
245
267
  */
246
- function applyEndLabels(e: Edge, g: Graph, measurer: TextMeasurer): void {
268
+ function applyEndLabels(e: Edge, g: Graph, measurer: TextMeasurer, syms: EdgeLabelSyms): void {
269
+ if (!syms.headlabel && !syms.taillabel) return;
247
270
  const lfi = getLabelFontInfo(e);
248
- applyHeadLabel(e, g, lfi, measurer);
249
- applyTailLabel(e, g, lfi, measurer);
271
+ if (syms.headlabel) applyHeadLabel(e, g, lfi, measurer); // utils.c:533
272
+ if (syms.taillabel) applyTailLabel(e, g, lfi, measurer); // utils.c:539
250
273
  }
251
274
 
252
- /**
253
- * Creates label, xlabel, head_label, and tail_label TextlabelT objects on the
254
- * edge, mirroring common_init_edge in C. C statement order is preserved:
255
- * label → xlabel → headlabel → taillabel.
256
- *
257
- * @see lib/common/utils.c:common_init_edge (lines 509-545)
258
- */
259
275
  /** Shape portfn: aiming point + slope for a named/compass port. */
260
276
  type PortFn = (n: unknown, portname: string, compass: string) => Port;
261
277
 
@@ -307,11 +323,21 @@ export function initEdgePorts(e: Edge): void {
307
323
  if (isClipDisabled(e.attrs.get('headclip'))) e.info.head_port.clip = false;
308
324
  }
309
325
 
310
- export function initEdgeLabels(e: Edge, g: Graph, measurer: TextMeasurer): void {
326
+ /**
327
+ * Creates label, xlabel, head_label, and tail_label TextlabelT objects on the
328
+ * edge, mirroring common_init_edge in C. C statement order is preserved:
329
+ * label → xlabel → headlabel → taillabel. `syms` stands for the global symbol
330
+ * state the three guarded reads test (unbound inside make_flat_adj_edges).
331
+ *
332
+ * @see lib/common/utils.c:common_init_edge (lines 509-545)
333
+ */
334
+ export function initEdgeLabels(
335
+ e: Edge, g: Graph, measurer: TextMeasurer, syms: EdgeLabelSyms = BOUND_EDGE_LABEL_SYMS,
336
+ ): void {
311
337
  initEdgePorts(e); // port block runs for every edge, before the label short-circuit
312
338
  const hasMain = e.attrs.has('label') || e.attrs.has('xlabel');
313
339
  const hasEnd = e.attrs.has('headlabel') || e.attrs.has('taillabel');
314
340
  if (!hasMain && !hasEnd) return;
315
- if (hasMain) applyMainLabels(e, g, measurer);
316
- if (hasEnd) applyEndLabels(e, g, measurer);
341
+ if (hasMain) applyMainLabels(e, g, measurer, syms);
342
+ if (hasEnd) applyEndLabels(e, g, measurer, syms);
317
343
  }
@@ -160,11 +160,28 @@ export function polySizeParamsFromNode(
160
160
  }
161
161
 
162
162
  /**
163
- * Create ND_xlabel when the xlabel attr is non-empty and set NODE_XLABEL.
163
+ * Which of common_init_node's guarded symbols are bound. C tests N_xlabel
164
+ * before reading it (`N_xlabel && (str = agxget(n, N_xlabel)) && str[0]`), and
165
+ * make_flat_adj_edges' setState nulls it for the aux layout, so an aux node's
166
+ * copied `xlabel` is never read.
167
+ * @see lib/common/utils.c:common_init_node (443)
168
+ * @see lib/dotgen/dotsplines.c:setState
169
+ */
170
+ export interface NodeInitSyms {
171
+ readonly nodeXlabel: boolean;
172
+ }
173
+
174
+ /** N_xlabel bound, as graph_init leaves it. @see lib/common/input.c:graph_init */
175
+ export const BOUND_NODE_INIT_SYMS: NodeInitSyms = { nodeXlabel: true };
176
+
177
+ /**
178
+ * Create ND_xlabel when N_xlabel is bound and the xlabel attr is non-empty,
179
+ * and set NODE_XLABEL.
164
180
  * @see lib/common/utils.c:443-447
165
181
  * @see lib/common/utils.c:447 — GD_has_labels scoped to agraphof(n) root
166
182
  */
167
- function initNodeXLabel(n: Node, g: Graph, measurer: TextMeasurer): void {
183
+ function initNodeXLabel(n: Node, g: Graph, measurer: TextMeasurer, syms: NodeInitSyms): void {
184
+ if (!syms.nodeXlabel) return; // utils.c:443 — the `N_xlabel &&` guard
168
185
  const str = nodeAttr(n, g, 'xlabel');
169
186
  if (!str || str.length === 0) return;
170
187
  const font = readFontAttrs(n, g);
@@ -228,7 +245,7 @@ function initPointSize(n: Node, g: Graph, shape: ShapeDesc & { polygon: PolygonT
228
245
  * has no polygon descriptor to size against.
229
246
  * @see lib/common/utils.c:common_init_node
230
247
  */
231
- function initNodeFromLabel(n: Node, g: Graph, measurer: TextMeasurer): boolean {
248
+ function initNodeFromLabel(n: Node, g: Graph, measurer: TextMeasurer, syms: NodeInitSyms): boolean {
232
249
  const shape = bindShape(nodeAttr(n, g, 'shape') ?? 'ellipse', nodeAttr(n, g, 'shapefile'));
233
250
  n.info.shape = shape;
234
251
  if (shape.kind === ShapeKind.SH_RECORD) {
@@ -237,12 +254,12 @@ function initNodeFromLabel(n: Node, g: Graph, measurer: TextMeasurer): boolean {
237
254
  // only selects make_label's is_record flag and initfn=record_init — it is
238
255
  // NOT a reason to skip the xlabel (utils.c:441/443/453).
239
256
  recordMakeLabel(n, g, measurer);
240
- initNodeXLabel(n, g, measurer);
257
+ initNodeXLabel(n, g, measurer, syms);
241
258
  recordInit(n, g, measurer); // initfn: sets lw/rw/ht from the field tree
242
259
  return true;
243
260
  }
244
261
  buildNodeLabel(n, g, measurer);
245
- initNodeXLabel(n, g, measurer);
262
+ initNodeXLabel(n, g, measurer, syms);
246
263
  // Layout-time poly_init warnings (once per layout; render-time polyInit is silent).
247
264
  if (shape.kind !== ShapeKind.SH_POINT) warnPolyInitImages(n, g);
248
265
  const poly = shape.polygon;
@@ -330,13 +347,16 @@ function initNodeDefaults(n: Node, g: Graph): void {
330
347
 
331
348
  /**
332
349
  * Initialise per-node geometry: shape-aware, label-driven sizing when a
333
- * text measurer is available; width/height attr defaults otherwise.
350
+ * text measurer is available; width/height attr defaults otherwise. `syms`
351
+ * stands for the global symbol state common_init_node reads.
334
352
  * @see lib/common/utils.c:common_init_node
335
353
  * @see lib/common/utils.c:gv_nodesize
336
354
  */
337
- export function commonInitNode(n: Node, g: Graph): void {
355
+ export function commonInitNode(
356
+ n: Node, g: Graph, syms: NodeInitSyms = BOUND_NODE_INIT_SYMS,
357
+ ): void {
338
358
  const measurer = layoutMeasurer(g);
339
- if (measurer !== undefined && initNodeFromLabel(n, g, measurer)) return;
359
+ if (measurer !== undefined && initNodeFromLabel(n, g, measurer, syms)) return;
340
360
  initNodeDefaults(n, g);
341
361
  }
342
362
 
@@ -35,9 +35,10 @@ class BeginRegSide {
35
35
  static topLeft(ctx: BeginCtx): void {
36
36
  const { P, n, endp, ranksep } = ctx;
37
37
  const b = endp.nb;
38
+ // C: GD_ranksep is int (types.h:335), so /2 truncates
38
39
  endp.boxes[0] = {
39
40
  ll: { x: b.ll.x - 1, y: P.start.p.y },
40
- ur: { x: b.ur.x, y: n.info.coord.y + n.info.ht / 2 + ranksep / 2 },
41
+ ur: { x: b.ur.x, y: n.info.coord.y + n.info.ht / 2 + Math.trunc(ranksep / 2) },
41
42
  };
42
43
  endp.boxes[1] = {
43
44
  ll: { x: b.ll.x - 1, y: n.info.coord.y - n.info.ht / 2 },
@@ -50,7 +51,7 @@ class BeginRegSide {
50
51
  const b = endp.nb;
51
52
  endp.boxes[0] = {
52
53
  ll: { x: b.ll.x, y: P.start.p.y },
53
- ur: { x: b.ur.x + 1, y: n.info.coord.y + n.info.ht / 2 + ranksep / 2 },
54
+ ur: { x: b.ur.x + 1, y: n.info.coord.y + n.info.ht / 2 + Math.trunc(ranksep / 2) },
54
55
  };
55
56
  endp.boxes[1] = {
56
57
  ll: { x: n.info.coord.x + n.info.rw + (FUDGE - 2), y: n.info.coord.y - n.info.ht / 2 },
@@ -121,7 +122,7 @@ class BeginFlatSide {
121
122
  const { P, n, endp, ranksep } = ctx;
122
123
  if (endp.sidemask === TOP) {
123
124
  endp.boxes[0] = {
124
- ll: { x: P.start.p.x, y: n.info.coord.y - n.info.ht / 2 - ranksep / 2 },
125
+ ll: { x: P.start.p.x, y: n.info.coord.y - n.info.ht / 2 - Math.trunc(ranksep / 2) },
125
126
  ur: { x: b.ur.x + 1, y: n.info.coord.y - n.info.ht / 2 },
126
127
  };
127
128
  endp.boxes[1] = {
@@ -45,8 +45,9 @@ class EndRegSide {
45
45
  const { P, n, e, endp, ranksep } = ctx;
46
46
  const b = endp.nb;
47
47
  if (P.end.p.x < n.info.coord.x) {
48
+ // C: GD_ranksep is int (types.h:335), so /2 truncates
48
49
  endp.boxes[0] = {
49
- ll: { x: b.ll.x - 1, y: n.info.coord.y - n.info.ht / 2 - ranksep / 2 },
50
+ ll: { x: b.ll.x - 1, y: n.info.coord.y - n.info.ht / 2 - Math.trunc(ranksep / 2) },
50
51
  ur: { x: b.ur.x, y: P.end.p.y },
51
52
  };
52
53
  endp.boxes[1] = {
@@ -55,7 +56,7 @@ class EndRegSide {
55
56
  };
56
57
  } else {
57
58
  endp.boxes[0] = {
58
- ll: { x: b.ll.x, y: n.info.coord.y - n.info.ht / 2 - ranksep / 2 },
59
+ ll: { x: b.ll.x, y: n.info.coord.y - n.info.ht / 2 - Math.trunc(ranksep / 2) },
59
60
  ur: { x: b.ur.x + 1, y: P.end.p.y },
60
61
  };
61
62
  endp.boxes[1] = {
@@ -121,7 +122,7 @@ class EndFlatSide {
121
122
  const { P, n, endp, ranksep } = ctx;
122
123
  if (endp.sidemask === TOP) {
123
124
  endp.boxes[0] = {
124
- ll: { x: b.ll.x - 1, y: n.info.coord.y - n.info.ht / 2 - ranksep / 2 },
125
+ ll: { x: b.ll.x - 1, y: n.info.coord.y - n.info.ht / 2 - Math.trunc(ranksep / 2) },
125
126
  ur: { x: P.end.p.x, y: n.info.coord.y - n.info.ht / 2 },
126
127
  };
127
128
  endp.boxes[1] = {
@@ -64,6 +64,14 @@ export interface RendererPlugin {
64
64
  readonly type: string;
65
65
  /** Capability quality — higher wins when multiple plugins match the same format. */
66
66
  readonly quality: number;
67
+ /**
68
+ * The pad around the drawing, in graph units (points), when the graph sets no
69
+ * `pad=`. A renderer that omits it gets `DEFAULT_GRAPH_PAD`, as C's output
70
+ * languages that are not render plugins do.
71
+ * @see lib/gvc/gvcjob.h gvrender_features_t.default_pad
72
+ * @see lib/common/emit.c:3290-3304 init_job_pad
73
+ */
74
+ readonly defaultPad?: number;
67
75
 
68
76
  beginGraph(g: Graph, job: RenderJob): void;
69
77
  endGraph(g: Graph, job: RenderJob): void;
package/src/gvc/device.ts CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  import { POINTS_PER_INCH } from '../model/geom.js';
16
16
  import { lateDouble } from '../common/nodeinit.js';
17
- import { parseDrawingSize, initJobViewportZoom, parseLandscape, parseGraphPad, parseGraphMargin } from './viewport.js';
17
+ import { parseDrawingSize, initJobViewportZoom, parseLandscape, parseGraphPad, parseGraphMargin, DEFAULT_GRAPH_PAD } from './viewport.js';
18
18
  import type { Graph } from '../model/graph.js';
19
19
  import type { Node } from '../model/node.js';
20
20
  import type { Edge } from '../model/edge.js';
@@ -231,7 +231,7 @@ export function renderEdge(e: Edge, renderer: RendererPlugin, job: RenderJob): v
231
231
  * @see lib/common/emit.c:emit_page (3656-3657)
232
232
  */
233
233
  export function renderGraphLabel(g: Graph, renderer: RendererPlugin, job: RenderJob): void {
234
- // @see lib/common/emit.c:emit_begin_graph / getObjId (root graph → graph0)
234
+ // @see lib/common/emit.c:emit_begin_graph / getObjId (graph being emitted → graph<AGSEQ>)
235
235
  setHtmlAnchorObj(svgGraphId(g, job), labelTextOf(g.info.label), job.obj ?? undefined);
236
236
  renderOneLabel(g.info.label as TextlabelT | undefined, renderer, job, false);
237
237
  }
@@ -450,10 +450,10 @@ export function render(ctx: GvcContext, g: Graph, format: string, inlineImages =
450
450
  // a recompute, it is the mechanism that produces C's near-empty output.
451
451
  // @see lib/common/emit.c:3272 init_gvc (gvc->bb = GD_bb(g))
452
452
  job.bb = g.info.bb;
453
- // init_job_pad: job.pad from `pad=`, before the size= fit, which uses the
454
- // padded bb (C calls init_job_pad before init_job_viewport, emit.c:4289-4291).
453
+ // init_job_pad: job.pad from `pad=`, else the render device's default pad,
454
+ // before the size= fit, which uses the padded bb (emit.c:4289-4291).
455
455
  // @see lib/common/emit.c:3241-3251 (attr read); :3290-3304 (fallback)
456
- job.pad = parseGraphPad(g.attrs.get('pad'));
456
+ job.pad = parseGraphPad(g.attrs.get('pad'), renderer.defaultPad ?? DEFAULT_GRAPH_PAD);
457
457
  // init_job_margin, right after init_job_pad (emit.c:4290-4291). margin does
458
458
  // not feed the size= fit (only pad does); emitSvgTag/svgBeginPage use it after
459
459
  // Z is known, as C resolves it before init_job_viewport and uses it after.
@@ -478,7 +478,7 @@ export function render(ctx: GvcContext, g: Graph, format: string, inlineImages =
478
478
  // not job->zoom. job.scale is read only by the SVG group/dims.
479
479
  const drawingSize = parseDrawingSize(g.attrs.get('size'));
480
480
  const z = initJobViewportZoom(job.bb, drawingSize, job.pad);
481
- job.clip = deviceClip(g, renderer, job); // @see emit.c:setup_page (xdot's default pad is 0)
481
+ job.clip = deviceClip(g, job); // @see lib/common/emit.c:1550-1564 setup_page
482
482
  // init_job_dpi (emit.c:3333): GD_drawing->dpi = late_double(dpi, resolution, 0)
483
483
  // (input.c:713). When >0 it becomes job->dpi; otherwise the SVG device's
484
484
  // default_dpi = 72 (gvrender_core_svg.c:814) applies. init_job_viewport then
@@ -31,27 +31,18 @@ function nodeBBox(n: Node): Box {
31
31
  }
32
32
 
33
33
  /**
34
- * node_in_box: is the node's own bbox within job's page/view clip?
34
+ * node_in_box: is the node's own bbox within the job's page clip?
35
35
  *
36
- * C's `job->clip` is derived from `job->bb` (= `GD_bb(g)`) expanded by
37
- * `job->pad` on every side (init_job_viewport's `job->bb = gvc->bb ±
38
- * job->pad`, feeding `job->view`/`job->focus`, which setup_page's `job->clip`
39
- * algebraically reduces back to for the single-page, unpaginated case this
40
- * port implements — Z and rotation cancel out of that derivation). This port
41
- * has no separate `page=` pagination model, so `job.bb` padded by `job.pad`
42
- * IS `job->clip` here.
36
+ * emit_node passes `job->clip`, which setup_page builds from the bb padded by
37
+ * the device's pad (see deviceClip). The edge gate, the clusters and the
38
+ * background read the same box, so `job.clip` has to be set before a node is
39
+ * rendered; `render` sets it.
43
40
  *
44
41
  * @see lib/common/emit.c:1636-1639 node_in_box
45
42
  * @see lib/common/emit.c:1808 emit_node gate
46
- * @see lib/common/emit.c:3356 init_job_viewport (job->bb = gvc->bb ± pad)
47
- * @see lib/common/emit.c:1553-1564 setup_page (job->clip from focus/view)
48
43
  */
49
44
  export function nodeInBox(n: Node, job: RenderJob): boolean {
50
- const clip: Box = {
51
- ll: { x: job.bb.ll.x - job.pad.x, y: job.bb.ll.y - job.pad.y },
52
- ur: { x: job.bb.ur.x + job.pad.x, y: job.bb.ur.y + job.pad.y },
53
- };
54
- return boxOverlap(nodeBBox(n), clip);
45
+ return boxOverlap(nodeBBox(n), job.clip);
55
46
  }
56
47
 
57
48
  /**
@@ -19,7 +19,7 @@ import { transformPoint } from './device-transform.js';
19
19
  import { graphXdots } from './init-xdot.js';
20
20
  import { gvrenderSetStyle } from './gvrender-set-style.js';
21
21
  import type { ObjState, RenderJob } from './job.js';
22
- import { initJobViewportZoom, parseDrawingSize, parseGraphPad, setupPageClip } from './viewport.js';
22
+ import { initJobViewportZoom, parseDrawingSize, setupPageClip } from './viewport.js';
23
23
 
24
24
  /** @see lib/common/const.h:48 */
25
25
  const DEFAULT_COLOR = 'black';
@@ -30,17 +30,16 @@ const DEFAULT_FILL = 'lightgrey';
30
30
  const DEFAULT_LINE_STYLE: readonly string[] = ['solid', 'setlinewidth(1)'];
31
31
 
32
32
  /**
33
- * job->clip for this device, computed in C's order, rounding included. svg's
34
- * pad is `job.pad` (default 4); the xdot device's default is 0, so with no
35
- * `pad` its clip is the bb.
36
- * @see plugin/core/gvrender_core_dot.c:739 render_features_dot
37
- * @see lib/common/emit.c:1558
33
+ * job->clip, computed in C's order, rounding included, from the bb and
34
+ * `job.pad`. init_job_pad has already made that pad the device's: with no
35
+ * `pad=` it is 4 on svg and map, and 0 on dot, xdot, plain and json, whose clip
36
+ * is then the bb.
37
+ * @see lib/common/emit.c:3290-3304 init_job_pad
38
+ * @see lib/common/emit.c:1550-1564 setup_page
38
39
  */
39
- export function deviceClip(g: Graph, renderer: RendererPlugin, job: RenderJob): Box {
40
- const attr = g.attrs.get('pad');
41
- const pad = renderer.type === 'svg' ? job.pad : attr ? parseGraphPad(attr) : { x: 0, y: 0 };
40
+ export function deviceClip(g: Graph, job: RenderJob): Box {
42
41
  const size = parseDrawingSize(g.attrs.get('size'));
43
- return setupPageClip(job.bb, size, pad, initJobViewportZoom(job.bb, size, pad));
42
+ return setupPageClip(job.bb, size, job.pad, initJobViewportZoom(job.bb, size, job.pad));
44
43
  }
45
44
 
46
45
  /**
@@ -210,7 +209,7 @@ export function emitXdot(g: Graph, renderer: RendererPlugin, job: RenderJob): vo
210
209
  const obj = job.obj;
211
210
  if (xd === undefined || obj === null) return;
212
211
  applyBackgroundState(g, renderer, obj);
213
- const inClip = zeroBoxInClip(deviceClip(g, renderer, job));
212
+ const inClip = zeroBoxInClip(deviceClip(g, job));
214
213
  const warned = { image: false };
215
214
  let styled = false;
216
215
  for (const op of xd.ops) {
package/src/gvc/job.ts CHANGED
@@ -274,10 +274,13 @@ export class RenderJob {
274
274
  readonly format: string;
275
275
 
276
276
  bb: Box = { ll: { x: 0, y: 0 }, ur: { x: 0, y: 0 } };
277
+ /** `pad=`, or else the render device's default pad (`RendererPlugin.defaultPad`).
278
+ * @see lib/common/emit.c:3290-3304 init_job_pad */
277
279
  pad: Point = { x: 0, y: 0 };
278
280
  /** Current page clip in graph units, as setup_page computes it from the
279
- * viewport focus/view (see setupPageClip). Read by the SVG page translate and
280
- * background. @see lib/gvc/gvcjob.h:GVJ_s.clip; lib/common/emit.c:setup_page */
281
+ * viewport focus/view (see setupPageClip). Read by the node and edge gates
282
+ * and by the SVG page translate and background.
283
+ * @see lib/gvc/gvcjob.h:GVJ_s.clip; lib/common/emit.c:setup_page */
281
284
  clip: Box = { ll: { x: 0, y: 0 }, ur: { x: 0, y: 0 } };
282
285
  /** Graph-level `margin=` (init_job_margin); page-pagination margin, distinct
283
286
  * from node/cluster label margin. @see lib/common/emit.c:3309-3331 */
@@ -26,7 +26,7 @@
26
26
 
27
27
  import type { Box, Point } from '../model/geom.js';
28
28
  import { POINTS_PER_INCH } from '../model/geom.js';
29
- import { SVG_PAD, SVG_MARGIN } from '../render/svg-helpers.js';
29
+ import { SVG_MARGIN } from '../render/svg-helpers.js';
30
30
  import type { Graph } from '../model/graph.js';
31
31
  import { cround } from '../common/arith.js';
32
32
 
@@ -76,14 +76,20 @@ export function parseDrawingSize(raw: string | undefined): DrawingSize | null {
76
76
  return null;
77
77
  }
78
78
 
79
+ /**
80
+ * The pad init_job_pad gives an output language that is not a render plugin,
81
+ * in points. Here it is the pad of a renderer that states no `defaultPad`.
82
+ * @see lib/common/const.h:96
83
+ */
84
+ export const DEFAULT_GRAPH_PAD = 4;
85
+
79
86
  /**
80
87
  * Port of the `pad=` graph-attribute parse: init_gvc reads it via
81
88
  * `sscanf(p, "%lf,%lf", &xf, &yf)` (2 values matched → both axes
82
89
  * independently; 1 value → y = x; 0 matched — attr absent or unparsable —
83
- * leaves `graph_sets_pad` false) and init_job_pad falls back to the SVG
84
- * plugin's `default_pad` (this port's only renderer) when unset, which is
85
- * numerically identical to `DEFAULT_GRAPH_PAD` (4pt) — so the two C fallback
86
- * branches collapse to the same constant here (`SVG_PAD`).
90
+ * leaves `graph_sets_pad` false) and init_job_pad then takes `fallback` on
91
+ * both axes: the render plugin's `default_pad` (`RendererPlugin.defaultPad`),
92
+ * or `DEFAULT_GRAPH_PAD` where there is none.
87
93
  *
88
94
  * Unlike `size=`, pad values are NOT rounded (`xf * POINTS_PER_INCH`
89
95
  * directly — no `POINTS()` macro) and are not required to be positive.
@@ -91,7 +97,7 @@ export function parseDrawingSize(raw: string | undefined): DrawingSize | null {
91
97
  * @see lib/common/emit.c:3241-3251 init_gvc (pad attr read)
92
98
  * @see lib/common/emit.c:3290-3304 init_job_pad (fallback)
93
99
  */
94
- export function parseGraphPad(raw: string | undefined): Point {
100
+ export function parseGraphPad(raw: string | undefined, fallback: number): Point {
95
101
  if (raw !== undefined) {
96
102
  const xy = PAD_XY_RE.exec(raw);
97
103
  if (xy) {
@@ -103,7 +109,7 @@ export function parseGraphPad(raw: string | undefined): Point {
103
109
  return { x: v, y: v };
104
110
  }
105
111
  }
106
- return { x: SVG_PAD, y: SVG_PAD };
112
+ return { x: fallback, y: fallback };
107
113
  }
108
114
 
109
115
  /**