From 2bb114bbb1905dfe52b205837fc120edad0875ef Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Wed, 13 Aug 2014 00:47:03 +0300 Subject: fix force and drag interaction according to wiki - could have also used the force.drag behavior (but we already had callbacks) --- scripts/rhizicore.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js index 287c55e7..bd31f6f8 100644 --- a/scripts/rhizicore.js +++ b/scripts/rhizicore.js @@ -20,7 +20,7 @@ var scrollValue = 0, zoomLevel = 0, zoomObject; - +var force; function myGraph(el) { @@ -344,23 +344,28 @@ function myGraph(el) { function dragstarted(d) { d3.event.sourceEvent.stopPropagation(); d3.select(this).classed("dragging", true); + force.stop(); } function dragged(d) { d3.select(this).attr("cx", d.x = d3.event.x).attr("cy", d.y = d3.event.y); + tick(); } function dragended(d) { d3.select(this).classed("dragging", false); d3.select(this).classed("fixed", true); d3.select(this).attr("dx", d3.event.x).attr("dy", d3.event.y); + tick(); + force.resume(); } - var force = d3.layout.force() + force = d3.layout.force() .distance(120) .gravity(0.12) .charge(-1800) - .size([w, h]); + .size([w, h]) + .start(); nodes = force.nodes(); links = force.links(); @@ -571,6 +576,7 @@ var graph = new myGraph(document.body); var newnodes=1; function tick(e) { //console.log(e); + //$(".debug").html(force.alpha()); function transform(d) { if (graphstate === "GRAPH" || d.type === "deliverable") { @@ -784,7 +790,7 @@ function showInfo(d, i) { $('.info').html('Name: ' + d.id + '



'); } - + $('.info').css("border-color", customColor(d.type)); $("#editenddate").datepicker({ @@ -958,4 +964,4 @@ function customSize(type) { break; } return size; -} \ No newline at end of file +} -- cgit v1.3.1