Reputation: 1560
I am building a sankey diagram, like this https://bost.ocks.org/mike/sankey/ however I need to be able to highlight an entire pathway when the user hovers over the node.
Is there anything built into D3 to do that? If not, how could I do this in Javascript?
Upvotes: 1
Views: 391
Reputation: 3155
In the posted example the hover effect is accomplished through a simple CSS rule for the :hover
pseudo class.
When the whole path should be highlighted, this isn't as simple anymore. I see two options.
mouseenter
and mouseleave
handlerhightlight
class for elements whose bound elements are marked to be highlightedmouseleave
as wellThis option more unconventional. The idea is as follows:
enter
selection, set individual classes on an element for each path it is part ofmouseenter
handler set the currently selected path as a class
– let's say hightlight-path-13
if it is path number 13 – on a parent DOM element of the edge elementsIn CSS have selectors similar to this
.highlight-path-13 .path-13 { stroke-opacity: 0.5; }
Upvotes: 1