title: Uncaught TypeError in D3 Sankey Drag Function
body: <p>I have created a d3 Sankey graph. The issue that I'm facing is that I am unable to drag the nodes.
  This is how the node is created:</p>
  
  <pre><code> var node = svg.append("g").selectAll(".node")
        .data(graph.nodes)
      .enter().append("g")
        .attr("class", "node")
        .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
        .on("click",highlight_node_links)
      .call(d3.behavior.drag()
        .origin(function(d) { return d; })
        .on("dragstart", function() { this.parentNode.appendChild(this); })
        .on("drag", dragmove));
  </code></pre>
  
  <p>And the dragmove function is as follows:</p>
  
  <pre><code> function dragmove(d) {
  
      d3.select(this).attr("transform", 
          "translate(" + (
                 d.x = Math.max(0, Math.min(width - d.dx, d3.event.x))
              ) + "," + (
                     d.y = Math.max(0, Math.min(height - d.dy, d3.event.y))
              ) + ")");
      sankey.relayout();
      link.attr("d", path);
    }
  </code></pre>
  
  <p>But everytime I run my code, it throws this error:
  <strong>Uncaught TypeError: Cannot read property 'target' of null</strong></p>
  
  <p>What am I doing wrong?</p>
  
  <p><a href="https://i.stack.imgur.com/DMRyk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DMRyk.png" alt="If I click on the error, it takes me to a blank line on the index page"></a></p>