I need to set the radius of some circles, i have the following data, made up of links and nodes. I need to set the radius of the circles(nodes), to the sum of the links connected to the nodes
var data = {
"nodes": [
{
"id": "s1",
"val": 12
},
{
"id": "s2",
"val": 12
},
{
"id": "s3",
"val": 12
},
{
"id": "s4",
"val": 12
},
{
"id": "s5",
"val": 12
},
{
"id": "s6",
"val": 12
}
],
"Links": [
{
"n1": "s1",
"n2": "s2",
"amount": 10
},
{
"n1": "s2",
"n2": "s3",
"amount": 10
},
{
"n1": "s2",
"n2": "s4",
"amount": 10
},
{
"n1": "s2",
"n2": "s6",
"amount": 10
},
{
"n1": "s3",
"n2": "s1",
"amount": 10
},
{
"n1": "s4",
"n2": "s5",
"amount": 10
},
{
"n1": "s5",
"n2": "s6",
"amount": 10
}
]
};
i.e. ( i expect the node to be in context at this point), i have written some pseudo code below
val1 = 0
val2 = 0
for i to len.links
if (links.node1 = nodes.id)
val1 = val1 + links.amount
else if (links.node02 = nodes.id)
val2 = val2 + links.amount
next
sum = val1 + val2
The code below, puts the circles to the screen, i have tried various methods but allays results in what i am referring to as the white screen of death
var w = 1200;
var h = 800;
var svg = d3.select("body").append("svg").attr("width",w).attr("height", h);
var lines = svg.attr("class", "line")
d3.json("data.json", function(error, data) {
console.log(data);
var circles = svg.selectAll("foo")
.data(data.nodes)
.enter()
.append("circle")
.attr("cx", function(d) {
return d.x;
})
.attr("cy", function(d) {
return d.y;
})
.attr("r", 20); // <- i want to put this calculation here
I am new to JS and have no idea how to translate this in to Javascript