From the course: D3.js Essential Training for Data Scientists

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Introducing dispatch

Introducing dispatch - D3.js Tutorial

From the course: D3.js Essential Training for Data Scientists

Start my 1-month free trial

Introducing dispatch

- [Teacher] Sometimes, you want to fire off an event without the used having done anything; or perhaps you want to trigger one event based on another. For this you can use d3.dispatch. We're going to create an example in our Voronoi diagram. So we already have a set of behaviors in our Voronoi example, we've already added a mouseover, which displays a tool-tip showing the number of sides of the polygon you're hovering over, and before we begin hovering or mouse moving, technically, the tooltip is hidden. So we've already got an event, and we've already got some behaviors that we want on that event. And what we're going to do now is trigger the event even though nobody is hovering. And to be more specific, we're going to trigger the event on one specific polygon, and I'm going to turn that polygon blue so you can see what we're aiming for. To do that, we select the group that contains the polygons, and then we use CSS terminology, nth-child, to select the 31st polygon, and I know it's…

Contents