I am new to d3.js library.
I am trying to create a tree, like this one , but with a link to an external page on each node.
Is it possible?
I tried adding "svg: a" to each node, but as a result the whole tree will disappear.
Update:
I am taking this code from the html page linked above.
Associated Libraries:
This is all the code:
<style type="text/css"> .node circle { cursor: pointer; fill: #fff; stroke: steelblue; stroke-width: 1.5px; } .node text { font-size: 11px; } path.link { fill: none; stroke: #ccc; stroke-width: 1.5px; } </style> <script> var m = [20, 120, 20, 120], w = 1280 - m[1] - m[3], h = 800 - m[0] - m[2], i = 0, root; var tree = d3.layout.tree() .size([h, w]); var diagonal = d3.svg.diagonal() .projection(function(d) { return [dy, dx]; }); var vis = d3.select("#body").append("svg:svg") .attr("width", w + m[1] + m[3]) .attr("height", h + m[0] + m[2]) .append("svg:g") .attr("transform", "translate(" + m[3] + "," + m[0] + ")"); d3.json("flare.json", function(json) { root = json; root.x0 = h / 2; root.y0 = 0; function toggleAll(d) { if (d.children) { d.children.forEach(toggleAll); toggle(d); } } </script>
Basically, I tried to add this piece of code just before nodeEnter.append("svg:text")
nodeEnter.append("svg:a") .attr("x", function(d) { return d.children || d._children ? -10 : 10; }) .attr("dy", ".35em") .attr("text-anchor", function(d) { return d.children || d._children ? "end" : "start"; }) .text("http://example.com") .style("fill-opacity", 1e-6);
source share