🌍 Public
Viewing a saved revision (read-only)
96178ab1712e4b55ae8078c10ec9bbf4
Mouse Follower Simple
This example demonstrates a simple interactive visualization where a circle follows the mouse cursor within an SVG container. The circle’s position is stored in the application state, and every mouse movement updates the state using immutable update patterns, spreading the previous state object and assigning new x and y coordinates. The code uses D3’s `select` and `pointer` APIs to handle the `mousemove` event, and a data join to render the SVG and circle elements. The circle is initialized at the center of the container before any mouse interaction occurs.
AI-generated descriptionA program that follows the mouse around and changes its color using immutable update patterns.
Challenge
- Use this pattern to make something else respond to mouse events