react-d3-graph
react-d3-graph copied to clipboard
[WIP] Feature/multiple edges between same nodes
Hello all,
With this draft I purpose a change to solve https://github.com/danielcaldas/react-d3-graph/issues/185 adding support for redundant links between nodes.
What do I Introduce in this PR
- Allow clients to define
id
property to uniquely identify links (alongside withsource
andtargert
) - Offer out of the box to render redundant links, by automatically smoothing the curve of redundant links so that they don't overlap, here I took inspiration from @Shrutijamgade where the following adaption of the radius calculation is added:
// link.helper.js
/**
* Computes radius for a smooth curve effect.
* @param {number} x1 - x value for point 1
* @param {number} y1 - y value for point 1
* @param {number} x2 - y value for point 2
* @param {number} y2 - y value for point 2
* @param {number} delta - additional factor to tweak curvature.
* @returns{number} value of radius.
* @memberof Link/helper
*/
function smoothCurveRadius(x1, y1, x2, y2, delta = 1) {
const dx = (x2 - x1) * delta;
const dy = (y2 - y1) * delta;
return Math.sqrt(dx * dx + dy * dy);
}
- Supporting redundant links fixes the JavaScript error that many are facing here.
How does it look like?
See for yourself a small dataset with redundant links looks like this.
I would like to have some of you trying this out before merging. Additionally, let me know if you think there's' a better way to achieve this.
The onClickLink
is going to need the id
passed to the callback so it can be identified.
I have been using this feature for a while as our data expects multiple edges between the same node and have not noticed any obvious errors. This is in a user base of 500+ with a dataset of 650K+ entities.
Any updates on this pull request?