@voxlz/graph-gen 4.5.2 → 4.5.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.
Files changed (3) hide show
  1. package/README.md +32 -26
  2. package/dist/index.js +114 -50
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -67,7 +67,7 @@ constraints {
67
67
 
68
68
  ## Install and run (npm)
69
69
 
70
- The recommended way to run graphgen is with Node.js 20 or newer and `npx`—no
70
+ The recommended way to run graph-gen is with Node.js 20 or newer and `npx`—no
71
71
  repository clone is needed:
72
72
 
73
73
  ```bash
@@ -117,7 +117,7 @@ environment variables, or `--version` for the installed version.
117
117
 
118
118
  ## Output paths
119
119
 
120
- The output argument is optional. If you omit it, graphgen picks the output path
120
+ The output argument is optional. If you omit it, graph-gen picks the output path
121
121
  in this order:
122
122
 
123
123
  1. CLI output argument (`npx @voxlz/graph-gen input.ggn out/output.png`)
@@ -355,7 +355,7 @@ when a clear route is available without adding crossings or hiding bends.
355
355
  With either engine, labels that still can't touch their edge become label nodes and
356
356
  the graph is laid out again: each such label pushes other nodes away and its
357
357
  edge is routed through it. This repeats until every label touches its edge. Control this with `labelNodes` in the
358
- `graph { ... }` block (or `GRAPHGEN_LABEL_NODES`):
358
+ `graph { ... }` block (or `GRAPH_GEN_LABEL_NODES`):
359
359
 
360
360
  - `auto` (default): only for labels that can't touch their edge otherwise.
361
361
  - `true`: always. Every label sits on its edge, at the cost of larger layouts.
@@ -407,37 +407,43 @@ styles; only the file being rendered contributes edges.
407
407
  flat constant so high-degree hubs don't fling their neighbours far away.
408
408
  - `graph.iterations` — the three WebCola solver passes
409
409
  `[unconstrained, userConstraint, allConstraint]` (also overridable at runtime
410
- with `GRAPHGEN_ITERS=a,b,c`).
410
+ with `GRAPH_GEN_ITERS=a,b,c`).
411
411
  - `shapes.<name>` — per-shape `color`, `lineStyle` (`solid`/`dashed`),
412
412
  `minWidth`, `minHeight`, `borderRadius`, and optional `borderColor`. Unknown
413
413
  shapes fall back to a plain box.
414
414
 
415
415
  ### Layout engines
416
416
 
417
- Set `graph.layout` to choose how nodes are positioned:
418
-
419
- - `curved` (default) — each edge is a single curve routed around nodes and
420
- boundaries, so nodes don't have to be pushed apart to make room for straight
421
- edges. Edges never cross each other or pass through nodes, and labels are
422
- placed beside their edge. Several starting layouts (WebCola variants and a
423
- grid) are compacted and the most compact routed result is kept.
424
- - `orthogonal` — like `curved`, but edges are horizontal and vertical segments
425
- joined by as few 90° bends as possible, connecting at the centre of each
426
- node's side. Parallel runs aim to stay at least 6 px apart, except for short
427
- shared attachment stubs. Routes favour straight sections of at least 20 px
428
- (including beside arrowheads) and balanced bends where obstacles allow.
429
- Subpixel alignment differences below 0.5 px do not introduce bends; straight
430
- connections stay within 0.25 px of the side centres. Labels keep a 10 px
431
- no-turn margin around their padded chips, so edge direction remains visible.
432
- - `constraint` — straight edges that never cross each other, nodes, or labels.
433
- It solves from both a grid and a WebCola starting layout and keeps the more
434
- compact result.
435
- - `cola` — plain WebCola layout pass (edges may cross nodes and labels).
436
- - `force` — force-directed layout.
417
+ Set `graph.layout` to choose how nodes and edges are arranged:
418
+
419
+ | Engine | Edge style and crossing behavior | Benefits and trade-offs |
420
+ | ------------------ | ----------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
421
+ | `curved` (default) | Single smooth curves route around obstacles and penalize crossings. | A good general-purpose choice for compact diagrams: edges can bend instead of pushing nodes apart. Labels are placed on or beside their edges. |
422
+ | `orthogonal` | Horizontal and vertical segments with 90° bends route around obstacles and strongly penalize crossings. | A structured, schematic look that makes direction and parallel connections easy to follow. Detours can add bends or space. |
423
+ | `constraint` | Straight edges; the solver rejects crossings between edges without a shared endpoint and edges through unrelated nodes. | Useful when straight, crossing-free connections are important. Nodes may need more space, and the solver can fail if it cannot find a valid layout. |
424
+ | `cola` | Straight edges from WebCola; edges may cross one another, nodes or labels. | A simple stress-based layout and useful baseline for comparison, especially when compactness matters more than avoiding crossings. |
425
+ | `force` | Straight edges from a force-directed starting layout, followed by constraint repair. | Uses attraction and repulsion to find an arrangement before enforcing the straight-edge constraints. If repair fails, it falls back to a constraint grid seed. |
426
+
427
+ `curved` and `orthogonal` try to avoid obstacles and crossings, but routing is
428
+ not a guarantee that every graph can be drawn without them. Both try several
429
+ starting layouts and score the routed results for crossings, obstacle hits,
430
+ size and edge length. They also support automatic label nodes to help labels
431
+ touch their edges; see [Edge label placement](#edge-label-placement).
432
+
433
+ Orthogonal routes favor side-centred connections, separated parallel runs and
434
+ long, balanced sections. Small alignment differences do not introduce extra
435
+ bends, and labels keep a no-turn margin so the edge direction remains visible.
436
+ Choose `curved` for a softer look, `orthogonal` for a diagram-like style, or
437
+ `constraint` when avoiding crossings with straight edges is more important
438
+ than compactness.
439
+
440
+ Environment variables use the `GRAPH_GEN_` prefix. The former `GRAPHGEN_`
441
+ prefix remains supported as a deprecated alias; if both are set, `GRAPH_GEN_`
442
+ takes precedence.
437
443
 
438
444
  If the same setting appears in multiple places, this precedence applies:
439
445
 
440
- 1. `GRAPHGEN_LAYOUT` environment variable
446
+ 1. `GRAPH_GEN_LAYOUT` environment variable
441
447
  2. per-graph `graph { layout "..." }`
442
448
  3. global style `style.jsonc` (`graph.layout`)
443
449
  4. default `curved`
@@ -462,7 +468,7 @@ graph {
462
468
  }
463
469
  ```
464
470
 
465
- You can also set `graph.layoutIterations` (or `GRAPHGEN_LAYOUT_ITERS`) to
471
+ You can also set `graph.layoutIterations` (or `GRAPH_GEN_LAYOUT_ITERS`) to
466
472
  control how many iterations the `constraint` engine can use before stopping.
467
473
 
468
474
  From a repository checkout, to compare engines on a folder of graphs, run
package/dist/index.js CHANGED
@@ -4899,19 +4899,19 @@ function packageVersion() {
4899
4899
  }
4900
4900
  }
4901
4901
  function helpText(version) {
4902
- return `graphgen ${version} \u2014 render .ggn graph files to PNG
4902
+ return `graph-gen ${version} \u2014 render .ggn graph files to PNG
4903
4903
 
4904
4904
  Usage:
4905
- graphgen <input.ggn|input.json> [output.png] [style.jsonc]
4906
- graphgen --watch [path] [output-directory]
4907
- graphgen --recursive [path]
4908
- graphgen --help | --version
4905
+ graph-gen <input.ggn|input.json> [output.png] [style.jsonc]
4906
+ graph-gen --watch [path] [output-directory]
4907
+ graph-gen --recursive [path]
4908
+ graph-gen --help | --version
4909
4909
 
4910
4910
  Arguments:
4911
4911
  input Graph to render (.ggn DSL or parsed .json).
4912
4912
  output PNG to write. Default: the graph's outputPath setting, else
4913
4913
  ../graphs/<name>.png relative to the input file.
4914
- style Global style file. Default: style.jsonc next to graphgen.
4914
+ style Global style file. Default: style.jsonc next to graph-gen.
4915
4915
 
4916
4916
  Options:
4917
4917
  -w, --watch Watch a .ggn file or folder (default: current folder) and
@@ -4924,12 +4924,13 @@ Options:
4924
4924
  -v, --version Print the version and exit.
4925
4925
 
4926
4926
  Environment:
4927
- GRAPHGEN_LAYOUT Layout engine: curved (default), orthogonal,
4928
- constraint, cola or force.
4929
- GRAPHGEN_CONSTRAINT_HINTS Set to 1 to report rules that block a smaller
4930
- layout.
4931
- GRAPHGEN_DUMP Write node positions and edge paths as JSON to
4932
- this file.
4927
+ GRAPH_GEN_LAYOUT Layout engine: curved (default), orthogonal,
4928
+ constraint, cola or force.
4929
+ GRAPH_GEN_CONSTRAINT_HINTS Set to 1 to report rules that block a smaller
4930
+ layout.
4931
+ GRAPH_GEN_DUMP Write node positions and edge paths as JSON to
4932
+ this file.
4933
+ The deprecated GRAPHGEN_* names are also accepted.
4933
4934
  `;
4934
4935
  }
4935
4936
  function isWatchFlag(arg) {
@@ -4950,7 +4951,7 @@ function handleInfoFlags(args2, version = packageVersion()) {
4950
4951
  if (isRecursiveFlag(first)) {
4951
4952
  if (args2.length > 2 || args2[1]?.startsWith("-")) {
4952
4953
  return {
4953
- output: `graphgen: expected --recursive [path]
4954
+ output: `graph-gen: expected --recursive [path]
4954
4955
 
4955
4956
  ${helpText(version)}`,
4956
4957
  exitCode: 2,
@@ -4961,7 +4962,7 @@ ${helpText(version)}`,
4961
4962
  }
4962
4963
  if (first?.startsWith("-") && first !== "-" && !isWatchFlag(first)) {
4963
4964
  return {
4964
- output: `graphgen: unknown option ${first}
4965
+ output: `graph-gen: unknown option ${first}
4965
4966
 
4966
4967
  ${helpText(version)}`,
4967
4968
  exitCode: 2,
@@ -5844,6 +5845,11 @@ function applyForceLayout(nodes, boundaries, edges, options) {
5844
5845
  return snapshots;
5845
5846
  }
5846
5847
 
5848
+ // src/env.ts
5849
+ function graphEnv(name) {
5850
+ return process.env[`GRAPH_GEN_${name}`] ?? process.env[`GRAPHGEN_${name}`];
5851
+ }
5852
+
5847
5853
  // src/render.ts
5848
5854
  var import_canvas = require("canvas");
5849
5855
 
@@ -9383,6 +9389,69 @@ function expand(box, pad) {
9383
9389
  function strictlyInside(p, box) {
9384
9390
  return p.x > box.minX + EPS && p.x < box.maxX - EPS && p.y > box.minY + EPS && p.y < box.maxY - EPS;
9385
9391
  }
9392
+ function insideNode(p, node) {
9393
+ const hw = node.width / 2;
9394
+ const hh = node.height / 2;
9395
+ const radius = Math.max(0, Math.min(node.borderRadius ?? 0, hw, hh));
9396
+ const x = Math.abs(p.x - node.x);
9397
+ const y = Math.abs(p.y - node.y);
9398
+ if (x > hw || y > hh) return false;
9399
+ if (node.outline === "cylinder") {
9400
+ const ry = Math.min(node.height * 0.16, hw * 0.45);
9401
+ const capY = Math.max(0, y - (hh - ry));
9402
+ return (x / hw) ** 2 + (capY / ry) ** 2 <= 1 || capY === 0;
9403
+ }
9404
+ const cornerX = Math.max(0, x - (hw - radius));
9405
+ const cornerY = Math.max(0, y - (hh - radius));
9406
+ return cornerX * cornerX + cornerY * cornerY <= radius * radius;
9407
+ }
9408
+ function nodeExit(node, inside, outside) {
9409
+ for (let i = 0; i < 40; i++) {
9410
+ const mid = {
9411
+ x: (inside.x + outside.x) / 2,
9412
+ y: (inside.y + outside.y) / 2
9413
+ };
9414
+ if (insideNode(mid, node)) inside = mid;
9415
+ else outside = mid;
9416
+ }
9417
+ return inside;
9418
+ }
9419
+ function nodeBoundaryPoint(node, toward) {
9420
+ const dx = toward.x - node.x;
9421
+ const dy = toward.y - node.y;
9422
+ if (dx === 0 && dy === 0) return { x: node.x, y: node.y };
9423
+ const scale = Math.min(
9424
+ dx === 0 ? Infinity : node.width / 2 / Math.abs(dx),
9425
+ dy === 0 ? Infinity : node.height / 2 / Math.abs(dy)
9426
+ );
9427
+ const outside = { x: node.x + dx * scale, y: node.y + dy * scale };
9428
+ return nodeExit(node, node, outside);
9429
+ }
9430
+ function clipOrthogonalToNodeShapes(route, source, target) {
9431
+ const points = route.points.slice();
9432
+ if (points.length < 2) return route;
9433
+ if (points.length === 2 && Math.hypot(points[0].x - source.x, points[0].y - source.y) < EPS && Math.hypot(points[1].x - target.x, points[1].y - target.y) < EPS) {
9434
+ return {
9435
+ ...route,
9436
+ points: [
9437
+ nodeBoundaryPoint(source, target),
9438
+ nodeBoundaryPoint(target, source)
9439
+ ]
9440
+ };
9441
+ }
9442
+ const clip = (index, next, node) => {
9443
+ const p = points[index];
9444
+ const q = points[next];
9445
+ if (insideNode(p, node)) return;
9446
+ const inside = Math.abs(p.x - q.x) < EPS ? { x: p.x, y: node.y } : Math.abs(p.y - q.y) < EPS ? { x: node.x, y: p.y } : null;
9447
+ if (inside && insideNode(inside, node)) {
9448
+ points[index] = nodeExit(node, inside, p);
9449
+ }
9450
+ };
9451
+ clip(0, 1, source);
9452
+ clip(points.length - 1, points.length - 2, target);
9453
+ return { ...route, points };
9454
+ }
9386
9455
  function boxesOverlap(a, b) {
9387
9456
  return a.minX < b.maxX && a.maxX > b.minX && a.minY < b.maxY && a.maxY > b.minY;
9388
9457
  }
@@ -9523,13 +9592,13 @@ function quadAt(p0, c, p2, t) {
9523
9592
  y: u * u * p0.y + 2 * u * t * c.y + t * t * p2.y
9524
9593
  };
9525
9594
  }
9526
- function exitParameter(p0, c, p2, box, fromStart) {
9595
+ function exitParameter(p0, c, p2, node, fromStart) {
9527
9596
  let inside = fromStart ? 0 : 1;
9528
9597
  let outside = fromStart ? 1 : 0;
9529
- if (strictlyInside(quadAt(p0, c, p2, outside), box)) return inside;
9598
+ if (insideNode(quadAt(p0, c, p2, outside), node)) return inside;
9530
9599
  for (let i = 0; i < 30; i++) {
9531
9600
  const mid = (inside + outside) / 2;
9532
- if (strictlyInside(quadAt(p0, c, p2, mid), box)) inside = mid;
9601
+ if (insideNode(quadAt(p0, c, p2, mid), node)) inside = mid;
9533
9602
  else outside = mid;
9534
9603
  }
9535
9604
  return outside;
@@ -9545,8 +9614,8 @@ function subCurve(p0, c, p2, t0, t1) {
9545
9614
  function curveRoute(source, target, control) {
9546
9615
  const p0 = { x: source.x, y: source.y };
9547
9616
  const p2 = { x: target.x, y: target.y };
9548
- const t0 = exitParameter(p0, control, p2, nodeBox(source), true);
9549
- const t1 = exitParameter(p0, control, p2, nodeBox(target), false);
9617
+ const t0 = exitParameter(p0, control, p2, source, true);
9618
+ const t1 = exitParameter(p0, control, p2, target, false);
9550
9619
  const curve = subCurve(p0, control, p2, t0, Math.max(t0, t1));
9551
9620
  const points = [];
9552
9621
  const samples = 16;
@@ -11072,7 +11141,7 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
11072
11141
  // labels that can't touch their edge otherwise; true always, false never.
11073
11142
  labelNodes: (() => {
11074
11143
  const value = String(
11075
- process.env.GRAPHGEN_LABEL_NODES ?? spec.graph?.labelNodes ?? globalStyle.graph?.labelNodes ?? "auto"
11144
+ graphEnv("LABEL_NODES") ?? spec.graph?.labelNodes ?? globalStyle.graph?.labelNodes ?? "auto"
11076
11145
  ).toLowerCase();
11077
11146
  if (value === "true" || value === "1") return "always";
11078
11147
  if (value === "false" || value === "0") return "never";
@@ -11086,19 +11155,19 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
11086
11155
  // the boundary nested inside it.
11087
11156
  nestPad: spec.graph?.nestPad ?? globalStyle.graph?.nestPad ?? 36,
11088
11157
  // WebCola solver iteration counts: [unconstrained, userConstraint,
11089
- // allConstraint]. Overridable via style or the GRAPHGEN_ITERS env var.
11158
+ // allConstraint]. Overridable via style or the GRAPH_GEN_ITERS env var.
11090
11159
  iterations: spec.graph?.iterations ?? globalStyle.graph?.iterations ?? [0, 100, 1e3],
11091
11160
  layout: String(
11092
- process.env.GRAPHGEN_LAYOUT ?? spec.graph?.layout ?? globalStyle.graph?.layout ?? "curved"
11161
+ graphEnv("LAYOUT") ?? spec.graph?.layout ?? globalStyle.graph?.layout ?? "curved"
11093
11162
  ).toLowerCase(),
11094
11163
  layoutIterations: Number(
11095
- process.env.GRAPHGEN_LAYOUT_ITERS ?? spec.graph?.layoutIterations ?? globalStyle.graph?.layoutIterations ?? 1e3
11164
+ graphEnv("LAYOUT_ITERS") ?? spec.graph?.layoutIterations ?? globalStyle.graph?.layoutIterations ?? 1e3
11096
11165
  ),
11097
11166
  debugFrameEvery: Number(
11098
- process.env.GRAPHGEN_DEBUG_FRAMES ?? spec.graph?.debugFrameEvery ?? globalStyle.graph?.debugFrameEvery ?? 0
11167
+ graphEnv("DEBUG_FRAMES") ?? spec.graph?.debugFrameEvery ?? globalStyle.graph?.debugFrameEvery ?? 0
11099
11168
  ),
11100
11169
  forceDebugFrameEvery: Number(
11101
- process.env.GRAPHGEN_FORCE_DEBUG_FRAMES ?? spec.graph?.forceDebugFrameEvery ?? globalStyle.graph?.forceDebugFrameEvery ?? process.env.GRAPHGEN_DEBUG_FRAMES ?? spec.graph?.debugFrameEvery ?? globalStyle.graph?.debugFrameEvery ?? 0
11170
+ graphEnv("FORCE_DEBUG_FRAMES") ?? spec.graph?.forceDebugFrameEvery ?? globalStyle.graph?.forceDebugFrameEvery ?? graphEnv("DEBUG_FRAMES") ?? spec.graph?.debugFrameEvery ?? globalStyle.graph?.debugFrameEvery ?? 0
11102
11171
  ),
11103
11172
  forceNodeGapMultiplier: Math.max(
11104
11173
  1,
@@ -11111,11 +11180,11 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
11111
11180
  // it's off by default; the watcher turns it on.
11112
11181
  constraintHints: !["0", "false", "off", "no", ""].includes(
11113
11182
  String(
11114
- process.env.GRAPHGEN_CONSTRAINT_HINTS ?? spec.graph?.constraintHints ?? globalStyle.graph?.constraintHints ?? false
11183
+ graphEnv("CONSTRAINT_HINTS") ?? spec.graph?.constraintHints ?? globalStyle.graph?.constraintHints ?? false
11115
11184
  ).toLowerCase()
11116
11185
  ),
11117
11186
  minimize: Number(
11118
- process.env.GRAPHGEN_MINIMIZE ?? spec.graph?.minimize ?? globalStyle.graph?.minimize ?? 100
11187
+ graphEnv("MINIMIZE") ?? spec.graph?.minimize ?? globalStyle.graph?.minimize ?? 100
11119
11188
  ),
11120
11189
  force: {
11121
11190
  nodeRepulsion: Number(
@@ -11186,6 +11255,8 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
11186
11255
  boundaryParent: n.parent ?? null,
11187
11256
  width: width2,
11188
11257
  height: height2,
11258
+ borderRadius: style.type === "actor" || style.type === "cylinder" ? 0 : style.borderRadius ?? 6,
11259
+ outline: style.type === "cylinder" ? "cylinder" : void 0,
11189
11260
  // deterministic-ish seed spread so the solver doesn't start degenerate
11190
11261
  x: 200 + i % 6 * 130 + i % 3 * 15,
11191
11262
  y: 150 + Math.floor(i / 6) * 130 + i % 2 * 15
@@ -11924,7 +11995,7 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
11924
11995
  return stressSeeds.get(linkScale);
11925
11996
  };
11926
11997
  const warmStart = (() => {
11927
- const file = process.env.GRAPHGEN_WARM_START;
11998
+ const file = graphEnv("WARM_START");
11928
11999
  if (!file || !import_node_fs3.default.existsSync(file)) return null;
11929
12000
  const dump = JSON.parse(import_node_fs3.default.readFileSync(file, "utf8"));
11930
12001
  const byId = new Map(dump.nodes.map((n) => [n.id, n]));
@@ -12049,7 +12120,7 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
12049
12120
  n.height += GAP;
12050
12121
  }
12051
12122
  const styleIters = Array.isArray(graphMeta.iterations) && graphMeta.iterations.length === 3 && graphMeta.iterations.every(Number.isFinite) ? graphMeta.iterations : [0, 100, 1e3];
12052
- const envIters = (process.env.GRAPHGEN_ITERS || "").split(",").map(Number);
12123
+ const envIters = (graphEnv("ITERS") || "").split(",").map(Number);
12053
12124
  const [i1, i2, i3] = envIters.length === 3 && envIters.every(Number.isFinite) ? envIters : styleIters;
12054
12125
  layout.start(i1, i2, i3, 0, false);
12055
12126
  for (const n of nodes) {
@@ -12171,7 +12242,11 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
12171
12242
  });
12172
12243
  }
12173
12244
  links.forEach((link, i) => {
12174
- link.route = finalRoutes[i];
12245
+ link.route = edgeRouting === "orthogonal" ? clipOrthogonalToNodeShapes(
12246
+ finalRoutes[i],
12247
+ resolveNode2(link.source),
12248
+ resolveNode2(link.target)
12249
+ ) : finalRoutes[i];
12175
12250
  const spot = spots[i];
12176
12251
  if (spot) {
12177
12252
  link.labelX = spot.x;
@@ -12292,19 +12367,6 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
12292
12367
  }
12293
12368
  });
12294
12369
  }
12295
- function boundaryPoint2(node, towardX, towardY) {
12296
- const cx = tx(node.x);
12297
- const cy = ty(node.y);
12298
- const dx = towardX - cx;
12299
- const dy = towardY - cy;
12300
- if (dx === 0 && dy === 0) return { x: cx, y: cy };
12301
- const hw = node.width / 2;
12302
- const hh = node.height / 2;
12303
- const scaleX = dx !== 0 ? hw / Math.abs(dx) : Infinity;
12304
- const scaleY = dy !== 0 ? hh / Math.abs(dy) : Infinity;
12305
- const scale = Math.min(scaleX, scaleY);
12306
- return { x: cx + dx * scale, y: cy + dy * scale };
12307
- }
12308
12370
  function drawArrowhead(x, y, angle) {
12309
12371
  const size = 10;
12310
12372
  ctx.save();
@@ -12391,14 +12453,15 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
12391
12453
  for (const link of links) {
12392
12454
  const source = resolveNode2(link.source);
12393
12455
  const target = resolveNode2(link.target);
12394
- const sc = { x: tx(source.x), y: ty(source.y) };
12395
- const tc = { x: tx(target.x), y: ty(target.y) };
12396
12456
  const route = link.route;
12397
12457
  const toCanvas = (p) => ({
12398
12458
  x: tx(p.x),
12399
12459
  y: ty(p.y)
12400
12460
  });
12401
- const path8 = route ? route.points.map(toCanvas) : [boundaryPoint2(source, tc.x, tc.y), boundaryPoint2(target, sc.x, sc.y)];
12461
+ const path8 = route ? route.points.map(toCanvas) : [
12462
+ toCanvas(nodeBoundaryPoint(source, target)),
12463
+ toCanvas(nodeBoundaryPoint(target, source))
12464
+ ];
12402
12465
  const p1 = path8[0];
12403
12466
  const p2 = path8[path8.length - 1];
12404
12467
  drawnPaths.push(path8);
@@ -12554,7 +12617,8 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
12554
12617
  throw new Error(`group label ${title.id} overlaps ${conflict}`);
12555
12618
  }
12556
12619
  }
12557
- if (process.env.GRAPHGEN_DUMP) {
12620
+ const dumpPath = graphEnv("DUMP");
12621
+ if (dumpPath) {
12558
12622
  const dump = {
12559
12623
  meta: {
12560
12624
  nodeGap: graphMeta.nodeGap,
@@ -12596,7 +12660,7 @@ async function renderGraph(spec, outputPath, stylePath2, labelNodeEdges = []) {
12596
12660
  maxY: r.maxY - offsetY
12597
12661
  }))
12598
12662
  };
12599
- import_node_fs3.default.writeFileSync(process.env.GRAPHGEN_DUMP, JSON.stringify(dump, null, 2));
12663
+ import_node_fs3.default.writeFileSync(dumpPath, JSON.stringify(dump, null, 2));
12600
12664
  }
12601
12665
  await writePng(canvas, outputPath);
12602
12666
  afterRender?.();
@@ -12645,8 +12709,8 @@ function buildBundle() {
12645
12709
  outfile: temporary,
12646
12710
  logLevel: "warning"
12647
12711
  });
12712
+ import_node_fs4.default.chmodSync(temporary, 493);
12648
12713
  import_node_fs4.default.renameSync(temporary, bundlePath);
12649
- import_node_fs4.default.chmodSync(bundlePath, 493);
12650
12714
  }
12651
12715
  function rendererCommand() {
12652
12716
  try {
@@ -12743,7 +12807,7 @@ function renderGraph2(renderer, file, outputDirectory) {
12743
12807
  // Hint about constraints that block a smaller layout while editing.
12744
12808
  env: {
12745
12809
  ...process.env,
12746
- GRAPHGEN_CONSTRAINT_HINTS: process.env.GRAPHGEN_CONSTRAINT_HINTS ?? "1"
12810
+ GRAPH_GEN_CONSTRAINT_HINTS: graphEnv("CONSTRAINT_HINTS") ?? "1"
12747
12811
  },
12748
12812
  stdio: ["ignore", "pipe", "pipe"]
12749
12813
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxlz/graph-gen",
3
- "version": "4.5.2",
3
+ "version": "4.5.3",
4
4
  "description": "Constraint-based graph layout -> PNG renderer",
5
5
  "main": "dist/index.js",
6
6
  "bin": {