title: D3 4.0 Graph with directed edges and labels
body: <p>I am trying to create a graph with d3 (v4.0) that has directed edges and labels for the nodes, something like this: <a href="http://jsfiddle.net/chrisJamesC/HgHqy/" rel="nofollow">http://jsfiddle.net/chrisJamesC/HgHqy/</a> but with a newer version of D3.</p>
  
  <p>This is what I have so far: <a href="https://jsfiddle.net/4nu57pgn/1/" rel="nofollow">https://jsfiddle.net/4nu57pgn/1/</a> but I can't seem to figure out how to tell D3 to make the edges appear visually directed (with arrows) or to have the node IDs displayed.</p>
  
  <pre><code>var svg = d3.select("svg");
  var width = svg.attr("width");
  var height = svg.attr("height");
  svg = svg.call(d3.zoom().on("zoom", zoomed)).append("g");
  var color = d3.scaleOrdinal(d3.schemeCategory10);
  
  var simulation = d3.forceSimulation()
      .force("link", d3.forceLink().id(function(d) { return d.id; }))
      .force("charge", d3.forceManyBody())
      .force("center", d3.forceCenter(width / 2, height / 2));
  
  function createGraph (error, graph) {
    if (error) throw error;
  
    var link = svg.append("g")
        .attr("class", "links")
      .selectAll("line")
      .data(graph.links)
      .enter().append("line")
        .attr("stroke", function(d) { return color(d.type); });
  
  
    var node = svg.append("g")
        .attr("class", "nodes")
      .selectAll("circle")
      .data(graph.nodes)
      .enter().append("circle")
        .attr("r", 10)
        .attr("fill", function(d) { if (d.root == "true") return color(d.root); return color(d.type); })
        .call(d3.drag()
            .on("start", dragstarted)
            .on("drag", dragged)
            .on("end", dragended));
  
    node.on("click",function(d){
      console.log("clicked", d.id);
    });
  
    node.append("title")
        .text(function(d) { return d.id; });
  
    simulation
        .nodes(graph.nodes)
        .on("tick", ticked);
  
    simulation.force("link")
        .links(graph.links);
  
    function ticked() {
      link
          .attr("x1", function(d) { return d.source.x; })
          .attr("y1", function(d) { return d.source.y; })
          .attr("x2", function(d) { return d.target.x; })
          .attr("y2", function(d) { return d.target.y; });
  
      node
          .attr("cx", function(d) { return d.x; })
          .attr("cy", function(d) { return d.y; });
    }
  }
  
  function dragstarted(d) {
    if (!d3.event.active) simulation.alphaTarget(0.3).restart();
    d.fx = d.x;
    d.fy = d.y;
  }
  
  function dragged(d) {
    d.fx = d3.event.x;
    d.fy = d3.event.y;
  }
  
  function dragended(d) {
    if (!d3.event.active) simulation.alphaTarget(0);
    d.fx = null;
    d.fy = null;
  }
  
  function zoomed() {
    svg.attr("transform", "translate(" + d3.event.transform.x + "," + d3.event.transform.y + ")" + " scale(" + d3.event.transform.k + ")");
  }
  </code></pre>
  
  <p>I am new to D3 and would appreciate any help pointing me in the correct direction.</p>