@phren/cli 0.0.12 → 0.0.14
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.
|
@@ -164,7 +164,27 @@ export function renderGraphScript() {
|
|
|
164
164
|
return path;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
+
/* pin a node so the force simulation skips it (prevents jitter while phren walks) */
|
|
168
|
+
var phrenPinnedNode = null;
|
|
169
|
+
|
|
170
|
+
function phrenPinNode(node) {
|
|
171
|
+
if (phrenPinnedNode && phrenPinnedNode !== node) {
|
|
172
|
+
/* unpin previous target — let physics resume on it */
|
|
173
|
+
phrenPinnedNode._phrenPinned = false;
|
|
174
|
+
phrenPinnedNode.vx = 0;
|
|
175
|
+
phrenPinnedNode.vy = 0;
|
|
176
|
+
}
|
|
177
|
+
if (node) {
|
|
178
|
+
node._phrenPinned = true;
|
|
179
|
+
node.vx = 0;
|
|
180
|
+
node.vy = 0;
|
|
181
|
+
}
|
|
182
|
+
phrenPinnedNode = node;
|
|
183
|
+
}
|
|
184
|
+
|
|
167
185
|
function phrenMoveTo(x, y, targetNode) {
|
|
186
|
+
/* pin the target node so physics doesn't move it while phren walks there */
|
|
187
|
+
phrenPinNode(targetNode);
|
|
168
188
|
phren.targetX = x;
|
|
169
189
|
phren.targetY = y;
|
|
170
190
|
phren.moving = true;
|
|
@@ -752,7 +772,7 @@ export function renderGraphScript() {
|
|
|
752
772
|
/* direct N^2 repulsion for small graphs (cheaper than quadtree overhead) */
|
|
753
773
|
for (var i = 0; i < n; i++) {
|
|
754
774
|
var nd = nodes[i];
|
|
755
|
-
if (nd === dragging) continue;
|
|
775
|
+
if (nd === dragging || nd._phrenPinned) continue;
|
|
756
776
|
var fx = 0, fy = 0;
|
|
757
777
|
for (var j = 0; j < n; j++) {
|
|
758
778
|
if (i === j) continue;
|
|
@@ -782,7 +802,7 @@ export function renderGraphScript() {
|
|
|
782
802
|
/* repulsion via quadtree */
|
|
783
803
|
for (var i = 0; i < n; i++) {
|
|
784
804
|
var nd = nodes[i];
|
|
785
|
-
if (nd === dragging) continue;
|
|
805
|
+
if (nd === dragging || nd._phrenPinned) continue;
|
|
786
806
|
var r = qt.computeForce(nd, THETA, REPULSION, 0, 0);
|
|
787
807
|
nd.vx = (nd.vx || 0) + r.fx * alpha;
|
|
788
808
|
nd.vy = (nd.vy || 0) + r.fy * alpha;
|
|
@@ -798,8 +818,8 @@ export function renderGraphScript() {
|
|
|
798
818
|
var dist = Math.sqrt(dx * dx + dy * dy) + 0.1;
|
|
799
819
|
var force = SPRING_K * (dist - REST_LEN) * alpha;
|
|
800
820
|
var fx = force * dx / dist, fy = force * dy / dist;
|
|
801
|
-
if (s !== dragging) { s.vx += fx; s.vy += fy; }
|
|
802
|
-
if (t !== dragging) { t.vx -= fx; t.vy -= fy; }
|
|
821
|
+
if (s !== dragging && !s._phrenPinned) { s.vx += fx; s.vy += fy; }
|
|
822
|
+
if (t !== dragging && !t._phrenPinned) { t.vx -= fx; t.vy -= fy; }
|
|
803
823
|
}
|
|
804
824
|
|
|
805
825
|
/* while a node is held, keep pulling its local cluster every frame */
|
|
@@ -814,7 +834,7 @@ export function renderGraphScript() {
|
|
|
814
834
|
var gravScale = n > 50 ? 80 / n : 1;
|
|
815
835
|
for (var i = 0; i < n; i++) {
|
|
816
836
|
var nd = nodes[i];
|
|
817
|
-
if (nd === dragging) continue;
|
|
837
|
+
if (nd === dragging || nd._phrenPinned) continue;
|
|
818
838
|
var grav = GRAVITY * gravScale;
|
|
819
839
|
nd.vx += (cx - nd.x) * grav * alpha;
|
|
820
840
|
nd.vy += (cy - nd.y) * grav * alpha;
|
|
@@ -823,7 +843,7 @@ export function renderGraphScript() {
|
|
|
823
843
|
/* integrate */
|
|
824
844
|
for (var i = 0; i < n; i++) {
|
|
825
845
|
var nd = nodes[i];
|
|
826
|
-
if (nd === dragging) continue;
|
|
846
|
+
if (nd === dragging || nd._phrenPinned) continue;
|
|
827
847
|
nd.vx *= DAMPING;
|
|
828
848
|
nd.vy *= DAMPING;
|
|
829
849
|
nd.x += nd.vx;
|