diff --git a/lib/labeledgraph.js b/lib/labeledgraph.js index 01d8322..7e3012a 100644 --- a/lib/labeledgraph.js +++ b/lib/labeledgraph.js @@ -21,6 +21,8 @@ function drawGraphInner({nodes, links}){ // List of node ids var nodeids = nodes.map(function(d){return d.id}) + var positionById = {} + nodeids.forEach((nodeid, i) => positionById[nodeid]=i) // A linear scale to position the nodes on the X axis var x = d3.scalePoint() @@ -56,9 +58,9 @@ function drawGraphInner({nodes, links}){ .enter() .append('path') .attr('d', function (d) { - let start = x(d.source) + let start = x(positionById[d.source]) // X position of start node on the X axis - let end = x(d.target) + let end = x(positionById[d.target]) // X position of end node return ['M', start, @@ -83,9 +85,9 @@ function drawGraphInner({nodes, links}){ .enter() .append("text") .attr("x", function(d){ - let start = x(d.source) + let start = x(positionById[d.source]) // X position of start node on the X axis - let end = x(d.target) + let end = x(positionById[d.target]) // X position of end node return start + (end-start)/2 -4*getlength(d.distance) })