简体   繁体   中英

Highlight specific link in D3.JS sankey diagram

In the example below, I want to permanently highlight a specific link (connection between each of the nodes) on initial load:

http://bl.ocks.org/d3noob/c2637e28b79fb3bfea13

As you can see, it will highlight a link on mouse hover.

This achieved with css:

.link:hover {
  stroke-opacity: .5;
}

How can I obtain the same result for a specific link (eg for link between the first two nodes), without using mouse hover (ie when the SVG elements are first added).

That's what you need: First, filter the link array accordingly.

var firstLink = link.filter(d => d.source.node === 0 && d.target.node === 4);

In that case, we get the first link (at the top), which goes from node 0 (source) to node 4 (target).

Then, apply the opacity:

firstLink.attr("opacity", .5);

Here is a fiddle showing it: https://jsfiddle.net/7mm1ko4f/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM