Skip to content

Commit

Permalink
Workaround for jquery problem with scale and drag
Browse files Browse the repository at this point in the history
  • Loading branch information
marcodiiga committed Apr 4, 2015
1 parent 54ced43 commit f4d1120
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions nodemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
// closer to their parents)
this.stabilityTimeout = 0; // A timeout for the subtree stability search
this.stopSubtreeMoving = false; // The variable that controls the timeout
this.beginDragging = false; // Since jquery messes around with a node's
// position when dragging starts, if this is
// true, we don't consider this node at all

// Create the node element in the page and append it to the map's object
this.$element = $('<a href="' + this.href + '"><p>' + this.name + '</p></a>')
Expand Down Expand Up @@ -91,8 +94,9 @@
var thisNode = this;
this.$element.draggable ({ // Set a jQuery callback function when dragging
start: function(event, ui) {
ui.position.left = 0;
ui.position.top = 0;
thisNode.beginDragging = true; // Avoid jquery problems with scale and drag
ui.position.left = 0;
ui.position.top = 0;
},
drag: function (event, ui) {

Expand All @@ -115,6 +119,9 @@
thisNode.animateToStaticPosition ();
else // If I'm not the root, animate my parent's subtree (where I belong)
thisNode.$parent.node.animateToStaticPosition ();

thisNode.beginDragging = false; // From now on, consider this node's
// position when moving the others
}
});

Expand Down Expand Up @@ -458,9 +465,9 @@
for (i = 0; i < mySiblingNodes.length; ++i) {
if (mySiblingNodes[i] === this)
continue; // Repulsive force from myself = nonsense
//
//if (!this.$map.nodes[i].visible) // TODO: a visible attribute could be useful
// continue;

if (mySiblingNodes[i].beginDragging === true)
continue; // Do not consider a node immediately being dragged (unreliable)

f = this.calculateSingleRepulsionForceFromNode (mySiblingNodes[i]);
fx += f.dx;
Expand All @@ -486,8 +493,6 @@
if (this.children.indexOf(otherEnd) !== -1)
continue; // This is one of my children, keep on searching

// TODO: ignore hidden nodes' pulling (visible)

f = this.calculateSingleAttractiveForceTowardsNode (otherEnd,
Math.pow(this.depthLevel, 4)); // Powerful damping if we're deeply nested
fx += f.dx;
Expand Down

0 comments on commit f4d1120

Please sign in to comment.