@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.
package/dist/index.js CHANGED
@@ -45709,6 +45709,102 @@ function scAdjust(g, equal) {
45709
45709
  return 1;
45710
45710
  }
45711
45711
 
45712
+ // src/layout/neato/simple-scale.ts
45713
+ var ISZERO = (d) => Math.abs(d) < 1e-9;
45714
+ var LF = /^\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/;
45715
+ function scanPair(p) {
45716
+ const m1 = LF.exec(p);
45717
+ if (m1 === null) return [];
45718
+ const rest = p.slice(m1[0].length);
45719
+ if (!rest.startsWith(",")) return [parseFloat(m1[1])];
45720
+ const m2 = LF.exec(rest.slice(1));
45721
+ return m2 === null ? [parseFloat(m1[1])] : [parseFloat(m1[1]), parseFloat(m2[1])];
45722
+ }
45723
+ function simpleScale(g) {
45724
+ const p = aggetGraph(g, "scale");
45725
+ if (p === void 0) return 0;
45726
+ const sc = scanPair(p);
45727
+ if (sc.length === 0) return 0;
45728
+ const x = sc[0];
45729
+ if (ISZERO(x)) return 0;
45730
+ const y = sc.length === 1 ? x : sc[1];
45731
+ if (ISZERO(y)) return 0;
45732
+ if (y === 1 && x === 1) return 0;
45733
+ for (const n of g.nodes.values()) {
45734
+ n.info.pos[0] *= x;
45735
+ n.info.pos[1] *= y;
45736
+ }
45737
+ return 1;
45738
+ }
45739
+
45740
+ // src/layout/fdp/normalize.ts
45741
+ function mapbool5(s) {
45742
+ const t = s.toLowerCase();
45743
+ if (t === "false" || t === "no") return false;
45744
+ if (t === "true" || t === "yes") return true;
45745
+ const v = parseInt(s, 10);
45746
+ return !Number.isNaN(v) && v !== 0;
45747
+ }
45748
+ function angleSet(g) {
45749
+ const a = aggetGraph(g, "normalize");
45750
+ if (a === void 0 || a === "") return null;
45751
+ const ang = parseAngle2(a);
45752
+ if (ang === null) return null;
45753
+ return wrapDegrees(ang) / 180 * Math.PI;
45754
+ }
45755
+ function parseAngle2(a) {
45756
+ const m = /^\s*[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?/.exec(a);
45757
+ if (m !== null) return parseFloat(m[0]);
45758
+ return mapbool5(a) ? 0 : null;
45759
+ }
45760
+ function wrapDegrees(ang) {
45761
+ while (ang > 180) ang -= 360;
45762
+ while (ang <= -180) ang += 360;
45763
+ return ang;
45764
+ }
45765
+ function normalizeG(g) {
45766
+ const phi0 = angleSet(g);
45767
+ if (phi0 === null) return 0;
45768
+ const nodes = [...g.nodes.values()];
45769
+ const first = nodes[0];
45770
+ if (first === void 0) return 0;
45771
+ const px = first.info.pos[0];
45772
+ const py = first.info.pos[1];
45773
+ for (const v of nodes) {
45774
+ v.info.pos[0] -= px;
45775
+ v.info.pos[1] -= py;
45776
+ }
45777
+ const ret = px || py ? 1 : 0;
45778
+ let e = null;
45779
+ for (const v of nodes) {
45780
+ const out = v.outEdges(g);
45781
+ if (out.length > 0) {
45782
+ e = out[0];
45783
+ break;
45784
+ }
45785
+ }
45786
+ if (e === null) return ret;
45787
+ const phi = phi0 - Math.atan2(
45788
+ e.head.info.pos[1] - e.tail.info.pos[1],
45789
+ e.head.info.pos[0] - e.tail.info.pos[0]
45790
+ );
45791
+ if (!phi) return ret;
45792
+ rotateAll(nodes, e.tail, phi);
45793
+ return 1;
45794
+ }
45795
+ function rotateAll(nodes, orig, phi) {
45796
+ const ox = orig.info.pos[0];
45797
+ const oy = orig.info.pos[1];
45798
+ const cosv = Math.cos(phi);
45799
+ const sinv = Math.sin(phi);
45800
+ for (const v of nodes) {
45801
+ const x = v.info.pos[0] - ox;
45802
+ const y = v.info.pos[1] - oy;
45803
+ v.info.pos[0] = x * cosv - y * sinv + ox;
45804
+ v.info.pos[1] = x * sinv + y * cosv + oy;
45805
+ }
45806
+ }
45807
+
45712
45808
  // src/layout/neato/constraint-adjust.ts
45713
45809
  var AM_ORTHO = 5;
45714
45810
  var AM_ORTHO_YX = 6;
@@ -47612,9 +47708,10 @@ function adjustVoronoi(g, am) {
47612
47708
  }
47613
47709
  function removeOverlapWith(g, am) {
47614
47710
  if (g.nodes.size < 2) return 0;
47615
- if (am.mode === AM_NONE) return 0;
47616
- if (am.mode > AM_SCALE) return adjustLate(g, am);
47617
- return am.mode === AM_SCALE ? sAdjustGraph(g) : adjustVoronoi(g, am);
47711
+ const nret = normalizeG(g) + simpleScale(g);
47712
+ if (am.mode === AM_NONE) return nret;
47713
+ if (am.mode > AM_SCALE) return nret + adjustLate(g, am);
47714
+ return nret + (am.mode === AM_SCALE ? sAdjustGraph(g) : adjustVoronoi(g, am));
47618
47715
  }
47619
47716
  function adjustNodesFull(g) {
47620
47717
  const flag = g.attrs.get("overlap") ?? g.root.attrs.get("overlap");
@@ -48750,71 +48847,6 @@ function fdpTLayout(g, xpms) {
48750
48847
  if (reset2) resetParams();
48751
48848
  }
48752
48849
 
48753
- // src/layout/fdp/normalize.ts
48754
- function mapbool5(s) {
48755
- const t = s.toLowerCase();
48756
- if (t === "false" || t === "no") return false;
48757
- if (t === "true" || t === "yes") return true;
48758
- const v = parseInt(s, 10);
48759
- return !Number.isNaN(v) && v !== 0;
48760
- }
48761
- function angleSet(g) {
48762
- const a = aggetGraph(g, "normalize");
48763
- if (a === void 0 || a === "") return null;
48764
- const ang = parseAngle2(a);
48765
- if (ang === null) return null;
48766
- return wrapDegrees(ang) * (Math.PI / 180);
48767
- }
48768
- function parseAngle2(a) {
48769
- const m = /^-?[\d.]+(?:[eE][-+]?\d+)?/.exec(a);
48770
- if (m !== null) return parseFloat(m[0]);
48771
- return mapbool5(a) ? 0 : null;
48772
- }
48773
- function wrapDegrees(ang) {
48774
- while (ang > 180) ang -= 360;
48775
- while (ang <= -180) ang += 360;
48776
- return ang;
48777
- }
48778
- function normalizeG(g) {
48779
- const phi0 = angleSet(g);
48780
- if (phi0 === null) return;
48781
- const nodes = [...g.nodes.values()];
48782
- const first = nodes[0];
48783
- if (first === void 0) return;
48784
- const px = first.info.pos[0];
48785
- const py = first.info.pos[1];
48786
- for (const v of nodes) {
48787
- v.info.pos[0] -= px;
48788
- v.info.pos[1] -= py;
48789
- }
48790
- let e = null;
48791
- for (const v of nodes) {
48792
- const out = v.outEdges(g);
48793
- if (out.length > 0) {
48794
- e = out[0];
48795
- break;
48796
- }
48797
- }
48798
- if (e === null) return;
48799
- const phi = phi0 - Math.atan2(
48800
- e.head.info.pos[1] - e.tail.info.pos[1],
48801
- e.head.info.pos[0] - e.tail.info.pos[0]
48802
- );
48803
- if (phi) rotateAll(nodes, e.tail, phi);
48804
- }
48805
- function rotateAll(nodes, orig, phi) {
48806
- const ox = orig.info.pos[0];
48807
- const oy = orig.info.pos[1];
48808
- const cosv = Math.cos(phi);
48809
- const sinv = Math.sin(phi);
48810
- for (const v of nodes) {
48811
- const x = v.info.pos[0] - ox;
48812
- const y = v.info.pos[1] - oy;
48813
- v.info.pos[0] = x * cosv - y * sinv + ox;
48814
- v.info.pos[1] = x * sinv + y * cosv + oy;
48815
- }
48816
- }
48817
-
48818
48850
  // src/layout/fdp/xlayout.ts
48819
48851
  var DFLT_OVERLAP = "9:prism";
48820
48852
  var PS2INCH3 = (x) => x / 72;
@@ -48991,6 +49023,7 @@ function fdpXLayout(g, xpms) {
48991
49023
  function removeOverlapAs(g, flag) {
48992
49024
  if (g.nodes.size < 2) return;
48993
49025
  normalizeG(g);
49026
+ simpleScale(g);
48994
49027
  const ntry = overlapPrismTries(flag);
48995
49028
  if (ntry !== null) {
48996
49029
  fdpAdjust(g, ntry);