@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
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
COMPUTED_EDGE_ATTRS, COMPUTED_NODE_ATTRS, appendRecordRects, computedPart, dictParts,
|
|
27
27
|
echoAttr, echoGraphAttr, edgeAttrsAttached, edgeConnector, edgePosRaw,
|
|
28
28
|
effectiveEdgeDefaults, effectiveNodeDefaults, graphInputParts, graphLabelAttrs,
|
|
29
|
-
isDirected, nodeDictParts, nodePosRaw, nodeRecord, objInputParts,
|
|
29
|
+
inClusterTree, isDirected, nodeDictParts, nodePosRaw, nodeRecord, objInputParts,
|
|
30
30
|
} from './attrs.js';
|
|
31
31
|
import { withLinelength } from './agwrite-linelength.js';
|
|
32
32
|
import { nodesInSeq } from '../../layout/dot/decomp.js';
|
|
@@ -36,7 +36,7 @@ import type { XdotDraws, SerCtx } from './types.js';
|
|
|
36
36
|
export abstract class DotWriterBase {
|
|
37
37
|
/** @see dot.ts XdotRenderer.emitDraws */
|
|
38
38
|
protected abstract readonly emitDraws: boolean;
|
|
39
|
-
/**
|
|
39
|
+
/** The clusters xdot_end_cluster ran for (not all of GD_clust: inClusterTree). */
|
|
40
40
|
protected clusters: Graph[] = [];
|
|
41
41
|
/** Draw strings for `obj`, or undefined in a format that emits none. */
|
|
42
42
|
protected abstract drawsOf(obj: Node | Edge | Graph): XdotDraws | undefined;
|
|
@@ -61,19 +61,22 @@ export abstract class DotWriterBase {
|
|
|
61
61
|
/**
|
|
62
62
|
* Serialize the whole laid-out graph to xdot DOT text — a faithful port of
|
|
63
63
|
* cgraph's agwrite (lib/cgraph/write.c). Recurses the subgraph tree
|
|
64
|
-
* (write_subgs/write_body)
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
64
|
+
* (write_subgs/write_body). A node is scoped to the subgraph(s) it belongs
|
|
65
|
+
* to via preorder numbers (write_node_test), and is re-emitted bare (no
|
|
66
|
+
* attrs) on any scope after the first (attrs_written). An edge is written
|
|
67
|
+
* once: each body pends its out-edges during the node walk and writes them
|
|
68
|
+
* after it in creation order (write_edges), and an edge already written is
|
|
69
|
+
* never pended again, so no later scope re-declares it (graphviz 16.1.1).
|
|
69
70
|
* @see lib/cgraph/write.c:agwrite
|
|
71
|
+
* @see lib/cgraph/write.c:before_write
|
|
70
72
|
*/
|
|
71
73
|
protected serialize(g: Graph): string {
|
|
72
74
|
const ctx: SerCtx = {
|
|
73
75
|
out: [],
|
|
74
76
|
preorder: new Map<Graph, number>(),
|
|
75
77
|
nodeLW: new Map<Node, number>(),
|
|
76
|
-
|
|
78
|
+
edgesTodo: new Map<number, Edge>(),
|
|
79
|
+
edgesDone: new Set<number>(),
|
|
77
80
|
attrsWritten: new Set<Node | Edge>(),
|
|
78
81
|
level: 0,
|
|
79
82
|
};
|
|
@@ -109,7 +112,7 @@ export abstract class DotWriterBase {
|
|
|
109
112
|
* a boxed graph and an unboxed child — the driver that makes an anon subgraph
|
|
110
113
|
* under the root or a cluster "relevant". @see lib/common/output.c:safe_dcl */
|
|
111
114
|
private hasBb(g: Graph): boolean {
|
|
112
|
-
return g === g.root ||
|
|
115
|
+
return g === g.root || inClusterTree(g);
|
|
113
116
|
}
|
|
114
117
|
|
|
115
118
|
/** Anonymous subgraph with no own node/edge defaults and no graph attrs
|
|
@@ -118,7 +121,7 @@ export abstract class DotWriterBase {
|
|
|
118
121
|
* the parent, empty on the child) and `rank`. @see write.c:irrelevant_subgraph */
|
|
119
122
|
private irrelevantSubgraph(g: Graph): boolean {
|
|
120
123
|
if (!this.isAnonymous(g)) return false;
|
|
121
|
-
if (
|
|
124
|
+
if (inClusterTree(g)) return false;
|
|
122
125
|
if (g.nodeDefaults.size > 0 || g.edgeDefaults.size > 0) return false;
|
|
123
126
|
if (g.parent) {
|
|
124
127
|
if (this.hasBb(g) !== this.hasBb(g.parent)) return false;
|
|
@@ -137,9 +140,8 @@ export abstract class DotWriterBase {
|
|
|
137
140
|
* `rec_attach_bb` walks the ROOT and then `GD_clust` recursively, so a
|
|
138
141
|
* subgraph the layout did not box is attached NEITHER `bb` NOR the label
|
|
139
142
|
* triple — both keep the INPUT's values, which agwrite echoes. circo and
|
|
140
|
-
* twopi lay out no clusters
|
|
141
|
-
*
|
|
142
|
-
* `cluster0` comes back carrying the *previous* run's `bb` and `lp`.
|
|
143
|
+
* twopi lay out no clusters (`GD_clust` empty, `inClusterTree` false), so on a
|
|
144
|
+
* re-fed dot output `cluster0` carries the *previous* run's `bb` and `lp`.
|
|
143
145
|
* @see lib/common/output.c:249 rec_attach_bb */
|
|
144
146
|
private subgGraphAttrs(sg: Graph): string[] {
|
|
145
147
|
// `rank` is not special-cased here: it is an ordinary input attribute and
|
|
@@ -180,7 +182,7 @@ export abstract class DotWriterBase {
|
|
|
180
182
|
private writeDicts(g: Graph, top: boolean, ctx: SerCtx): void {
|
|
181
183
|
const graphParts = top
|
|
182
184
|
? this.graphAttrs(g)
|
|
183
|
-
:
|
|
185
|
+
: inClusterTree(g)
|
|
184
186
|
? this.clusterAttrs(g)
|
|
185
187
|
: this.subgGraphAttrs(g);
|
|
186
188
|
this.writeDict('graph', graphParts, ctx);
|
|
@@ -260,7 +262,10 @@ export abstract class DotWriterBase {
|
|
|
260
262
|
}
|
|
261
263
|
}
|
|
262
264
|
|
|
263
|
-
/**
|
|
265
|
+
/** Subgraphs, then this scope's nodes, then the edges the node walk pended.
|
|
266
|
+
* The walk still writes an out-edge's head node right after its tail, but
|
|
267
|
+
* the edge itself waits for writeEdges unless an earlier body wrote it.
|
|
268
|
+
* @see lib/cgraph/write.c:write_body */
|
|
264
269
|
private writeBody(g: Graph, ctx: SerCtx): void {
|
|
265
270
|
this.writeSubgs(g, ctx);
|
|
266
271
|
// agfstnode/agnxtnode walk a subgraph's node set in AGSEQ (root creation)
|
|
@@ -275,9 +280,24 @@ export abstract class DotWriterBase {
|
|
|
275
280
|
this.writeNode(g, e.head, ctx);
|
|
276
281
|
prev = e.head;
|
|
277
282
|
}
|
|
278
|
-
|
|
283
|
+
// pend this edge to be emitted later
|
|
284
|
+
if (!ctx.edgesDone.has(e.seq)) ctx.edgesTodo.set(e.seq, e);
|
|
279
285
|
}
|
|
280
286
|
}
|
|
287
|
+
// flush pending edges to the output
|
|
288
|
+
this.writeEdges(g, ctx);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Write the pending edges in ascending `Edge.seq` (the C walks a Dtoset
|
|
292
|
+
* keyed on AGSEQ), mark each done, and empty the set for the next body.
|
|
293
|
+
* @see lib/cgraph/write.c:write_edges */
|
|
294
|
+
private writeEdges(g: Graph, ctx: SerCtx): void {
|
|
295
|
+
const seqs = [...ctx.edgesTodo.keys()].sort((a, b) => a - b);
|
|
296
|
+
for (const seq of seqs) {
|
|
297
|
+
this.writeEdge(g, ctx.edgesTodo.get(seq)!, ctx);
|
|
298
|
+
ctx.edgesDone.add(seq);
|
|
299
|
+
}
|
|
300
|
+
ctx.edgesTodo.clear();
|
|
281
301
|
}
|
|
282
302
|
|
|
283
303
|
/** @see write.c:write_node_test — every xdot node carries pos/size, so it is
|
|
@@ -299,11 +319,6 @@ export abstract class DotWriterBase {
|
|
|
299
319
|
return n.name;
|
|
300
320
|
}
|
|
301
321
|
|
|
302
|
-
/** @see write.c:write_edge_test */
|
|
303
|
-
private writeEdgeTest(g: Graph, e: Edge, ctx: SerCtx): boolean {
|
|
304
|
-
return (ctx.edgeLW.get(e) ?? 0) < ctx.preorder.get(g)!;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
322
|
/** @see write.c:write_node */
|
|
308
323
|
private writeNode(g: Graph, n: Node, ctx: SerCtx): void {
|
|
309
324
|
let s = this.indent(ctx) + xdotId(this.emitNodeName(n));
|
|
@@ -315,7 +330,6 @@ export abstract class DotWriterBase {
|
|
|
315
330
|
ctx.nodeLW.set(n, ctx.preorder.get(g)!);
|
|
316
331
|
}
|
|
317
332
|
|
|
318
|
-
/** @see write.c:write_edge — attrs only on first emission, bare thereafter. */
|
|
319
333
|
/**
|
|
320
334
|
* The `:port` / `:port:compass` suffix C writes after an endpoint name.
|
|
321
335
|
*
|
|
@@ -341,6 +355,12 @@ export abstract class DotWriterBase {
|
|
|
341
355
|
return ':' + agstrcanonText(val.slice(0, i)) + ':' + agstrcanonText(val.slice(i + 1));
|
|
342
356
|
}
|
|
343
357
|
|
|
358
|
+
/** One edge statement. The C's `else` arm (write_edge_name: a bare `[key=…]`
|
|
359
|
+
* for an edge whose attributes were already written) is not ported: since
|
|
360
|
+
* 16.1.1 edges_done makes write_body write each edge once per agwrite, and
|
|
361
|
+
* before_write's set_attrwf clears every flag first, so the arm cannot run.
|
|
362
|
+
* The attrsWritten gate stays, as the C's `if (!attrs_written(e))` does.
|
|
363
|
+
* @see lib/cgraph/write.c:write_edge */
|
|
344
364
|
private writeEdge(g: Graph, e: Edge, ctx: SerCtx): void {
|
|
345
365
|
const conn = edgeConnector(isDirected(g));
|
|
346
366
|
let s = this.indent(ctx) + xdotId(this.emitNodeName(e.tail)) +
|
|
@@ -351,7 +371,6 @@ export abstract class DotWriterBase {
|
|
|
351
371
|
ctx.attrsWritten.add(e);
|
|
352
372
|
}
|
|
353
373
|
ctx.out.push(s + ';\n');
|
|
354
|
-
ctx.edgeLW.set(e, ctx.preorder.get(g)!);
|
|
355
374
|
}
|
|
356
375
|
|
|
357
376
|
/** Root-graph attribute block: `_draw_`, `_ldraw_`, `bb`, `xdotversion`. */
|
|
@@ -371,13 +390,14 @@ export abstract class DotWriterBase {
|
|
|
371
390
|
return parts;
|
|
372
391
|
}
|
|
373
392
|
|
|
374
|
-
/** Cluster attribute block. C's xdot_end_cluster ALWAYS agsets `_draw_`
|
|
375
|
-
*
|
|
376
|
-
*
|
|
393
|
+
/** Cluster attribute block. C's xdot_end_cluster ALWAYS agsets `_draw_` for a
|
|
394
|
+
* cluster it ran for (even empty, e.g. peripheries=0); one that emit_clusters
|
|
395
|
+
* skipped (clust_in_layer) keeps only a stored one. `_ldraw_` only with a label.
|
|
377
396
|
* @see plugin/core/gvrender_core_dot.c:284 xdot_end_cluster */
|
|
378
397
|
private clusterAttrs(sg: Graph): string[] {
|
|
379
398
|
const d = this.drawsOf(sg);
|
|
380
|
-
const
|
|
399
|
+
const drawn = this.emitDraws && this.clusters.includes(sg);
|
|
400
|
+
const parts: string[] = drawn || d?.draw ? [this.drawAttr('_draw_', d?.draw ?? '')] : [];
|
|
381
401
|
if (d?.ldraw) parts.push(this.drawAttr('_ldraw_', d.ldraw));
|
|
382
402
|
if (sg.info.bb) parts.push('bb="' + this.bbStr(sg) + '"');
|
|
383
403
|
// rec_attach_bb recurses into GD_clust, so a labelled cluster carries the
|
package/src/render/dot/attrs.ts
CHANGED
|
@@ -240,8 +240,10 @@ function ownComputedAttrs(g: Graph, top: boolean, computed: Set<string>): Readon
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
/** Whether an ancestor's GD_clust holds `g` (a cluster inside an anonymous
|
|
243
|
-
* subgraph belongs to the nearest cluster or root above it).
|
|
244
|
-
|
|
243
|
+
* subgraph belongs to the nearest cluster or root above it). This is the set
|
|
244
|
+
* rec_attach_bb walks: every cluster the layout made, drawn or not.
|
|
245
|
+
* @see lib/common/output.c:rec_attach_bb */
|
|
246
|
+
export function inClusterTree(g: Graph): boolean {
|
|
245
247
|
for (let a = g.parent; a !== null; a = a.parent) {
|
|
246
248
|
if ((a.info.clust ?? []).slice(0, a.info.n_cluster ?? 0).includes(g)) return true;
|
|
247
249
|
}
|
|
@@ -404,6 +406,8 @@ export function writeDictSkips(v: string, inherited: string | undefined): boolea
|
|
|
404
406
|
export function echoGraphAttr(g: Graph, key: string): string[] {
|
|
405
407
|
const v = g.attrs.get(key);
|
|
406
408
|
if (v === undefined) return [];
|
|
409
|
+
// A seeded value has no local dict symbol: write_dict does not print it.
|
|
410
|
+
if (g.seededAttrs?.has(key) === true) return [];
|
|
407
411
|
if (writeDictSkips(v, g.graphDefaultsSnapshot?.get(key))) return [];
|
|
408
412
|
return [`${key}=${agstrcanon(v)}`];
|
|
409
413
|
}
|
package/src/render/dot/types.ts
CHANGED
|
@@ -23,8 +23,13 @@ export interface SerCtx {
|
|
|
23
23
|
preorder: Map<Graph, number>;
|
|
24
24
|
/** node → preorder of the subgraph it was last written in (node_last_written). */
|
|
25
25
|
nodeLW: Map<Node, number>;
|
|
26
|
-
/**
|
|
27
|
-
|
|
26
|
+
/** Edges the current body has pended, keyed on `Edge.seq` (AGSEQ), which dedupes as the C's
|
|
27
|
+
* ordered dictionary does. Empty at the start of every body's node walk.
|
|
28
|
+
* @see lib/cgraph/write.c:info_t (edges_todo) */
|
|
29
|
+
edgesTodo: Map<number, Edge>;
|
|
30
|
+
/** `Edge.seq` of every edge already written in this agwrite.
|
|
31
|
+
* @see lib/cgraph/write.c:info_t (edges_done) */
|
|
32
|
+
edgesDone: Set<number>;
|
|
28
33
|
/** objects whose attributes have already been emitted (AGATTRWF/attrs_written). */
|
|
29
34
|
attrsWritten: Set<Node | Edge>;
|
|
30
35
|
/** current indentation depth. */
|
|
@@ -6,8 +6,11 @@
|
|
|
6
6
|
* proxy nodes `__<i>:<cluster>` never print. The port's writers otherwise read
|
|
7
7
|
* the proxies as they print and undo at the next layout (`layout-reset.ts`);
|
|
8
8
|
* json prints from the graph itself, so it takes the undo at C's point, through
|
|
9
|
-
* the same helper.
|
|
10
|
-
*
|
|
9
|
+
* the same helper. json0 attaches before it writes on every graph: it prints
|
|
10
|
+
* what the write-back stored (`bb`, an edge's `pos`) and has nothing else to
|
|
11
|
+
* take them from. json, on a graph with no cluster edges, defers its held
|
|
12
|
+
* write-back until after the write: its xdot draw lookup overlays the same
|
|
13
|
+
* values, so nothing there can differ.
|
|
11
14
|
*
|
|
12
15
|
* Also the json cluster map: write_graph's top pass numbers the subgraphs and
|
|
13
16
|
* maps each cluster's name to its gid (label_subgs, insert), which is where a
|
|
@@ -27,8 +30,9 @@ import type { Node } from '../model/node.js';
|
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
32
|
* With cluster edges on `g`: runs `attach` (attach_attrs' write-back) and the
|
|
30
|
-
* undo now, and returns a no-op. Otherwise returns `attach
|
|
31
|
-
*
|
|
33
|
+
* undo now, and returns a no-op. Otherwise returns `attach` uncalled: json runs
|
|
34
|
+
* it after the write (its draw lookup overlays the values), and json0 runs it
|
|
35
|
+
* at once, before the write.
|
|
32
36
|
* @see lib/common/output.c:416 attach_attrs
|
|
33
37
|
*/
|
|
34
38
|
export function attachBeforeWriteWithClusterEdges(g: Graph, attach: () => void): () => void {
|
package/src/render/json.ts
CHANGED
|
@@ -47,6 +47,7 @@ import { gfmt5, XdotRenderer, type XdotDraws } from './dot.js';
|
|
|
47
47
|
import { attachAttrs, nodeLayoutAttrs } from './dot/write-back.js';
|
|
48
48
|
import { attachBeforeWriteWithClusterEdges as attachFirst, jsonNodes, labelSubgs, lookupCluster } from './json-cluster-edge.js';
|
|
49
49
|
import { attrsWithoutLayoutBb } from '../gvc/layout-bb.js';
|
|
50
|
+
import { agNameOf, localGraphAttrs } from '../model/cgraph-ops.js';
|
|
50
51
|
import { CHAR_LATIN1 } from '../common/graph-init.js';
|
|
51
52
|
import { parse } from '../parser/index.js';
|
|
52
53
|
import { render as deviceRender } from '../gvc/device.js';
|
|
@@ -276,7 +277,7 @@ function collectDrawLookup(g: Graph): DrawLookup | undefined {
|
|
|
276
277
|
for (const [nm, gChild] of gSub.subgraphs) {
|
|
277
278
|
const xgChild = xgSub.subgraphs.get(nm);
|
|
278
279
|
if (xgChild !== undefined) {
|
|
279
|
-
cluster.set(gChild,
|
|
280
|
+
cluster.set(gChild, localGraphAttrs(xgChild));
|
|
280
281
|
correlate(gChild, xgChild);
|
|
281
282
|
} else {
|
|
282
283
|
correlate(gChild, xgSub);
|
|
@@ -518,8 +519,9 @@ function buildNodeObject(n: Node, ctx: BuildCtx): JObj {
|
|
|
518
519
|
const eff = nodeEffectiveAttrs(n);
|
|
519
520
|
const xd = ctx.draws?.node.get(n.name);
|
|
520
521
|
if (xd === undefined) {
|
|
521
|
-
// Fallback
|
|
522
|
-
//
|
|
522
|
+
// Fallback for a json render whose xdot re-render failed (a hand-built
|
|
523
|
+
// graph): take the strings attach_attrs writes (output.c:296-309). json0
|
|
524
|
+
// has no draw lookup either, so it repeats what attachAttrs just stored.
|
|
523
525
|
const layout = nodeLayoutAttrs(n);
|
|
524
526
|
eff.set('pos', layout.pos).set('width', layout.width).set('height', layout.height);
|
|
525
527
|
}
|
|
@@ -577,8 +579,7 @@ function buildEdgesArray(g: Graph, ctx: BuildCtx): JObj[] {
|
|
|
577
579
|
/** @see plugin/core/gvrender_core_json.c:write_graph */
|
|
578
580
|
function buildGraphObject(g: Graph, top: boolean, ctx: BuildCtx): JObj {
|
|
579
581
|
const o: JObj = {};
|
|
580
|
-
// write_hdr
|
|
581
|
-
o.name = g.name;
|
|
582
|
+
o.name = agNameOf(g); // write_hdr: agnameof (%1 for a nameless root)
|
|
582
583
|
if (top) {
|
|
583
584
|
o.directed = g.kind === 'directed' || g.kind === 'strict-directed';
|
|
584
585
|
o.strict = g.kind === 'strict-directed' || g.kind === 'strict-undirected';
|
|
@@ -682,10 +683,16 @@ export class Json0Renderer extends JsonRendererBase implements RendererPlugin {
|
|
|
682
683
|
|
|
683
684
|
beginGraph(_g: Graph, _job: RenderJob): void { /* no-op */ }
|
|
684
685
|
|
|
685
|
-
/**
|
|
686
|
+
/**
|
|
687
|
+
* Attach, then write: C's json_begin_graph runs attach_attrs (which ends by
|
|
688
|
+
* undoing cluster edges) before json_end_graph writes, and json0 prints what
|
|
689
|
+
* that stored. Nothing overlays `bb` or an edge's `pos` here, as json's xdot
|
|
690
|
+
* draw lookup does, so the write-back cannot wait until after the write.
|
|
691
|
+
* @see plugin/core/gvrender_core_json.c:json_begin_graph
|
|
692
|
+
*/
|
|
686
693
|
endGraph(g: Graph, job: RenderJob): void {
|
|
687
|
-
|
|
688
|
-
job.write(buildJson(g, false));
|
|
694
|
+
attachFirst(g, () => attachAttrs(g))();
|
|
695
|
+
job.write(buildJson(g, false));
|
|
689
696
|
}
|
|
690
697
|
}
|
|
691
698
|
|
package/src/render/map.ts
CHANGED
|
@@ -27,14 +27,13 @@ import type { RendererPlugin } from '../gvc/context.js';
|
|
|
27
27
|
import type { ObjState, RenderJob } from '../gvc/job.js';
|
|
28
28
|
import { MapShape, EMIT_CLUSTERS_LAST } from '../gvc/job.js';
|
|
29
29
|
import {
|
|
30
|
-
type MapCtx,
|
|
31
|
-
|
|
32
|
-
computeGraphUrlMap,
|
|
33
|
-
computeClusterUrlMap,
|
|
34
|
-
computeLabelRectMap,
|
|
35
|
-
computeEdgeSplineMaps,
|
|
30
|
+
type MapCtx, computeNodeUrlMap, computeGraphUrlMap, computeClusterUrlMap,
|
|
31
|
+
computeLabelRectMap, computeEdgeSplineMaps,
|
|
36
32
|
} from '../gvc/anchor.js';
|
|
37
|
-
import {
|
|
33
|
+
import { printfFixed0 } from '../util/printf-round.js';
|
|
34
|
+
import {
|
|
35
|
+
initJobViewportZoom, parseDrawingSize, setupPageBox, setupPageClip, setupPageSize,
|
|
36
|
+
} from '../gvc/viewport.js';
|
|
38
37
|
import { escapeXml } from './svg-helpers.js';
|
|
39
38
|
import { escapeXmlTitle } from './xml-escape.js';
|
|
40
39
|
import { maxOutputline } from './dot/agwrite-linelength.js';
|
|
@@ -466,23 +465,22 @@ export function cmapxShape(shape: MapShape): string {
|
|
|
466
465
|
return 'poly';
|
|
467
466
|
}
|
|
468
467
|
|
|
469
|
-
/** CMAPX coords for a rectangle (UL→LR in Y-down space)
|
|
468
|
+
/** CMAPX coords for a rectangle (UL→LR in Y-down space), each printed "%.0f"
|
|
469
|
+
* (`-0` at the page top, ties to even). @see gvrender_core_map.c:map_output_shape */
|
|
470
470
|
export function cmapxCoordsRect(pts: Point[]): string {
|
|
471
|
-
return
|
|
472
|
-
+ ',' +
|
|
471
|
+
return printfFixed0(pts[0]!.x) + ',' + printfFixed0(pts[1]!.y)
|
|
472
|
+
+ ',' + printfFixed0(pts[1]!.x) + ',' + printfFixed0(pts[0]!.y);
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
-
/** CMAPX coords for a circle: `cx,cy,r
|
|
475
|
+
/** CMAPX coords for a circle: `cx,cy,r`, "%.0f". @see map_output_shape */
|
|
476
476
|
export function cmapxCoordsCircle(pts: Point[]): string {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
const r = Math.round(pts[1]!.x - pts[0]!.x);
|
|
480
|
-
return String(cx) + ',' + String(cy) + ',' + String(r);
|
|
477
|
+
return printfFixed0(pts[0]!.x) + ',' + printfFixed0(pts[0]!.y)
|
|
478
|
+
+ ',' + printfFixed0(pts[1]!.x - pts[0]!.x);
|
|
481
479
|
}
|
|
482
480
|
|
|
483
|
-
/** CMAPX coords for a polygon: `x0,y0,x1,y1
|
|
481
|
+
/** CMAPX coords for a polygon: `x0,y0,x1,y1,...`, "%.0f". @see map_output_shape */
|
|
484
482
|
export function cmapxCoordsPoly(pts: Point[]): string {
|
|
485
|
-
return pts.map(p =>
|
|
483
|
+
return pts.map(p => printfFixed0(p.x) + ',' + printfFixed0(p.y)).join(',');
|
|
486
484
|
}
|
|
487
485
|
|
|
488
486
|
/** Dispatch to the correct CMAPX coordinate formatter. */
|
|
@@ -513,21 +511,19 @@ export function mapOutputCmapx(
|
|
|
513
511
|
out.push(isXml ? '/>\n' : '>\n');
|
|
514
512
|
}
|
|
515
513
|
|
|
516
|
-
/** Write one IMAP shape line; skipped when url is empty.
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
): void {
|
|
514
|
+
/** Write one IMAP shape line ("%.0f" coordinates); skipped when url is empty.
|
|
515
|
+
* @see plugin/core/gvrender_core_map.c:map_output_shape (FORMAT_IMAP) */
|
|
516
|
+
export function mapOutputImap(shape: MapShape, pts: Point[], url: string, out: string[]): void {
|
|
520
517
|
if (!url) return;
|
|
521
518
|
if (shape === MapShape.Rectangle) {
|
|
522
519
|
out.push('rect ' + url + ' '
|
|
523
|
-
+
|
|
524
|
-
+ ' ' +
|
|
520
|
+
+ printfFixed0(pts[0]!.x) + ',' + printfFixed0(pts[1]!.y)
|
|
521
|
+
+ ' ' + printfFixed0(pts[1]!.x) + ',' + printfFixed0(pts[0]!.y) + '\n');
|
|
525
522
|
} else if (shape === MapShape.Circle) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
+ Math.round(pts[0]!.x) + ',' + Math.round(pts[0]!.y) + ',' + String(r) + '\n');
|
|
523
|
+
out.push('circle ' + url + ' ' + printfFixed0(pts[0]!.x) + ',' + printfFixed0(pts[0]!.y)
|
|
524
|
+
+ ',' + printfFixed0(pts[1]!.x - pts[0]!.x) + '\n');
|
|
529
525
|
} else {
|
|
530
|
-
const pairs = pts.map(p =>
|
|
526
|
+
const pairs = pts.map(p => printfFixed0(p.x) + ',' + printfFixed0(p.y)).join(' ');
|
|
531
527
|
out.push('poly ' + url + ' ' + pairs + '\n');
|
|
532
528
|
}
|
|
533
529
|
}
|
|
@@ -606,22 +602,26 @@ export function graphMapUrl(g: Graph): string | null {
|
|
|
606
602
|
return raw === undefined ? null : substObjAnchor(raw, g);
|
|
607
603
|
}
|
|
608
604
|
|
|
609
|
-
/** Build the imagemap coordinate context
|
|
610
|
-
* (
|
|
611
|
-
*
|
|
605
|
+
/** Build the imagemap coordinate context: setup_page's pageBox and translation
|
|
606
|
+
* (non-rotated, GVRENDER_Y_GOES_DOWN; canvasBox.LL is the graph `margin=`, the
|
|
607
|
+
* map device having no default page size to centre in) and emit_graph's
|
|
608
|
+
* devscale, negated on y. The map device's default dpi is 96 (dpi/resolution
|
|
609
|
+
* attrs override); zoom fits the drawing into `size=` (initJobViewportZoom).
|
|
610
|
+
* @see lib/common/emit.c:setup_page (1515-1555) ; emit_graph (3631-3633) */
|
|
612
611
|
export function buildMapCtx(g: Graph, job: RenderJob, mapPolygon: boolean): MapCtx {
|
|
613
612
|
const drawingDpi = lateDouble(g.attrs.get('dpi'), lateDouble(g.attrs.get('resolution'), 0, 0), 0);
|
|
614
|
-
const
|
|
615
|
-
const
|
|
616
|
-
const z = initJobViewportZoom(job.bb,
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
const
|
|
620
|
-
return {
|
|
613
|
+
const devscale = (drawingDpi > 0 ? drawingDpi : 96) / POINTS_PER_INCH;
|
|
614
|
+
const size = parseDrawingSize(g.attrs.get('size'));
|
|
615
|
+
const z = initJobViewportZoom(job.bb, size, job.pad);
|
|
616
|
+
const clip = setupPageClip(job.bb, size, job.pad, z);
|
|
617
|
+
const pageBox = setupPageBox(setupPageSize(job.bb, size, job.pad, z), job.pad);
|
|
618
|
+
const translation = { x: -clip.ll.x + job.margin.x / z, y: -clip.ur.y - job.margin.y / z };
|
|
619
|
+
return { pageBox, translation, scale: { x: z * devscale, y: z * -devscale }, mapPolygon };
|
|
621
620
|
}
|
|
622
621
|
|
|
623
|
-
/** Head/tail/center label anchor bundle. */
|
|
624
|
-
interface EdgeLabelAnchor { url: string | null; tooltip: string | null; target: string | null; explicit: boolean;
|
|
622
|
+
/** Head/tail/center label anchor bundle; `suffix` is emit_edge_label's `type` (from lkind). */
|
|
623
|
+
interface EdgeLabelAnchor { url: string | null; tooltip: string | null; target: string | null; explicit: boolean;
|
|
624
|
+
suffix: 'label' | 'headlabel' | 'taillabel'; }
|
|
625
625
|
|
|
626
626
|
/** Coalesce nullable anchor fields to '' (gvrender_begin_anchor passes ""). */
|
|
627
627
|
function anchorOf(url: string | null, tooltip: string | null, target: string | null, id: string | null): AnchorCtx {
|
|
@@ -678,13 +678,6 @@ abstract class MapRendererBase implements RendererPlugin {
|
|
|
678
678
|
if (this.mapCtx !== null && job.obj !== null) computeNodeUrlMap(n, job.obj, this.mapCtx);
|
|
679
679
|
}
|
|
680
680
|
|
|
681
|
-
beginCluster(sg: Graph, job: RenderJob): void {
|
|
682
|
-
const bb = sg.info.bb;
|
|
683
|
-
if (this.mapCtx !== null && job.obj !== null && bb !== undefined) {
|
|
684
|
-
computeClusterUrlMap(bb, job.obj, this.mapCtx);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
681
|
endEdge(e: Edge, job: RenderJob): void {
|
|
689
682
|
if (this.mapCtx !== null && job.obj !== null) this.emitEdge(e, job.obj, job);
|
|
690
683
|
}
|
|
@@ -732,26 +725,24 @@ abstract class MapRendererBase implements RendererPlugin {
|
|
|
732
725
|
this.emitShape(MapShape.Polygon, poly, anchor, job);
|
|
733
726
|
}
|
|
734
727
|
}
|
|
735
|
-
const centerA: EdgeLabelAnchor = {
|
|
736
|
-
|
|
737
|
-
};
|
|
728
|
+
const centerA: EdgeLabelAnchor = { url: obj.labelUrl, tooltip: obj.labelTooltip,
|
|
729
|
+
target: obj.labelTarget, explicit: obj.explicitLabelTooltip, suffix: 'label' };
|
|
738
730
|
this.emitEdgeLabel(e.info.label, centerA, obj, job);
|
|
739
731
|
this.emitEdgeLabel(e.info.xlabel, centerA, obj, job);
|
|
740
|
-
this.emitEdgeLabel(e.info.head_label,
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
{ url: obj.tailUrl, tooltip: obj.tailTooltip, target: obj.tailTarget, explicit: obj.explicitTailTooltip },
|
|
745
|
-
obj, job);
|
|
732
|
+
this.emitEdgeLabel(e.info.head_label, { url: obj.headUrl, tooltip: obj.headTooltip,
|
|
733
|
+
target: obj.headTarget, explicit: obj.explicitHeadTooltip, suffix: 'headlabel' }, obj, job);
|
|
734
|
+
this.emitEdgeLabel(e.info.tail_label, { url: obj.tailUrl, tooltip: obj.tailTooltip,
|
|
735
|
+
target: obj.tailTarget, explicit: obj.explicitTailTooltip, suffix: 'taillabel' }, obj, job);
|
|
746
736
|
}
|
|
747
737
|
|
|
748
|
-
/** One edge label hot spot (map_label rect), if placed and url/explicit-tip
|
|
749
|
-
* @see lib/common/emit.c:emit_edge_label */
|
|
738
|
+
/** One edge label hot spot (map_label rect), if placed and url/explicit-tip; its id is
|
|
739
|
+
* `<obj.id>-<suffix>` (C: `if (id)`, else NULL). @see lib/common/emit.c:emit_edge_label (2851-2876) */
|
|
750
740
|
private emitEdgeLabel(lab: TextlabelT | undefined, la: EdgeLabelAnchor, obj: ObjState, job: RenderJob): void {
|
|
751
741
|
const placed = lab !== undefined && lab.set && this.mapCtx !== null;
|
|
752
742
|
if (!placed || (la.url === null && !la.explicit)) return;
|
|
753
743
|
computeLabelRectMap(lab, obj, this.mapCtx!);
|
|
754
|
-
|
|
744
|
+
const id = obj.id === null ? null : `${obj.id}-${la.suffix}`;
|
|
745
|
+
this.emitShape(MapShape.Rectangle, obj.urlMapPts, anchorOf(la.url, la.tooltip, la.target, id), job);
|
|
755
746
|
}
|
|
756
747
|
}
|
|
757
748
|
|
|
@@ -11,10 +11,10 @@ import { escapeXmlTitle } from './svg-helpers.js';
|
|
|
11
11
|
import { svgClusterId, svgClusterClass } from './svg-id.js';
|
|
12
12
|
|
|
13
13
|
export function svgBeginCluster(sg: Graph, job: RenderJob): void {
|
|
14
|
-
// Id from getObjId (DOT `id` attr / gid prefix / clust<seq>);
|
|
15
|
-
//
|
|
14
|
+
// Id from getObjId (layer prefix / DOT `id` attr / gid prefix / clust<seq>);
|
|
15
|
+
// no per-object suffix for graph/cluster ids. DOT `class` is appended.
|
|
16
16
|
// @see lib/common/emit.c:getObjId; plugin/core/gvrender_core_svg.c:svg_print_id_class
|
|
17
|
-
job.write('<g id="' + escapeXmlTitle(
|
|
17
|
+
job.write('<g id="' + escapeXmlTitle(svgClusterId(sg, job))
|
|
18
18
|
+ '" ' + svgClusterClass(sg) + '>\n');
|
|
19
19
|
job.write('<title>' + escapeXmlTitle(sg.name) + '</title>\n');
|
|
20
20
|
}
|
package/src/render/svg-graph.ts
CHANGED
|
@@ -338,8 +338,6 @@ export function svgBeginGraph(g: Graph, job: RenderJob): void {
|
|
|
338
338
|
// C reads GD_fontnames(job->gvc->g) at each span; the port carries it on the
|
|
339
339
|
// job, set here alongside the other root-graph-derived fields.
|
|
340
340
|
job.fontnames = g.info.fontnames ?? FontnameKind.NativeFonts;
|
|
341
|
-
// GD_drawing(root)->id — used as the `<gid>_` prefix for non-root object ids.
|
|
342
|
-
job.drawingId = g.attrs.get('id') ?? '';
|
|
343
341
|
job.write(SVG_XML_DECL);
|
|
344
342
|
// C svg_begin_job emits the stylesheet PI (raw href) between the XML
|
|
345
343
|
// declaration and the DOCTYPE when the graph has a `stylesheet` attribute.
|
|
@@ -409,7 +407,7 @@ export function svgBeginPage(g: Graph, job: RenderJob): void {
|
|
|
409
407
|
: -clip.ll.x + job.margin.x / z;
|
|
410
408
|
const ty = clip.ur.y + job.margin.y / z;
|
|
411
409
|
emitGraphGroupOpen(
|
|
412
|
-
|
|
410
|
+
svgGraphId(g, job),
|
|
413
411
|
svgGraphClass(g),
|
|
414
412
|
tx, ty, job,
|
|
415
413
|
);
|
|
@@ -180,13 +180,13 @@ export {
|
|
|
180
180
|
// ---------------------------------------------------------------------------
|
|
181
181
|
|
|
182
182
|
export function svgBeginNode(n: Node, job: RenderJob): void {
|
|
183
|
-
// Id from getObjId (DOT `id` attr / gid prefix / node<seq>);
|
|
184
|
-
// prefix
|
|
183
|
+
// Id from getObjId (layer prefix / DOT `id` attr / gid prefix / node<seq>);
|
|
184
|
+
// the prefix and the suffix are empty unless layerNum>1. The DOT
|
|
185
185
|
// `class` attr is appended to the SVG class string (svg_print_id_class).
|
|
186
186
|
// @see lib/common/emit.c:getObjId; plugin/core/gvrender_core_svg.c:svg_begin_node
|
|
187
187
|
// C's svg_print_id_class prints the assembled id through gvputs_xml, so the
|
|
188
188
|
// DOT `id` attr (and user-controlled layer names) are XML-escaped at emission.
|
|
189
|
-
job.write('<g id="' + escapeXmlTitle(
|
|
189
|
+
job.write('<g id="' + escapeXmlTitle(svgNodeId(n, job) + job.idLayerSuffix())
|
|
190
190
|
+ '" ' + svgNodeClass(n) + '>\n');
|
|
191
191
|
job.write('<title>' + escapeXmlTitle(n.name) + '</title>\n');
|
|
192
192
|
}
|
|
@@ -223,9 +223,9 @@ export function svgBeginEdge(e: Edge, job: RenderJob): void {
|
|
|
223
223
|
const hp = e.info.head_port?.name;
|
|
224
224
|
const raw = e.tail.name + (tp ? ':' + tp : '')
|
|
225
225
|
+ sep + e.head.name + (hp ? ':' + hp : '');
|
|
226
|
-
// Edges get the layer prefix
|
|
227
|
-
// passes idx=NULL, unlike svg_begin_node).
|
|
228
|
-
job.write('<g id="' + escapeXmlTitle(
|
|
226
|
+
// Edges get the layer prefix with the id (objId) — no per-object suffix
|
|
227
|
+
// (svg_begin_edge passes idx=NULL, unlike svg_begin_node). `class` applies.
|
|
228
|
+
job.write('<g id="' + escapeXmlTitle(svgEdgeId(e, job))
|
|
229
229
|
+ '" ' + svgEdgeClass(e) + '>\n');
|
|
230
230
|
job.write('<title>' + escapeEdgeTitle(raw) + '</title>\n');
|
|
231
231
|
}
|
package/src/render/svg-id.ts
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SVG object id + class resolution, faithful to C's getObjId
|
|
4
4
|
// (lib/common/emit.c:209) and svg_print_id_class
|
|
5
|
-
// (plugin/core/gvrender_core_svg.c).
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
5
|
+
// (plugin/core/gvrender_core_svg.c). Every id starts with `<layer>_` on a
|
|
6
|
+
// layer after the first (layerPagePrefix, in job.objId). Then a non-empty DOT
|
|
7
|
+
// `id` attribute wins; otherwise the generated `<pfx><seq>` id is used, with a
|
|
8
|
+
// `<gid>_` prefix on non-root objects when the root graph carries an `id`
|
|
9
|
+
// attribute
|
|
10
|
+
// (job.drawingId, from drawingIdOf). That prefix belongs to the graph, not to
|
|
11
|
+
// the svg plugin: every renderer that prints an object id (svg, the imagemaps)
|
|
12
|
+
// gets the same one. The DOT `class` attribute, when present, is appended to
|
|
13
|
+
// the SVG class string. Attribute reads use C's `agget` semantics (defaults
|
|
10
14
|
// inherited) via nodeAttr / clusterAttr.
|
|
11
15
|
|
|
12
16
|
import type { Node } from '../model/node.js';
|
|
@@ -16,6 +20,20 @@ import type { RenderJob } from '../gvc/job.js';
|
|
|
16
20
|
import { escapeXmlTitle } from './xml-escape.js';
|
|
17
21
|
import { nodeAttr } from '../common/poly-init.js';
|
|
18
22
|
import { clusterAttr } from '../gvc/device-cluster.js';
|
|
23
|
+
import { substObjAnchor } from '../common/subst.js';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* C's `GD_drawing(root)->id`: the root graph's `id` attribute with its `\`
|
|
27
|
+
* escapes substituted (`\G` and the like), or '' when it is unset or empty.
|
|
28
|
+
* graph_init sets it once for every renderer; getObjId prefixes each non-root
|
|
29
|
+
* object id with it.
|
|
30
|
+
* @see lib/common/input.c:graph_init (786-788)
|
|
31
|
+
* @see lib/common/emit.c:getObjId
|
|
32
|
+
*/
|
|
33
|
+
export function drawingIdOf(g: Graph): string {
|
|
34
|
+
const id = g.attrs.get('id');
|
|
35
|
+
return id !== undefined && id.length > 0 ? substObjAnchor(id, g) : '';
|
|
36
|
+
}
|
|
19
37
|
|
|
20
38
|
/**
|
|
21
39
|
* `class="<kind>"`, with the DOT `class` attribute appended (` <class>`,
|