Oh, right! We can simplify this much further in fact.
Note that when you add a title the input event is sent to the FIGURE element, and not on the SVG anymore, so this is currently half-broken. Fix coming up.
oh that's really nice! I was curious if it would work for dots, and it does – I made a lightly edited version below. The .raise() call was slow so I used a separate mark for the gray dots.
I like the generality of this way of doing linked cross-facet interactions. And I like that it generalizes to arbitrary relatedness predicates and multi-element selections, too.
Though it does take advantage of a (currently undocumented) feature of the plot marks, namely the index data that's associated with the individual elements by d3. And I wonder how this sort of thing would compose with non-d3-powered marks (eg. canvas-backed displays). But it's still damn cool...
- it's true that the index data association is implementation specific. I don't think it's too fragile, because if the mark’s underlying implementation ever changed, we can think of other ways to make that link: for example by adding a “data-z” property, or by setting up a WeakMap (from path to z). But worth calling out if we publish this example
- the only canvas-backed displays we have so far is Plot.raster and your experiments with density plots; it would be fun to make them react to the pointer transform
- I think raise() would be faster if the nodes were grouped by z, and we would raise the group (however, the default render doesn't do this, so it would mean we'd need more code).