@knowvah/dot-engine 2.12.2 → 2.12.3
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/compass-port.d.ts.map +1 -1
- package/dist/common/graph-init.d.ts.map +1 -1
- package/dist/common/htmltable-label.d.ts.map +1 -1
- package/dist/common/htmltable-lex.d.ts +3 -1
- package/dist/common/htmltable-lex.d.ts.map +1 -1
- package/dist/common/htmltable-parse-image.d.ts +23 -0
- package/dist/common/htmltable-parse-image.d.ts.map +1 -0
- package/dist/common/htmltable-parse-state.d.ts +4 -0
- package/dist/common/htmltable-parse-state.d.ts.map +1 -1
- package/dist/common/htmltable-parse.d.ts +33 -2
- package/dist/common/htmltable-parse.d.ts.map +1 -1
- package/dist/common/poly-inside.d.ts.map +1 -1
- package/dist/common/splines-geom.d.ts +2 -1
- package/dist/common/splines-geom.d.ts.map +1 -1
- package/dist/common/splines-routespl.d.ts +3 -0
- package/dist/common/splines-routespl.d.ts.map +1 -1
- package/dist/index.js +21301 -21229
- package/dist/index.js.map +4 -4
- package/dist/layout/dot/classify.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
- package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
- package/dist/layout/dot/edge-route-chain.d.ts +20 -16
- package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
- package/dist/layout/dot/flat.d.ts +22 -7
- package/dist/layout/dot/flat.d.ts.map +1 -1
- package/dist/layout/dot/mincross-flat.d.ts +10 -1
- package/dist/layout/dot/mincross-flat.d.ts.map +1 -1
- package/dist/layout/dot/mincross.d.ts +6 -1
- package/dist/layout/dot/mincross.d.ts.map +1 -1
- package/dist/layout/dot/ns-subtree.d.ts +9 -6
- package/dist/layout/dot/ns-subtree.d.ts.map +1 -1
- package/dist/layout/dot/pack-components.d.ts +4 -3
- package/dist/layout/dot/pack-components.d.ts.map +1 -1
- package/dist/layout/dot/position-aux.d.ts +62 -20
- package/dist/layout/dot/position-aux.d.ts.map +1 -1
- package/dist/layout/dot/position-bbox.d.ts.map +1 -1
- package/dist/layout/dot/position-ycoords.d.ts.map +1 -1
- package/dist/layout/dot/position.d.ts.map +1 -1
- package/dist/layout/dot/rank-dot2.d.ts +7 -25
- package/dist/layout/dot/rank-dot2.d.ts.map +1 -1
- package/dist/layout/dot/self-loop.d.ts +11 -4
- package/dist/layout/dot/self-loop.d.ts.map +1 -1
- package/dist/layout/dot/splines-flat-multi.d.ts +11 -3
- package/dist/layout/dot/splines-flat-multi.d.ts.map +1 -1
- package/dist/layout/dot/splines-route.d.ts +6 -3
- package/dist/layout/dot/splines-route.d.ts.map +1 -1
- package/dist/layout/dot/straight-edges.d.ts.map +1 -1
- package/dist/layout/fdp/tlayout.d.ts +3 -0
- package/dist/layout/fdp/tlayout.d.ts.map +1 -1
- package/dist/layout/neato/__fixtures__/hier-imds.d.ts +5 -4
- package/dist/layout/neato/__fixtures__/hier-imds.d.ts.map +1 -1
- package/dist/layout/neato/__fixtures__/hier-majorization.d.ts +6 -5
- package/dist/layout/neato/__fixtures__/hier-majorization.d.ts.map +1 -1
- package/dist/layout/neato/conjgrad.d.ts +7 -6
- package/dist/layout/neato/conjgrad.d.ts.map +1 -1
- package/dist/layout/neato/matrix-ops-dense.d.ts +1 -6
- package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -1
- package/dist/layout/neato/matrix-ops.d.ts +0 -6
- package/dist/layout/neato/matrix-ops.d.ts.map +1 -1
- package/dist/layout/neato/quad-prog-vpsc.d.ts.map +1 -1
- package/dist/model/rankEntry.d.ts +3 -1
- package/dist/model/rankEntry.d.ts.map +1 -1
- package/dist/ortho/index.d.ts +0 -1
- package/dist/ortho/index.d.ts.map +1 -1
- package/dist/ortho/partition.d.ts +2 -4
- package/dist/ortho/partition.d.ts.map +1 -1
- package/dist/pathplan/route.d.ts +93 -0
- package/dist/pathplan/route.d.ts.map +1 -1
- package/dist/render/dot/agwrite.d.ts +21 -9
- package/dist/render/dot/agwrite.d.ts.map +1 -1
- package/dist/render/dot/types.d.ts +7 -2
- package/dist/render/dot/types.d.ts.map +1 -1
- package/dist/render.js +21301 -21229
- package/dist/render.js.map +4 -4
- package/dist/util/overflow.d.ts +37 -0
- package/dist/util/overflow.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/common/compass-port.ts +36 -20
- package/src/common/graph-init.ts +11 -1
- package/src/common/htmltable-label.ts +9 -4
- package/src/common/htmltable-lex.ts +5 -2
- package/src/common/htmltable-parse-image.ts +69 -0
- package/src/common/htmltable-parse-state.ts +6 -0
- package/src/common/htmltable-parse.ts +34 -44
- package/src/common/poly-inside.ts +11 -5
- package/src/common/splines-geom.ts +24 -6
- package/src/common/splines-routespl.ts +32 -0
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
- package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
- package/src/layout/dot/classify.ts +5 -2
- package/src/layout/dot/edge-route-chain-views.ts +120 -0
- package/src/layout/dot/edge-route-chain.ts +103 -117
- package/src/layout/dot/edge-route-faithful.ts +20 -5
- package/src/layout/dot/flat.ts +38 -17
- package/src/layout/dot/mincross-flat.ts +15 -5
- package/src/layout/dot/mincross.ts +6 -2
- package/src/layout/dot/ns-subtree.ts +11 -7
- package/src/layout/dot/pack-components.ts +6 -4
- package/src/layout/dot/position-aux.ts +112 -39
- package/src/layout/dot/position-bbox.ts +14 -1
- package/src/layout/dot/position-ycoords.ts +7 -1
- package/src/layout/dot/position.ts +4 -1
- package/src/layout/dot/rank-dot2.ts +13 -94
- package/src/layout/dot/self-loop.ts +29 -11
- package/src/layout/dot/splines-flat-multi.ts +12 -4
- package/src/layout/dot/splines-route.ts +10 -11
- package/src/layout/dot/straight-edges.ts +5 -3
- package/src/layout/fdp/tlayout.ts +6 -5
- package/src/layout/neato/__fixtures__/conjgrad-d.json +1 -0
- package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +141 -141
- package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +339 -339
- package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +140 -140
- package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +323 -323
- package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +141 -141
- package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +339 -339
- package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +251 -251
- package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +535 -535
- package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +32 -32
- package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +8 -8
- package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +17 -17
- package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +35 -35
- package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +2 -2
- package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +2 -2
- package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +11 -11
- package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +21 -21
- package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +14 -14
- package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +26 -26
- package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +13 -13
- package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +30 -30
- package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +10 -10
- package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +19 -19
- package/src/layout/neato/__fixtures__/dim/smart-units.json +1 -1
- package/src/layout/neato/__fixtures__/hier/cases/dirnone.plain +10 -10
- package/src/layout/neato/__fixtures__/hier/cases/tdist.plain +12 -12
- package/src/layout/neato/__fixtures__/hier/hier-probe.plain +1 -1
- package/src/layout/neato/__fixtures__/hier/hier-probe.xdot +19 -19
- package/src/layout/neato/__fixtures__/hier-imds.ts +14 -13
- package/src/layout/neato/__fixtures__/hier-majorization.ts +24 -23
- package/src/layout/neato/__fixtures__/ipsep/ipsep-grid.xdot +20 -20
- package/src/layout/neato/__fixtures__/ipsep/ipsep-k6.xdot +8 -8
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand-len.xdot +34 -34
- package/src/layout/neato/__fixtures__/ipsep/ipsep-rand.xdot +32 -32
- package/src/layout/neato/__fixtures__/ipsep/ipsep-tree.xdot +18 -18
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep-len.xdot +13 -13
- package/src/layout/neato/__fixtures__/ipsep/kd-ipsep.xdot +12 -12
- package/src/layout/neato/__fixtures__/models/hier-circuit.xdot +33 -33
- package/src/layout/neato/__fixtures__/models/hier-default.xdot +30 -30
- package/src/layout/neato/__fixtures__/models/hier-mds-nolen.xdot +30 -30
- package/src/layout/neato/__fixtures__/models/hier-pin-disc-circuit.xdot +35 -35
- package/src/layout/neato/__fixtures__/models/hier-shortpath.xdot +30 -30
- package/src/layout/neato/conjgrad.ts +38 -35
- package/src/layout/neato/matrix-ops-dense.ts +2 -20
- package/src/layout/neato/matrix-ops.ts +0 -20
- package/src/layout/neato/quad-prog-vpsc.ts +7 -5
- package/src/layout/neato/smart-ini-x.ts +15 -15
- package/src/layout/neato/stress-subspace.ts +5 -5
- package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/dim3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +6 -6
- package/src/layout/sfdp/__fixtures__/dim/regen.sh +2 -0
- package/src/model/rankEntry.ts +3 -1
- package/src/ortho/index.ts +0 -1
- package/src/ortho/partition.ts +10 -22
- package/src/pathplan/route.ts +14 -4
- package/src/render/dot/agwrite.ts +35 -15
- package/src/render/dot/types.ts +7 -2
- package/src/util/overflow.ts +74 -0
|
@@ -150,15 +150,25 @@ export function postorder(g: Graph, v: Node, list: Node[], r: number): void {
|
|
|
150
150
|
list.push(v);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Builds the reverse topological sort order of one rank in `temprank` and
|
|
155
|
+
* returns C's `valid_rank`: false as soon as the walk meets a node that is
|
|
156
|
+
* neither free of constraining flat edges nor an unmarked source (C's
|
|
157
|
+
* `break`), which tells the caller to leave the rank as mincross ordered it.
|
|
158
|
+
* Graphviz 16.1.1, upstream 9fb21f570.
|
|
159
|
+
*
|
|
160
|
+
* @see lib/dotgen/mincross.c:flat_reorder
|
|
161
|
+
*/
|
|
162
|
+
export function flatReorderBuildTemprank(g: Graph, rk: RankEntry, temprank: Node[], flip: boolean): boolean {
|
|
155
163
|
for (let i = 0; i < rk.n; i++) {
|
|
156
164
|
const v = flip ? rankGet(rk, i) : rankGet(rk, rk.n - i - 1);
|
|
157
165
|
const inCnt = v.info.flat_in !== undefined ? countConstraining(g, v.info.flat_in) : 0;
|
|
158
166
|
const outCnt = v.info.flat_out !== undefined ? countConstraining(g, v.info.flat_out) : 0;
|
|
159
167
|
if (inCnt === 0 && outCnt === 0) { temprank.push(v); continue; }
|
|
160
|
-
if (!v.info.mark && inCnt === 0) postorder(g, v, temprank, v.info.rank !== undefined ? v.info.rank! : 0);
|
|
168
|
+
if (!v.info.mark && inCnt === 0) { postorder(g, v, temprank, v.info.rank !== undefined ? v.info.rank! : 0); continue; }
|
|
169
|
+
return false;
|
|
161
170
|
}
|
|
171
|
+
return true;
|
|
162
172
|
}
|
|
163
173
|
|
|
164
174
|
export function flatReorderFixEdges(g: Graph, rk: RankEntry, flip: boolean): void {
|
|
@@ -188,8 +198,8 @@ export function flatReorderRank(g: Graph, rk: RankEntry, rootRank: RankEntry[],
|
|
|
188
198
|
const baseOrder = rankGet(rk, 0).info.order !== undefined ? rankGet(rk, 0).info.order! : 0;
|
|
189
199
|
for (let i = 0; i < rk.n; i++) rankGet(rk, i).info.mark = 0;
|
|
190
200
|
const temprank: Node[] = [];
|
|
191
|
-
flatReorderBuildTemprank(g, rk, temprank, flip);
|
|
192
|
-
if (temprank.length > 0) {
|
|
201
|
+
const validRank = flatReorderBuildTemprank(g, rk, temprank, flip);
|
|
202
|
+
if (validRank && temprank.length > 0) {
|
|
193
203
|
if (!flip) temprank.reverse();
|
|
194
204
|
for (let i = 0; i < rk.n; i++) {
|
|
195
205
|
rankSet(rk, i, temprank[i]!);
|
|
@@ -237,7 +237,12 @@ export function cleanup2(ctx: MincrossContext, g: Graph): void {
|
|
|
237
237
|
cleanup2Ranks(g);
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
/**
|
|
240
|
+
/**
|
|
241
|
+
* `rank[r].flat` is left set: C's `free_matrix(GD_rank(g)[r].flat)` frees the
|
|
242
|
+
* matrix without nulling the field (mincross.c:415-420), and flat_edges then
|
|
243
|
+
* reads `GD_rank(g)[0].flat` as a flag (flat.c:274, `needsAbomination`).
|
|
244
|
+
* @see lib/dotgen/mincross.c:cleanup2 (rank loop; 16.1.1 853-865)
|
|
245
|
+
*/
|
|
241
246
|
export function cleanup2Ranks(g: Graph): void {
|
|
242
247
|
const rank = g.info.rank;
|
|
243
248
|
if (!rank) return;
|
|
@@ -248,7 +253,6 @@ export function cleanup2Ranks(g: Graph): void {
|
|
|
248
253
|
rank[r].v[i].info.order = i;
|
|
249
254
|
removeFlatorderEdges(rank[r].v[i]);
|
|
250
255
|
}
|
|
251
|
-
rank[r].flat = undefined;
|
|
252
256
|
}
|
|
253
257
|
}
|
|
254
258
|
|
|
@@ -5,6 +5,7 @@ import type { Edge } from '../../model/edge.js';
|
|
|
5
5
|
import { addTreeEdge, isTreeEdge, nsSlack } from './ns-core.js';
|
|
6
6
|
import type { NsCtx } from './ns-core.js';
|
|
7
7
|
import { initCutvalues } from './ns-range.js';
|
|
8
|
+
import { saddSaturate } from '../../util/overflow.js';
|
|
8
9
|
|
|
9
10
|
// ---------------------------------------------------------------------------
|
|
10
11
|
// Types
|
|
@@ -262,19 +263,22 @@ export function stExtractMin(heap: STheap): Subtree {
|
|
|
262
263
|
|
|
263
264
|
/**
|
|
264
265
|
* Add `delta` to ND_rank of every node in the tight tree reachable from `v`
|
|
265
|
-
* (the parent back-edge to `from` excluded)
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
266
|
+
* (the parent back-edge to `from` excluded), clamping each sum to
|
|
267
|
+
* [INT_MIN, INT_MAX] as C's `sadd_saturate` does (graphviz 16.1.1, upstream
|
|
268
|
+
* issue 2758). C's `tree_adjust` is a DFS; the tight tree is acyclic, so each
|
|
269
|
+
* node is visited exactly once and the mutation
|
|
270
|
+
* (`rank = sadd_saturate(rank, delta)`) depends only on the node's own rank,
|
|
271
|
+
* which makes it order-independent. Ported with an explicit stack instead of
|
|
272
|
+
* recursion: deep trees (e.g. corpus 2646, a 7-deep quadtree with thousands of
|
|
273
|
+
* nodes) overflow the JS call stack where C's larger native stack does not.
|
|
274
|
+
* Outcome is identical to the recursive form.
|
|
271
275
|
* @see lib/common/ns.c:tree_adjust
|
|
272
276
|
*/
|
|
273
277
|
export function treeAdjust(v: Node, from: Node | undefined, delta: number): void {
|
|
274
278
|
const stack: Array<[Node, Node | undefined]> = [[v, from]];
|
|
275
279
|
while (stack.length > 0) {
|
|
276
280
|
const [n, f] = stack.pop()!;
|
|
277
|
-
n.info.rank = (n.info.rank ?? 0
|
|
281
|
+
n.info.rank = saddSaturate(n.info.rank ?? 0, delta);
|
|
278
282
|
const ti = n.info.tree_in;
|
|
279
283
|
if (ti) for (let i = 0; i < ti.size; i++) {
|
|
280
284
|
const w = ti.list[i].tail;
|
|
@@ -216,9 +216,10 @@ export function initSubg(sg: Graph, root: Graph): void {
|
|
|
216
216
|
* ranking reads them. Node sizing in `dotPhaseInit` reads `sg.root.info.flip`
|
|
217
217
|
* (the real root), so it is correct regardless of this ordering.
|
|
218
218
|
*
|
|
219
|
-
* Returns the component's
|
|
220
|
-
*
|
|
221
|
-
*
|
|
219
|
+
* Returns the component's dot_position status when it is non-zero (16.1.1: an
|
|
220
|
+
* aux edge longer than INT_MAX, issue #162), else its dot_splines status. A
|
|
221
|
+
* non-zero status is C's dotLayout(sg) failing, which makes doDot return
|
|
222
|
+
* before packing. The mincross status is not consulted on this arm (#235).
|
|
222
223
|
* @see lib/dotgen/dotinit.c:dotLayout (static)
|
|
223
224
|
*/
|
|
224
225
|
export function dotLayoutComponent(sg: Graph, root: Graph): number {
|
|
@@ -248,7 +249,8 @@ export function dotLayoutComponent(sg: Graph, root: Graph): number {
|
|
|
248
249
|
sg.info.has_labels = 0;
|
|
249
250
|
dotRank(sg);
|
|
250
251
|
dotMincross(sg);
|
|
251
|
-
dotPosition(sg);
|
|
252
|
+
const posRc = dotPosition(sg);
|
|
253
|
+
if (posRc !== 0) return posRc;
|
|
252
254
|
return dotPhasePostNoFinish(sg);
|
|
253
255
|
}
|
|
254
256
|
|
|
@@ -15,10 +15,15 @@ import { SLACKNODE, EDGE_LABEL } from './rank.js';
|
|
|
15
15
|
import { selfRightSpace } from '../../common/splines-selfedge.js';
|
|
16
16
|
import { lateInt } from '../../common/nodeinit.js';
|
|
17
17
|
import { cround } from '../../common/arith.js';
|
|
18
|
+
import { agerrorf } from '../../common/agerr.js';
|
|
19
|
+
import { printfFixed } from '../../util/printf-round.js';
|
|
18
20
|
|
|
19
21
|
/** @see lib/common/const.h:CL_OFFSET */
|
|
20
22
|
export const CL_OFFSET = 8;
|
|
21
23
|
|
|
24
|
+
/** C `INT_MAX`: the longest aux edge `make_aux_edge` accepts. */
|
|
25
|
+
const INT_MAX = 2147483647;
|
|
26
|
+
|
|
22
27
|
/**
|
|
23
28
|
* Cluster margin = `late_int(g, G_margin, CL_OFFSET, 0)`. The `margin` attribute
|
|
24
29
|
* is resolved up the subgraph chain (matching `agxget` inheritance), so a
|
|
@@ -104,12 +109,27 @@ export function graphRanksep(g: Graph): number { return g.info.ranksep ?? 0; }
|
|
|
104
109
|
* Agedgeinfo_t it allocates here and never writes them. Its attributes are the
|
|
105
110
|
* shared empty map: C binds no attribute record to an aux edge, only the
|
|
106
111
|
* Agedgeinfo_t (issue #145).
|
|
112
|
+
*
|
|
113
|
+
* A length above INT_MAX is refused: the error prints and the result is null,
|
|
114
|
+
* with no edge linked into the fast lists (graphviz 16.1.1, upstream
|
|
115
|
+
* f86899fcc; 16.1.0 clamped the length). make_LR_constraints and
|
|
116
|
+
* make_edge_pairs test the result and fail the layout; every other caller
|
|
117
|
+
* ignores it, as C does, and simply has no edge there. The `%f` is
|
|
118
|
+
* `printfFixed`: `toFixed` goes exponential at 1e21, and corpus 2781's length
|
|
119
|
+
* is 7.2e25.
|
|
107
120
|
* @see lib/dotgen/position.c:make_aux_edge
|
|
108
121
|
*/
|
|
109
|
-
export function makeAuxEdge(u: Node, v: Node, len: number, wt: number): Edge {
|
|
122
|
+
export function makeAuxEdge(u: Node, v: Node, len: number, wt: number): Edge | null {
|
|
123
|
+
if (len > INT_MAX) {
|
|
124
|
+
agerrorf(
|
|
125
|
+
`Edge length ${printfFixed(len, 6)} larger than maximum ${INT_MAX} allowed.\n`
|
|
126
|
+
+ 'Check for overwide node(s).',
|
|
127
|
+
);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
110
130
|
const e = new EdgeClass(u, v, '', true, true);
|
|
111
131
|
// C ROUND() is half away from zero. @see lib/dotgen/position.c:195
|
|
112
|
-
e.info.minlen = cround(
|
|
132
|
+
e.info.minlen = cround(len);
|
|
113
133
|
e.info.weight = wt;
|
|
114
134
|
fastEdge(e);
|
|
115
135
|
return e;
|
|
@@ -154,8 +174,11 @@ export function lrSep(g: Graph, rankIdx: number): number {
|
|
|
154
174
|
return (rankIdx + (g.info.abomShift ?? 0)) & 1 ? 5 : nodesep;
|
|
155
175
|
}
|
|
156
176
|
|
|
157
|
-
/**
|
|
158
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Returns -1 when the aux edge is refused (16.1.1, upstream e62e35be5), else 0.
|
|
179
|
+
* @see lib/dotgen/position.c:make_LR_constraints (single flat-edge constraint)
|
|
180
|
+
*/
|
|
181
|
+
export function processFlatEdge(g: Graph, u: Node, e: Edge): number {
|
|
159
182
|
const nodesep = graphNodesep(g);
|
|
160
183
|
const isOrdered = nodeOrder(u) < nodeOrder(e.head);
|
|
161
184
|
const t0 = isOrdered ? e.tail : e.head;
|
|
@@ -175,44 +198,61 @@ export function processFlatEdge(g: Graph, u: Node, e: Edge): void {
|
|
|
175
198
|
ex.info.minlen = Math.max(ex.info.minlen ?? 1, m0);
|
|
176
199
|
ex.info.weight = Math.max(ex.info.weight ?? 0, edgeWeight(e));
|
|
177
200
|
} else if (!e.info.label) {
|
|
178
|
-
makeAuxEdge(t0, h0, m0, edgeWeight(e));
|
|
201
|
+
if (makeAuxEdge(t0, h0, m0, edgeWeight(e)) === null) return -1;
|
|
179
202
|
}
|
|
203
|
+
return 0;
|
|
180
204
|
}
|
|
181
205
|
|
|
182
|
-
/**
|
|
183
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Returns -1 at the first refused aux edge, else 0.
|
|
208
|
+
* @see lib/dotgen/position.c:make_LR_constraints (flat-edge endpoint loop)
|
|
209
|
+
*/
|
|
210
|
+
export function makeFlatEdgeConstraints(g: Graph, u: Node): number {
|
|
184
211
|
const flatOut = u.info.flat_out;
|
|
185
|
-
if (!flatOut) return;
|
|
212
|
+
if (!flatOut) return 0;
|
|
186
213
|
for (let k = 0; k < flatOut.size; k++) {
|
|
187
|
-
processFlatEdge(g, u, flatOut.list[k]);
|
|
214
|
+
if (processFlatEdge(g, u, flatOut.list[k]) !== 0) return -1;
|
|
188
215
|
}
|
|
216
|
+
return 0;
|
|
189
217
|
}
|
|
190
218
|
|
|
191
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Returns -1 when either aux edge is refused (16.1.1, upstream e62e35be5); the
|
|
221
|
+
* second is not tried after the first fails. Else 0.
|
|
222
|
+
* @see lib/dotgen/position.c:make_LR_constraints (flat-label constraint body)
|
|
223
|
+
*/
|
|
192
224
|
export function applyFlatLabel(
|
|
193
225
|
g: Graph,
|
|
194
226
|
e: Edge,
|
|
195
227
|
e0raw: Edge,
|
|
196
228
|
e1raw: Edge,
|
|
197
|
-
):
|
|
229
|
+
): number {
|
|
198
230
|
const nodesep = graphNodesep(g);
|
|
199
231
|
const e0 = nodeOrder(e0raw.head) <= nodeOrder(e1raw.head) ? e0raw : e1raw;
|
|
200
232
|
const e1 = e0 === e0raw ? e1raw : e0raw;
|
|
201
233
|
// C: int m0 (position.c:222,276), so the half truncates
|
|
202
234
|
const m0 = Math.trunc(edgeMinlen(e) * nodesep / 2);
|
|
203
235
|
const m1a = m0 + nodeRw(e0.head) + nodeLw(e0.tail);
|
|
204
|
-
if (!canReach(e0.tail, e0.head))
|
|
236
|
+
if (!canReach(e0.tail, e0.head)) {
|
|
237
|
+
if (makeAuxEdge(e0.head, e0.tail, m1a, edgeWeight(e)) === null) return -1;
|
|
238
|
+
}
|
|
205
239
|
const m1b = m0 + nodeRw(e1.tail) + nodeLw(e1.head);
|
|
206
|
-
if (!canReach(e1.head, e1.tail))
|
|
240
|
+
if (!canReach(e1.head, e1.tail)) {
|
|
241
|
+
if (makeAuxEdge(e1.tail, e1.head, m1b, edgeWeight(e)) === null) return -1;
|
|
242
|
+
}
|
|
243
|
+
return 0;
|
|
207
244
|
}
|
|
208
245
|
|
|
209
|
-
/**
|
|
210
|
-
|
|
246
|
+
/**
|
|
247
|
+
* Returns -1 when a label aux edge is refused, else 0.
|
|
248
|
+
* @see lib/dotgen/position.c:make_LR_constraints (flat-label constraints via ND_alg)
|
|
249
|
+
*/
|
|
250
|
+
export function makeFlatLabelConstraints(g: Graph, u: Node): number {
|
|
211
251
|
const e = u.info.posAlg;
|
|
212
|
-
if (!e) return;
|
|
252
|
+
if (!e) return 0;
|
|
213
253
|
const so = u.info.save_out;
|
|
214
|
-
if (!so || so.size < 2) return;
|
|
215
|
-
applyFlatLabel(g, e, so.list[0], so.list[1]);
|
|
254
|
+
if (!so || so.size < 2) return 0;
|
|
255
|
+
return applyFlatLabel(g, e, so.list[0], so.list[1]);
|
|
216
256
|
}
|
|
217
257
|
|
|
218
258
|
/** @see lib/dotgen/position.c:go */
|
|
@@ -243,11 +283,16 @@ export function selfWidth(u: Node): number {
|
|
|
243
283
|
return sw;
|
|
244
284
|
}
|
|
245
285
|
|
|
246
|
-
/**
|
|
247
|
-
|
|
286
|
+
/**
|
|
287
|
+
* Returns the next `last`, or null when the adjacent-pair aux edge is refused
|
|
288
|
+
* (16.1.1, upstream e62e35be5, 92ef8d508). C tests the edge before the
|
|
289
|
+
* `ND_rank(v)` assignment, so `v`'s rank is not written on failure.
|
|
290
|
+
* @see lib/dotgen/position.c:make_LR_constraints (per-rank inner loop, one node pair)
|
|
291
|
+
*/
|
|
292
|
+
export function lrRankPair(g: Graph, r: number, u: Node, v: Node, last: number): number | null {
|
|
248
293
|
const nodesep = lrSep(g, r);
|
|
249
294
|
const width = nodeRw(u) + nodeLw(v) + nodesep;
|
|
250
|
-
makeAuxEdge(u, v, width, 0);
|
|
295
|
+
if (makeAuxEdge(u, v, width, 0) === null) return null;
|
|
251
296
|
/* C: `last = (ND_rank(v) = last + width)`. ND_rank is an int, so the
|
|
252
297
|
* double `last + width` truncates toward zero on assignment, and the
|
|
253
298
|
* truncated *integer* flows back into `last` — positions accumulate as
|
|
@@ -261,10 +306,16 @@ export function lrRankPair(g: Graph, r: number, u: Node, v: Node, last: number):
|
|
|
261
306
|
return next;
|
|
262
307
|
}
|
|
263
308
|
|
|
264
|
-
/**
|
|
265
|
-
|
|
309
|
+
/**
|
|
310
|
+
* 16.1.1 skips a rank with no leader (`rank[i].v[0] == NULL` → `continue`).
|
|
311
|
+
* The per-rank body is its own function here, so C's `continue` is a `return`.
|
|
312
|
+
* @see lib/dotgen/position.c:make_LR_constraints (per-rank inner loop;
|
|
313
|
+
* 16.1.1 :240-243, d49e3a529 "anticipate empty ranks")
|
|
314
|
+
*/
|
|
315
|
+
export function makeLrRankConstraints(g: Graph, r: number): number {
|
|
266
316
|
const rank = g.info.rank!;
|
|
267
317
|
const rk = rank[r];
|
|
318
|
+
if (rk.v[0] == null) return 0;
|
|
268
319
|
let last = 0;
|
|
269
320
|
for (let j = 0; j < rk.n; j++) {
|
|
270
321
|
const u = rk.v[j];
|
|
@@ -272,26 +323,40 @@ export function makeLrRankConstraints(g: Graph, r: number): void {
|
|
|
272
323
|
u.info.rw = nodeRw(u) + selfWidth(u);
|
|
273
324
|
if (rk.v[0]) u.info.rank = last;
|
|
274
325
|
const v = rk.v[j + 1];
|
|
275
|
-
if (v)
|
|
276
|
-
|
|
277
|
-
|
|
326
|
+
if (v) {
|
|
327
|
+
const next = lrRankPair(g, r, u, v, last);
|
|
328
|
+
if (next === null) return -1;
|
|
329
|
+
last = next;
|
|
330
|
+
}
|
|
331
|
+
if (makeFlatLabelConstraints(g, u) !== 0) return -1;
|
|
332
|
+
if (makeFlatEdgeConstraints(g, u) !== 0) return -1;
|
|
278
333
|
}
|
|
279
334
|
if (rk.n > 0) rk.v[0].info.rank = 0;
|
|
335
|
+
return 0;
|
|
280
336
|
}
|
|
281
337
|
|
|
282
|
-
/**
|
|
283
|
-
|
|
338
|
+
/**
|
|
339
|
+
* Returns -1 at the first refused aux edge (C's `return -1` from inside the
|
|
340
|
+
* rank loops), else 0.
|
|
341
|
+
* @see lib/dotgen/position.c:make_LR_constraints
|
|
342
|
+
*/
|
|
343
|
+
export function makeLrConstraints(g: Graph): number {
|
|
284
344
|
for (let i = (g.info.minrank ?? 0); i <= (g.info.maxrank ?? 0); i++) {
|
|
285
|
-
makeLrRankConstraints(g, i);
|
|
345
|
+
if (makeLrRankConstraints(g, i) !== 0) return -1;
|
|
286
346
|
}
|
|
347
|
+
return 0;
|
|
287
348
|
}
|
|
288
349
|
|
|
289
350
|
// ---------------------------------------------------------------------------
|
|
290
351
|
// make_edge_pairs — @see lib/dotgen/position.c:make_edge_pairs
|
|
291
352
|
// ---------------------------------------------------------------------------
|
|
292
353
|
|
|
293
|
-
/**
|
|
294
|
-
|
|
354
|
+
/**
|
|
355
|
+
* Returns -1 when either aux edge is refused (16.1.1, upstream 73c1fd4d1,
|
|
356
|
+
* f0d837f19), leaving the slack node unranked. Else 0.
|
|
357
|
+
* @see lib/dotgen/position.c:make_edge_pairs (per-edge)
|
|
358
|
+
*/
|
|
359
|
+
export function addEdgePair(g: Graph, e: Edge): number {
|
|
295
360
|
const sn = makeSlackNode(g);
|
|
296
361
|
const hp = e.info.head_port.p;
|
|
297
362
|
const tp = e.info.tail_port.p;
|
|
@@ -303,20 +368,25 @@ export function addEdgePair(g: Graph, e: Edge): void {
|
|
|
303
368
|
const d = Math.trunc(hp.x - tp.x);
|
|
304
369
|
const m0 = Math.max(0, d);
|
|
305
370
|
const m1 = Math.max(0, -d);
|
|
306
|
-
makeAuxEdge(sn, e.tail, m0 + 1, edgeWeight(e));
|
|
307
|
-
makeAuxEdge(sn, e.head, m1 + 1, edgeWeight(e));
|
|
371
|
+
if (makeAuxEdge(sn, e.tail, m0 + 1, edgeWeight(e)) === null) return -1;
|
|
372
|
+
if (makeAuxEdge(sn, e.head, m1 + 1, edgeWeight(e)) === null) return -1;
|
|
308
373
|
sn.info.rank = Math.min(nodeRank(e.tail) - m0 - 1, nodeRank(e.head) - m1 - 1);
|
|
374
|
+
return 0;
|
|
309
375
|
}
|
|
310
376
|
|
|
311
|
-
/**
|
|
312
|
-
|
|
377
|
+
/**
|
|
378
|
+
* Returns -1 at the first refused aux edge, else 0.
|
|
379
|
+
* @see lib/dotgen/position.c:make_edge_pairs
|
|
380
|
+
*/
|
|
381
|
+
export function makeEdgePairs(g: Graph): number {
|
|
313
382
|
for (let n = g.info.nlist; n !== undefined; n = n.info.next) {
|
|
314
383
|
const so = n.info.save_out;
|
|
315
384
|
if (!so) continue;
|
|
316
385
|
for (let i = 0; i < so.size; i++) {
|
|
317
|
-
addEdgePair(g, so.list[i]);
|
|
386
|
+
if (addEdgePair(g, so.list[i]) !== 0) return -1;
|
|
318
387
|
}
|
|
319
388
|
}
|
|
389
|
+
return 0;
|
|
320
390
|
}
|
|
321
391
|
|
|
322
392
|
/** Create a SLACKNODE virtual node and prepend to nlist. */
|
|
@@ -340,12 +410,15 @@ export function createAuxEdges(
|
|
|
340
410
|
g: Graph,
|
|
341
411
|
posClusters: (g: Graph) => void,
|
|
342
412
|
compressGraph: (g: Graph) => void,
|
|
343
|
-
):
|
|
413
|
+
): number {
|
|
344
414
|
allocateAuxEdges(g);
|
|
345
|
-
makeLrConstraints(g);
|
|
346
|
-
|
|
415
|
+
const lrRc = makeLrConstraints(g);
|
|
416
|
+
if (lrRc !== 0) return lrRc;
|
|
417
|
+
const pairRc = makeEdgePairs(g);
|
|
418
|
+
if (pairRc !== 0) return pairRc;
|
|
347
419
|
posClusters(g);
|
|
348
420
|
compressGraph(g);
|
|
421
|
+
return 0;
|
|
349
422
|
}
|
|
350
423
|
|
|
351
424
|
/** @see lib/dotgen/position.c:remove_aux_edges (SLACKNODE removal loop) */
|
|
@@ -82,7 +82,20 @@ export function dotComputeBb(g: Graph, root: Graph): void {
|
|
|
82
82
|
}
|
|
83
83
|
const rankArr = root.info.rank!;
|
|
84
84
|
const lly = rankArr[graphMaxrank(g)].v[0].info.coord.y - graphHt1(g);
|
|
85
|
-
|
|
85
|
+
// 16.1.1 takes UR.y from the first rank that is not empty, where 16.1.0 read
|
|
86
|
+
// the min rank's leader outright. C leaves UR.y uninitialised when no rank
|
|
87
|
+
// qualifies; that cannot be read here, because LL.y above has already
|
|
88
|
+
// dereferenced the max rank's leader, so at least the max rank qualifies
|
|
89
|
+
// whenever its `n` is nonzero. NaN marks the value as never meant to be used.
|
|
90
|
+
// @see lib/dotgen/position.c:dot_compute_bb (16.1.1 :885-894, 8e06a6261
|
|
91
|
+
// "anticipate min rank being empty")
|
|
92
|
+
let ury = Number.NaN;
|
|
93
|
+
for (let r = graphMinrank(g); r <= graphMaxrank(g); ++r) {
|
|
94
|
+
if (rankArr[r].n === 0) continue;
|
|
95
|
+
if (rankArr[r].v[0] == null) continue;
|
|
96
|
+
ury = rankArr[r].v[0].info.coord.y + graphHt2(g);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
86
99
|
g.info.bb = { ll: { x: llx, y: lly }, ur: { x: urx, y: ury } };
|
|
87
100
|
}
|
|
88
101
|
|
|
@@ -175,7 +175,13 @@ export function setYcoordsInitial(g: Graph, lbl: boolean): void {
|
|
|
175
175
|
const d1 = rankArr[r + 1].ht2 + rankArr[r].ht1 + CL_OFFSET;
|
|
176
176
|
const delta = Math.max(d0, d1);
|
|
177
177
|
if (rankArr[r].n > 0) {
|
|
178
|
-
|
|
178
|
+
// 16.1.1: assign only when the rank below has a leader (`!= NULL`; the
|
|
179
|
+
// port's empty ranks hold null or nothing at v[0], hence `!= null`).
|
|
180
|
+
// @see lib/dotgen/position.c:set_ycoords (16.1.1 :793-797, 9fca64d0f
|
|
181
|
+
// "anticipate empty ranks")
|
|
182
|
+
if (rankArr[r + 1].v[0] != null) {
|
|
183
|
+
rankArr[r].v[0].info.coord.y = rankArr[r + 1].v[0].info.coord.y + delta;
|
|
184
|
+
}
|
|
179
185
|
}
|
|
180
186
|
maxht = Math.max(maxht, delta);
|
|
181
187
|
}
|
|
@@ -188,7 +188,10 @@ export function dotPosition(g: Graph): number {
|
|
|
188
188
|
}
|
|
189
189
|
expandLeaves(g);
|
|
190
190
|
if (flatEdges(g)) setYcoords(g);
|
|
191
|
-
|
|
191
|
+
// 16.1.1 (upstream f444e5192): an aux edge longer than INT_MAX fails the
|
|
192
|
+
// layout here, ahead of the x-coordinate network simplex.
|
|
193
|
+
const auxRc = createAuxEdges(g, posClusters, compressGraph);
|
|
194
|
+
if (auxRc !== 0) return auxRc;
|
|
192
195
|
g.info.rankIsXCoord = true;
|
|
193
196
|
if (rank(g, 2, nsiter2(g))) {
|
|
194
197
|
connectGraph(g);
|
|
@@ -17,15 +17,11 @@ import { nodesInSeq } from './decomp.js';
|
|
|
17
17
|
// Constants @see lib/dotgen/rank.c
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
19
19
|
|
|
20
|
-
const BACKWARD_PENALTY = 1000;
|
|
21
|
-
const STRONG_CLUSTER_WEIGHT = 1000;
|
|
22
20
|
const NORANK = 6;
|
|
23
21
|
const ROOT_NAME = '\x7froot';
|
|
24
|
-
const TOPNODE_NAME = '\x7ftop';
|
|
25
|
-
const BOTNODE_NAME = '\x7fbot';
|
|
26
22
|
|
|
27
|
-
/** Mutable state replacing C
|
|
28
|
-
export interface XgState { lastNode: Node | undefined;
|
|
23
|
+
/** Mutable state replacing the C static Last_node. */
|
|
24
|
+
export interface XgState { lastNode: Node | undefined; }
|
|
29
25
|
|
|
30
26
|
// ---------------------------------------------------------------------------
|
|
31
27
|
// Accessor helpers — extract ?? and ?. so callers stay within CCN ≤ 10
|
|
@@ -79,17 +75,15 @@ export function d2unionAll(g: Graph): Node | undefined {
|
|
|
79
75
|
// could later widen a node's membership out of creation order (the exact
|
|
80
76
|
// precondition that makes `g.nodes.values()` diverge from AGSEQ elsewhere).
|
|
81
77
|
// Xg's node-creation order is itself already driven by `nodesInSeq(g)`
|
|
82
|
-
// (compileNodes
|
|
78
|
+
// (compileNodes, converted above; connectComponents adds ROOT last), so
|
|
83
79
|
// `Xg.nodes.values()` is provably already AGSEQ-equivalent order.
|
|
84
80
|
// ---------------------------------------------------------------------------
|
|
85
81
|
|
|
86
82
|
/** @see lib/dotgen/rank.c:makeXnode — C's `agnode(G, name, 1)` returns the
|
|
87
|
-
* existing node when one with `name` is present
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* constraint and derailing the rank solve. Real/weak node names are unique, so
|
|
92
|
-
* this dedup only affects TOP/BOT/ROOT — exactly as in C. */
|
|
83
|
+
* existing node when one with `name` is present. Since graphviz 16.1.1 removed
|
|
84
|
+
* compile_clusters and its shared TOP/BOT nodes, the callers are compile_nodes
|
|
85
|
+
* (one call per set leader, each name unique) and connect_components (ROOT, at
|
|
86
|
+
* most once per Xg), so the dedup matters only for ROOT. */
|
|
93
87
|
export function makeXnode(Xg: Graph, name: string, st: XgState): Node {
|
|
94
88
|
const existing = Xg.nodes.get(name);
|
|
95
89
|
if (existing) return existing;
|
|
@@ -212,30 +206,6 @@ export function xgStrong(Xg: Graph, t: Node, h: Node, orig: Edge): void {
|
|
|
212
206
|
xgMerge(e, eMinlen(orig), eWeight(orig));
|
|
213
207
|
}
|
|
214
208
|
|
|
215
|
-
/** @see lib/dotgen/rank.c:weak — find existing weak diamond v→t, v→h */
|
|
216
|
-
export function xgWeakExists(Xg: Graph, t: Node, h: Node): boolean {
|
|
217
|
-
for (const e of Xg.edges) {
|
|
218
|
-
if (e.head !== t) continue;
|
|
219
|
-
const v = e.tail;
|
|
220
|
-
for (const f of Xg.edges) { if (f.tail === v && f.head === h) return true; }
|
|
221
|
-
}
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export function xgWeakSetWeights(e: Edge, f: Edge, origW: number, origML: number): void {
|
|
226
|
-
e.info.minlen = Math.max(eMinlen(e), 0);
|
|
227
|
-
e.info.weight = eWeight(e) + origW * BACKWARD_PENALTY;
|
|
228
|
-
f.info.minlen = Math.max(eMinlen(f), origML);
|
|
229
|
-
f.info.weight = eWeight(f) + origW;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** @see lib/dotgen/rank.c:weak */
|
|
233
|
-
export function xgWeak(Xg: Graph, t: Node, h: Node, orig: Edge, st: XgState): void {
|
|
234
|
-
if (xgWeakExists(Xg, t, h)) return;
|
|
235
|
-
const v = makeXnode(Xg, `_weak_${st.weakId++}`, st);
|
|
236
|
-
xgWeakSetWeights(xgAddEdge(Xg, v, t), xgAddEdge(Xg, v, h), eWeight(orig), eMinlen(orig));
|
|
237
|
-
}
|
|
238
|
-
|
|
239
209
|
/** @see lib/dotgen/rank.c:is_nonconstraint */
|
|
240
210
|
export function isNonConstraint(e: Edge): boolean {
|
|
241
211
|
const v = e.attrs.get('constraint');
|
|
@@ -243,11 +213,6 @@ export function isNonConstraint(e: Edge): boolean {
|
|
|
243
213
|
return !mapbool(v);
|
|
244
214
|
}
|
|
245
215
|
|
|
246
|
-
/** @see lib/dotgen/rank.c:is_a_strong_cluster */
|
|
247
|
-
export function isAStrongCluster(g: Graph): boolean {
|
|
248
|
-
return mapbool(g.attrs.get('compact') ?? '');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
216
|
/** @see lib/dotgen/rank.c:dot_lca */
|
|
252
217
|
export function dotLca(c0: Graph, c1: Graph): Graph {
|
|
253
218
|
let a = c0; let b = c1;
|
|
@@ -283,66 +248,21 @@ export function ceInternal(Xg: Graph, e: Edge, Xt: Node, Xh: Node): void {
|
|
|
283
248
|
}
|
|
284
249
|
|
|
285
250
|
/** @see lib/dotgen/rank.c:compile_edges inner body */
|
|
286
|
-
export function compileEdgeItem(Xg: Graph, e: Edge, Xt: Node
|
|
251
|
+
export function compileEdgeItem(Xg: Graph, e: Edge, Xt: Node): void {
|
|
287
252
|
if (isNonConstraint(e)) return;
|
|
288
253
|
const Xh = d2find(e.head).info.rep;
|
|
289
254
|
if (!Xh || Xt === Xh) return;
|
|
290
255
|
if (isInternalToCluster(e)) { ceInternal(Xg, e, Xt, Xh); return; }
|
|
291
|
-
|
|
292
|
-
if ((tc && isAStrongCluster(tc)) || (hc && isAStrongCluster(hc))) xgWeak(Xg, Xt, Xh, e, st);
|
|
293
|
-
else xgStrong(Xg, Xt, Xh, e);
|
|
256
|
+
xgStrong(Xg, Xt, Xh, e);
|
|
294
257
|
}
|
|
295
258
|
|
|
296
259
|
/** @see lib/dotgen/rank.c:compile_edges */
|
|
297
|
-
export function compileEdges(g: Graph, Xg: Graph
|
|
260
|
+
export function compileEdges(g: Graph, Xg: Graph): void {
|
|
298
261
|
for (const n of nodesInSeq(g)) {
|
|
299
262
|
const Xt = n.info.rep;
|
|
300
263
|
if (!Xt) continue;
|
|
301
|
-
for (const e of n.outEdges(g)) compileEdgeItem(Xg, e, Xt
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
// ---------------------------------------------------------------------------
|
|
306
|
-
// compile_clusters helpers
|
|
307
|
-
// ---------------------------------------------------------------------------
|
|
308
|
-
|
|
309
|
-
interface ClusterBounds { top: Node | undefined; bot: Node | undefined; }
|
|
310
|
-
|
|
311
|
-
export function ccProcessNode(g: Graph, Xg: Graph, st: XgState, n: Node, b: ClusterBounds): void {
|
|
312
|
-
const rep = d2find(n).info.rep;
|
|
313
|
-
if (!rep) return;
|
|
314
|
-
if (n.inEdges(g).length === 0) {
|
|
315
|
-
if (!b.top) b.top = makeXnode(Xg, TOPNODE_NAME, st);
|
|
316
|
-
xgAddEdge(Xg, b.top, rep);
|
|
317
|
-
}
|
|
318
|
-
if (n.outEdges(g).length === 0) {
|
|
319
|
-
if (!b.bot) b.bot = makeXnode(Xg, BOTNODE_NAME, st);
|
|
320
|
-
xgAddEdge(Xg, rep, b.bot);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
export function ccStrongCluster(
|
|
325
|
-
g: Graph, Xg: Graph, st: XgState, top: Node | undefined, bot: Node | undefined
|
|
326
|
-
): ClusterBounds {
|
|
327
|
-
const b: ClusterBounds = { top, bot };
|
|
328
|
-
for (const n of nodesInSeq(g)) ccProcessNode(g, Xg, st, n, b);
|
|
329
|
-
// Xg is Agstrictdirected, so C's `agedge(Xg, top, bot)` returns the one shared
|
|
330
|
-
// TOP->BOT edge (TOP/BOT dedup in makeXnode) and merge() accumulates onto it.
|
|
331
|
-
// Mirror strict agedge with find-or-add so the weight sums instead of forking.
|
|
332
|
-
if (b.top && b.bot) xgMerge(xgFindEdge(Xg, b.top, b.bot) ?? xgAddEdge(Xg, b.top, b.bot), 0, STRONG_CLUSTER_WEIGHT);
|
|
333
|
-
return b;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/** @see lib/dotgen/rank.c:compile_clusters */
|
|
337
|
-
export function compileClusters(
|
|
338
|
-
g: Graph, Xg: Graph, st: XgState, top: Node | undefined, bot: Node | undefined
|
|
339
|
-
): void {
|
|
340
|
-
let t = top; let b = bot;
|
|
341
|
-
if (isACluster(g) && isAStrongCluster(g)) {
|
|
342
|
-
const bounds = ccStrongCluster(g, Xg, st, t, b);
|
|
343
|
-
t = bounds.top; b = bounds.bot;
|
|
264
|
+
for (const e of n.outEdges(g)) compileEdgeItem(Xg, e, Xt);
|
|
344
265
|
}
|
|
345
|
-
for (const sub of g.subgraphs.values()) compileClusters(sub, Xg, st, t, b);
|
|
346
266
|
}
|
|
347
267
|
|
|
348
268
|
// ---------------------------------------------------------------------------
|
|
@@ -507,7 +427,7 @@ export function readoutLevels(g: Graph, Xg: Graph, ncc: number): void {
|
|
|
507
427
|
|
|
508
428
|
/** @see lib/dotgen/rank.c:dot2_rank */
|
|
509
429
|
export function dot2Rank(g: Graph): void {
|
|
510
|
-
const st: XgState = { lastNode: undefined
|
|
430
|
+
const st: XgState = { lastNode: undefined };
|
|
511
431
|
const Xg = new Graph('level assignment constraints', 'strict-directed');
|
|
512
432
|
edgelabelRanks(g);
|
|
513
433
|
const nslimit1 = g.attrs.get('nslimit1');
|
|
@@ -518,8 +438,7 @@ export function dot2Rank(g: Graph): void {
|
|
|
518
438
|
const ssize = ssStr ? parseInt(ssStr, 10) : -1;
|
|
519
439
|
compileSamerank(g, undefined);
|
|
520
440
|
compileNodes(g, Xg, st);
|
|
521
|
-
compileEdges(g, Xg
|
|
522
|
-
compileClusters(g, Xg, st, undefined, undefined);
|
|
441
|
+
compileEdges(g, Xg);
|
|
523
442
|
breakCycles(Xg);
|
|
524
443
|
const ncc = connectComponents(Xg, st);
|
|
525
444
|
addFastEdges(Xg);
|