Better Code Organization with selection.call() with D3 v4

Share this video with your friends

Send Tweet

Most of D3’s native selection APIs also return the selection (or a new selection), to enable multiple method calls to be chained together. Since the code you write isn’t on the selection prototype, chaining your methods would take some extra work. selection.call() will call any function reference you give it, providing the selection as the first parameter, and then it returns the selection for you to ensure chaining is supported.

Noah Rawlins
~ 8 years ago

Interesting transcript. I missed the parts about Juanita in the video. Anyway, when you mouseover the text itself, the mouseover for the rect is lost. Is there a clean way to handle that so that the rect still expands when the mouse is over the text?

Ben Clinkinbeardinstructor
~ 8 years ago

LOL, good catch on the transcript, I've reported that to the Eggheads in charge.

Also a good catch on the code. If you add .style('pointer-events', 'none') to the part that creates the text elements that will fix that issue.