Skip to main content
100%

Adding links to objects in v5

✓ Published0🌍 Public
Dd3noob
Last edited Nov 28, 2019
Created on Nov 28, 2019

This example shows how to make an SVG rectangle clickable as a hyperlink in D3 v5, with text displayed on top that remains transparent to pointer events. It uses d3.select and .append to create the SVG container, an anchor element with xlink:href, and a styled rect element. The text element uses pointer-events set to "none" so clicks pass through to the linked rectangle beneath. The code draws a light-green, rounded rectangle with the word "gongoozler" centered inside, linking to the corresponding Wikipedia page.

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 5 of d3.js.

mit Licensed

Similar vizzes