@knowvah/dot-engine 2.12.1 → 2.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/builder.d.ts +7 -1
- package/dist/api/builder.d.ts.map +1 -1
- package/dist/api.js +14 -7
- package/dist/api.js.map +2 -2
- package/dist/common/compass-port.d.ts.map +1 -1
- package/dist/common/edge-label-init.d.ts +26 -1
- package/dist/common/edge-label-init.d.ts.map +1 -1
- package/dist/common/graph-init.d.ts.map +1 -1
- package/dist/common/htmltable-label.d.ts.map +1 -1
- package/dist/common/htmltable-lex.d.ts +3 -1
- package/dist/common/htmltable-lex.d.ts.map +1 -1
- package/dist/common/htmltable-parse-image.d.ts +23 -0
- package/dist/common/htmltable-parse-image.d.ts.map +1 -0
- package/dist/common/htmltable-parse-state.d.ts +4 -0
- package/dist/common/htmltable-parse-state.d.ts.map +1 -1
- package/dist/common/htmltable-parse.d.ts +33 -2
- package/dist/common/htmltable-parse.d.ts.map +1 -1
- package/dist/common/nodeinit.d.ts +16 -2
- package/dist/common/nodeinit.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-path-begin.d.ts.map +1 -1
- package/dist/common/splines-path-end.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/gvc/context.d.ts +8 -0
- package/dist/gvc/context.d.ts.map +1 -1
- package/dist/gvc/emit-gates.d.ts +5 -10
- package/dist/gvc/emit-gates.d.ts.map +1 -1
- package/dist/gvc/emit-xdot.d.ts +7 -6
- package/dist/gvc/emit-xdot.d.ts.map +1 -1
- package/dist/gvc/job.d.ts +5 -2
- package/dist/gvc/job.d.ts.map +1 -1
- package/dist/gvc/viewport.d.ts +10 -5
- package/dist/gvc/viewport.d.ts.map +1 -1
- package/dist/index.js +21565 -21326
- package/dist/index.js.map +4 -4
- package/dist/layout/dot/classify.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-chain-views.d.ts +35 -0
- package/dist/layout/dot/edge-route-chain-views.d.ts.map +1 -0
- package/dist/layout/dot/edge-route-chain.d.ts +20 -16
- package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
- package/dist/layout/dot/edge-route-faithful.d.ts.map +1 -1
- package/dist/layout/dot/edge-route.d.ts +7 -3
- package/dist/layout/dot/edge-route.d.ts.map +1 -1
- package/dist/layout/dot/fastgr.d.ts +5 -3
- package/dist/layout/dot/fastgr.d.ts.map +1 -1
- package/dist/layout/dot/flat-adj-record.d.ts +22 -0
- package/dist/layout/dot/flat-adj-record.d.ts.map +1 -0
- package/dist/layout/dot/flat.d.ts +22 -7
- package/dist/layout/dot/flat.d.ts.map +1 -1
- package/dist/layout/dot/init.d.ts +49 -9
- package/dist/layout/dot/init.d.ts.map +1 -1
- package/dist/layout/dot/mincross-build.d.ts +6 -0
- package/dist/layout/dot/mincross-build.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 +69 -21
- 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-clone.d.ts +2 -1
- package/dist/layout/dot/splines-clone.d.ts.map +1 -1
- package/dist/layout/dot/splines-flat-labeled.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-flat.d.ts +18 -0
- package/dist/layout/dot/splines-flat.d.ts.map +1 -1
- package/dist/layout/dot/splines-groups.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/ports.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-mkernel.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/layout/neato/sgd.d.ts.map +1 -1
- package/dist/model/cgraph-ops.d.ts +10 -2
- package/dist/model/cgraph-ops.d.ts.map +1 -1
- package/dist/model/edge.d.ts +7 -2
- package/dist/model/edge.d.ts.map +1 -1
- package/dist/model/edgeInfo.d.ts +17 -2
- package/dist/model/edgeInfo.d.ts.map +1 -1
- package/dist/model/graph.d.ts +4 -3
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/lazy-attrs.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.map +1 -1
- package/dist/pathplan/route.d.ts +93 -0
- package/dist/pathplan/route.d.ts.map +1 -1
- package/dist/render/dot/agwrite.d.ts +26 -10
- package/dist/render/dot/agwrite.d.ts.map +1 -1
- package/dist/render/dot/attrs.d.ts +15 -4
- 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/dot/write-back.d.ts +14 -0
- package/dist/render/dot/write-back.d.ts.map +1 -1
- package/dist/render/dot/xdot-ops.d.ts +20 -29
- package/dist/render/dot/xdot-ops.d.ts.map +1 -1
- package/dist/render/dot.d.ts +4 -2
- package/dist/render/dot.d.ts.map +1 -1
- package/dist/render/json-cluster-edge.d.ts +17 -4
- package/dist/render/json-cluster-edge.d.ts.map +1 -1
- package/dist/render/json-nonfinite.d.ts +17 -0
- package/dist/render/json-nonfinite.d.ts.map +1 -0
- package/dist/render/json.d.ts +4 -0
- package/dist/render/json.d.ts.map +1 -1
- package/dist/render/map.d.ts +3 -0
- 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 +10 -1
- package/dist/render/svg-id.d.ts.map +1 -1
- package/dist/render/svg.d.ts +3 -1
- package/dist/render/svg.d.ts.map +1 -1
- package/dist/render.js +21517 -21278
- package/dist/render.js.map +4 -4
- package/dist/util/bsd-qsort.d.ts.map +1 -1
- package/dist/util/overflow.d.ts +37 -0
- package/dist/util/overflow.d.ts.map +1 -0
- package/dist/xdot/parse.d.ts.map +1 -1
- package/dist/xdot/strtod.d.ts +23 -0
- package/dist/xdot/strtod.d.ts.map +1 -0
- package/package.json +3 -2
- package/src/api/builder.ts +8 -2
- package/src/common/compass-port.ts +36 -20
- package/src/common/edge-label-init.ts +43 -17
- package/src/common/graph-init.ts +11 -1
- package/src/common/htmltable-label.ts +9 -4
- package/src/common/htmltable-lex.ts +5 -2
- package/src/common/htmltable-parse-image.ts +69 -0
- package/src/common/htmltable-parse-state.ts +6 -0
- package/src/common/htmltable-parse.ts +34 -44
- package/src/common/nodeinit.ts +28 -8
- package/src/common/poly-inside.ts +11 -5
- package/src/common/splines-geom.ts +24 -6
- package/src/common/splines-path-begin.ts +4 -3
- package/src/common/splines-path-end.ts +4 -3
- package/src/common/splines-routespl.ts +32 -0
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +19 -19
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +18 -18
- package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +12 -12
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +20 -20
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +31 -31
- package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +33 -33
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.1 +10 -10
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.2 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.plain.nofree.3 +28 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +21 -28
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +100 -102
- package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +137 -139
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.1 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.2 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.dot.nofree.3 +1 -1
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.1 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.2 +3 -3
- package/src/gvc/__fixtures__/rerender/nestedclust.dot.xdot.nofree.3 +3 -3
- package/src/gvc/__fixtures__/rerender/regen.sh +6 -0
- package/src/gvc/context.ts +8 -0
- package/src/gvc/device.ts +6 -6
- package/src/gvc/emit-gates.ts +6 -15
- package/src/gvc/emit-xdot.ts +10 -11
- package/src/gvc/job.ts +5 -2
- package/src/gvc/viewport.ts +13 -7
- package/src/layout/dot/__fixtures__/flat-adj-aux-syms.native-16.1.json +1210 -0
- package/src/layout/dot/classify.ts +5 -2
- package/src/layout/dot/edge-route-chain-views.ts +120 -0
- package/src/layout/dot/edge-route-chain.ts +103 -117
- package/src/layout/dot/edge-route-faithful.ts +20 -5
- package/src/layout/dot/edge-route.ts +44 -49
- package/src/layout/dot/fastgr.ts +9 -3
- package/src/layout/dot/flat-adj-record.ts +68 -0
- package/src/layout/dot/flat.ts +38 -17
- package/src/layout/dot/init.ts +59 -13
- package/src/layout/dot/mincross-build.ts +14 -1
- 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 +122 -42
- 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-clone.ts +8 -2
- package/src/layout/dot/splines-flat-labeled.ts +3 -2
- package/src/layout/dot/splines-flat-multi.ts +12 -4
- package/src/layout/dot/splines-flat.ts +9 -19
- package/src/layout/dot/splines-groups.ts +5 -3
- package/src/layout/dot/splines-route.ts +10 -11
- package/src/layout/dot/straight-edges.ts +5 -3
- package/src/layout/fdp/ports.ts +6 -2
- 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-mkernel.ts +6 -2
- 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/sgd.ts +2 -1
- 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 +4 -3
- package/src/model/edge.ts +11 -4
- package/src/model/edgeInfo.ts +18 -2
- package/src/model/graph.ts +4 -3
- package/src/model/lazy-attrs.ts +3 -1
- 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 +12 -3
- package/src/pathplan/route.ts +14 -4
- package/src/render/dot/agwrite.ts +45 -18
- package/src/render/dot/attrs.ts +18 -7
- package/src/render/dot/types.ts +7 -2
- package/src/render/dot/write-back.ts +27 -3
- package/src/render/dot/xdot-ops.ts +25 -56
- package/src/render/dot.ts +7 -5
- package/src/render/json-cluster-edge.ts +42 -5
- package/src/render/json-nonfinite.ts +51 -0
- package/src/render/json.ts +23 -26
- package/src/render/map.ts +3 -0
- package/src/render/svg-graph.ts +3 -15
- package/src/render/svg-id.ts +11 -2
- package/src/render/svg.ts +4 -1
- package/src/util/bsd-qsort.ts +2 -1
- package/src/util/overflow.ts +74 -0
- package/src/xdot/parse.ts +9 -19
- package/src/xdot/strtod.ts +167 -0
|
@@ -13,6 +13,8 @@ import { colorxlate } from '../../common/color.js';
|
|
|
13
13
|
import { getGradientPoints } from '../svg-gradient.js';
|
|
14
14
|
import { EmitState, toFixed2HalfEven } from '../../gvc/job.js';
|
|
15
15
|
import { printfSig, printfFixed } from '../../util/printf-round.js';
|
|
16
|
+
import { isHtmlValue } from '../../common/html-string.js';
|
|
17
|
+
import { agstrcanon } from '../map.js';
|
|
16
18
|
|
|
17
19
|
// ---------------------------------------------------------------------------
|
|
18
20
|
// Constants
|
|
@@ -296,31 +298,34 @@ export function xdotStrOp(prefix: string, s: string): string {
|
|
|
296
298
|
}
|
|
297
299
|
|
|
298
300
|
/**
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
301
|
+
* Canonicalize a node, edge-endpoint or graph/subgraph name for `-Tdot`/`-Txdot`
|
|
302
|
+
* as agwrite does: `write_nodename` and `write_hdr` both print the name through
|
|
303
|
+
* `write_canonstr`, i.e. `agstrcanon` with the html check on. So a name is bare
|
|
304
|
+
* when it is an id or numeral, quoted when it is a keyword or holds any other
|
|
305
|
+
* byte, wrapped at `Max_outputline`, and angle-bracketed when it is html-like.
|
|
306
|
+
* A `\` is copied verbatim: it is already the start of a stored escape like
|
|
307
|
+
* `\n`/`\l`, so doubling it would change the name.
|
|
308
|
+
* @see lib/cgraph/write.c:write_nodename
|
|
309
|
+
* @see lib/cgraph/write.c:write_hdr
|
|
310
|
+
* @see lib/cgraph/write.c:write_canonstr
|
|
306
311
|
*
|
|
307
|
-
* ONE DELIBERATE DIVERGENCE from _agstrcanon: an ODD trailing backslash run
|
|
308
|
-
* padded to even. C copies it verbatim and appends the
|
|
309
|
-
* ending in a single `\` serializes as `"a\"` — the
|
|
310
|
-
* and the output does not reparse. The DOT lexer
|
|
311
|
-
* (source `"a\"` never terminates), so this is
|
|
312
|
-
* corpus id changes; it is reachable only
|
|
313
|
-
*
|
|
314
|
-
* `a\\` instead of `a\`, which beats
|
|
312
|
+
* ONE DELIBERATE DIVERGENCE from _agstrcanon: an ODD trailing backslash run on
|
|
313
|
+
* a non-html name is padded to even. C copies it verbatim and appends the
|
|
314
|
+
* closing quote, so a name ending in a single `\` serializes as `"a\"` — the
|
|
315
|
+
* backslash escapes the quote and the output does not reparse. The DOT lexer
|
|
316
|
+
* cannot produce such a name (source `"a\"` never terminates), so this is
|
|
317
|
+
* unreachable from any file and no corpus id changes; it is reachable only
|
|
318
|
+
* through the programmatic API, where a caller supplies the string directly.
|
|
319
|
+
* Padding costs a name that round-trips to `a\\` instead of `a\`, which beats
|
|
320
|
+
* emitting a document that cannot be parsed. An html name is never padded: C
|
|
321
|
+
* prints `<a\>` and that reparses.
|
|
315
322
|
* @see CodeQL "Incomplete string escaping or encoding" — the alert's own remedy
|
|
316
323
|
* (escape every `\`) is wrong here and breaks `\n`/`\l` parity.
|
|
317
324
|
*/
|
|
318
325
|
export function xdotId(s: string): string {
|
|
319
|
-
if (
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const trailingBackslashes = /\\*$/.exec(body)![0].length;
|
|
323
|
-
return '"' + body + (trailingBackslashes % 2 === 1 ? '\\' : '') + '"';
|
|
326
|
+
if (isHtmlValue(s)) return agstrcanon(s);
|
|
327
|
+
const oddTrailingRun = /\\*$/.exec(s)![0].length % 2 === 1;
|
|
328
|
+
return agstrcanon(oddTrailingRun ? `${s}\\` : s);
|
|
324
329
|
}
|
|
325
330
|
|
|
326
331
|
/**
|
|
@@ -385,42 +390,6 @@ export function escBackslash(s: string): string {
|
|
|
385
390
|
return s.replace(/\\/g, '\\\\');
|
|
386
391
|
}
|
|
387
392
|
|
|
388
|
-
/** True if s[i..] starts an escape sequence agcanonStr keeps verbatim: a `\`
|
|
389
|
-
* followed by one of E G H L N T l n r \ ". @see lib/cgraph/write.c:is_escape */
|
|
390
|
-
export function isEscapeSeq(s: string, i: number): boolean {
|
|
391
|
-
if (s[i] !== '\\') return false;
|
|
392
|
-
const n = s[i + 1];
|
|
393
|
-
return n === 'E' || n === 'G' || n === 'H' || n === 'L' || n === 'N' || n === 'T'
|
|
394
|
-
|| n === 'l' || n === 'n' || n === 'r' || n === '\\' || n === '"';
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* Escape a value for a DOT attribute exactly as agwrite's agcanonStr does: a `"`
|
|
399
|
-
* becomes `\"` ONLY when it is not already part of an escape sequence, so an
|
|
400
|
-
* existing `\"` or `\\` in the value is passed through verbatim rather than
|
|
401
|
-
* double-escaped. For an already-backslash-doubled value (node/edge/graph labels,
|
|
402
|
-
* post put_escaping_backslashes) this is identical to a naive `"`→`\"` — every
|
|
403
|
-
* `"` follows a doubled `\\`, so none are ever part_of_escape. For raw cluster
|
|
404
|
-
* labels (agset, no put_escaping) it preserves the source `\"`/`\\` unchanged.
|
|
405
|
-
* @see lib/cgraph/write.c:_agstrcanon (135-167)
|
|
406
|
-
*/
|
|
407
|
-
export function agcanonEscape(s: string): string {
|
|
408
|
-
let out = '';
|
|
409
|
-
let partOfEscape = false;
|
|
410
|
-
for (let i = 0; i < s.length; i++) {
|
|
411
|
-
const c = s[i]!;
|
|
412
|
-
if (c === '"' && !partOfEscape) {
|
|
413
|
-
out += '\\';
|
|
414
|
-
} else if (!partOfEscape && isEscapeSeq(s, i)) {
|
|
415
|
-
partOfEscape = true;
|
|
416
|
-
} else {
|
|
417
|
-
partOfEscape = false;
|
|
418
|
-
}
|
|
419
|
-
out += c;
|
|
420
|
-
}
|
|
421
|
-
return out;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
393
|
/** Trim a "%.3f" fixed string like C's agxbuf_trim_zeros (trailing 0s + dot). */
|
|
425
394
|
export function trimFixed3(v: number): string {
|
|
426
395
|
let s = v.toFixed(3);
|
package/src/render/dot.ts
CHANGED
|
@@ -68,6 +68,8 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
|
|
|
68
68
|
readonly type: string = 'xdot';
|
|
69
69
|
/** @see plugin/core/gvplugin_core.c registration table */
|
|
70
70
|
readonly quality = 0;
|
|
71
|
+
/** `-Tdot` too (`:734`). @see plugin/core/gvrender_core_dot.c:745 render_features_xdot */
|
|
72
|
+
readonly defaultPad = 0;
|
|
71
73
|
|
|
72
74
|
/**
|
|
73
75
|
* Whether this format attaches the xdot draw attributes before agwrite.
|
|
@@ -104,8 +106,8 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
|
|
|
104
106
|
this.clusters = [];
|
|
105
107
|
}
|
|
106
108
|
|
|
107
|
-
/**
|
|
108
|
-
*
|
|
109
|
+
/** This render's draw strings by ORIGINAL object. `-Tjson` lays them over the re-parsed xdot text,
|
|
110
|
+
* which cannot represent draw text containing `"` (id 2239); stored strings reach it by that text. */
|
|
109
111
|
drawStringsByObject(): ReadonlyMap<Node | Edge | Graph, XdotDraws> {
|
|
110
112
|
return this.draws;
|
|
111
113
|
}
|
|
@@ -139,8 +141,8 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
|
|
|
139
141
|
if (fillSpec === 'transparent') fillSpec = 'white';
|
|
140
142
|
// The canvas fill covers job->clip, which setup_page derives from the focus
|
|
141
143
|
// and page size: bb ± pad (xdot's default pad is 0), and nan for an infinite
|
|
142
|
-
// bb. @see emit.c:1559-1562 setup_page · gvrender_core_dot.c:
|
|
143
|
-
const c = deviceClip(g,
|
|
144
|
+
// bb. @see emit.c:1559-1562 setup_page · gvrender_core_dot.c:745 (default_pad)
|
|
145
|
+
const c = deviceClip(g, job);
|
|
144
146
|
const corners: Point[] = [
|
|
145
147
|
{ x: c.ll.x, y: c.ll.y }, { x: c.ll.x, y: c.ur.y }, { x: c.ur.x, y: c.ur.y }, { x: c.ur.x, y: c.ll.y },
|
|
146
148
|
];
|
|
@@ -301,7 +303,7 @@ export class XdotRenderer extends EdgeDrawBase implements RendererPlugin {
|
|
|
301
303
|
if (draw) set.draw = draw;
|
|
302
304
|
// Cluster labels are stored via plain agxset (xdot_end_cluster:286), NOT
|
|
303
305
|
// put_escaping_backslashes like node/edge/graph labels — so NO escBackslash.
|
|
304
|
-
// The source `\"`/`\\` in the label survive as-is through
|
|
306
|
+
// The source `\"`/`\\` in the label survive as-is through agstrcanonText on
|
|
305
307
|
// serialize (drawAttr). @see gvrender_core_dot.c:286
|
|
306
308
|
if (ldraw) set.ldraw = ldraw;
|
|
307
309
|
}
|
|
@@ -9,10 +9,17 @@
|
|
|
9
9
|
* the same helper. A graph with no cluster edges keeps the usual order (attach
|
|
10
10
|
* after the write): nothing there can differ.
|
|
11
11
|
*
|
|
12
|
+
* Also the json cluster map: write_graph's top pass numbers the subgraphs and
|
|
13
|
+
* maps each cluster's name to its gid (label_subgs, insert), which is where a
|
|
14
|
+
* cluster node's gid comes from (lookup) and where a repeated cluster name is
|
|
15
|
+
* warned about.
|
|
16
|
+
*
|
|
12
17
|
* @see plugin/core/gvrender_core_json.c:json_begin_graph
|
|
18
|
+
* @see plugin/core/gvrender_core_json.c:write_graph
|
|
13
19
|
* @see lib/common/output.c:403 (if (HAS_CLUST_EDGE(g)) undoClusterEdges(g))
|
|
14
20
|
*/
|
|
15
21
|
|
|
22
|
+
import { agwarningf } from '../common/agerr.js';
|
|
16
23
|
import { undoRenderedClusterEdges } from '../gvc/layout-reset.js';
|
|
17
24
|
import { isACluster } from '../layout/dot/rank.js';
|
|
18
25
|
import type { Graph } from '../model/graph.js';
|
|
@@ -41,10 +48,40 @@ export function jsonNodes(g: Graph): Node[] {
|
|
|
41
48
|
}
|
|
42
49
|
|
|
43
50
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
51
|
+
* The gid mapped to cluster `name`, or -1 when there is none.
|
|
52
|
+
* @see plugin/core/gvrender_core_json.c:lookup
|
|
53
|
+
*/
|
|
54
|
+
export function lookupCluster(map: ReadonlyMap<string, number>, name: string): number {
|
|
55
|
+
return map.get(name) ?? -1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Maps cluster `name` to gid `v`. The first entry of a name is kept; a later
|
|
60
|
+
* one with another value is warned about and dropped.
|
|
61
|
+
* @see plugin/core/gvrender_core_json.c:insert
|
|
62
|
+
*/
|
|
63
|
+
export function insertCluster(map: Map<string, number>, name: string, v: number): void {
|
|
64
|
+
const ip = map.get(name);
|
|
65
|
+
if (ip !== undefined) {
|
|
66
|
+
if (ip !== v) agwarningf(`Duplicate cluster name "${name}"`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
map.set(name, v);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Numbers `g`'s subgraphs in DFS preorder from `lbl` (C's `GD_gid(g) = lbl++`;
|
|
74
|
+
* here a subgraph's gid is its index in `out`) and maps each cluster's name to
|
|
75
|
+
* its gid. Returns the next label: the subgraph count when called on the root
|
|
76
|
+
* with 0.
|
|
77
|
+
* @see plugin/core/gvrender_core_json.c:label_subgs
|
|
47
78
|
*/
|
|
48
|
-
export function
|
|
49
|
-
|
|
79
|
+
export function labelSubgs(g: Graph, lbl: number, map: Map<string, number>, out: Graph[]): number {
|
|
80
|
+
if (g !== g.root) {
|
|
81
|
+
const gid = lbl++;
|
|
82
|
+
out.push(g);
|
|
83
|
+
if (isACluster(g)) insertCluster(map, g.name, gid);
|
|
84
|
+
}
|
|
85
|
+
for (const [, sg] of g.subgraphs) lbl = labelSubgs(sg, lbl, map, out);
|
|
86
|
+
return lbl;
|
|
50
87
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
/**
|
|
3
|
+
* The json writers' serialization step. C prints every draw-op number with
|
|
4
|
+
* `%.03f`, and on the oracle platform (macOS libc) that prints a non-finite
|
|
5
|
+
* double as the bare token `inf`, `-inf` or `nan` (a negative NaN prints
|
|
6
|
+
* `nan` too). `JSON.stringify` would print `null`, so the tree is serialized
|
|
7
|
+
* with those tokens instead. A document that holds one is not valid JSON,
|
|
8
|
+
* exactly as native's is not; a tree with no non-finite number serializes
|
|
9
|
+
* byte for byte as `JSON.stringify(tree, null, 2)`.
|
|
10
|
+
* @see plugin/core/gvrender_core_json.c:write_polyline (%.03f)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const JSON_INDENT = 2;
|
|
14
|
+
|
|
15
|
+
const INF_TOKEN = 'inf';
|
|
16
|
+
const NEG_INF_TOKEN = '-inf';
|
|
17
|
+
const NAN_TOKEN = 'nan';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Brackets a token while it travels through JSON.stringify as a string. A C
|
|
21
|
+
* string cannot hold NUL, so no attribute value cgraph could store spells a
|
|
22
|
+
* bracketed token.
|
|
23
|
+
*/
|
|
24
|
+
const MARK = '\u0000';
|
|
25
|
+
/** MARK as JSON.stringify escapes it. */
|
|
26
|
+
const ESCAPED_MARK = JSON.stringify(MARK).slice(1, -1).replace(/\\/g, '\\\\');
|
|
27
|
+
/** A whole string value that is one bracketed token. */
|
|
28
|
+
const QUOTED_TOKEN = new RegExp(
|
|
29
|
+
`"${ESCAPED_MARK}(${INF_TOKEN}|${NEG_INF_TOKEN}|${NAN_TOKEN})${ESCAPED_MARK}"`, 'g',
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/** What C's `%.03f` prints for a non-finite double. */
|
|
33
|
+
function nonFiniteToken(v: number): string {
|
|
34
|
+
if (Number.isNaN(v)) return NAN_TOKEN;
|
|
35
|
+
return v > 0 ? INF_TOKEN : NEG_INF_TOKEN;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `JSON.stringify(tree, null, 2)`, except that a non-finite number prints as
|
|
40
|
+
* C's `%.03f` token.
|
|
41
|
+
* @see plugin/core/gvrender_core_json.c:write_polyline (%.03f)
|
|
42
|
+
*/
|
|
43
|
+
export function stringifyJsonTree(tree: unknown): string {
|
|
44
|
+
let sawNonFinite = false;
|
|
45
|
+
const text = JSON.stringify(tree, (_key, v: unknown) => {
|
|
46
|
+
if (typeof v !== 'number' || Number.isFinite(v)) return v;
|
|
47
|
+
sawNonFinite = true;
|
|
48
|
+
return `${MARK}${nonFiniteToken(v)}${MARK}`;
|
|
49
|
+
}, JSON_INDENT);
|
|
50
|
+
return sawNonFinite ? text.replace(QUOTED_TOKEN, '$1') : text;
|
|
51
|
+
}
|
package/src/render/json.ts
CHANGED
|
@@ -28,6 +28,8 @@
|
|
|
28
28
|
* conformance bar is the semantic `compare-json` comparator (±0.01, colors /
|
|
29
29
|
* fonts canonicalized). `stoj`/`ind` are retained as the C-faithful string
|
|
30
30
|
* helpers referenced by the unit tests.
|
|
31
|
+
* A non-finite draw coordinate prints as C's `%.03f` token (`inf`, `-inf`,
|
|
32
|
+
* `nan`), so such a document is not valid JSON, exactly as native's is not.
|
|
31
33
|
*
|
|
32
34
|
* @see plugin/core/gvrender_core_json.c
|
|
33
35
|
*/
|
|
@@ -41,15 +43,16 @@ import type { RendererPlugin } from '../gvc/context.js';
|
|
|
41
43
|
import type { RenderJob } from '../gvc/job.js';
|
|
42
44
|
import type { XdotOp, XdotColor } from '../xdot/types.js';
|
|
43
45
|
import type { TextlabelT, FieldT } from '../common/types.js';
|
|
44
|
-
import {
|
|
45
|
-
import { attachAttrs } from './dot/write-back.js';
|
|
46
|
-
import { attachBeforeWriteWithClusterEdges as attachFirst,
|
|
46
|
+
import { gfmt5, XdotRenderer, type XdotDraws } from './dot.js';
|
|
47
|
+
import { attachAttrs, nodeLayoutAttrs } from './dot/write-back.js';
|
|
48
|
+
import { attachBeforeWriteWithClusterEdges as attachFirst, jsonNodes, labelSubgs, lookupCluster } from './json-cluster-edge.js';
|
|
47
49
|
import { attrsWithoutLayoutBb } from '../gvc/layout-bb.js';
|
|
48
50
|
import { CHAR_LATIN1 } from '../common/graph-init.js';
|
|
49
51
|
import { parse } from '../parser/index.js';
|
|
50
52
|
import { render as deviceRender } from '../gvc/device.js';
|
|
51
53
|
import { createDefaultContext } from '../gvc/default-context.js';
|
|
52
54
|
import { parseXDot } from '../xdot/index.js';
|
|
55
|
+
import { stringifyJsonTree } from './json-nonfinite.js';
|
|
53
56
|
import { isHtmlValue, htmlValueContent } from '../common/html-string.js';
|
|
54
57
|
|
|
55
58
|
// ---------------------------------------------------------------------------
|
|
@@ -219,10 +222,10 @@ function canonicalRootEdges(g: Graph): Array<{ e: Edge; key: string }> {
|
|
|
219
222
|
const counter = new Map<string, number>();
|
|
220
223
|
for (const [, n] of g.nodes) {
|
|
221
224
|
for (const e of n.outEdges(g)) {
|
|
222
|
-
const base = e.tail.name + '
|
|
225
|
+
const base = e.tail.name + '\0' + e.head.name;
|
|
223
226
|
const occ = counter.get(base) ?? 0;
|
|
224
227
|
counter.set(base, occ + 1);
|
|
225
|
-
out.push({ e, key: base + '
|
|
228
|
+
out.push({ e, key: base + '\0' + occ });
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
231
|
return out;
|
|
@@ -310,7 +313,7 @@ interface BuildCtx {
|
|
|
310
313
|
subgGid: Map<Graph, number>;
|
|
311
314
|
nodeGid: Map<Node, number>;
|
|
312
315
|
edgeGid: Map<Edge, number>;
|
|
313
|
-
/**
|
|
316
|
+
/** The subgraphs below the rendered graph in DFS preorder (the flat top-level "objects" ordering). */
|
|
314
317
|
dfsSubs: Graph[];
|
|
315
318
|
/** True once any edge (or edge default) declares `label`: cgraph then carries
|
|
316
319
|
* a global `label` edge symbol, and write_attrs emits `label` (its value or
|
|
@@ -358,26 +361,19 @@ function isEdgeLabelDeclared(g: Graph): boolean {
|
|
|
358
361
|
return walk(g);
|
|
359
362
|
}
|
|
360
363
|
|
|
361
|
-
/** DFS preorder over the subgraph tree. @see label_subgs recursion order */
|
|
362
|
-
function dfsSubgraphs(g: Graph, out: Graph[]): void {
|
|
363
|
-
for (const [, sg] of g.subgraphs) {
|
|
364
|
-
out.push(sg);
|
|
365
|
-
dfsSubgraphs(sg, out);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
364
|
/** Assign every object its `_gvid`, mirroring write_graph's top-level pass:
|
|
370
365
|
* subgraphs DFS-preorder 0..sgcnt-1, then nodes sgcnt.., then edges 0.. in
|
|
371
366
|
* agfstnode/agfstout order. @see plugin/core/gvrender_core_json.c:write_graph */
|
|
372
367
|
function assignIds(g: Graph, doXDot: boolean, draws?: DrawLookup): BuildCtx {
|
|
373
368
|
const dfsSubs: Graph[] = [];
|
|
374
|
-
|
|
369
|
+
const clusters = new Map<string, number>();
|
|
370
|
+
const sgcnt = labelSubgs(g, 0, clusters, dfsSubs);
|
|
375
371
|
const subgGid = new Map<Graph, number>();
|
|
376
372
|
dfsSubs.forEach((sg, i) => subgGid.set(sg, i));
|
|
377
|
-
|
|
373
|
+
if (dfsSubs[0] === g) dfsSubs.shift(); // a subgraph render: label_subgs numbers g, write_subgs lists below it
|
|
378
374
|
const nodeGid = new Map<Node, number>();
|
|
379
375
|
let ncnt = 0;
|
|
380
|
-
for (const [, n] of g.nodes) nodeGid.set(n, n.info.clustnode ?
|
|
376
|
+
for (const [, n] of g.nodes) nodeGid.set(n, n.info.clustnode ? lookupCluster(clusters, n.name) : sgcnt + ncnt++);
|
|
381
377
|
const edgeGid = new Map<Edge, number>();
|
|
382
378
|
let ecnt = 0;
|
|
383
379
|
for (const { e } of canonicalRootEdges(g)) edgeGid.set(e, ecnt++);
|
|
@@ -397,9 +393,9 @@ function assignIds(g: Graph, doXDot: boolean, draws?: DrawLookup): BuildCtx {
|
|
|
397
393
|
* Emit an object's attributes into `o`, mirroring C's write_attrs: `agxget`
|
|
398
394
|
* returns HTML-string content with the marker stripped, empty non-`label`
|
|
399
395
|
* values are skipped, and xdot draw attrs are re-serialized as op arrays.
|
|
400
|
-
* `base`
|
|
401
|
-
*
|
|
402
|
-
* on conflict.
|
|
396
|
+
* `base` is the object's own attrs: user/inherited values and the draw strings the input or an
|
|
397
|
+
* earlier render stored, which an object this render does not draw prints as agxget would.
|
|
398
|
+
* `overlay` (the xdot re-render: `pos`/`width`/`height`/`bb`/draw strings) wins on conflict.
|
|
403
399
|
*/
|
|
404
400
|
function emitAttrs(
|
|
405
401
|
o: JObj,
|
|
@@ -522,11 +518,10 @@ function buildNodeObject(n: Node, ctx: BuildCtx): JObj {
|
|
|
522
518
|
const eff = nodeEffectiveAttrs(n);
|
|
523
519
|
const xd = ctx.draws?.node.get(n.name);
|
|
524
520
|
if (xd === undefined) {
|
|
525
|
-
// Fallback (json0 / hand-built graph):
|
|
526
|
-
//
|
|
527
|
-
|
|
528
|
-
eff.set('
|
|
529
|
-
eff.set('height', printNum(n.info.height));
|
|
521
|
+
// Fallback (json0 / hand-built graph): no xdot render supplies the layout
|
|
522
|
+
// attrs, so take the strings attach_attrs writes (output.c:296-309).
|
|
523
|
+
const layout = nodeLayoutAttrs(n);
|
|
524
|
+
eff.set('pos', layout.pos).set('width', layout.width).set('height', layout.height);
|
|
530
525
|
}
|
|
531
526
|
emitAttrs(o, eff, xd, ctx);
|
|
532
527
|
attachNodeRects(o, n);
|
|
@@ -653,13 +648,15 @@ function latin1Reencode(s: string): string {
|
|
|
653
648
|
export function buildJson(g: Graph, doXDot: boolean, preDraws?: DrawLookup): string {
|
|
654
649
|
const draws = doXDot ? (preDraws ?? collectDrawLookup(g)) : undefined;
|
|
655
650
|
const ctx = assignIds(g, doXDot, draws);
|
|
656
|
-
return
|
|
651
|
+
return stringifyJsonTree(buildGraphObject(g, true, ctx)) + '\n';
|
|
657
652
|
}
|
|
658
653
|
|
|
659
654
|
/** Everything the JSON writers leave to the graph walk: they write once, at the end. */
|
|
660
655
|
abstract class JsonRendererBase {
|
|
661
656
|
/** @see plugin/core/gvplugin_core.c registration table */
|
|
662
657
|
readonly quality = 0;
|
|
658
|
+
/** @see plugin/core/gvrender_core_json.c:745 render_features_json (default pad) */
|
|
659
|
+
readonly defaultPad = 0;
|
|
663
660
|
beginNode(_n: Node, _job: RenderJob): void { /* no-op */ }
|
|
664
661
|
endNode(_n: Node, _job: RenderJob): void { /* no-op */ }
|
|
665
662
|
beginEdge(_e: Edge, _job: RenderJob): void { /* no-op */ }
|
package/src/render/map.ts
CHANGED
|
@@ -540,6 +540,7 @@ export function mapOutputImap(
|
|
|
540
540
|
export class PlainRenderer implements RendererPlugin {
|
|
541
541
|
readonly type = 'plain';
|
|
542
542
|
readonly quality = 0;
|
|
543
|
+
readonly defaultPad = 0; // @see plugin/core/gvrender_core_dot.c:734 render_features_dot
|
|
543
544
|
|
|
544
545
|
beginGraph(_g: Graph, _job: RenderJob): void { /* no-op */ }
|
|
545
546
|
endGraph(g: Graph, job: RenderJob): void { writePlain(g, job, false); }
|
|
@@ -562,6 +563,7 @@ export class PlainRenderer implements RendererPlugin {
|
|
|
562
563
|
export class PlainExtRenderer implements RendererPlugin {
|
|
563
564
|
readonly type = 'plain-ext';
|
|
564
565
|
readonly quality = 0;
|
|
566
|
+
readonly defaultPad = 0; // @see plugin/core/gvrender_core_dot.c:734 render_features_dot
|
|
565
567
|
|
|
566
568
|
beginGraph(_g: Graph, _job: RenderJob): void { /* no-op */ }
|
|
567
569
|
endGraph(g: Graph, job: RenderJob): void { writePlain(g, job, true); }
|
|
@@ -637,6 +639,7 @@ function anchorOf(url: string | null, tooltip: string | null, target: string | n
|
|
|
637
639
|
abstract class MapRendererBase implements RendererPlugin {
|
|
638
640
|
abstract readonly type: string;
|
|
639
641
|
readonly quality = 0;
|
|
642
|
+
readonly defaultPad = 4; // @see plugin/core/gvrender_core_map.c:244 render_features_map
|
|
640
643
|
protected abstract readonly isCmapx: boolean;
|
|
641
644
|
protected abstract readonly mapPolygon: boolean;
|
|
642
645
|
private mapCtx: MapCtx | null = null;
|
package/src/render/svg-graph.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { createObjState, ObjType } from '../gvc/job.js';
|
|
|
18
18
|
import { FillType } from '../gvc/context.js';
|
|
19
19
|
import { escapeXml, escapeXmlTitle, svgComment } from './svg-helpers.js';
|
|
20
20
|
import { resolveRenderColor, colorPaint } from './color-resolve.js';
|
|
21
|
-
import { svgGraphClass } from './svg-id.js';
|
|
21
|
+
import { svgGraphClass, svgGraphId } from './svg-id.js';
|
|
22
22
|
import { parseGradientSpec } from '../common/htmltable-emit-fill.js';
|
|
23
23
|
import { findStopColor, parseStyleFlags } from '../common/style-resolve.js';
|
|
24
24
|
import { croundNarrow32 } from '../common/arith.js';
|
|
@@ -232,18 +232,6 @@ function bgGradientPts(clip: Box): Point[] {
|
|
|
232
232
|
];
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
/**
|
|
236
|
-
* Object id of the graph being emitted, as getObjId builds it for an AGRAPH:
|
|
237
|
-
* the DOT `id` attr wins; else "graph" + AGSEQ. The graph being emitted is
|
|
238
|
-
* job->gvc->g, i.e. `root == obj`, so neither the `<gid>_` prefix nor the
|
|
239
|
-
* "clust" prefix applies. The root's AGSEQ is 0; a subgraph rendered after
|
|
240
|
-
* its own layout carries its creation sequence among subgraphs.
|
|
241
|
-
* @see lib/common/emit.c:getObjId
|
|
242
|
-
*/
|
|
243
|
-
function graphObjId(g: Graph, job: RenderJob): string {
|
|
244
|
-
return job.objId(g.attrs.get('id'), 'graph' + g.seq, true);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
235
|
/**
|
|
248
236
|
* Write background polygon element with gradient fill url reference.
|
|
249
237
|
* Coords identical to emitGraphBackground; only fill changes.
|
|
@@ -281,7 +269,7 @@ function writeGradientPolygon(clip: Box, id: string, job: RenderJob): void {
|
|
|
281
269
|
*/
|
|
282
270
|
function emitGradientBackground(g: Graph, clip: Box, spec: BgGradientSpec, job: RenderJob): void {
|
|
283
271
|
const obj = createObjState(ObjType.RootGraph);
|
|
284
|
-
obj.id =
|
|
272
|
+
obj.id = svgGraphId(g, job);
|
|
285
273
|
obj.fillColor = resolveRenderColor(spec.fillColor);
|
|
286
274
|
obj.stopColor = resolveRenderColor(spec.stopColor);
|
|
287
275
|
obj.gradientFrac = spec.frac;
|
|
@@ -421,7 +409,7 @@ export function svgBeginPage(g: Graph, job: RenderJob): void {
|
|
|
421
409
|
: -clip.ll.x + job.margin.x / z;
|
|
422
410
|
const ty = clip.ur.y + job.margin.y / z;
|
|
423
411
|
emitGraphGroupOpen(
|
|
424
|
-
job.idLayerPrefix() +
|
|
412
|
+
job.idLayerPrefix() + svgGraphId(g, job),
|
|
425
413
|
svgGraphClass(g),
|
|
426
414
|
tx, ty, job,
|
|
427
415
|
);
|
package/src/render/svg-id.ts
CHANGED
|
@@ -50,9 +50,18 @@ export function svgClusterId(sg: Graph, job: RenderJob): string {
|
|
|
50
50
|
return job.objId(sg.attrs.get('id'), 'clust' + sg.seq);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Object id of the graph being emitted, as getObjId builds it for an AGRAPH:
|
|
55
|
+
* the DOT `id` attr wins; else `graph<AGSEQ>`. The graph being emitted is
|
|
56
|
+
* job->gvc->g, i.e. `root == obj`, so neither the `<gid>_` prefix nor the
|
|
57
|
+
* "clust" prefix applies. The root's AGSEQ is 0; a subgraph rendered after
|
|
58
|
+
* its own layout carries its creation sequence among subgraphs. It names the
|
|
59
|
+
* top group, the gradients, the graph anchor and map area (obj->id) and the
|
|
60
|
+
* base of the graph label's HTML anchor ids.
|
|
61
|
+
* @see lib/common/emit.c:getObjId
|
|
62
|
+
*/
|
|
54
63
|
export function svgGraphId(g: Graph, job: RenderJob): string {
|
|
55
|
-
return job.objId(g.attrs.get('id'), '
|
|
64
|
+
return job.objId(g.attrs.get('id'), 'graph' + g.seq, true);
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
/** `class="node[ <class>]"`, reading the inherited DOT `class` attribute. */
|
package/src/render/svg.ts
CHANGED
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
emitParallelEdgePaths,
|
|
54
54
|
escapeXml,
|
|
55
55
|
emitPoints,
|
|
56
|
+
SVG_PAD,
|
|
56
57
|
} from './svg-helpers.js';
|
|
57
58
|
import { emitArrowOps } from './svg-arrow-ops.js';
|
|
58
59
|
import { resolveRenderColor, colorOpacity, colorPaint } from './color-resolve.js';
|
|
@@ -93,6 +94,8 @@ export class SvgRenderer implements RendererPlugin {
|
|
|
93
94
|
readonly type = 'svg';
|
|
94
95
|
/** @see plugin/core/gvplugin_core.c registration table */
|
|
95
96
|
readonly quality = 0;
|
|
97
|
+
/** @see plugin/core/gvrender_core_svg.c:810 render_features_svg (default pad) */
|
|
98
|
+
readonly defaultPad = SVG_PAD;
|
|
96
99
|
/** Whether the current edge's <g> group was opened (deferred-emit state). */
|
|
97
100
|
private edgeGroupOpen = false;
|
|
98
101
|
|
|
@@ -116,7 +119,7 @@ export class SvgRenderer implements RendererPlugin {
|
|
|
116
119
|
/**
|
|
117
120
|
* Close the edge group. Edge graphics (path + arrowhead) are emitted here
|
|
118
121
|
* because the full spline is available on e.info.spl only after layout has
|
|
119
|
-
*
|
|
122
|
+
* routed the edges.
|
|
120
123
|
*
|
|
121
124
|
* For multi-color edges (color="c1:c2:…"), emits parallel offset Béziers
|
|
122
125
|
* (one per color, SEP=2.0 apart) then arrows in headcolor/tailcolor.
|
package/src/util/bsd-qsort.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* (`lib/util/list.c:gv_list_sort_`). libc `qsort` is **not stable**: it reorders
|
|
9
9
|
* comparator-equal elements in an implementation-defined permutation. Most port
|
|
10
10
|
* sort sites can use JS's stable `Array.prototype.sort` because their comparator
|
|
11
|
-
* never reports a tie (e.g. `
|
|
11
|
+
* never reports a tie (e.g. `routeCurvedGroup`'s sort of distinct originals by
|
|
12
|
+
* creation seq, `splines-groups.ts`). Where ties DO occur AND the
|
|
12
13
|
* downstream result depends on their order, a stable sort diverges from the C
|
|
13
14
|
* oracle.
|
|
14
15
|
*
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
/**
|
|
3
|
+
* Overflow-checked arithmetic helpers.
|
|
4
|
+
*
|
|
5
|
+
* @see lib/util/overflow.h
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// C's INT_MAX / INT_MIN for a 32-bit int.
|
|
9
|
+
const INT_MAX = 2_147_483_647;
|
|
10
|
+
const INT_MIN = -2_147_483_648;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Add two integers, clamping to lower and upper type bounds.
|
|
14
|
+
*
|
|
15
|
+
* Returns the sum `a + b`, or `INT_MAX`/`INT_MIN` on overflow/underflow. C's
|
|
16
|
+
* operands are `int`; the port applies the same three branches to its numbers
|
|
17
|
+
* as they are, with no int32 wrap of the inputs.
|
|
18
|
+
* @see lib/util/overflow.h:sadd_saturate
|
|
19
|
+
*/
|
|
20
|
+
export function saddSaturate(a: number, b: number): number {
|
|
21
|
+
// overflow?
|
|
22
|
+
if (b > 0 && INT_MAX - b < a) {
|
|
23
|
+
return INT_MAX;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// underflow?
|
|
27
|
+
if (b < 0 && INT_MIN - b > a) {
|
|
28
|
+
return INT_MIN;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return a + b;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Divide two double floating-point values, checking for overflow.
|
|
36
|
+
*
|
|
37
|
+
* Returns the quotient `n / d`, or `null` where C returns `true` and leaves
|
|
38
|
+
* `*res` as it was: the quotient is not finite (a zero or subnormal divisor,
|
|
39
|
+
* a non-finite operand, or a result past `DBL_MAX`). A call site writes C's
|
|
40
|
+
* "assign the fallback, then overwrite on success" as `fdivOverflow(n, d) ??
|
|
41
|
+
* fallback`; a zero quotient is a result, and `??` keeps it.
|
|
42
|
+
* @see lib/util/overflow.h:fdiv_overflow
|
|
43
|
+
*/
|
|
44
|
+
export function fdivOverflow(n: number, d: number): number | null {
|
|
45
|
+
const r = n / d;
|
|
46
|
+
|
|
47
|
+
// did we overflow?
|
|
48
|
+
if (!Number.isFinite(r)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return r;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Divide two floating-point values, checking for overflow.
|
|
57
|
+
*
|
|
58
|
+
* The `float` twin of {@link fdivOverflow}. C's parameters and quotient are
|
|
59
|
+
* `float`, so the operands and the quotient are rounded to float32: a
|
|
60
|
+
* quotient past `FLT_MAX` is an overflow here though it is finite as a
|
|
61
|
+
* double. Dividing two float32 values in double and rounding once gives
|
|
62
|
+
* IEEE single division's result (53 >= 2 * 24 + 2 bits).
|
|
63
|
+
* @see lib/util/overflow.h:fdivf_overflow
|
|
64
|
+
*/
|
|
65
|
+
export function fdivfOverflow(n: number, d: number): number | null {
|
|
66
|
+
const r = Math.fround(Math.fround(n) / Math.fround(d));
|
|
67
|
+
|
|
68
|
+
// did we overflow?
|
|
69
|
+
if (!Number.isFinite(r)) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return r;
|
|
74
|
+
}
|
package/src/xdot/parse.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
XdotRadialGrad, XdotColorStop, OpFunctions,
|
|
13
13
|
} from "./types.js";
|
|
14
14
|
import { XDOT_PARSE_ERROR } from "./types.js";
|
|
15
|
+
import { isSpace, scanStrtod } from "./strtod.js";
|
|
15
16
|
|
|
16
17
|
/** ULONG_MAX on an LP64 target: strtoul saturation value. */
|
|
17
18
|
const ULONG_MAX = 0xffff_ffff_ffff_ffffn;
|
|
@@ -21,8 +22,9 @@ type OpResult = { op: XdotOp; pos: number } | "error";
|
|
|
21
22
|
type OpMaybeResult = OpResult | null;
|
|
22
23
|
|
|
23
24
|
class XdotParser {
|
|
25
|
+
/** @see lib/util/gv_ctype.h:gv_isspace */
|
|
24
26
|
static isWs(c: string): boolean {
|
|
25
|
-
return c
|
|
27
|
+
return isSpace(c);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
static skipWs(s: string, pos: number): number {
|
|
@@ -35,25 +37,13 @@ class XdotParser {
|
|
|
35
37
|
return i;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return i;
|
|
45
|
-
}
|
|
46
|
-
|
|
40
|
+
/**
|
|
41
|
+
* C reads every xdot double with strtod, so a number may be a decimal, a
|
|
42
|
+
* hex float, inf/infinity or nan/nan(...); null is C's `p == s`.
|
|
43
|
+
* @see lib/xdot/xdot.c:parseReal
|
|
44
|
+
*/
|
|
47
45
|
static parseReal(s: string, pos: number): PR<number> {
|
|
48
|
-
|
|
49
|
-
const start = i;
|
|
50
|
-
if (i < s.length && (s[i] === "-" || s[i] === "+")) i++;
|
|
51
|
-
const digStart = i;
|
|
52
|
-
i = XdotParser.consumeDigits(s, i);
|
|
53
|
-
if (i < s.length && s[i] === ".") { i++; i = XdotParser.consumeDigits(s, i); }
|
|
54
|
-
i = XdotParser.consumeExponent(s, i);
|
|
55
|
-
if (i === start || i === digStart) return null;
|
|
56
|
-
return { val: parseFloat(s.slice(start, i)), pos: i };
|
|
46
|
+
return scanStrtod(s, pos);
|
|
57
47
|
}
|
|
58
48
|
|
|
59
49
|
static parseInt_(s: string, pos: number): PR<number> {
|