From 5f03f187c68174b4be9ef1f5c124cdb1a3556b3d Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Fri, 11 Jun 2021 09:05:23 +0200 Subject: [PATCH] Fixed bug in graph implementation --- lib/labeledgraph.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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) })