I am using a force directed graph (d3js v4), and I would like to have the text on the link. I'm using the following code for this;
    link.append("text")
        .attr("text-anchor", "middle")
        .attr("transform", function(d) {
            return "translate(" +
                ((d.source.y + d.target.y)/2) + "," + 
                ((d.source.x + d.target.x)/2) + ")";
        })
        .text(function(d) {
            console.log(d);
            console.log(d.source.x);
            return d.link_name;
        });
I only get an error with:
Error: <text> attribute transform: Expected number, "translate(NaN,NaN)".
The strange thing is when looking at my debug console the d object has a source and the x property. However when I debug the d.source.x the debug says it is undefined. Any clue what might be wrong? Here is the full code:
http://blockbuilder.org/anonymous/17bac3017a5aaab26268c4f687c302ec
