@knowvah/dot-engine 2.0.0 → 2.0.2
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/async/collect.d.ts.map +1 -1
- package/dist/async/render-async.d.ts.map +1 -1
- package/dist/gvc/device-labels.d.ts +30 -0
- package/dist/gvc/device-labels.d.ts.map +1 -0
- package/dist/gvc/device-transform.d.ts +22 -0
- package/dist/gvc/device-transform.d.ts.map +1 -0
- package/dist/gvc/device.d.ts +2 -42
- package/dist/gvc/device.d.ts.map +1 -1
- package/dist/index.js +174 -137
- package/dist/index.js.map +4 -4
- package/dist/layout/dot/graph-label.d.ts +10 -0
- package/dist/layout/dot/graph-label.d.ts.map +1 -1
- package/dist/layout/fdp/normalize.d.ts +2 -1
- package/dist/layout/fdp/normalize.d.ts.map +1 -1
- package/dist/layout/fdp/xlayout.d.ts +1 -1
- package/dist/layout/fdp/xlayout.d.ts.map +1 -1
- package/dist/layout/neato/dijkstra.d.ts +0 -32
- package/dist/layout/neato/dijkstra.d.ts.map +1 -1
- package/dist/layout/neato/fdp-adjust.d.ts +14 -3
- package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
- package/dist/layout/neato/index.d.ts +5 -5
- package/dist/layout/neato/index.d.ts.map +1 -1
- package/dist/layout/neato/sc-adjust.d.ts +2 -9
- package/dist/layout/neato/sc-adjust.d.ts.map +1 -1
- package/dist/layout/neato/simple-scale.d.ts +15 -0
- package/dist/layout/neato/simple-scale.d.ts.map +1 -0
- package/dist/layout/sfdp/index.d.ts.map +1 -1
- package/dist/render/public.d.ts +5 -0
- package/dist/render/public.d.ts.map +1 -1
- package/dist/render.js +171 -134
- package/dist/render.js.map +4 -4
- package/package.json +1 -1
- package/src/async/collect.ts +2 -14
- package/src/async/render-async.ts +1 -9
- package/src/gvc/device-labels.ts +98 -0
- package/src/gvc/device-transform.ts +58 -0
- package/src/gvc/device.ts +8 -132
- package/src/layout/dot/graph-label.ts +6 -1
- package/src/layout/fdp/normalize.ts +12 -8
- package/src/layout/fdp/xlayout.ts +8 -6
- package/src/layout/neato/dijkstra.ts +0 -141
- package/src/layout/neato/fdp-adjust.ts +33 -8
- package/src/layout/neato/index.ts +13 -12
- package/src/layout/neato/sc-adjust.ts +2 -16
- package/src/layout/neato/simple-scale.ts +54 -0
- package/src/layout/sfdp/index.ts +2 -1
- package/src/render/public.ts +6 -5
- package/dist/layout/neato/overlap.d.ts +0 -85
- package/dist/layout/neato/overlap.d.ts.map +0 -1
- package/src/layout/neato/overlap.ts +0 -158
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knowvah/dot-engine",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Faithful TypeScript port of Graphviz (dot, neato, fdp, sfdp, circo, twopi, osage, patchwork) — no C: no native binary, no WASM. Oracle-verified against the C implementation, runs in the browser.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphviz",
|
package/src/async/collect.ts
CHANGED
|
@@ -19,12 +19,12 @@ import type { Edge } from '../model/edge.js';
|
|
|
19
19
|
import type { Node } from '../model/node.js';
|
|
20
20
|
import type { TextVariantFlags } from '../common/textmeasure.js';
|
|
21
21
|
import { canvasFont } from '../common/css-font.js';
|
|
22
|
-
import { DEFAULT_FONTNAME, DEFAULT_FONTSIZE } from '../common/make-label.js';
|
|
23
22
|
import { isHtmlValue, htmlValueContent } from '../common/html-string.js';
|
|
24
23
|
import { nodeAttr, readFontAttrs } from '../common/poly-init.js';
|
|
25
24
|
import { initFontEdgeAttr, initFontLabelEdgeAttr } from '../common/edge-label-init.js';
|
|
26
25
|
import { parseHtmlLabel } from '../common/htmltable-parse.js';
|
|
27
26
|
import { isACluster } from '../layout/dot/rank.js';
|
|
27
|
+
import { readFontParams } from '../layout/dot/graph-label.js';
|
|
28
28
|
import type {
|
|
29
29
|
HtmlCellContent, HtmlLabel, HtmlTable, HtmlTextItem,
|
|
30
30
|
} from '../common/htmltable-types.js';
|
|
@@ -160,21 +160,9 @@ function collectEdge(acc: Acc, e: Edge): void {
|
|
|
160
160
|
addLabel(acc, e.attrs.get('taillabel'), lfi);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
/**
|
|
164
|
-
* Root/cluster label font. A subgraph reads through its parse-time defaults
|
|
165
|
-
* snapshot, as doGraphLabel does. @see src/layout/dot/graph-label.ts:readFontParams
|
|
166
|
-
*/
|
|
167
|
-
function graphLabelFont(sg: Graph): LabelFont {
|
|
168
|
-
const get = (k: string): string | undefined => sg.attrs.get(k) ?? sg.graphDefaultsSnapshot?.get(k);
|
|
169
|
-
return {
|
|
170
|
-
fontname: get('fontname') ?? DEFAULT_FONTNAME,
|
|
171
|
-
fontsize: parseFloat(get('fontsize') ?? '') || DEFAULT_FONTSIZE,
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
163
|
function collectGraphLabels(acc: Acc, sg: Graph, root: Graph): void {
|
|
176
164
|
if (isACluster(sg)) {
|
|
177
|
-
addLabel(acc, sg.attrs.get('label') ?? sg.graphDefaultsSnapshot?.get('label'),
|
|
165
|
+
addLabel(acc, sg.attrs.get('label') ?? sg.graphDefaultsSnapshot?.get('label'), readFontParams(sg));
|
|
178
166
|
}
|
|
179
167
|
for (const child of sg.subgraphs.values()) collectGraphLabels(acc, child, root);
|
|
180
168
|
}
|
|
@@ -16,6 +16,7 @@ import { parse } from '../parser/index.js';
|
|
|
16
16
|
import { invalidArgType, rethrowAtBoundary } from '../errors.js';
|
|
17
17
|
import type { EngineName } from '../gvc/context.js';
|
|
18
18
|
import { createDefaultContext } from '../gvc/default-context.js';
|
|
19
|
+
import { checkRenderArgs } from '../render/public.js';
|
|
19
20
|
import { render as deviceRender } from '../gvc/device.js';
|
|
20
21
|
import type { ImageSizer } from '../common/htmltable-types.js';
|
|
21
22
|
import type { ImageResolver } from '../gvc/image-resolver.js';
|
|
@@ -62,15 +63,6 @@ export interface AsyncSvgResult {
|
|
|
62
63
|
fontIssues: FontIssue[];
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
/** Reject a bad `g` / `format` / `opts` before any work starts (mirrors `render`). */
|
|
66
|
-
function checkRenderArgs(g: unknown, format: unknown, opts: unknown): void {
|
|
67
|
-
if (typeof g !== 'object' || g === null) throw invalidArgType('g', 'object', g);
|
|
68
|
-
if (typeof format !== 'string') throw invalidArgType('format', 'string', format);
|
|
69
|
-
if (opts !== undefined && (typeof opts !== 'object' || opts === null)) {
|
|
70
|
-
throw invalidArgType('opts', 'object or undefined', opts);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
66
|
/** `document.fonts` when a document exposes one (absent in Node and Workers). */
|
|
75
67
|
function defaultFontSet(): FontSetLike | undefined {
|
|
76
68
|
const doc: unknown = Reflect.get(globalThis, 'document');
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Label emission shared by edge labels, node xlabels and cluster/graph
|
|
5
|
+
* labels (split from device.ts for the file-size cap; re-exported there).
|
|
6
|
+
*
|
|
7
|
+
* @see lib/common/labels.c:emit_label
|
|
8
|
+
* @see lib/common/emit.c:emit_label
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Graph } from '../model/graph.js';
|
|
12
|
+
import type { Node } from '../model/node.js';
|
|
13
|
+
import type { RendererPlugin } from './context.js';
|
|
14
|
+
import type { RenderJob } from './job.js';
|
|
15
|
+
import type { TextlabelT } from '../common/types.js';
|
|
16
|
+
import type { TextSpan } from '../common/emit-types.js';
|
|
17
|
+
import type { PlacedHtml } from '../common/htmltable-pos.js';
|
|
18
|
+
import { gvrenderTextspan, withLabelEmitState } from './textspan-emit.js';
|
|
19
|
+
import { emitHtmlLabel } from '../common/htmltable-emit.js';
|
|
20
|
+
|
|
21
|
+
/** valign codes stored on textlabel_t. @see lib/common/types.h:textlabel_t.valign */
|
|
22
|
+
const VALIGN_TOP = 't'.charCodeAt(0);
|
|
23
|
+
const VALIGN_BOTTOM = 'b'.charCodeAt(0);
|
|
24
|
+
|
|
25
|
+
/** First-span baseline y per valign. @see lib/common/labels.c:emit_label (240-251) */
|
|
26
|
+
function labelFirstSpanY(lp: TextlabelT): number {
|
|
27
|
+
if (lp.valign === VALIGN_TOP) return lp.pos.y + lp.space.y / 2.0 - lp.fontsize;
|
|
28
|
+
if (lp.valign === VALIGN_BOTTOM) {
|
|
29
|
+
return lp.pos.y - lp.space.y / 2.0 + lp.dimen.y - lp.fontsize;
|
|
30
|
+
}
|
|
31
|
+
return lp.pos.y + lp.dimen.y / 2.0 - lp.fontsize;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Span x position per justification. @see lib/common/labels.c:emit_label (254-266) */
|
|
35
|
+
function labelSpanX(lp: TextlabelT, just: 'l' | 'n' | 'r'): number {
|
|
36
|
+
if (just === 'l') return lp.pos.x - lp.space.x / 2.0;
|
|
37
|
+
if (just === 'r') return lp.pos.x + lp.space.x / 2.0;
|
|
38
|
+
return lp.pos.x;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Emit one label's text spans if present and placed.
|
|
43
|
+
* Shared by edge-label, node-xlabel, and graph-label slots.
|
|
44
|
+
* URL/anchor/map machinery and E_decorate attachment (emit.c:emit_attachment)
|
|
45
|
+
* are not ported, matching the live path's AD-2 scope.
|
|
46
|
+
* @see lib/common/emit.c:emit_label
|
|
47
|
+
* @see lib/common/labels.c:emit_label
|
|
48
|
+
*/
|
|
49
|
+
export function renderOneLabel(
|
|
50
|
+
lp: TextlabelT | undefined,
|
|
51
|
+
renderer: RendererPlugin,
|
|
52
|
+
job: RenderJob,
|
|
53
|
+
requireSet = true,
|
|
54
|
+
): void {
|
|
55
|
+
// C gates `->set` at the xlabel/edge-label CALL SITES (emit.c:1829,
|
|
56
|
+
// emit_edge_label:2891), but draws root-graph and cluster labels on
|
|
57
|
+
// existence alone (emit.c:3656, 3920) — an unplaced label (e.g. fdp's
|
|
58
|
+
// non-comparable-clusters abort skips gv_postprocess) still renders at its
|
|
59
|
+
// default pos. Callers mirroring the existence-only sites pass false.
|
|
60
|
+
if (!lp) return;
|
|
61
|
+
if (requireSet && !lp.set) return;
|
|
62
|
+
// HTML branch: @see lib/common/labels.c:emit_label (226-230)
|
|
63
|
+
// C routes to emit_html_label(job, lp->u.html, lp) using lp->pos as anchor.
|
|
64
|
+
if (lp.html) {
|
|
65
|
+
if (lp.u.kind === 'html') {
|
|
66
|
+
// Route the whole HTML label (table box/fill polygons + text) into the
|
|
67
|
+
// object's LABEL emit-state so its ops land in _ldraw_, not _draw_.
|
|
68
|
+
const html = lp.u.html as PlacedHtml;
|
|
69
|
+
const pos = lp.pos;
|
|
70
|
+
withLabelEmitState(job, () => emitHtmlLabel(html, pos, renderer, job));
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (lp.u.kind !== 'txt' || lp.u.nspans < 1) return;
|
|
75
|
+
let y = labelFirstSpanY(lp);
|
|
76
|
+
for (let i = 0; i < lp.u.nspans; i++) {
|
|
77
|
+
const span = lp.u.span[i] as TextSpan | undefined;
|
|
78
|
+
if (!span) break;
|
|
79
|
+
// Emit only visible spans; the baseline still advances below so blank
|
|
80
|
+
// lines reserve vertical space. @see gvrender_textspan (gvrender.c:419).
|
|
81
|
+
gvrenderTextspan(renderer, { x: labelSpanX(lp, span.just), y }, span, job);
|
|
82
|
+
y -= span.size.y; // UL position for next span (unconditional)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Emit node external label (ND_xlabel) if placed.
|
|
88
|
+
* Must run inside the node group, after codefn (shape draw), matching C order.
|
|
89
|
+
* @see lib/common/emit.c:emit_node (1829-1830)
|
|
90
|
+
*/
|
|
91
|
+
export function renderNodeXLabel(n: Node, renderer: RendererPlugin, job: RenderJob): void {
|
|
92
|
+
renderOneLabel(n.info.xlabel as TextlabelT | undefined, renderer, job);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Cluster labels go through the single emit_label port. @see labels.c:emit_label */
|
|
96
|
+
export function renderClusterLabel(sg: Graph, renderer: RendererPlugin, job: RenderJob): void {
|
|
97
|
+
renderOneLabel(sg.info.label as TextlabelT | undefined, renderer, job, false);
|
|
98
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// SPDX-License-Identifier: EPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Graph-to-device point transform (split from device.ts for the file-size
|
|
5
|
+
* cap; re-exported there).
|
|
6
|
+
*
|
|
7
|
+
* @see lib/gvc/gvrender.c:gvrender_ptf
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Point } from '../model/geom.js';
|
|
11
|
+
import { type RenderJob, GVRENDER_DOES_TRANSFORM } from './job.js';
|
|
12
|
+
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
// transformPoint — @see lib/gvc/gvrender.c:gvrender_ptf
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Transform a point from graph to device coordinates.
|
|
19
|
+
* Short-circuits when GVRENDER_DOES_TRANSFORM is set (renderer owns mapping).
|
|
20
|
+
*
|
|
21
|
+
* @see lib/gvc/gvrender.c:gvrender_ptf
|
|
22
|
+
*/
|
|
23
|
+
export function transformPoint(p: Point, job: RenderJob): Point {
|
|
24
|
+
if ((job.flags & GVRENDER_DOES_TRANSFORM) !== 0) {
|
|
25
|
+
return p;
|
|
26
|
+
}
|
|
27
|
+
const sx = job.zoom * job.devscale.x;
|
|
28
|
+
const sy = job.zoom * job.devscale.y;
|
|
29
|
+
const tx = job.translation.x;
|
|
30
|
+
const ty = job.translation.y;
|
|
31
|
+
// ADR-2: SVG landscape rotation lives entirely in the graph `<g>` group
|
|
32
|
+
// transform (svg_begin_page emits rotate(-job->rotation)); inner coords stay
|
|
33
|
+
// in the unrotated frame. The ptf rotation branch (applyRotation) is the
|
|
34
|
+
// raster/imagemap path and must NOT fire here, else job.rotation=90 would
|
|
35
|
+
// double-rotate every SVG coordinate. applyRotation stays exported as the
|
|
36
|
+
// faithful gvrender_ptf port (currently dead). @see ADR-2; gvrender.c:gvrender_ptf
|
|
37
|
+
return applyScale(p, tx, ty, sx, sy);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Rotation branch: out.x = -(p.y+ty)*sx, out.y = (p.x+tx)*sy @see gvrender_ptf */
|
|
41
|
+
export function applyRotation(p: Point, tx: number, ty: number, sx: number, sy: number): Point {
|
|
42
|
+
const x = -(p.y + ty) * sx;
|
|
43
|
+
const y = (p.x + tx) * sy;
|
|
44
|
+
return buildPoint(x, y);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** No-rotation branch: out.x = (p.x+tx)*sx, out.y = (p.y+ty)*sy @see gvrender_ptf */
|
|
48
|
+
export function applyScale(p: Point, tx: number, ty: number, sx: number, sy: number): Point {
|
|
49
|
+
const x = (p.x + tx) * sx;
|
|
50
|
+
const y = (p.y + ty) * sy;
|
|
51
|
+
return buildPoint(x, y);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Construct a Point value. Extracted to avoid inline object literals in return position. */
|
|
55
|
+
export function buildPoint(x: number, y: number): Point {
|
|
56
|
+
const pt: Point = { x, y };
|
|
57
|
+
return pt;
|
|
58
|
+
}
|
package/src/gvc/device.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: EPL-2.0
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Device render loop
|
|
4
|
+
* Device render loop (point transform: device-transform.ts; label emission:
|
|
5
|
+
* device-labels.ts).
|
|
5
6
|
*
|
|
6
7
|
* Ports gvrender_ptf, gvrender_begin_graph, and gvrender_end_graph from
|
|
7
8
|
* lib/gvc/gvrender.c. render() is the top-level entry point; it lives here
|
|
@@ -11,7 +12,7 @@
|
|
|
11
12
|
* @see lib/gvc/gvdevice.c
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
|
-
import type {
|
|
15
|
+
import type { Box } from '../model/geom.js';
|
|
15
16
|
import { boxOverlap, POINTS_PER_INCH } from '../model/geom.js';
|
|
16
17
|
import { lateDouble } from '../common/nodeinit.js';
|
|
17
18
|
import { parseDrawingSize, initJobViewportZoom, parseLandscape, parseGraphPad, parseGraphMargin } from './viewport.js';
|
|
@@ -21,22 +22,18 @@ import type { Edge } from '../model/edge.js';
|
|
|
21
22
|
import type { RendererPlugin } from './context.js';
|
|
22
23
|
import { GvcContext, PenType } from './context.js';
|
|
23
24
|
import { invalidArgType } from '../errors.js';
|
|
24
|
-
import { gvrenderTextspan, withLabelEmitState } from './textspan-emit.js';
|
|
25
25
|
import { resolveEdgeAnchor, resolveObjAnchor, beginAnchorIf } from './anchor.js';
|
|
26
26
|
import type { ShapeDesc, TextlabelT } from '../common/types.js';
|
|
27
|
-
import type { TextSpan } from '../common/emit-types.js';
|
|
28
27
|
import { type LayerInfo, parseLayers } from '../common/layers.js';
|
|
29
|
-
import { RenderJob,
|
|
28
|
+
import { RenderJob, EMIT_CLUSTERS_LAST, createObjState, ObjType, EmitState } from './job.js';
|
|
30
29
|
import { walkNodesAndEdges } from './emit-walk.js';
|
|
31
30
|
import { polyInit } from '../common/poly-init.js';
|
|
32
|
-
import { emitHtmlLabel } from '../common/htmltable-emit.js';
|
|
33
31
|
import {
|
|
34
32
|
setHtmlAnchorObj,
|
|
35
33
|
setHtmlObjImgscale,
|
|
36
34
|
resetHtmlAnchorIds,
|
|
37
35
|
} from '../common/htmltable-emit-rules.js';
|
|
38
36
|
import { nodeAttr } from '../common/poly-init.js';
|
|
39
|
-
import type { PlacedHtml } from '../common/htmltable-pos.js';
|
|
40
37
|
import {
|
|
41
38
|
parseStyleFlags,
|
|
42
39
|
resolvePenColor,
|
|
@@ -49,10 +46,10 @@ import { isPointNode } from '../common/poly-gencode.js';
|
|
|
49
46
|
import { resolveRenderColor, withColorScheme } from '../render/color-resolve.js';
|
|
50
47
|
import { emitRoundedBezier } from '../common/poly-shapes.js';
|
|
51
48
|
import { applyClusterObjState, clusterStyle, clusterPeripheries } from './device-cluster.js';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
49
|
+
import { transformPoint } from './device-transform.js';
|
|
50
|
+
import { renderOneLabel, renderNodeXLabel, renderClusterLabel } from './device-labels.js';
|
|
51
|
+
export { transformPoint, applyRotation, applyScale, buildPoint } from './device-transform.js';
|
|
52
|
+
export { renderOneLabel, renderNodeXLabel, renderClusterLabel } from './device-labels.js';
|
|
56
53
|
import { svgNodeId, svgEdgeId, svgClusterId, svgGraphId } from '../render/svg-id.js';
|
|
57
54
|
|
|
58
55
|
// ---------------------------------------------------------------------------
|
|
@@ -72,53 +69,6 @@ declare module './job.js' {
|
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
// ---------------------------------------------------------------------------
|
|
76
|
-
// transformPoint — @see lib/gvc/gvrender.c:gvrender_ptf
|
|
77
|
-
// ---------------------------------------------------------------------------
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Transform a point from graph to device coordinates.
|
|
81
|
-
* Short-circuits when GVRENDER_DOES_TRANSFORM is set (renderer owns mapping).
|
|
82
|
-
*
|
|
83
|
-
* @see lib/gvc/gvrender.c:gvrender_ptf
|
|
84
|
-
*/
|
|
85
|
-
export function transformPoint(p: Point, job: RenderJob): Point {
|
|
86
|
-
if ((job.flags & GVRENDER_DOES_TRANSFORM) !== 0) {
|
|
87
|
-
return p;
|
|
88
|
-
}
|
|
89
|
-
const sx = job.zoom * job.devscale.x;
|
|
90
|
-
const sy = job.zoom * job.devscale.y;
|
|
91
|
-
const tx = job.translation.x;
|
|
92
|
-
const ty = job.translation.y;
|
|
93
|
-
// ADR-2: SVG landscape rotation lives entirely in the graph `<g>` group
|
|
94
|
-
// transform (svg_begin_page emits rotate(-job->rotation)); inner coords stay
|
|
95
|
-
// in the unrotated frame. The ptf rotation branch (applyRotation) is the
|
|
96
|
-
// raster/imagemap path and must NOT fire here, else job.rotation=90 would
|
|
97
|
-
// double-rotate every SVG coordinate. applyRotation stays exported as the
|
|
98
|
-
// faithful gvrender_ptf port (currently dead). @see ADR-2; gvrender.c:gvrender_ptf
|
|
99
|
-
return applyScale(p, tx, ty, sx, sy);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/** Rotation branch: out.x = -(p.y+ty)*sx, out.y = (p.x+tx)*sy @see gvrender_ptf */
|
|
103
|
-
export function applyRotation(p: Point, tx: number, ty: number, sx: number, sy: number): Point {
|
|
104
|
-
const x = -(p.y + ty) * sx;
|
|
105
|
-
const y = (p.x + tx) * sy;
|
|
106
|
-
return buildPoint(x, y);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** No-rotation branch: out.x = (p.x+tx)*sx, out.y = (p.y+ty)*sy @see gvrender_ptf */
|
|
110
|
-
export function applyScale(p: Point, tx: number, ty: number, sx: number, sy: number): Point {
|
|
111
|
-
const x = (p.x + tx) * sx;
|
|
112
|
-
const y = (p.y + ty) * sy;
|
|
113
|
-
return buildPoint(x, y);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/** Construct a Point value. Extracted to avoid inline object literals in return position. */
|
|
117
|
-
export function buildPoint(x: number, y: number): Point {
|
|
118
|
-
const pt: Point = { x, y };
|
|
119
|
-
return pt;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
72
|
// ---------------------------------------------------------------------------
|
|
123
73
|
// Node/Edge walk helpers
|
|
124
74
|
// ---------------------------------------------------------------------------
|
|
@@ -282,80 +232,6 @@ export function renderEdge(e: Edge, renderer: RendererPlugin, job: RenderJob): v
|
|
|
282
232
|
}
|
|
283
233
|
}
|
|
284
234
|
|
|
285
|
-
/** valign codes stored on textlabel_t. @see lib/common/types.h:textlabel_t.valign */
|
|
286
|
-
const VALIGN_TOP = 't'.charCodeAt(0);
|
|
287
|
-
const VALIGN_BOTTOM = 'b'.charCodeAt(0);
|
|
288
|
-
|
|
289
|
-
/** First-span baseline y per valign. @see lib/common/labels.c:emit_label (240-251) */
|
|
290
|
-
function labelFirstSpanY(lp: TextlabelT): number {
|
|
291
|
-
if (lp.valign === VALIGN_TOP) return lp.pos.y + lp.space.y / 2.0 - lp.fontsize;
|
|
292
|
-
if (lp.valign === VALIGN_BOTTOM) {
|
|
293
|
-
return lp.pos.y - lp.space.y / 2.0 + lp.dimen.y - lp.fontsize;
|
|
294
|
-
}
|
|
295
|
-
return lp.pos.y + lp.dimen.y / 2.0 - lp.fontsize;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/** Span x position per justification. @see lib/common/labels.c:emit_label (254-266) */
|
|
299
|
-
function labelSpanX(lp: TextlabelT, just: 'l' | 'n' | 'r'): number {
|
|
300
|
-
if (just === 'l') return lp.pos.x - lp.space.x / 2.0;
|
|
301
|
-
if (just === 'r') return lp.pos.x + lp.space.x / 2.0;
|
|
302
|
-
return lp.pos.x;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Emit one label's text spans if present and placed.
|
|
307
|
-
* Shared by edge-label, node-xlabel, and graph-label slots.
|
|
308
|
-
* URL/anchor/map machinery and E_decorate attachment (emit.c:emit_attachment)
|
|
309
|
-
* are not ported, matching the live path's AD-2 scope.
|
|
310
|
-
* @see lib/common/emit.c:emit_label
|
|
311
|
-
* @see lib/common/labels.c:emit_label
|
|
312
|
-
*/
|
|
313
|
-
export function renderOneLabel(
|
|
314
|
-
lp: TextlabelT | undefined,
|
|
315
|
-
renderer: RendererPlugin,
|
|
316
|
-
job: RenderJob,
|
|
317
|
-
requireSet = true,
|
|
318
|
-
): void {
|
|
319
|
-
// C gates `->set` at the xlabel/edge-label CALL SITES (emit.c:1829,
|
|
320
|
-
// emit_edge_label:2891), but draws root-graph and cluster labels on
|
|
321
|
-
// existence alone (emit.c:3656, 3920) — an unplaced label (e.g. fdp's
|
|
322
|
-
// non-comparable-clusters abort skips gv_postprocess) still renders at its
|
|
323
|
-
// default pos. Callers mirroring the existence-only sites pass false.
|
|
324
|
-
if (!lp) return;
|
|
325
|
-
if (requireSet && !lp.set) return;
|
|
326
|
-
// HTML branch: @see lib/common/labels.c:emit_label (226-230)
|
|
327
|
-
// C routes to emit_html_label(job, lp->u.html, lp) using lp->pos as anchor.
|
|
328
|
-
if (lp.html) {
|
|
329
|
-
if (lp.u.kind === 'html') {
|
|
330
|
-
// Route the whole HTML label (table box/fill polygons + text) into the
|
|
331
|
-
// object's LABEL emit-state so its ops land in _ldraw_, not _draw_.
|
|
332
|
-
const html = lp.u.html as PlacedHtml;
|
|
333
|
-
const pos = lp.pos;
|
|
334
|
-
withLabelEmitState(job, () => emitHtmlLabel(html, pos, renderer, job));
|
|
335
|
-
}
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
if (lp.u.kind !== 'txt' || lp.u.nspans < 1) return;
|
|
339
|
-
let y = labelFirstSpanY(lp);
|
|
340
|
-
for (let i = 0; i < lp.u.nspans; i++) {
|
|
341
|
-
const span = lp.u.span[i] as TextSpan | undefined;
|
|
342
|
-
if (!span) break;
|
|
343
|
-
// Emit only visible spans; the baseline still advances below so blank
|
|
344
|
-
// lines reserve vertical space. @see gvrender_textspan (gvrender.c:419).
|
|
345
|
-
gvrenderTextspan(renderer, { x: labelSpanX(lp, span.just), y }, span, job);
|
|
346
|
-
y -= span.size.y; // UL position for next span (unconditional)
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* Emit node external label (ND_xlabel) if placed.
|
|
352
|
-
* Must run inside the node group, after codefn (shape draw), matching C order.
|
|
353
|
-
* @see lib/common/emit.c:emit_node (1829-1830)
|
|
354
|
-
*/
|
|
355
|
-
export function renderNodeXLabel(n: Node, renderer: RendererPlugin, job: RenderJob): void {
|
|
356
|
-
renderOneLabel(n.info.xlabel as TextlabelT | undefined, renderer, job);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
235
|
/**
|
|
360
236
|
* Emit root-graph label (GD_label) if present and placed.
|
|
361
237
|
* Must run before clusters and nodes (emit_page order: background, then label,
|
|
@@ -60,7 +60,12 @@ function graphAttrInherited(sg: Graph, key: string): string | undefined {
|
|
|
60
60
|
return sg.attrs.get(key) ?? sg.graphDefaultsSnapshot?.get(key);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Graph/cluster label font, read through graphAttrInherited.
|
|
65
|
+
* @internal also used by src/async/collect.ts to request the same face.
|
|
66
|
+
* @see lib/common/input.c:do_graph_label
|
|
67
|
+
*/
|
|
68
|
+
export function readFontParams(sg: Graph): { fontsize: number; fontname: string; fontcolor: string } {
|
|
64
69
|
return {
|
|
65
70
|
fontsize: parseFloat(graphAttrInherited(sg, 'fontsize') ?? '') || DEFAULT_FONTSIZE,
|
|
66
71
|
fontname: graphAttrInherited(sg, 'fontname') ?? DEFAULT_FONTNAME,
|
|
@@ -34,12 +34,12 @@ function angleSet(g: Graph): number | null {
|
|
|
34
34
|
if (a === undefined || a === '') return null;
|
|
35
35
|
const ang = parseAngle(a);
|
|
36
36
|
if (ang === null) return null;
|
|
37
|
-
return wrapDegrees(ang) *
|
|
37
|
+
return (wrapDegrees(ang) / 180.0) * Math.PI; // RADIANS(a) = a/180.0*M_PI
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
/** strtod with the mapbool fallback of angleSet. */
|
|
40
|
+
/** strtod (leading whitespace, sign) with the mapbool fallback of angleSet. */
|
|
41
41
|
function parseAngle(a: string): number | null {
|
|
42
|
-
const m =
|
|
42
|
+
const m = /^\s*[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/.exec(a);
|
|
43
43
|
if (m !== null) return parseFloat(m[0]);
|
|
44
44
|
/* no number */
|
|
45
45
|
return mapbool(a) ? 0.0 : null;
|
|
@@ -55,34 +55,38 @@ function wrapDegrees(ang: number): number {
|
|
|
55
55
|
/**
|
|
56
56
|
* If "normalize" is set, move the first node to the origin, then
|
|
57
57
|
* rotate the layout so the first edge sits at the given angle.
|
|
58
|
+
* Returns 1 if nodes moved, else 0.
|
|
58
59
|
* @see lib/neatogen/adjust.c:normalize (15.0.0)
|
|
59
60
|
*/
|
|
60
|
-
export function normalizeG(g: Graph):
|
|
61
|
+
export function normalizeG(g: Graph): number {
|
|
61
62
|
const phi0 = angleSet(g);
|
|
62
|
-
if (phi0 === null) return;
|
|
63
|
+
if (phi0 === null) return 0;
|
|
63
64
|
|
|
64
65
|
const nodes = [...g.nodes.values()];
|
|
65
66
|
const first = nodes[0];
|
|
66
|
-
if (first === undefined) return;
|
|
67
|
+
if (first === undefined) return 0;
|
|
67
68
|
const px = first.info.pos![0]!;
|
|
68
69
|
const py = first.info.pos![1]!;
|
|
69
70
|
for (const v of nodes) {
|
|
70
71
|
v.info.pos![0]! -= px;
|
|
71
72
|
v.info.pos![1]! -= py;
|
|
72
73
|
}
|
|
74
|
+
const ret = px || py ? 1 : 0;
|
|
73
75
|
|
|
74
76
|
let e = null;
|
|
75
77
|
for (const v of nodes) {
|
|
76
78
|
const out = v.outEdges(g);
|
|
77
79
|
if (out.length > 0) { e = out[0]!; break; }
|
|
78
80
|
}
|
|
79
|
-
if (e === null) return;
|
|
81
|
+
if (e === null) return ret;
|
|
80
82
|
|
|
81
83
|
/* rotation necessary; pos => ccw */
|
|
82
84
|
const phi = phi0 - Math.atan2(
|
|
83
85
|
e.head.info.pos![1]! - e.tail.info.pos![1]!,
|
|
84
86
|
e.head.info.pos![0]! - e.tail.info.pos![0]!);
|
|
85
|
-
if (phi)
|
|
87
|
+
if (!phi) return ret;
|
|
88
|
+
rotateAll(nodes, e.tail, phi);
|
|
89
|
+
return 1;
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
/** Rotate all positions by phi about the orig node. */
|
|
@@ -21,7 +21,7 @@ import { RenderError } from '../../errors.js';
|
|
|
21
21
|
import type { Graph } from '../../model/graph.js';
|
|
22
22
|
import type { Node } from '../../model/node.js';
|
|
23
23
|
import { sepFactor, type ExpandT } from '../neato/sep-factor.js';
|
|
24
|
-
import { fdpAdjust, overlapPrismTries } from '../neato/fdp-adjust.js';
|
|
24
|
+
import { fdpAdjust, overlapPrismTries, warnUnrecognizedOverlap } from '../neato/fdp-adjust.js';
|
|
25
25
|
import { scAdjust } from '../neato/sc-adjust.js';
|
|
26
26
|
import {
|
|
27
27
|
type XParams,
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from './fdp-model.js';
|
|
33
33
|
import { coincidentDelta } from './tlayout.js';
|
|
34
34
|
import { normalizeG } from './normalize.js';
|
|
35
|
+
import { simpleScale } from '../neato/simple-scale.js';
|
|
35
36
|
|
|
36
37
|
/** @see lib/fdpgen/xlayout.c:DFLT_overlap */
|
|
37
38
|
const DFLT_OVERLAP = '9:prism';
|
|
@@ -294,7 +295,7 @@ function parseOverlapTries(ovlp: string): { tries: number; rest: string } {
|
|
|
294
295
|
/**
|
|
295
296
|
* Overlap-removal dispatch on the overlap attribute:
|
|
296
297
|
* ""/null → default "9:prism"; "n:mode" → n x_layout tries, then
|
|
297
|
-
*
|
|
298
|
+
* removeOverlapAs with mode; "true" → keep overlaps.
|
|
298
299
|
* @see lib/fdpgen/xlayout.c:fdp_xLayout
|
|
299
300
|
*/
|
|
300
301
|
export function fdpXLayout(g: Graph, xpms: XParams): void {
|
|
@@ -314,14 +315,15 @@ export function fdpXLayout(g: Graph, xpms: XParams): void {
|
|
|
314
315
|
* scale family (scale/scalexy/compress) → scAdjust;
|
|
315
316
|
* AM_NONE ('' / 'true') and unported modes (voronoi) → no-op.
|
|
316
317
|
* normalize reads "normalize" and simpleScale reads "scale"; deriveGraph
|
|
317
|
-
* copies only overlap/sep/K, so both are faithfully dead here
|
|
318
|
-
*
|
|
319
|
-
* follows the project's decision to leave it unported.
|
|
318
|
+
* copies only overlap/sep/K, so both are faithfully dead here unless set on
|
|
319
|
+
* the derived chain (native fdp ignores both attributes).
|
|
320
320
|
* @see lib/neatogen/adjust.c:removeOverlapAs / removeOverlapWith / getAdjustMode
|
|
321
321
|
*/
|
|
322
322
|
function removeOverlapAs(g: Graph, flag: string): void {
|
|
323
323
|
if (g.nodes.size < 2) return; // removeOverlapWith: <2 nodes short-circuits
|
|
324
|
-
|
|
324
|
+
warnUnrecognizedOverlap(flag); // getAdjustMode
|
|
325
|
+
normalizeG(g); // removeOverlapWith runs normalize + simpleScale first
|
|
326
|
+
simpleScale(g);
|
|
325
327
|
const ntry = overlapPrismTries(flag);
|
|
326
328
|
if (ntry !== null) {
|
|
327
329
|
fdpAdjust(g, ntry); // AM_PRISM
|