I came across a helpful post on StackOverflow about dynamically setting the size of a node in my graph based on the number of links it has. The link is provided here: D3 Node radius depends on number of links : weight property.
Following the guidance from the StackOverflow answer, I implemented the dynamic weight calculation for each node in my graph like this:
node.append("circle")
.attr("r", function(d) {
d.weight = links.filter(function(l) {
return l.source.index == d.index || l.target.index == d.index;
}).size();
var minRadius = 10;
return minRadius + (d.weight * 2);
});
However, during the implementation, I encountered an error message:
TypeError: links.filter(...).size is not a function
I'm puzzled by this error and unsure about what mistake I might have made. Any suggestions?
Here is the full script that I've been working with:
d3.dsv(",", "board_games.csv", function(d) {
return {
source: d.source,
target: d.target,
value: +d.value
}
}).then(function(data) {
var links = data;
var nodes = {};
// code to compute distinct nodes from the links...
}).catch(function(error) {
console.log(error);
});