Fixed bug in graph implementation

This commit is contained in:
NunoSempere 2021-06-11 09:05:23 +02:00
parent 4d6abd382b
commit 5f03f187c6

View File

@ -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)
})