@knowvah/dot-engine 2.12.2 → 2.12.4
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/api.js +12 -2
- package/dist/api.js.map +2 -2
- package/dist/common/clust-map.d.ts +16 -0
- package/dist/common/clust-map.d.ts.map +1 -0
- package/dist/common/compass-port.d.ts.map +1 -1
- package/dist/common/graph-init.d.ts.map +1 -1
- package/dist/common/htmltable-emit.d.ts +9 -6
- package/dist/common/htmltable-emit.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/layers.d.ts +9 -0
- package/dist/common/layers.d.ts.map +1 -1
- package/dist/common/poly-gencode.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/common/xlabels-place.d.ts.map +1 -1
- package/dist/gvc/anchor.d.ts +17 -19
- package/dist/gvc/anchor.d.ts.map +1 -1
- package/dist/gvc/device-cluster.d.ts +9 -0
- package/dist/gvc/device-cluster.d.ts.map +1 -1
- package/dist/gvc/device.d.ts +2 -1
- package/dist/gvc/device.d.ts.map +1 -1
- package/dist/gvc/emit-walk.d.ts +7 -0
- package/dist/gvc/emit-walk.d.ts.map +1 -1
- package/dist/gvc/job.d.ts +13 -6
- package/dist/gvc/job.d.ts.map +1 -1
- package/dist/gvc/viewport.d.ts +14 -0
- package/dist/gvc/viewport.d.ts.map +1 -1
- package/dist/index.js +21767 -21607
- package/dist/index.js.map +4 -4
- package/dist/layout/dot/classify.d.ts.map +1 -1
- package/dist/layout/dot/compound.d.ts +0 -4
- package/dist/layout/dot/compound.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/cluster-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/cgraph-ops.d.ts +7 -0
- package/dist/model/cgraph-ops.d.ts.map +1 -1
- package/dist/model/graph.d.ts +12 -2
- package/dist/model/graph.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/parser/builder.d.ts +11 -10
- package/dist/parser/builder.d.ts.map +1 -1
- package/dist/parser/graph-attr-syms.d.ts +35 -0
- package/dist/parser/graph-attr-syms.d.ts.map +1 -0
- package/dist/pathplan/route.d.ts +93 -0
- package/dist/pathplan/route.d.ts.map +1 -1
- package/dist/render/dot/agwrite.d.ts +27 -16
- package/dist/render/dot/agwrite.d.ts.map +1 -1
- package/dist/render/dot/attrs.d.ts +5 -0
- package/dist/render/dot/attrs.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/json-cluster-edge.d.ts +3 -2
- package/dist/render/json-cluster-edge.d.ts.map +1 -1
- package/dist/render/json.d.ts +7 -1
- package/dist/render/json.d.ts.map +1 -1
- package/dist/render/map.d.ts +14 -10
- package/dist/render/map.d.ts.map +1 -1
- package/dist/render/svg-graph.d.ts.map +1 -1
- package/dist/render/svg-id.d.ts +9 -0
- package/dist/render/svg-id.d.ts.map +1 -1
- package/dist/render.js +22009 -21849
- 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/dist/util/printf-round.d.ts +8 -0
- package/dist/util/printf-round.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/common/clust-map.ts +58 -0
- package/src/common/compass-port.ts +36 -20
- package/src/common/graph-init.ts +11 -1
- package/src/common/htmltable-emit.ts +87 -7
- 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/layers.ts +25 -4
- package/src/common/poly-gencode.ts +3 -11
- 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/common/xlabels-place.ts +22 -4
- 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/gvc/anchor.ts +18 -30
- package/src/gvc/device-cluster.ts +16 -0
- package/src/gvc/device.ts +20 -20
- package/src/gvc/emit-walk.ts +11 -1
- package/src/gvc/job.ts +17 -9
- package/src/gvc/viewport.ts +27 -6
- package/src/layout/dot/classify.ts +5 -2
- package/src/layout/dot/compound.ts +1 -21
- 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/cluster-edges.ts +2 -23
- 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/cgraph-ops.ts +12 -0
- package/src/model/graph.ts +13 -2
- package/src/model/rankEntry.ts +3 -1
- package/src/ortho/index.ts +0 -1
- package/src/ortho/partition.ts +10 -22
- package/src/parser/builder.ts +67 -100
- package/src/parser/graph-attr-syms.ts +62 -0
- package/src/pathplan/route.ts +14 -4
- package/src/render/dot/agwrite.ts +47 -27
- package/src/render/dot/attrs.ts +6 -2
- package/src/render/dot/types.ts +7 -2
- package/src/render/json-cluster-edge.ts +8 -4
- package/src/render/json.ts +15 -8
- package/src/render/map.ts +49 -58
- package/src/render/svg-cluster.ts +3 -3
- package/src/render/svg-graph.ts +1 -3
- package/src/render/svg-helpers.ts +6 -6
- package/src/render/svg-id.ts +23 -5
- package/src/util/overflow.ts +74 -0
- package/src/util/printf-round.ts +11 -0
|
@@ -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);
|
|
@@ -71,19 +71,30 @@ export function collectOtherEdges(n: Node, edges: Edge[]): void {
|
|
|
71
71
|
|
|
72
72
|
// ---------------------------------------------------------------------------
|
|
73
73
|
// computeSizey — rank-gap geometry for self-loop sizing
|
|
74
|
-
// @see lib/dotgen/dotsplines.c:
|
|
74
|
+
// @see lib/dotgen/dotsplines.c:dot_splines_ (16.1.1 :396-411)
|
|
75
75
|
// ---------------------------------------------------------------------------
|
|
76
76
|
|
|
77
|
+
/** C's `GD_rank(g)[r].v[0] != NULL`: rank r is not empty. The port's empty
|
|
78
|
+
* ranks carry `v[0]` as null or as absent (`v` is `[]`), so the test is loose.
|
|
79
|
+
* @see lib/dotgen/dotsplines.c:dot_splines_ (16.1.1, ca3353d80, 1a77ac9df) */
|
|
80
|
+
function rankHasLeader(g: Graph, r: number): boolean {
|
|
81
|
+
return g.info.rank![r].v[0] != null;
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
/** y-coord of first node in rank r. @see lib/dotgen/dotsplines.c:394 */
|
|
78
85
|
function rankY(g: Graph, r: number): number {
|
|
79
86
|
return g.info.rank![r].v[0].info.coord?.y ?? 0;
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
/** sizey when n is at the maximum rank
|
|
83
|
-
*
|
|
84
|
-
* index -1).
|
|
89
|
+
/** sizey when n is at the maximum rank, or the rank below it is empty. C's
|
|
90
|
+
* `r > 0` is a literal index test; after abomination C's rank is
|
|
91
|
+
* r - abomShift (AD-2 renumbers +1 where C uses index -1). 16.1.1 also wants
|
|
92
|
+
* a leader on the rank above: `r > 0 && GD_rank(g)[r - 1].v[0] != NULL`.
|
|
93
|
+
* @see lib/dotgen/dotsplines.c:dot_splines_ (16.1.1 :400-404, 1a77ac9df) */
|
|
85
94
|
function sizeyAtMaxrank(g: Graph, n: Node, r: number): number {
|
|
86
|
-
if (r - (g.info.abomShift ?? 0) > 0
|
|
95
|
+
if (r - (g.info.abomShift ?? 0) > 0 && rankHasLeader(g, r - 1)) {
|
|
96
|
+
return rankY(g, r - 1) - (n.info.coord?.y ?? 0);
|
|
97
|
+
}
|
|
87
98
|
return n.info.ht ?? 0;
|
|
88
99
|
}
|
|
89
100
|
|
|
@@ -103,19 +114,26 @@ function sizeyAtMidrank(g: Graph, n: Node, r: number): number {
|
|
|
103
114
|
/**
|
|
104
115
|
* Compute the vertical sizing parameter for self-loops on node n.
|
|
105
116
|
*
|
|
106
|
-
* Mirrors the C branch exactly:
|
|
107
|
-
* if r == maxrank
|
|
108
|
-
*
|
|
117
|
+
* Mirrors the C branch exactly (16.1.1 guards an empty neighbouring rank):
|
|
118
|
+
* if r == maxrank || rank[r+1].v[0] == NULL:
|
|
119
|
+
* sizey = rank[r-1].v[0].y - n.y (or ht if r==0 or rank[r-1] is empty)
|
|
120
|
+
* elif r == minrank || rank[r-1].v[0] == NULL:
|
|
121
|
+
* sizey = n.y - rank[r+1].v[0].y
|
|
109
122
|
* else: sizey = min(rank[r-1].v[0].y - n.y, n.y - rank[r+1].v[0].y)
|
|
110
123
|
*
|
|
111
|
-
*
|
|
124
|
+
* The `||` order is C's: the rank table has no entry past either end, so the
|
|
125
|
+
* neighbour is read only once `r` is known not to be that end.
|
|
126
|
+
*
|
|
127
|
+
* @see lib/dotgen/dotsplines.c:dot_splines_ (16.1.1 :396-411; ca3353d80
|
|
128
|
+
* "anticipate an empty rank above", 1a77ac9df "anticipate an empty rank
|
|
129
|
+
* below")
|
|
112
130
|
*/
|
|
113
131
|
export function computeSizey(g: Graph, n: Node): number {
|
|
114
132
|
const r = n.info.rank ?? 0;
|
|
115
133
|
const minrank = g.info.minrank ?? 0;
|
|
116
134
|
const maxrank = g.info.maxrank ?? 0;
|
|
117
|
-
if (r === maxrank) return sizeyAtMaxrank(g, n, r);
|
|
118
|
-
if (r === minrank) return sizeyAtMinrank(g, n, r);
|
|
135
|
+
if (r === maxrank || !rankHasLeader(g, r + 1)) return sizeyAtMaxrank(g, n, r);
|
|
136
|
+
if (r === minrank || !rankHasLeader(g, r - 1)) return sizeyAtMinrank(g, n, r);
|
|
119
137
|
return sizeyAtMidrank(g, n, r);
|
|
120
138
|
}
|
|
121
139
|
|
|
@@ -89,9 +89,17 @@ function samePortsAs(x: Edge, lo: Node, key: { loP: Port; hiP: Port }): boolean
|
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* Collect all unrouted non-adjacent same-rank side-port flat edges between e's
|
|
92
|
-
* endpoints that share e's tail/head ports (C portcmp),
|
|
93
|
-
*
|
|
94
|
-
*
|
|
92
|
+
* endpoints that share e's tail/head ports (C portcmp), in C's edgecmp order.
|
|
93
|
+
* Inside one make_flat_edge run every edgecmp key before the last is equal
|
|
94
|
+
* (same main edge, so the same rank and x difference; the same ports through
|
|
95
|
+
* makefwdedge; the same graph type and label), so the order is AGSEQ's,
|
|
96
|
+
* whichever node is on the left. make_flat_edge gives edge i the (i+1)-th
|
|
97
|
+
* route out. This follows C where "left tail first" differed from it
|
|
98
|
+
* (nonadjacent-flat-multi AD-3: "if C's order differs, follow C"; issue #158,
|
|
99
|
+
* 700813). `lo` keys the port match only, not the order. Mirrors
|
|
100
|
+
* edge-route.ts: collectAdjacentFlatGroup with the non-adjacent +
|
|
101
|
+
* identical-port group key.
|
|
102
|
+
* @see lib/dotgen/dotsplines.c:edgecmp
|
|
95
103
|
* @see lib/dotgen/dotsplines.c:dot_splines_ (portcmp 370-373), make_flat_edge
|
|
96
104
|
*/
|
|
97
105
|
export function collectNonAdjacentFlatGroup(e: Edge, g: Graph): Edge[] {
|
|
@@ -106,7 +114,7 @@ export function collectNonAdjacentFlatGroup(e: Edge, g: Graph): Edge[] {
|
|
|
106
114
|
const group = g.edges.filter(
|
|
107
115
|
x => sharesPair(x) && isNonAdjGroupable(x, g) && samePortsAs(x, lo, key)
|
|
108
116
|
&& x.info.label === e.info.label);
|
|
109
|
-
group.sort((a, b) =>
|
|
117
|
+
group.sort((a, b) => a.seq - b.seq);
|
|
110
118
|
return group;
|
|
111
119
|
}
|
|
112
120
|
|
|
@@ -89,19 +89,18 @@ export function isStraightContinuation(v: Node, n: Node): boolean {
|
|
|
89
89
|
return nodeCoordX(v) === nodeCoordX(n);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
/** @see lib/dotgen/dotsplines.c:straight_len */
|
|
92
|
+
/**
|
|
93
|
+
* Count of vertically aligned edges starting at n. The walk stops at a node
|
|
94
|
+
* with no out edge: 16.1.1 loops on `ND_out(v).size > 0`, where 16.1.0 read
|
|
95
|
+
* `ND_out(v).list[0]` of a virtual node that has none (upstream issue 2765).
|
|
96
|
+
* @see lib/dotgen/dotsplines.c:straight_len (16.1.1, 5649d079c)
|
|
97
|
+
*/
|
|
99
98
|
export function straightLen(n: Node): number {
|
|
100
99
|
let cnt = 0;
|
|
101
|
-
let v: Node
|
|
102
|
-
|
|
103
|
-
v =
|
|
104
|
-
if (!
|
|
100
|
+
let v: Node = n;
|
|
101
|
+
while (nodeOutSize(v) > 0) {
|
|
102
|
+
v = v.info.out!.list[0].head;
|
|
103
|
+
if (!isStraightContinuation(v, n)) break;
|
|
105
104
|
cnt++;
|
|
106
105
|
}
|
|
107
106
|
return cnt;
|
|
@@ -30,6 +30,7 @@ import { midPointf } from './compound-geom.js';
|
|
|
30
30
|
import { placePortlabel, updateBB } from './splines-label.js';
|
|
31
31
|
import { dotRoot } from './mincross-utils.js';
|
|
32
32
|
import { nodesInSeq } from './decomp.js';
|
|
33
|
+
import { fdivOverflow } from '../../util/overflow.js';
|
|
33
34
|
|
|
34
35
|
// Edge-type values, mirroring the constants in splines.ts. Defined locally to
|
|
35
36
|
// avoid a straight-edges ↔ splines import cycle (splines.ts imports
|
|
@@ -174,10 +175,10 @@ function getCycleCentroid(g: Graph, edge: Edge): Point {
|
|
|
174
175
|
|
|
175
176
|
// ---------------------------------------------------------------------------
|
|
176
177
|
// bend — pull the two interior control points toward the centroid
|
|
177
|
-
// @see lib/common/routespl.c:
|
|
178
|
+
// @see lib/common/routespl.c:937-951
|
|
178
179
|
// ---------------------------------------------------------------------------
|
|
179
180
|
|
|
180
|
-
/** @see lib/common/routespl.c:
|
|
181
|
+
/** @see lib/common/routespl.c:937-951 (bend) */
|
|
181
182
|
function bend(spl: Point[], centroid: Point): void {
|
|
182
183
|
const midpt = midPointf(spl[0], spl[3]);
|
|
183
184
|
const distVal = dist(spl[3], spl[0]); // DIST(spl[3], spl[0])
|
|
@@ -185,7 +186,8 @@ function bend(spl: Point[], centroid: Point): void {
|
|
|
185
186
|
const vX = centroid.x - midpt.x;
|
|
186
187
|
const vY = centroid.y - midpt.y;
|
|
187
188
|
const magV = Math.hypot(vX, vY);
|
|
188
|
-
|
|
189
|
+
// avoid out of range division results
|
|
190
|
+
if (fdivOverflow(vX, magV) === null || fdivOverflow(vY, magV) === null) return;
|
|
189
191
|
const ax = midpt.x - (vX / magV) * r; // + would be closest point
|
|
190
192
|
const ay = midpt.y - (vY / magV) * r;
|
|
191
193
|
// this can be improved
|