Comments (7)
@yrokhlin's solution didn't work for me, so based on his solution I modify the calculated path.
.attr('d', d => {
// Prevents exact horizontal sankey links from disappearing.
// See for reference https://github.com/d3/d3-sankey/issues/28
const path = sankeyLinkHorizontal()(d);
const match = path.match(/,([^C]+)C/);
if (match.length !== 2) {
return path;
}
const replacementValue = +match[1] + 0.01;
const fixedPath = path.replace(match[1], '' + replacementValue);
return fixedPath;
})
This turns M16,352.50000000000005C249.66666666666666,etc..
into M16,352.51000000000005C249.66666666666666,etc..
.
from d3-sankey.
For any future googlers such as myself that may stumble upon this problem, I found a neat little hack that will let you get around this issue.
.attr('d', d3.sankeyLinkHorizontal())
.attr('d', (d, i, items) => {
const path = d3.select(items[i]).attr('d');
return path + ' l0,0.001';
})
This takes your d
attribute after you set it with d3.sankeyLinkHorizontal()
and adds a small string at the end which basically just picks up the last point of the path and slightly jitters it on the y
axis. This makes it so d.y1 - d.y0 === 0
will never be true
and the jitter is visually imperceivable.
I think this is a better solution than creating a rect
especially if you are doing any sort of highlighting.
I hope this helps someone else out who is stuck.
from d3-sankey.
This is an unfortunate limitation of SVG’s design; the default gradientUnits = objectBoundingBox, and when the path is horizontal, the bounding box is degenerate (height = zero) because the bounding box does not consider the stroke.
The “easiest” fix is to gradientUnits = userSpaceOnUse, but then you have to compute the coordinates of the gradient relative to the SVG container rather than using the local coordinates of the path.
Or, you could compute the outline of the path yourself by computing the offset Bézier—not trivial! Bezier.js might help with that.
Or, you could special-case horizontal lines and draw a rect instead of a line, or some such.
In the future, please use Stack Overflow tag d3.js to ask for help. Although I make an effort to assist everyone that asks, I am not always available to provide help promptly or directly. Stack Overflow provides a better collaborative forum for self-help: tens of thousands of D3-related questions have already been asked there, and some answered questions may be relevant to you.
If you have a question about D3’s behavior and want to discuss it with other users, also consider the d3-js Google Group or joining the d3-js Slack.
Thank you! 🤗
from d3-sankey.
Thank you very much for your detailed answer! I did a quick fix, with userSpaceOnUse, but I will maybe just draw a rect to avoid this problem at all.
"Quickfix" with wrong colors:
if(d.y1 - d.y0 === 0) {
linearGradient.attr('gradientUnits', "userSpaceOnUse")
}
from d3-sankey.
That fix probably isn’t sufficient because you’ll need to specify different coordinates for the gradient when you switch to userSpaceOnUse.
from d3-sankey.
Yes I know - but the color is at least visible! 😅 (despite being wrong / incorrect).
// edit: I added a rect if d.y1 - d.y0 === 0
- works perfectly.
from d3-sankey.
For me issue was that I had spaces in gradient id so it was not picking up correctly.
from d3-sankey.
Related Issues (20)
- Support to apply styles to node title HOT 2
- D3 Sankey customization HOT 1
- nodeAlign not aligning the nodes properly HOT 1
- Y coordinates of links control points calculates with error
- Unwanted circle on link path HOT 1
- Distribute or normalize nodes to fill available space
- Documentation image screenshots look strange with github's dark mode
- Uncaught RangeError: Invalid array length computeNodeBreadths
- Reconsider adding maintainers HOT 1
- Is it possible to sort source or target nodes in one column?
- Little to no activity on this plugin HOT 2
- Issues With Zero Values
- Issues with 0 values
- c.length undefined HOT 3
- what algorithm the sankey uses to arrange the node positions
- Unwanted overlap of multiple/parallel links with sankeyLinkHorizontal
- sankey with mouseover links not working with d3@6 HOT 1
- Different Link Width at Source and Target HOT 3
- sourceLinks `y0` and `y1` calculated the wrong way round HOT 1
- Setting min height of node to avoid overlap issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-sankey.