@knowvah/dot-engine 2.12.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.
- package/dist/common/edge-in-box.d.ts +6 -20
- package/dist/common/edge-in-box.d.ts.map +1 -1
- package/dist/common/emit-bb.d.ts +36 -0
- package/dist/common/emit-bb.d.ts.map +1 -0
- package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts +10 -0
- package/dist/gvc/__fixtures__/subg-renders/subg-renders.d.ts.map +1 -0
- package/dist/gvc/device.d.ts.map +1 -1
- package/dist/gvc/emit-xdot.d.ts +9 -0
- package/dist/gvc/emit-xdot.d.ts.map +1 -1
- package/dist/index.js +7316 -7200
- package/dist/index.js.map +4 -4
- package/dist/layout/dot/decomp.d.ts.map +1 -1
- package/dist/layout/dot/edge-route.d.ts +3 -8
- package/dist/layout/dot/edge-route.d.ts.map +1 -1
- package/dist/layout/dot/init.d.ts +25 -4
- package/dist/layout/dot/init.d.ts.map +1 -1
- package/dist/layout/dot/splines.d.ts +5 -3
- package/dist/layout/dot/splines.d.ts.map +1 -1
- package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
- package/dist/layout/sfdp/spring-electrical.d.ts.map +1 -1
- package/dist/render/dot/agwrite-linelength.d.ts +25 -0
- package/dist/render/dot/agwrite-linelength.d.ts.map +1 -0
- package/dist/render/dot/agwrite.d.ts +4 -7
- package/dist/render/dot/agwrite.d.ts.map +1 -1
- package/dist/render/dot/attrs.d.ts.map +1 -1
- package/dist/render/dot/write-back.d.ts +10 -0
- package/dist/render/dot/write-back.d.ts.map +1 -1
- package/dist/render/dot.d.ts +1 -2
- package/dist/render/dot.d.ts.map +1 -1
- package/dist/render/json-cluster-edge.d.ts +22 -0
- package/dist/render/json-cluster-edge.d.ts.map +1 -0
- package/dist/render/json.d.ts.map +1 -1
- package/dist/render/map.d.ts.map +1 -1
- package/dist/render/svg-graph.d.ts.map +1 -1
- package/dist/render.js +7316 -7200
- package/dist/render.js.map +4 -4
- package/dist/util/printf-round.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/edge-in-box.ts +9 -24
- package/src/common/emit-bb.ts +128 -0
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +45 -0
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +45 -0
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +45 -0
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +74 -0
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +74 -0
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +76 -0
- package/src/gvc/__fixtures__/rerender/nestedclust.gv +4 -0
- package/src/gvc/__fixtures__/rerender/regen.sh +5 -0
- package/src/gvc/__fixtures__/subg-renders/subg-renders.ts +48 -0
- package/src/gvc/device.ts +26 -27
- package/src/gvc/emit-gates.ts +1 -1
- package/src/gvc/emit-xdot.ts +5 -6
- package/src/layout/dot/decomp.ts +23 -2
- package/src/layout/dot/edge-route.ts +8 -37
- package/src/layout/dot/init.ts +36 -11
- package/src/layout/dot/splines-flat.ts +2 -2
- package/src/layout/dot/splines-groups.ts +2 -2
- package/src/layout/dot/splines-route.ts +2 -2
- package/src/layout/dot/splines.ts +8 -8
- package/src/layout/neato/conjgrad.ts +2 -2
- package/src/layout/neato/fdp-adjust.ts +1 -16
- package/src/layout/sfdp/spring-electrical.ts +5 -3
- package/src/render/dot/agwrite-linelength.ts +58 -0
- package/src/render/dot/agwrite.ts +13 -13
- package/src/render/dot/attrs.ts +27 -1
- package/src/render/dot/write-back.ts +21 -0
- package/src/render/dot/xdot-ops.ts +1 -1
- package/src/render/dot.ts +11 -17
- package/src/render/json-cluster-edge.ts +50 -0
- package/src/render/json.ts +16 -19
- package/src/render/map.ts +3 -7
- package/src/render/svg-graph.ts +22 -9
- package/src/render/svg.ts +3 -3
- package/src/util/printf-round.ts +16 -10
- package/dist/layout/dot/edge-order.d.ts +0 -27
- package/dist/layout/dot/edge-order.d.ts.map +0 -1
- package/src/layout/dot/edge-order.ts +0 -62
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
|
|
17
|
+
import { parseDrawingSize, initJobViewportZoom, parseLandscape, parseGraphPad, parseGraphMargin } 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';
|
|
@@ -26,6 +26,7 @@ import type { ShapeDesc, TextlabelT } from '../common/types.js';
|
|
|
26
26
|
import { type LayerInfo, parseLayers } from '../common/layers.js';
|
|
27
27
|
import { RenderJob, EMIT_CLUSTERS_LAST, createObjState, ObjType, EmitState } from './job.js';
|
|
28
28
|
import { walkNodesAndEdges } from './emit-walk.js';
|
|
29
|
+
import { initBb } from '../common/emit-bb.js';
|
|
29
30
|
import { firstLayer, nextLayer, numPhysicalLayers, validLayer } from './first-layer.js';
|
|
30
31
|
import { polyInit } from '../common/poly-init.js';
|
|
31
32
|
import {
|
|
@@ -50,7 +51,7 @@ import {
|
|
|
50
51
|
import { emitRoundedBezier } from '../common/poly-shapes.js';
|
|
51
52
|
import { applyClusterObjState, clusterAttr, clusterStyle, clusterPeripheries, isStripedCluster, renderStripedClusterBox } from './device-cluster.js';
|
|
52
53
|
import { transformPoint } from './device-transform.js';
|
|
53
|
-
import { emitXdot } from './emit-xdot.js';
|
|
54
|
+
import { deviceClip, emitXdot } from './emit-xdot.js';
|
|
54
55
|
import { gvrenderSetStyle, edgeStyleResets } from './gvrender-set-style.js';
|
|
55
56
|
import { renderOneLabel, renderNodeXLabel, renderClusterLabel, reportEdgeLabelColors } from './device-labels.js';
|
|
56
57
|
export { transformPoint, applyRotation, applyScale, buildPoint } from './device-transform.js';
|
|
@@ -413,6 +414,15 @@ function renderPage(g: Graph, renderer: RendererPlugin, job: RenderJob, info: La
|
|
|
413
414
|
// render — top-level convenience
|
|
414
415
|
// ---------------------------------------------------------------------------
|
|
415
416
|
|
|
417
|
+
/** A job for `format` carrying the context's image hooks. */
|
|
418
|
+
function newRenderJob(ctx: GvcContext, format: string, inlineImages: boolean): RenderJob {
|
|
419
|
+
const job = new RenderJob(format, ctx.textMeasurer);
|
|
420
|
+
job.inlineImages = inlineImages;
|
|
421
|
+
if (ctx.imageResolver !== undefined) job.imageResolver = ctx.imageResolver;
|
|
422
|
+
if (ctx.imageSizer !== undefined) job.imageSizer = ctx.imageSizer;
|
|
423
|
+
return job;
|
|
424
|
+
}
|
|
425
|
+
|
|
416
426
|
/**
|
|
417
427
|
* Select renderer, create job, initialise bb from graph, then render.
|
|
418
428
|
*
|
|
@@ -430,38 +440,27 @@ export function render(ctx: GvcContext, g: Graph, format: string, inlineImages =
|
|
|
430
440
|
if (!(ctx instanceof GvcContext)) throw invalidArgType('ctx', 'GvcContext', ctx);
|
|
431
441
|
if (typeof g !== 'object' || g === null) throw invalidArgType('g', 'object', g);
|
|
432
442
|
const renderer = ctx.bestRenderer(format);
|
|
433
|
-
const job =
|
|
434
|
-
|
|
435
|
-
if (ctx.imageResolver !== undefined) job.imageResolver = ctx.imageResolver;
|
|
436
|
-
if (ctx.imageSizer !== undefined) job.imageSizer = ctx.imageSizer;
|
|
443
|
+
const job = newRenderJob(ctx, format, inlineImages);
|
|
444
|
+
initBb(g); // spl->bb for edge_in_box, before init_gvc. @see lib/common/emit.c:4216
|
|
437
445
|
// gvc->bb = GD_bb(g) verbatim -- no recompute fallback. Every layout engine
|
|
438
|
-
// sets g.info.bb itself before render() runs
|
|
439
|
-
//
|
|
440
|
-
//
|
|
441
|
-
//
|
|
442
|
-
// the
|
|
443
|
-
// excluding every node via node_in_box -- do not paper over that with a
|
|
444
|
-
// recompute, it is the mechanism that produces C's near-empty output.
|
|
446
|
+
// sets g.info.bb itself before render() runs; when a layout phase aborts
|
|
447
|
+
// before that point (2825: dot_position fails before set_aspect), C leaves
|
|
448
|
+
// GD_bb at its zero default and the degenerate box propagates into the clip
|
|
449
|
+
// below, excluding every node via node_in_box -- do not paper over that with
|
|
450
|
+
// a recompute, it is the mechanism that produces C's near-empty output.
|
|
445
451
|
// @see lib/common/emit.c:3272 init_gvc (gvc->bb = GD_bb(g))
|
|
446
452
|
job.bb = g.info.bb;
|
|
447
|
-
// init_job_pad:
|
|
448
|
-
//
|
|
449
|
-
// (emit.c:4289-4291) because the fit uses the padded 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).
|
|
450
455
|
// @see lib/common/emit.c:3241-3251 (attr read); :3290-3304 (fallback)
|
|
451
456
|
job.pad = parseGraphPad(g.attrs.get('pad'));
|
|
452
|
-
// init_job_margin
|
|
453
|
-
//
|
|
454
|
-
//
|
|
455
|
-
// read here and consumed later, after Z is known, by emitSvgTag/svgBeginPage
|
|
456
|
-
// (job.width/height and the page group translate), matching C's
|
|
457
|
-
// init_job_margin -> init_job_dpi -> init_job_viewport -> init_job_pagination
|
|
458
|
-
// order where margin is resolved before Z but only used after it.
|
|
457
|
+
// init_job_margin, right after init_job_pad (emit.c:4290-4291). margin does
|
|
458
|
+
// not feed the size= fit (only pad does); emitSvgTag/svgBeginPage use it after
|
|
459
|
+
// Z is known, as C resolves it before init_job_viewport and uses it after.
|
|
459
460
|
// @see lib/common/emit.c:3229-3239 (attr read); :3309-3331 (fallback)
|
|
460
461
|
job.margin = parseGraphMargin(g.attrs.get('margin'));
|
|
461
462
|
// init_job_viewport: fit the drawing into size= via a zoom Z carried by the
|
|
462
|
-
// SVG group transform (D1: parse here, not graph_init).
|
|
463
|
-
//
|
|
464
|
-
// Correction to D3: only the trailing `!` on size= sets the *filled* flag
|
|
463
|
+
// SVG group transform (D1: parse here, not graph_init). Correction to D3: only the trailing `!` on size= sets the *filled* flag
|
|
465
464
|
// that init_job_viewport reads (input.c:694 GD_drawing->filled =
|
|
466
465
|
// getdoubles2ptf). `ratio=fill` instead sets ratio_kind=R_FILL (setRatio),
|
|
467
466
|
// which reshapes the *layout* (out of scope, D3) and does NOT feed
|
|
@@ -479,7 +478,7 @@ export function render(ctx: GvcContext, g: Graph, format: string, inlineImages =
|
|
|
479
478
|
// not job->zoom. job.scale is read only by the SVG group/dims.
|
|
480
479
|
const drawingSize = parseDrawingSize(g.attrs.get('size'));
|
|
481
480
|
const z = initJobViewportZoom(job.bb, drawingSize, job.pad);
|
|
482
|
-
job.clip =
|
|
481
|
+
job.clip = deviceClip(g, renderer, job); // @see emit.c:setup_page (xdot's default pad is 0)
|
|
483
482
|
// init_job_dpi (emit.c:3333): GD_drawing->dpi = late_double(dpi, resolution, 0)
|
|
484
483
|
// (input.c:713). When >0 it becomes job->dpi; otherwise the SVG device's
|
|
485
484
|
// default_dpi = 72 (gvrender_core_svg.c:814) applies. init_job_viewport then
|
package/src/gvc/emit-gates.ts
CHANGED
|
@@ -81,7 +81,7 @@ export function emitNodeComments(n: Node, renderer: RendererPlugin, job: RenderJ
|
|
|
81
81
|
* @see lib/common/emit.c:emit_edge (gvrender_comment x2)
|
|
82
82
|
*/
|
|
83
83
|
export function emitEdgeComments(e: Edge, renderer: RendererPlugin, job: RenderJob): void {
|
|
84
|
-
if (!edgeHasDrawableContent(e, job.
|
|
84
|
+
if (!edgeHasDrawableContent(e, job.clip)) return;
|
|
85
85
|
const kind = e.head.root.kind; // agisdirected(agraphof(aghead(e)))
|
|
86
86
|
const op = kind === 'directed' || kind === 'strict-directed' ? '->' : '--';
|
|
87
87
|
gvrenderComment(renderer, job, e.tail.name + op + e.head.name);
|
package/src/gvc/emit-xdot.ts
CHANGED
|
@@ -30,16 +30,15 @@ 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
|
|
34
|
-
* xdot device's default is 0, so with no
|
|
35
|
-
*
|
|
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
36
|
* @see plugin/core/gvrender_core_dot.c:739 render_features_dot
|
|
37
37
|
* @see lib/common/emit.c:1558
|
|
38
38
|
*/
|
|
39
|
-
function deviceClip(g: Graph, renderer: RendererPlugin, job: RenderJob): Box {
|
|
40
|
-
if (renderer.type === 'svg') return job.clip;
|
|
39
|
+
export function deviceClip(g: Graph, renderer: RendererPlugin, job: RenderJob): Box {
|
|
41
40
|
const attr = g.attrs.get('pad');
|
|
42
|
-
const pad = attr ? parseGraphPad(attr) : { x: 0, y: 0 };
|
|
41
|
+
const pad = renderer.type === 'svg' ? job.pad : attr ? parseGraphPad(attr) : { x: 0, y: 0 };
|
|
43
42
|
const size = parseDrawingSize(g.attrs.get('size'));
|
|
44
43
|
return setupPageClip(job.bb, size, pad, initJobViewportZoom(job.bb, size, pad));
|
|
45
44
|
}
|
package/src/layout/dot/decomp.ts
CHANGED
|
@@ -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
|
-
|
|
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,7 +26,6 @@ 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
30
|
import { ShapeKind, type ShapeDesc } from '../../common/types.js';
|
|
33
31
|
import {
|
|
@@ -138,7 +136,7 @@ export function hasValidCoords(e: GraphEdge): boolean {
|
|
|
138
136
|
}
|
|
139
137
|
|
|
140
138
|
// ---------------------------------------------------------------------------
|
|
141
|
-
// routeOneEdge /
|
|
139
|
+
// routeOneEdge / routeLoneEdge
|
|
142
140
|
// @see lib/dotgen/dotsplines.c:dot_splines_
|
|
143
141
|
// ---------------------------------------------------------------------------
|
|
144
142
|
|
|
@@ -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`).
|
|
235
|
-
*
|
|
236
|
-
*
|
|
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 {
|
|
@@ -453,39 +450,17 @@ function routeForwardEdge(
|
|
|
453
450
|
e.info.headArrowOps = arrowDrawOpsForEnd(e, 'head', result.arrowTip, result.arrowDir, pw);
|
|
454
451
|
}
|
|
455
452
|
|
|
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;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Compute and install edge splines for all unrouted edges in g.
|
|
476
|
-
* @see lib/dotgen/dotsplines.c:dot_splines_
|
|
477
|
-
*/
|
|
478
453
|
/**
|
|
479
454
|
* Route one not-yet-routed edge, applying the `dot_splines_` skip guards. No-op
|
|
480
455
|
* if the edge is already routed or ineligible (FLATORDER/IGNORED, self-loop, or
|
|
481
|
-
* lacking valid coords).
|
|
482
|
-
*
|
|
483
|
-
*
|
|
456
|
+
* lacking valid coords). The `dotSplines_` group loop calls it for the edges it
|
|
457
|
+
* collected from the rank arrays, at their `edgecmp` position, as C does; an
|
|
458
|
+
* edge it did not collect keeps the route it had, as `ED_spl` does in C.
|
|
484
459
|
* @see lib/dotgen/dotsplines.c:dot_splines_ (per-edge dispatch + 295 skip)
|
|
485
460
|
*/
|
|
486
461
|
export function routeLoneEdge(e: GraphEdge, g: Graph): void {
|
|
487
462
|
// A lost edge (routesplines failure, C semantics) is consumed: C routes each
|
|
488
|
-
// edge exactly once, so
|
|
463
|
+
// edge exactly once, so a later group must not re-attempt it.
|
|
489
464
|
if (routedThisPass(e) || e.info.lost === true) return;
|
|
490
465
|
// C dot_splines_ skips FLATORDER/IGNORED edges when building the route list;
|
|
491
466
|
// an IGNORED edge (e.g. a concentrate-merged parallel duplicate) must get no
|
|
@@ -507,7 +482,3 @@ export function routeLoneEdge(e: GraphEdge, g: Graph): void {
|
|
|
507
482
|
if (!hasValidCoords(e)) return;
|
|
508
483
|
routeOneEdge(e, g);
|
|
509
484
|
}
|
|
510
|
-
|
|
511
|
-
export function routeDotEdges(g: Graph): void {
|
|
512
|
-
for (const e of orderedDotEdges(g)) routeLoneEdge(e, g);
|
|
513
|
-
}
|
package/src/layout/dot/init.ts
CHANGED
|
@@ -118,6 +118,28 @@ export function dotInitNode(n: Node): void {
|
|
|
118
118
|
// dotInitEdge
|
|
119
119
|
// ---------------------------------------------------------------------------
|
|
120
120
|
|
|
121
|
+
/**
|
|
122
|
+
* Which of dot_init_edge's attribute symbols are bound. C reads `constraint`,
|
|
123
|
+
* `minlen` and `group` through the globals E_constr, E_minlen and N_group
|
|
124
|
+
* (bound per graph by graph_init). make_flat_adj_edges' setState nulls all
|
|
125
|
+
* three for the aux layout and cleanupCloneGraph restores them, so an aux
|
|
126
|
+
* edge's copied `constraint=false` or `minlen`, and its clones' `group`, are
|
|
127
|
+
* never read: late_int(e, NULL, 1, 0) is 1 and late_string(n, NULL, "") "".
|
|
128
|
+
* @see lib/common/input.c:graph_init (E_constr, E_minlen, N_group)
|
|
129
|
+
* @see lib/dotgen/dotsplines.c:setState, cleanupCloneGraph
|
|
130
|
+
*/
|
|
131
|
+
export interface InitEdgeSyms {
|
|
132
|
+
readonly constr: boolean;
|
|
133
|
+
readonly minlen: boolean;
|
|
134
|
+
readonly group: boolean;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The main graph's symbols, as graph_init binds them. */
|
|
138
|
+
export const DOT_INIT_SYMS: InitEdgeSyms = { constr: true, minlen: true, group: true };
|
|
139
|
+
|
|
140
|
+
/** The flat-adj aux graph's symbols. @see lib/dotgen/dotsplines.c:setState */
|
|
141
|
+
export const AUX_INIT_SYMS: InitEdgeSyms = { constr: false, minlen: false, group: false };
|
|
142
|
+
|
|
121
143
|
/**
|
|
122
144
|
* True when tail and head carry the same non-empty `group` attribute.
|
|
123
145
|
* C compares interned refstr pointers (`tailgroup == headgroup`); cgraph's
|
|
@@ -125,7 +147,8 @@ export function dotInitNode(n: Node): void {
|
|
|
125
147
|
* `tailgroup[0]` guard excludes the shared "" default.
|
|
126
148
|
* @see lib/dotgen/dotinit.c:dot_init_edge (tailgroup/headgroup check)
|
|
127
149
|
*/
|
|
128
|
-
export function sameNonemptyGroup(e: Edge): boolean {
|
|
150
|
+
export function sameNonemptyGroup(e: Edge, syms: InitEdgeSyms = DOT_INIT_SYMS): boolean {
|
|
151
|
+
if (!syms.group) return false;
|
|
129
152
|
const tailgroup = nodeAttr(e.tail, e.tail.root, 'group') ?? '';
|
|
130
153
|
const headgroup = nodeAttr(e.head, e.head.root, 'group') ?? '';
|
|
131
154
|
return tailgroup !== '' && tailgroup === headgroup;
|
|
@@ -146,8 +169,8 @@ function initEdgeConstraint(e: Edge): void {
|
|
|
146
169
|
* Applies the same-group penalty to xpenalty and weight.
|
|
147
170
|
* @see lib/dotgen/dotinit.c:dot_init_edge (tailgroup/headgroup block)
|
|
148
171
|
*/
|
|
149
|
-
function applyGroupPenalty(e: Edge): void {
|
|
150
|
-
if (!sameNonemptyGroup(e)) return;
|
|
172
|
+
function applyGroupPenalty(e: Edge, syms: InitEdgeSyms): void {
|
|
173
|
+
if (!sameNonemptyGroup(e, syms)) return;
|
|
151
174
|
e.info.xpenalty = CL_CROSS;
|
|
152
175
|
e.info.weight = (e.info.weight ?? 1) * 100;
|
|
153
176
|
}
|
|
@@ -168,8 +191,8 @@ function applyNonconstraintZero(e: Edge): void {
|
|
|
168
191
|
*
|
|
169
192
|
* @see lib/dotgen/dotinit.c:dot_init_edge
|
|
170
193
|
*/
|
|
171
|
-
export function dotInitEdge(e: Edge): void {
|
|
172
|
-
initEdgeConstraint(e);
|
|
194
|
+
export function dotInitEdge(e: Edge, syms: InitEdgeSyms = DOT_INIT_SYMS): void {
|
|
195
|
+
if (syms.constr) initEdgeConstraint(e);
|
|
173
196
|
// C: ED_weight(e) = late_int(e, E_weight, 1, 0), the attribute only, on an aux
|
|
174
197
|
// edge too: make_flat_adj_edges writes its 10000 with agxset. The group and
|
|
175
198
|
// nonconstraint adjustments below then apply on top, matching C's order.
|
|
@@ -177,11 +200,11 @@ export function dotInitEdge(e: Edge): void {
|
|
|
177
200
|
e.info.weight = lateInt(e.attrs.get('weight'), 1, 0);
|
|
178
201
|
e.info.count = 1;
|
|
179
202
|
e.info.xpenalty = 1;
|
|
180
|
-
applyGroupPenalty(e);
|
|
203
|
+
applyGroupPenalty(e, syms);
|
|
181
204
|
applyNonconstraintZero(e);
|
|
182
|
-
// late_int semantics: default 1, minimum 0.
|
|
205
|
+
// late_int semantics: default 1, minimum 0; an unbound E_minlen gives 1.
|
|
183
206
|
// @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);
|
|
207
|
+
e.info.minlen = lateInt(syms.minlen ? e.attrs.get('minlen') : undefined, 1, 0);
|
|
185
208
|
// samehead / sametail group ids for shared-port merging. C reads these via
|
|
186
209
|
// agxget(e, E_samehead/E_sametail) in dot_sameports and treats an empty
|
|
187
210
|
// string (id[0] == '\0') as "no group". Without populating these, the ported
|
|
@@ -233,19 +256,21 @@ function clearFastGraphLists(n: Node): void {
|
|
|
233
256
|
|
|
234
257
|
/**
|
|
235
258
|
* Calls commonInitNode (shape-aware, label-driven sizing) then
|
|
236
|
-
* dotInitNode for every node, then dotInitEdge for every edge.
|
|
259
|
+
* dotInitNode for every node, then dotInitEdge for every edge. `syms` stands
|
|
260
|
+
* for the global symbol state C's dot_init_edge reads (AUX_INIT_SYMS inside
|
|
261
|
+
* make_flat_adj_edges).
|
|
237
262
|
*
|
|
238
263
|
* @see lib/dotgen/dotinit.c:dot_init_node_edge
|
|
239
264
|
* @see lib/dotgen/dotinit.c:dot_init_node (common_init_node + gv_nodesize)
|
|
240
265
|
*/
|
|
241
|
-
export function dotInitNodeEdge(g: Graph): void {
|
|
266
|
+
export function dotInitNodeEdge(g: Graph, syms: InitEdgeSyms = DOT_INIT_SYMS): void {
|
|
242
267
|
for (const n of nodesInSeq(g)) {
|
|
243
268
|
commonInitNode(n, g);
|
|
244
269
|
dotInitNode(n);
|
|
245
270
|
}
|
|
246
271
|
const measurer = g.root.info.gvc?.textMeasurer;
|
|
247
272
|
for (const e of g.edges) {
|
|
248
|
-
dotInitEdge(e);
|
|
273
|
+
dotInitEdge(e, syms);
|
|
249
274
|
if (measurer) initEdgeLabels(e, g, measurer);
|
|
250
275
|
}
|
|
251
276
|
}
|
|
@@ -34,7 +34,7 @@ import { getSplineBounds, staleAdjacent } from './edge-route-rank.js';
|
|
|
34
34
|
import { graphRanksep } from './position-aux.js';
|
|
35
35
|
import { Edge as EdgeClass } from '../../model/edge.js';
|
|
36
36
|
import { cloneNode, cloneEdge, cleanupCloneGraph, transformf } from './splines-clone.js';
|
|
37
|
-
import { dotInitNodeEdge } from './init.js';
|
|
37
|
+
import { dotInitNodeEdge, AUX_INIT_SYMS } from './init.js';
|
|
38
38
|
import { gvPostprocess } from '../../common/postproc.js';
|
|
39
39
|
import { newSpline } from '../../common/splines-clip.js';
|
|
40
40
|
import { mapArrowOpPoints } from '../../common/arrows-shapes-util.js';
|
|
@@ -367,7 +367,7 @@ export function makeFlatAdjEdges(g: Graph, edges: Edge[], cnt: number, et: numbe
|
|
|
367
367
|
// C setEdgeType(auxg, et); inlined (index.ts's setEdgeType would be an import cycle).
|
|
368
368
|
// @see lib/dotgen/dotsplines.c:make_flat_adj_edges
|
|
369
369
|
aux.auxg.info.flags = (aux.auxg.info.flags & ~0xf) | (et & 0xf);
|
|
370
|
-
dotInitNodeEdge(aux.auxg);
|
|
370
|
+
dotInitNodeEdge(aux.auxg, AUX_INIT_SYMS);
|
|
371
371
|
dotRank(aux.auxg);
|
|
372
372
|
if (dotMincross(aux.auxg) !== 0) return 1;
|
|
373
373
|
if (dotPosition(aux.auxg) !== 0) return 1;
|
|
@@ -94,8 +94,8 @@ export function dedupByOrig(group: Edge[]): Edge[] {
|
|
|
94
94
|
/**
|
|
95
95
|
* Dispatch one edgecmp group: self-loop → routeSelfEdgeGroup; cross-rank cnt>1 →
|
|
96
96
|
* routeParallelEdgeGroup (Multisep offsets); cross-rank cnt==1 → per-run or
|
|
97
|
-
* whole-chain lone routing in-place (C order); same-rank flat →
|
|
98
|
-
*
|
|
97
|
+
* whole-chain lone routing in-place (C order); same-rank flat → routed in place
|
|
98
|
+
* at its edgecmp position.
|
|
99
99
|
* @see lib/dotgen/dotsplines.c:367-419
|
|
100
100
|
*/
|
|
101
101
|
function dispatchEdgeGroup(g: Graph, group: Edge[], ctx: GroupRouteCtx): void {
|
|
@@ -387,8 +387,8 @@ export function routeParallelEdgeGroup(
|
|
|
387
387
|
}) ?? edges[0]!;
|
|
388
388
|
const base = baseSplineForGroup(g, baseEdge);
|
|
389
389
|
// A lost group base consumes every member: C's dot_splines_ calls
|
|
390
|
-
// make_regular_edge once per group and never re-routes its edges, so
|
|
391
|
-
//
|
|
390
|
+
// make_regular_edge once per group and never re-routes its edges, so no
|
|
391
|
+
// later group may re-attempt (and re-report) them.
|
|
392
392
|
// @see lib/dotgen/dotsplines.c:dot_splines_ (group loop, one call per group)
|
|
393
393
|
if (base === 'lost') {
|
|
394
394
|
for (const e of edges) resolveOrigEdge(e).info.lost = true;
|
|
@@ -19,7 +19,6 @@ import { VIRTUAL, NORMAL, FLATORDER } from './fastgr.js';
|
|
|
19
19
|
import { gvQsort } from '../../util/bsd-qsort.js';
|
|
20
20
|
import { IGNORED, EDGE_LABEL } from './rank.js';
|
|
21
21
|
import { markLowclusters } from './cluster.js';
|
|
22
|
-
import { routeDotEdges } from './edge-route.js';
|
|
23
22
|
import { collectOtherEdges } from './self-loop.js';
|
|
24
23
|
import { beginRoutingPass, staleBezierCount, swapStaleBeziers } from './edge-route-rank.js';
|
|
25
24
|
import { dispatchOrthoEdges } from './ortho-adapter.js';
|
|
@@ -417,9 +416,11 @@ export function collectRankEdges(g: Graph, edges: Edge[]): void {
|
|
|
417
416
|
/**
|
|
418
417
|
* Main spline routing entry point (internal, with normalize flag).
|
|
419
418
|
*
|
|
420
|
-
*
|
|
421
|
-
* spline orientation when normalize=true.
|
|
422
|
-
*
|
|
419
|
+
* Routes the edges collected from the rank arrays, group by group in
|
|
420
|
+
* `edgecmp` order, then normalizes spline orientation when normalize=true. An
|
|
421
|
+
* edge that is not in the rank arrays is not routed and keeps whatever route
|
|
422
|
+
* it already had: a layout with no free between it and the last one appends
|
|
423
|
+
* nothing to such an edge's spline, as `new_spline` is never called for it.
|
|
423
424
|
*
|
|
424
425
|
* @see lib/dotgen/dotsplines.c:dot_splines_
|
|
425
426
|
*/
|
|
@@ -481,12 +482,11 @@ function curvedTop(g: Graph): void {
|
|
|
481
482
|
}
|
|
482
483
|
|
|
483
484
|
/**
|
|
484
|
-
* Post-loop: labels, normalize,
|
|
485
|
+
* Post-loop: labels, normalize, port labels. @see c:422-471
|
|
485
486
|
*/
|
|
486
|
-
function finalizeSplines(g: Graph,
|
|
487
|
+
function finalizeSplines(g: Graph, normalize: boolean): void {
|
|
487
488
|
placeRegularEdgeLabels(g);
|
|
488
489
|
if (normalize) edgeNormalize(g);
|
|
489
|
-
if (et !== EDGETYPE_CURVED) routeDotEdges(g);
|
|
490
490
|
if (normalize) swapStaleBeziers(g);
|
|
491
491
|
placePortLabels(g);
|
|
492
492
|
setState(GVSPLINES); // @see dotsplines.c:477
|
|
@@ -520,7 +520,7 @@ export function dotSplines_(g: Graph, normalize: boolean): number {
|
|
|
520
520
|
if (et === EDGETYPE_LINE) placeRegularEdgeLabels(g);
|
|
521
521
|
const runOrigs = routeEdgeGroups(g, edges, g.info.nodesep ?? 18, et);
|
|
522
522
|
if (normalize) normalizeRunOrigs(runOrigs);
|
|
523
|
-
finalizeSplines(g,
|
|
523
|
+
finalizeSplines(g, normalize);
|
|
524
524
|
return 0;
|
|
525
525
|
}
|
|
526
526
|
|
|
@@ -206,7 +206,7 @@ function cgNextDirection(n: number, w: CgWork, alpha: number, rR: number): numbe
|
|
|
206
206
|
vectorsSubtraction(n, w.r, w.Ap, w.r); // fast computation of r, the residual
|
|
207
207
|
const rRNew = innerProduct(n, w.r, w.r, BLOCK_NONE);
|
|
208
208
|
if (rR === 0) {
|
|
209
|
-
agerrorf('conjugate_gradient: unexpected length 0 vector
|
|
209
|
+
agerrorf('conjugate_gradient: unexpected length 0 vector');
|
|
210
210
|
return null;
|
|
211
211
|
}
|
|
212
212
|
const beta = rRNew / rR;
|
|
@@ -323,7 +323,7 @@ function cgfUpdate(n: number, alpha: number, st: CgfState): number {
|
|
|
323
323
|
vectorsSubtraction(n, st.r, st.Ap, st.r);
|
|
324
324
|
const rrNew = innerProduct(n, st.r, st.r, BLOCK_NONE);
|
|
325
325
|
if (st.rr === 0) {
|
|
326
|
-
agerrorf('conjugate_gradient: unexpected length 0 vector
|
|
326
|
+
agerrorf('conjugate_gradient: unexpected length 0 vector');
|
|
327
327
|
return 1;
|
|
328
328
|
}
|
|
329
329
|
const beta = rrNew / st.rr;
|
|
@@ -32,21 +32,6 @@ import { agwarningf } from '../../common/agerr.js';
|
|
|
32
32
|
/** @see lib/neatogen/adjust.c:DFLT_MARGIN (points) */
|
|
33
33
|
const DFLT_MARGIN = 4;
|
|
34
34
|
|
|
35
|
-
/**
|
|
36
|
-
* getSizes lays `sizes` out Ndim apart (x, y, then zeros); sfdp's getSizes
|
|
37
|
-
* returns the 2-wide layout, so widen it to `ndim`.
|
|
38
|
-
* @see lib/neatogen/adjust.c:getSizes
|
|
39
|
-
*/
|
|
40
|
-
function sizesByNdim(sizes2: number[], ndim: number): number[] {
|
|
41
|
-
if (ndim === 2) return sizes2;
|
|
42
|
-
const sizes = new Array<number>((sizes2.length / 2) * ndim).fill(0);
|
|
43
|
-
for (let i = 0; i < sizes2.length / 2; i++) {
|
|
44
|
-
sizes[i * ndim] = sizes2[i * 2]!;
|
|
45
|
-
sizes[i * ndim + 1] = sizes2[i * 2 + 1]!;
|
|
46
|
-
}
|
|
47
|
-
return sizes;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
35
|
/** @see lib/common/utils.c:mapBool */
|
|
51
36
|
function mapBoolDflt(p: string | undefined, defaultValue: boolean): boolean {
|
|
52
37
|
if (p === undefined || p === '') return defaultValue;
|
|
@@ -102,7 +87,7 @@ export function fdpAdjust(g: Graph, ntry: number): void {
|
|
|
102
87
|
const pad = sep.doAdd
|
|
103
88
|
? { x: sep.x / 72, y: sep.y / 72 }
|
|
104
89
|
: { x: DFLT_MARGIN / 72, y: DFLT_MARGIN / 72 };
|
|
105
|
-
const sizes =
|
|
90
|
+
const sizes = getSizes(g, pad, ndim);
|
|
106
91
|
|
|
107
92
|
for (const n of g.nodes.values()) {
|
|
108
93
|
const i = n.info.id!;
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
* _spring_electrical_embedding), the attractive update to
|
|
10
10
|
* `fnmul`+`fmadd` (the CRK·Δ product is rounded, then fused with
|
|
11
11
|
* dist), and the position update to fmadd. The repulsive pow() is a
|
|
12
|
-
* REAL libm call in the binary (runtime exponent)
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* REAL libm call in the binary (runtime exponent); this port calls
|
|
13
|
+
* `armPow` (src/common/arm-pow.ts). Its last bit can differ from the
|
|
14
|
+
* platform's `pow`, which flips adaptive-cooling branches; that drift is
|
|
15
|
+
* accepted (user decision, PR 119; `.agent-notes/post-16-1-followups-10.md`,
|
|
16
|
+
* "sfdp's drift is the repulsive pow's last bit").
|
|
15
17
|
*
|
|
16
18
|
* The slow (QUAD_TREE_NONE) and fast (QUAD_TREE_FAST/large-HYBRID)
|
|
17
19
|
* embedding variants are unreachable at sfdp defaults and not ported.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* agwrite's `linelength` handling: the root's `linelength` sets C's static
|
|
5
|
+
* `Max_outputline` for the duration of one write, and 128 is restored after.
|
|
6
|
+
*
|
|
7
|
+
* @see lib/cgraph/write.c:agwrite (670-677, 692)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Graph } from '../../model/graph.js';
|
|
11
|
+
|
|
12
|
+
/** Default line-break threshold. @see lib/cgraph/write.c:MAX_OUTPUTLINE */
|
|
13
|
+
export const MAX_OUTPUTLINE = 128;
|
|
14
|
+
|
|
15
|
+
/** Smallest nonzero `linelength` agwrite accepts. @see lib/cgraph/write.c:MIN_OUTPUTLINE */
|
|
16
|
+
export const MIN_OUTPUTLINE = 60;
|
|
17
|
+
|
|
18
|
+
/** C's static `Max_outputline` (write.c): agwrite sets it from the root's
|
|
19
|
+
* `linelength` and restores {@link MAX_OUTPUTLINE} after, so the plain path
|
|
20
|
+
* (direct agstrcanon, no agwrite) observes the default. 0 disables breaking.
|
|
21
|
+
* Single-threaded, set and restored synchronously around one serialize.
|
|
22
|
+
* @see lib/cgraph/write.c:44,676,692 */
|
|
23
|
+
let maxOutputlineValue = MAX_OUTPUTLINE;
|
|
24
|
+
|
|
25
|
+
/** `Max_outputline`, as `_write_canonstr` reads it. @see lib/cgraph/write.c:_write_canonstr */
|
|
26
|
+
export function maxOutputline(): number { return maxOutputlineValue; }
|
|
27
|
+
|
|
28
|
+
/** Set `Max_outputline`. @see lib/cgraph/write.c:agwrite */
|
|
29
|
+
function setMaxOutputline(n: number): void { maxOutputlineValue = n; }
|
|
30
|
+
|
|
31
|
+
/** `INT_MAX`, the upper bound agwrite accepts for `linelength`. */
|
|
32
|
+
const INT_MAX = 2147483647;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The `Max_outputline` agwrite would set for `s` (the root's `linelength`), or
|
|
36
|
+
* `undefined` when C leaves it unchanged: C needs a leading digit, then
|
|
37
|
+
* `strtoul` (which stops at the first non-digit), and accepts 0 or
|
|
38
|
+
* ≥ MIN_OUTPUTLINE up to INT_MAX.
|
|
39
|
+
* @see lib/cgraph/write.c:agwrite (670-677)
|
|
40
|
+
*/
|
|
41
|
+
export function linelengthOf(s: string | undefined): number | undefined {
|
|
42
|
+
if (s === undefined || !/^[0-9]/.test(s)) return undefined;
|
|
43
|
+
const len = Number(/^[0-9]+/.exec(s)![0]);
|
|
44
|
+
if ((len === 0 || len >= MIN_OUTPUTLINE) && len <= INT_MAX) return len;
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Run `write` with `Max_outputline` set from `g`'s `linelength`, restoring 128
|
|
49
|
+
* after. @see lib/cgraph/write.c:agwrite */
|
|
50
|
+
export function withLinelength(g: Graph, write: () => string): string {
|
|
51
|
+
const len = linelengthOf(g.attrs.get('linelength'));
|
|
52
|
+
if (len !== undefined) setMaxOutputline(len);
|
|
53
|
+
try {
|
|
54
|
+
return write();
|
|
55
|
+
} finally {
|
|
56
|
+
setMaxOutputline(MAX_OUTPUTLINE);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -20,13 +20,14 @@ import type { Edge } from '../../model/edge.js';
|
|
|
20
20
|
import type { TextlabelT, FieldT, ShapeDesc } from '../../common/types.js';
|
|
21
21
|
import { agstrcanon, agstrcanonText } from '../map.js';
|
|
22
22
|
import { isHtmlValue } from '../../common/html-string.js';
|
|
23
|
-
import { XDOT_VERSION,
|
|
23
|
+
import { XDOT_VERSION, gfmt5, lpStr, xdotId } from './xdot-ops.js';
|
|
24
24
|
import {
|
|
25
25
|
COMPUTED_EDGE_ATTRS, COMPUTED_NODE_ATTRS, appendRecordRects, computedPart, dictParts,
|
|
26
26
|
echoAttr, echoGraphAttr, edgeAttrsAttached, edgeConnector, edgePosRaw,
|
|
27
27
|
effectiveEdgeDefaults, effectiveNodeDefaults, graphInputParts, graphLabelAttrs,
|
|
28
28
|
isDirected, nodeDictParts, nodePosRaw, nodeRecord, objInputParts,
|
|
29
29
|
} from './attrs.js';
|
|
30
|
+
import { withLinelength } from './agwrite-linelength.js';
|
|
30
31
|
import { nodesInSeq } from '../../layout/dot/decomp.js';
|
|
31
32
|
import type { XdotDraws, SerCtx } from './types.js';
|
|
32
33
|
|
|
@@ -40,16 +41,13 @@ export abstract class DotWriterBase {
|
|
|
40
41
|
protected abstract drawsOf(obj: Node | Edge | Graph): XdotDraws | undefined;
|
|
41
42
|
|
|
42
43
|
/**
|
|
43
|
-
* Emit `key
|
|
44
|
-
* `"` becomes `\"` unless
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* double-escaped). The byte-length prefix stays on the UNescaped text (the
|
|
48
|
-
* parser un-escapes before parseXDot re-reads it), matching native exactly.
|
|
49
|
-
* @see lib/cgraph/write.c:_agstrcanon (135-167)
|
|
44
|
+
* Emit `key=<canon value>` through `_agstrcanon`, as `agwrite` does for the xdot
|
|
45
|
+
* op attributes: `"` becomes `\"` unless part of an escape, and long strings
|
|
46
|
+
* wrap at Max_outputline. The byte-length prefix stays on the UNescaped text.
|
|
47
|
+
* @see lib/cgraph/write.c:_agstrcanon
|
|
50
48
|
*/
|
|
51
49
|
private drawAttr(key: string, value: string): string {
|
|
52
|
-
return key + '=
|
|
50
|
+
return key + '=' + agstrcanonText(value);
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
/** `llx,lly,urx,ury` from a graph's layout bb. */
|
|
@@ -79,10 +77,12 @@ export abstract class DotWriterBase {
|
|
|
79
77
|
level: 0,
|
|
80
78
|
};
|
|
81
79
|
this.subgdfs(g, 1, ctx.preorder);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
return withLinelength(g, () => {
|
|
81
|
+
this.writeHdr(g, true, ctx);
|
|
82
|
+
this.writeBody(g, ctx);
|
|
83
|
+
this.writeTrl(ctx);
|
|
84
|
+
return ctx.out.join('');
|
|
85
|
+
});
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
/** Preorder-number the subgraph tree. @see write.c:subgdfs */
|