react-d3-graph icon indicating copy to clipboard operation
react-d3-graph copied to clipboard

[WIP] Feature/multiple edges between same nodes

Open danielcaldas opened this issue 3 years ago • 3 comments

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 with source and targert)
  • 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.

support-for-redundant-links

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.

danielcaldas avatar Aug 29 '20 05:08 danielcaldas

The onClickLink is going to need the id passed to the callback so it can be identified.

lifehackett avatar Oct 21 '20 18:10 lifehackett

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.

zebde avatar Mar 24 '21 16:03 zebde

Any updates on this pull request?

akat12 avatar May 04 '21 14:05 akat12