There are no issues with the method you are using to construct the URL. Perhaps the value you are trying to access is not defined on objects in the data array? For example, make sure that d.url
is defined.
Here is a small working example that shows links working using the same method you are using (also hosted on bl.ocks.org):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>D3 Links Example</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
</head>
<body>
<script>
var data = ["JavaScript", "Document_Object_Model", "Ajax_(programming)"];
d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
.selectAll("a").data(data)
.enter()
.append("a")
.attr("xlink:href", function (d){
return "http://en.wikipedia.org/wiki/" + d;
})
.append("rect")
.attr("x", function (d, i){
return 140 + i * 240;
})
.attr("y", 150)
.attr("width", 200)
.attr("height", 200);
</script>
</body>
</html>
Update 6/10/2015 re: updated fiddle:
When your code computes "submissionsByCountry = d3.nest()...", you are losing the entityid property, because it is being aggregated away.
If you inspect the values you have for "d" where you are adding the link, you can see that they look like this
Object {key: "OrgUU", values: 1, parent: Object, depth: 2, value: 1…}
because these objects are the result from the circle packing layout, not elements in the original data array.
If there is a 1-1 mapping between Organization and id (which looks to be true in your example data), you can look up the id from the organization. First you can build the lookup table like this:
var idByOrg = {};
data.forEach(function (d) {
idByOrg[d.Organisation] = d.entityid;
});
Then later access it like this:
//Create nodes/circles
node.append("svg:a")
.attr("xlink:href", function (d) {
console.log(d); // Shows {key: "OrgUU", values: 1, parent: Object, depth: 2, value: 1…}
var entityid = idByOrg[d.key];
return "http://www.example.com/entityform/" + entityid;
})
.append("circle")
.attr("r", function (d) {
return d.r;
});
Now if you inspect the generated URLs, you see things like "http://www.example.com/entityform/10" and "http://www.example.com/entityform/3".
Here's a working fiddle that does this.
Note that the links only work on leaf nodes in the circle tree. I suppose the next step would be to only include links on the leaf nodes, and not the outer circles.