Skip to main content
100%

Adding links to objects in v4

✓ Published0🌍 Public
Dd3noob
Last edited Aug 18, 2016
Created on Aug 18, 2016

A hyperlink encloses a rounded rectangle, while the text label "gongoozler" sits on top. The example shows how to make a non-rectangular object clickable by adding an anchor element with `xlink:href` to the SVG, and how to let mouse clicks pass through the text to the link below it. The text uses `pointer-events: none`, so hovering or clicking the label triggers the rectangle's link. The code relies on D3 v4's selection and SVG creation methods to build the static graphic and set the necessary attributes.

AI-generated description

The above example is intended to demonstrate adding a hyperlink to an object (the rectangle) and instructing the text object to be transparent to the pointer so that the link on the rectangle is recognised 'through' the text.

This is one of the code samples for the update to the book D3 Tips and Tricks to version 4 of d3.js.

Similar vizzes