@knowvah/dot-engine 2.0.0 → 2.0.1

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.
@@ -12,7 +12,8 @@ import type { Graph } from '../../model/graph.js';
12
12
  /**
13
13
  * If "normalize" is set, move the first node to the origin, then
14
14
  * rotate the layout so the first edge sits at the given angle.
15
+ * Returns 1 if nodes moved, else 0.
15
16
  * @see lib/neatogen/adjust.c:normalize (15.0.0)
16
17
  */
17
- export declare function normalizeG(g: Graph): void;
18
+ export declare function normalizeG(g: Graph): number;
18
19
  //# sourceMappingURL=normalize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/layout/fdp/normalize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAyClD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CA0BzC"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../src/layout/fdp/normalize.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAyClD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CA6B3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"xlayout.d.ts","sourceRoot":"","sources":["../../../src/layout/fdp/xlayout.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAKlD,OAAO,EACL,KAAK,OAAO,EAKb,MAAM,gBAAgB,CAAC;AAsQxB;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAMxD"}
1
+ {"version":3,"file":"xlayout.d.ts","sourceRoot":"","sources":["../../../src/layout/fdp/xlayout.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAKlD,OAAO,EACL,KAAK,OAAO,EAKb,MAAM,gBAAgB,CAAC;AAuQxB;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,GAAG,IAAI,CAMxD"}
@@ -46,8 +46,8 @@ export interface AdjustData {
46
46
  export declare function getAdjustMode(flag: string | undefined): AdjustData;
47
47
  /**
48
48
  * Use `am` to decide if and how to remove node overlaps. normalize and
49
- * simpleScale (only active with the `normalize`/`scale` attributes) are not
50
- * ported (see sc-adjust module doc).
49
+ * simpleScale run first, whatever the mode (the `normalize` / `scale`
50
+ * attributes); returns non-zero if nodes moved.
51
51
  * @see lib/neatogen/adjust.c:removeOverlapWith
52
52
  */
53
53
  export declare function removeOverlapWith(g: Graph, am: AdjustData): number;
@@ -1 +1 @@
1
- {"version":3,"file":"fdp-adjust.d.ts","sourceRoot":"","sources":["../../../src/layout/neato/fdp-adjust.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AA2ClD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAUzE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAgCtD;AAED;wCACwC;AACxC,eAAO,MAAM,OAAO,IAAI,CAAC;AACzB,eAAO,MAAM,MAAM,IAAI,CAAC;AACxB,eAAO,MAAM,QAAQ,IAAI,CAAC;AAC1B,eAAO,MAAM,SAAS,IAAI,CAAC;AAC3B,eAAO,MAAM,UAAU,IAAI,CAAC;AAC5B,eAAO,MAAM,WAAW,KAAK,CAA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AAQ,KAAK,CAAC;AAE3B,kEAAkE;AAClE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAsBD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAMlE;AA8CD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,GAAG,MAAM,CAMlE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAGhD"}
@@ -9,9 +9,8 @@
9
9
  * Using Constrained Optimization", Constraints 8(2):143-172, 2003 (per the
10
10
  * C source comment).
11
11
  *
12
- * Other overlap modes (voronoi, prism, vpsc, ortho*) remain unported; with
13
- * the attr unset C's getAdjustMode resolves to AM_NONE and the pass is a
14
- * no-op (normalize/simpleScale only fire on rare attrs, also unported).
12
+ * Dispatched from removeOverlapWith (fdp-adjust.ts) for overlap=scale,
13
+ * scalexy and compress.
15
14
  *
16
15
  * @see lib/neatogen/constraint.c:scAdjust
17
16
  * @see lib/neatogen/adjust.c:removeOverlapWith / getAdjustMode
@@ -24,10 +23,4 @@ import type { Graph } from '../../model/graph.js';
24
23
  * @see lib/neatogen/constraint.c:767 scAdjust
25
24
  */
26
25
  export declare function scAdjust(g: Graph, equal: number): number;
27
- /**
28
- * The adjustNodes overlap-mode subset reaching scAdjust; other modes are
29
- * no-ops (see module doc).
30
- * @see lib/neatogen/adjust.c:999 adjustNodes, :776 adjustMode table
31
- */
32
- export declare function adjustNodesScale(g: Graph): number;
33
26
  //# sourceMappingURL=sc-adjust.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sc-adjust.d.ts","sourceRoot":"","sources":["../../../src/layout/neato/sc-adjust.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAsHlD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA8CxD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAOjD"}
1
+ {"version":3,"file":"sc-adjust.d.ts","sourceRoot":"","sources":["../../../src/layout/neato/sc-adjust.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAsHlD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CA8CxD"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The `scale` graph attribute: multiply every node position by (sx, sy)
3
+ * before overlap removal. removeOverlapWith runs it right after normalize,
4
+ * whatever the overlap mode.
5
+ *
6
+ * @see lib/neatogen/adjust.c:simpleScale
7
+ */
8
+ import type { Graph } from '../../model/graph.js';
9
+ /**
10
+ * Scale node positions by the `scale` attribute ("s" or "sx,sy"). Returns 1
11
+ * if nodes moved, else 0 (unset, unparsable, a zero factor, or 1,1).
12
+ * @see lib/neatogen/adjust.c:simpleScale
13
+ */
14
+ export declare function simpleScale(g: Graph): number;
15
+ //# sourceMappingURL=simple-scale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"simple-scale.d.ts","sourceRoot":"","sources":["../../../src/layout/neato/simple-scale.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAuBlD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAe5C"}
package/dist/render.js CHANGED
@@ -41737,6 +41737,102 @@ function scAdjust(g, equal) {
41737
41737
  return 1;
41738
41738
  }
41739
41739
 
41740
+ // src/layout/neato/simple-scale.ts
41741
+ var ISZERO = (d) => Math.abs(d) < 1e-9;
41742
+ var LF = /^\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/;
41743
+ function scanPair(p) {
41744
+ const m1 = LF.exec(p);
41745
+ if (m1 === null) return [];
41746
+ const rest = p.slice(m1[0].length);
41747
+ if (!rest.startsWith(",")) return [parseFloat(m1[1])];
41748
+ const m2 = LF.exec(rest.slice(1));
41749
+ return m2 === null ? [parseFloat(m1[1])] : [parseFloat(m1[1]), parseFloat(m2[1])];
41750
+ }
41751
+ function simpleScale(g) {
41752
+ const p = aggetGraph(g, "scale");
41753
+ if (p === void 0) return 0;
41754
+ const sc = scanPair(p);
41755
+ if (sc.length === 0) return 0;
41756
+ const x = sc[0];
41757
+ if (ISZERO(x)) return 0;
41758
+ const y = sc.length === 1 ? x : sc[1];
41759
+ if (ISZERO(y)) return 0;
41760
+ if (y === 1 && x === 1) return 0;
41761
+ for (const n of g.nodes.values()) {
41762
+ n.info.pos[0] *= x;
41763
+ n.info.pos[1] *= y;
41764
+ }
41765
+ return 1;
41766
+ }
41767
+
41768
+ // src/layout/fdp/normalize.ts
41769
+ function mapbool5(s) {
41770
+ const t = s.toLowerCase();
41771
+ if (t === "false" || t === "no") return false;
41772
+ if (t === "true" || t === "yes") return true;
41773
+ const v = parseInt(s, 10);
41774
+ return !Number.isNaN(v) && v !== 0;
41775
+ }
41776
+ function angleSet(g) {
41777
+ const a = aggetGraph(g, "normalize");
41778
+ if (a === void 0 || a === "") return null;
41779
+ const ang = parseAngle2(a);
41780
+ if (ang === null) return null;
41781
+ return wrapDegrees(ang) / 180 * Math.PI;
41782
+ }
41783
+ function parseAngle2(a) {
41784
+ const m = /^\s*[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/.exec(a);
41785
+ if (m !== null) return parseFloat(m[0]);
41786
+ return mapbool5(a) ? 0 : null;
41787
+ }
41788
+ function wrapDegrees(ang) {
41789
+ while (ang > 180) ang -= 360;
41790
+ while (ang <= -180) ang += 360;
41791
+ return ang;
41792
+ }
41793
+ function normalizeG(g) {
41794
+ const phi0 = angleSet(g);
41795
+ if (phi0 === null) return 0;
41796
+ const nodes = [...g.nodes.values()];
41797
+ const first = nodes[0];
41798
+ if (first === void 0) return 0;
41799
+ const px = first.info.pos[0];
41800
+ const py = first.info.pos[1];
41801
+ for (const v of nodes) {
41802
+ v.info.pos[0] -= px;
41803
+ v.info.pos[1] -= py;
41804
+ }
41805
+ const ret = px || py ? 1 : 0;
41806
+ let e = null;
41807
+ for (const v of nodes) {
41808
+ const out = v.outEdges(g);
41809
+ if (out.length > 0) {
41810
+ e = out[0];
41811
+ break;
41812
+ }
41813
+ }
41814
+ if (e === null) return ret;
41815
+ const phi = phi0 - Math.atan2(
41816
+ e.head.info.pos[1] - e.tail.info.pos[1],
41817
+ e.head.info.pos[0] - e.tail.info.pos[0]
41818
+ );
41819
+ if (!phi) return ret;
41820
+ rotateAll(nodes, e.tail, phi);
41821
+ return 1;
41822
+ }
41823
+ function rotateAll(nodes, orig, phi) {
41824
+ const ox = orig.info.pos[0];
41825
+ const oy = orig.info.pos[1];
41826
+ const cosv = Math.cos(phi);
41827
+ const sinv = Math.sin(phi);
41828
+ for (const v of nodes) {
41829
+ const x = v.info.pos[0] - ox;
41830
+ const y = v.info.pos[1] - oy;
41831
+ v.info.pos[0] = x * cosv - y * sinv + ox;
41832
+ v.info.pos[1] = x * sinv + y * cosv + oy;
41833
+ }
41834
+ }
41835
+
41740
41836
  // src/layout/neato/constraint-adjust.ts
41741
41837
  var AM_ORTHO = 5;
41742
41838
  var AM_ORTHO_YX = 6;
@@ -43640,9 +43736,10 @@ function adjustVoronoi(g, am) {
43640
43736
  }
43641
43737
  function removeOverlapWith(g, am) {
43642
43738
  if (g.nodes.size < 2) return 0;
43643
- if (am.mode === AM_NONE) return 0;
43644
- if (am.mode > AM_SCALE) return adjustLate(g, am);
43645
- return am.mode === AM_SCALE ? sAdjustGraph(g) : adjustVoronoi(g, am);
43739
+ const nret = normalizeG(g) + simpleScale(g);
43740
+ if (am.mode === AM_NONE) return nret;
43741
+ if (am.mode > AM_SCALE) return nret + adjustLate(g, am);
43742
+ return nret + (am.mode === AM_SCALE ? sAdjustGraph(g) : adjustVoronoi(g, am));
43646
43743
  }
43647
43744
  function adjustNodesFull(g) {
43648
43745
  const flag = g.attrs.get("overlap") ?? g.root.attrs.get("overlap");
@@ -44778,71 +44875,6 @@ function fdpTLayout(g, xpms) {
44778
44875
  if (reset2) resetParams();
44779
44876
  }
44780
44877
 
44781
- // src/layout/fdp/normalize.ts
44782
- function mapbool5(s) {
44783
- const t = s.toLowerCase();
44784
- if (t === "false" || t === "no") return false;
44785
- if (t === "true" || t === "yes") return true;
44786
- const v = parseInt(s, 10);
44787
- return !Number.isNaN(v) && v !== 0;
44788
- }
44789
- function angleSet(g) {
44790
- const a = aggetGraph(g, "normalize");
44791
- if (a === void 0 || a === "") return null;
44792
- const ang = parseAngle2(a);
44793
- if (ang === null) return null;
44794
- return wrapDegrees(ang) * (Math.PI / 180);
44795
- }
44796
- function parseAngle2(a) {
44797
- const m = /^-?[\d.]+(?:[eE][-+]?\d+)?/.exec(a);
44798
- if (m !== null) return parseFloat(m[0]);
44799
- return mapbool5(a) ? 0 : null;
44800
- }
44801
- function wrapDegrees(ang) {
44802
- while (ang > 180) ang -= 360;
44803
- while (ang <= -180) ang += 360;
44804
- return ang;
44805
- }
44806
- function normalizeG(g) {
44807
- const phi0 = angleSet(g);
44808
- if (phi0 === null) return;
44809
- const nodes = [...g.nodes.values()];
44810
- const first = nodes[0];
44811
- if (first === void 0) return;
44812
- const px = first.info.pos[0];
44813
- const py = first.info.pos[1];
44814
- for (const v of nodes) {
44815
- v.info.pos[0] -= px;
44816
- v.info.pos[1] -= py;
44817
- }
44818
- let e = null;
44819
- for (const v of nodes) {
44820
- const out = v.outEdges(g);
44821
- if (out.length > 0) {
44822
- e = out[0];
44823
- break;
44824
- }
44825
- }
44826
- if (e === null) return;
44827
- const phi = phi0 - Math.atan2(
44828
- e.head.info.pos[1] - e.tail.info.pos[1],
44829
- e.head.info.pos[0] - e.tail.info.pos[0]
44830
- );
44831
- if (phi) rotateAll(nodes, e.tail, phi);
44832
- }
44833
- function rotateAll(nodes, orig, phi) {
44834
- const ox = orig.info.pos[0];
44835
- const oy = orig.info.pos[1];
44836
- const cosv = Math.cos(phi);
44837
- const sinv = Math.sin(phi);
44838
- for (const v of nodes) {
44839
- const x = v.info.pos[0] - ox;
44840
- const y = v.info.pos[1] - oy;
44841
- v.info.pos[0] = x * cosv - y * sinv + ox;
44842
- v.info.pos[1] = x * sinv + y * cosv + oy;
44843
- }
44844
- }
44845
-
44846
44878
  // src/layout/fdp/xlayout.ts
44847
44879
  var DFLT_OVERLAP = "9:prism";
44848
44880
  var PS2INCH3 = (x) => x / 72;
@@ -45019,6 +45051,7 @@ function fdpXLayout(g, xpms) {
45019
45051
  function removeOverlapAs(g, flag) {
45020
45052
  if (g.nodes.size < 2) return;
45021
45053
  normalizeG(g);
45054
+ simpleScale(g);
45022
45055
  const ntry = overlapPrismTries(flag);
45023
45056
  if (ntry !== null) {
45024
45057
  fdpAdjust(g, ntry);