Adding hyeperlinks to zoomable d3 circle pack

Tim Gottgetreu

I've been trying to add clickable hyperlinks to a zoomable d3 circle pack based on this code: http://bl.ocks.org/nilanjenator/4950148, but I just can't get it to work. Ideally I'd link a link under the text label for the circle, but at this point a clickable label would be just as rad.

I'm sure its a misunderstanding of d3 on my part. I've researched several stack topics that should work: (Hyperlinks in d3.js objects) and here are my failed attempts. I've also updated the json data file to include urls, ie.

{
 "name": "data",
 "children": [
  {"name": "Data", "size": 20544, "url":"http://katetempest.co.uk/audio"},
  {"name": "Ellington Willoughby", "size": 19788, "url": "http://wwww.ellingotnwilloughby.com"},
  {"name": "HELP", "size": 10349,"url":"http://en.wikipedia.org/wiki/Help!_%28album%29" },

  {

etc.

First crash and burn..adding a xlink to either the circle or the text, or node as mentioned in the other stack questions. This is where my d3 understanding breaks down.

vis.selectAll(".node")//also tried "cirlce" and "text"
 .append("svg:a").attr("xlink:href", function(d){ return d.url })
  .append("svg:text")
  .text(function(d) { return d.name; })
  .attr("dy", 3.5)
  .attr("dx", 5.5)
  .attr("text-anchor", "bottom");

I've added

<html xmlns:xlink="http://www.w3.org/1999/xlink">

to my html at the beginning of the project. But nothing happends.

Next burn - Adding on "onclick" event to the text such as:

  vis.selectAll("text")
  .data(nodes)
  .enter().append("svg:text")
  .attr("class", function(d) { return d.children ? "parent" : "child"; })
  .attr("x", function(d) { return d.x; })
  .attr("y", function(d) { return d.y; })
  .attr("dy", ".35em")
  .attr("text-anchor", "middle")
  .style("opacity", function(d) { return d.r > 20 ? 1 : 0; })
  .text(function(d) { return d.name; })
  .on("click",function(d){window.location = d.url}); ///<----Party here? Nope!

I'v also made sure to set my css as:

circle.child {
pointer-events: all;
}

Since I've read this gets in the way of tool-tips and general clickable thingamajigs, etc.

So what am I doing wrong? I'm pretty sure its my lack of understanding on which element to select and add the "svg:a" attr, but I'm stuck, which of course is a bummer. Exponential thanks to the stack community for taking a crack at it, and apologizes if I over looked something trivial and wasted everyone's time.

Cheers!

Tim Gottgetreu

Thanks to the FernOfTheAndes comment I was able to get this all going. Just thought I'd post if someone else ran into this. I've modified the "onclick" circle event to only allow the link to work if you're at the lowest circle, otherwise its a bit messy...here you go:

vis.selectAll("circle")
  .data(nodes)
  .enter().append("svg:circle")
  .attr("class", function(d) { return d.children ? "parent" : "child"; })
  .attr("cx", function(d) { return d.x; })
  .attr("cy", function(d) { return d.y; })
  .attr("r", function(d) { return d.r; })
  .on("click", function(d) {

    //Enables links when elements have no childern
    if(typeof d.children === 'undefined'){
      vis.selectAll("text")
         .style("pointer-events","all")
    }
    else
    {
      vis.selectAll("text")
         .style("pointer-events","none")
    }

    return zoom(node == d ? root : d); 

    });

and in the css to allow access to childless circles (I think):

circle.child {
pointer-events: all;

}

Thanks again to the stack community!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

'd3-circle-text' on zoomable circle-pack

From Dev

how to update data form file json using d3.js (zoomable circle pack)

From Dev

D3 add zoom to circle pack

From Dev

d3 zoomable treemap - adding new captions in the right place

From Dev

Different colors for each circle - D3 circle pack

From Dev

Adding text to d3 circle

From Dev

How to Hide Overlapping Text of Labels in D3 Zoomable Pack Layout?

From Dev

How to Hide Overlapping Text of Labels in D3 Zoomable Pack Layout?

From Dev

D3 Zoomable Circle Packing in IE11 is expanding beyond the SVG boundary

From Dev

Realtime D3 bubble chart (circle pack)

From Dev

D3 Circle Pack Layout with a horizontal arrangement

From Dev

Keeping aspect ratio of D3 circle pack - responsive design

From Dev

Text along circles in a D3 circle pack layout

From Dev

Tooltips for nested circles in D3 circle pack layout

From Dev

Controlling order of circles in D3 circle pack layout algorithm

From Dev

stop d3 circle pack labels from overlapping

From Dev

Controlling order of circles in D3 circle pack layout algorithm

From Dev

Keeping aspect ratio of D3 circle pack - responsive design

From Dev

Undefined function when loading D3 circle pack

From Dev

Zoomable Circle Packing with Automatic Text Sizing in D3.js

From Dev

D3 - How to convert circle-pack to ellipse-pack?

From Dev

Adding d3.js interactive zoomable treemap in RAW

From Dev

Adding an image within a circle object in d3 javascript?

From Dev

D3: adding a line when clicking on a circle in scatter plot

From Dev

Zoomable Circle packing - parent undefined

From Dev

D3 update circle-pack data new nodes overlap existing nodes

From Dev

is it possible to tweak the d3 bubble chart to obtain the bubbles at scattered positions instead of a circle pack?

From Dev

Circle Pack Layout D3 - remove add nodes on new data

From Dev

Zoomable D3 Angular Treemap Directive

Related Related

  1. 1

    'd3-circle-text' on zoomable circle-pack

  2. 2

    how to update data form file json using d3.js (zoomable circle pack)

  3. 3

    D3 add zoom to circle pack

  4. 4

    d3 zoomable treemap - adding new captions in the right place

  5. 5

    Different colors for each circle - D3 circle pack

  6. 6

    Adding text to d3 circle

  7. 7

    How to Hide Overlapping Text of Labels in D3 Zoomable Pack Layout?

  8. 8

    How to Hide Overlapping Text of Labels in D3 Zoomable Pack Layout?

  9. 9

    D3 Zoomable Circle Packing in IE11 is expanding beyond the SVG boundary

  10. 10

    Realtime D3 bubble chart (circle pack)

  11. 11

    D3 Circle Pack Layout with a horizontal arrangement

  12. 12

    Keeping aspect ratio of D3 circle pack - responsive design

  13. 13

    Text along circles in a D3 circle pack layout

  14. 14

    Tooltips for nested circles in D3 circle pack layout

  15. 15

    Controlling order of circles in D3 circle pack layout algorithm

  16. 16

    stop d3 circle pack labels from overlapping

  17. 17

    Controlling order of circles in D3 circle pack layout algorithm

  18. 18

    Keeping aspect ratio of D3 circle pack - responsive design

  19. 19

    Undefined function when loading D3 circle pack

  20. 20

    Zoomable Circle Packing with Automatic Text Sizing in D3.js

  21. 21

    D3 - How to convert circle-pack to ellipse-pack?

  22. 22

    Adding d3.js interactive zoomable treemap in RAW

  23. 23

    Adding an image within a circle object in d3 javascript?

  24. 24

    D3: adding a line when clicking on a circle in scatter plot

  25. 25

    Zoomable Circle packing - parent undefined

  26. 26

    D3 update circle-pack data new nodes overlap existing nodes

  27. 27

    is it possible to tweak the d3 bubble chart to obtain the bubbles at scattered positions instead of a circle pack?

  28. 28

    Circle Pack Layout D3 - remove add nodes on new data

  29. 29

    Zoomable D3 Angular Treemap Directive

HotTag

Archive