Skip to main content
100%

Dispatching Events Example

✓ Published1🌍 Public
CCurran Kelleher
Last edited Oct 26, 2021
Created on Oct 20, 2021
Forked from D3 Starter

A circle rendered as an SVG element changes its radius in response to clicks, demonstrating how chart instances can emit and handle custom events. Clicking the circle triggers a click handler in the Circle component, which dispatches an `input` event with a random value and a `detail` property. The main script listens for this event using D3’s `select().on()`, reads the radius from `event.target.value`, and calls the `update()` method to animate the radius via a D3 transition. The example uses `d3.create`, `d3.select`, and `transition.attr`, based on the Observable chart pattern.

AI-generated description

Click the circle to make it change size.

Trying to understand the pattern found in Observable: D3 Charts in terms of how one might adapt it so that chart instances can emit events.

Reference examples:

MIT Licensed

Similar vizzes