Friday, 13 September 2019

d3.js mistakes object for string

I have a graph with nodes that carry more attributes than names/ids, but also the degree for some filtering. When I run some logging, for some reason d3 mistakes the object (node) for a string.

The code:

svg.selectAll("line").each(function (l) {
    let opacity =  l.source.degree >= nodeDegreeFilter && l.target.degree >= nodeDegreeFilter ? 1 : 0;
    d3.select(this).style("opacity", opacity);
    console.info(opacity, l.target, typeof l.target, l);
  });

yields this output:

0 North Carolina string Object
{
​
index: 222
​
source: Object { id: "Impotency", group: 2, class: 1, … }
​
target: Object { id: "North Carolina", group: 2, class: 0, … }
​
value: 1
}

Can someone help me figure out what is going on?



from d3.js mistakes object for string

No comments:

Post a Comment