From 6f060a662b3ca2e9b1fb9bbb2db37ea8449b2535 Mon Sep 17 00:00:00 2001
From: Merle Stahl <merle.stahl@studium.uni-hamburg.de>
Date: Fri, 26 Nov 2021 20:09:34 +0100
Subject: [PATCH] drag nodes

---
 Output/cn.js | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/Output/cn.js b/Output/cn.js
index 539084c..b9a5da2 100644
--- a/Output/cn.js
+++ b/Output/cn.js
@@ -158,10 +158,11 @@ function updateNodes(nodes) {
         .attr('dx', function(d) {return xscale(parseFloat(d.year))})
         .attr("initial_x", function(d) {return d.dx;})
         .attr("initial_y", function(d) {return d.dy;})
-        /*.call(d3.drag()
+        .call(d3.drag()
             .on("start", dragstarted)
             .on("drag", dragged)
-        )*/;
+            .on("end", dragended)
+        );
 
     node.append("circle")
         .attr("class", "circle")
@@ -303,6 +304,16 @@ function dragged(node) {
     node.fy = d3.event.y;
 }
 
+/**
+* ends the dragging and resets the position of the node
+* @param {object} node - data of current node
+*/
+function dragended(node) {
+    if (!d3.event.active) simulation.alphaTarget(.03);
+    node.fx = null;
+    node.fy = null;
+}
+
 /**
 * resets the positions of the nodes
 */
-- 
GitLab