The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

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

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

4:22
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.
Watch this lesson now
Avatar
egghead.io

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.

Avatar
Noah Rawlins

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?

Avatar
Ben

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.

In reply to Noah Rawlins
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?