Skip to main content
🌍 Public

Share visualization

Send this visualization to others.

D3 Letter Inserting

Public visualization

D3 Letter Inserting

0 stars1🌍 Public
SSubhendu Karmakar
Last edited Dec 26, 2023
Created on Dec 25, 2023
Forked from Learn D3

Two animations run side by side to demonstrate the key function in D3 data joins. Each click of the “Insert Element” button prepends a new letter from the alphabet, shifting the existing letters rightward. The left panel uses a plain `.data(data)` join, causing elements to be matched by index and thus reordered incorrectly. The right panel uses `.data(data, d => d)` with a key function, ensuring each letter stays bound to its original DOM element. Both panels use `.join('div')`, `transition()`, and inline styles to animate the horizontal position.

AI-generated description

Learning D3

Comments

Sign in to join the discussion.

MIT Licensed