react-d3-graph
react-d3-graph copied to clipboard
Self Linking does not render
Describe the bug When attempting to create a link where the source and target node are the same, it does not appear to work.
EG:
const data = {
links: [
{
id: "ParentId",
source: "Account",
target: "Account",
label: "ParentId"
},
{
id: "BillingContact",
source: "Account",
target: "Contact",
label: "BillingContact"
}
],
nodes: [{ id: "Account" }, { id: "Contact" }]
};
To Reproduce Steps to reproduce the behavior:
- Go to https://codesandbox.io/s/restless-sound-jo7o8?file=/src/App.tsx:113-423
Expected behavior
I would expect that there would be a "self loop" from Account -> Account with the label of ParentId

Screenshots
Environment: See Code sandbox
Additional Information:
This currently isn't supported, however I can see how this could be a useful addition to the library. This is what I was able to achieve by adding a condition to build a self loop when the source and target have the same x and y values in the buildLinkPathDefinition function in link.helper.js:
So it seems like implementing this would not be too complicated. However I do have some questions/concerns that I'd want to be addressed before moving ahead with this:
- How can we add this feature without breaking existing graphs? (We could add a new option in the config to enable self loops)
- Since this link can't be manipulated (stretched, rotated) by moving the node, how do we decide the default dimensions and positioning of the link? Or how do we let developers have control over this?
Would love to get your thoughts on this @danielcaldas @LonelyPrincess
Since this link can't be manipulated (stretched, rotated) by moving the node, how do we decide the default dimensions and positioning of the link? Or how do we let developers have control over this?
I think if you can achieve the behavior you have in that screenshot of yours, that would be perfect, even if you have some hardcoded values it would be a great start & addition to being able to render self links.
How can we add this feature without breaking existing graphs?
It's ok to have breaking changes, we can tag it with breaking change
if we decide to move in that direction.
Ok sounds good. I will get a pull request going then.
@terahn @danielcaldas @LonelyPrincess Have this feature been removed along the way? Because I am not able to generate a self linking graph! I am using version ^2.6.0