title: D3 javascript network: How to parametrize node size with the number of links?
body: <p>I want to create a network with d3.js. I have created one as you see below, but I want the node size to depend on the number of links each node has (the more links a node has, the bigger the size of the node, vice versa). Below is the JS I wrote for the nodes.</p>
  
  <p>How do I change the node size with the number of links?</p>
  
  <pre><code>var nodes = graph.nodes.slice(),
        links = [],
        bilinks = [];
  
    graph.links.forEach(function(link) {
      var s = nodes[link.source],
          t = nodes[link.target],
          i = {}; // intermediate node
      nodes.push(i);
      links.push({source: s, target: i}, {source: i, target: t});
      bilinks.push([s, i, t]);
    });
  
  var node = svg.selectAll(".node")
        .data(graph.nodes)
        .enter().append("circle")
        .attr("class", "node")
        .attr("r", 3)
        .style("fill", function(d) { return color(d.group); })
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fsrKX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fsrKX.png" alt="enter image description here"></a></p>