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

Self Linking does not render

Open ChuckJonas opened this issue 4 years ago • 4 comments

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:

  1. 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

Edit_fiddle_-_JSFiddle_-_Code_Playground

Screenshots restless-sound-jo7o8_-_CodeSandbox

Environment: See Code sandbox

Additional Information:

Related Question on Stackoverflow

ChuckJonas avatar Nov 03 '20 08:11 ChuckJonas

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:

Screen Shot 2020-11-16 at 11 06 47 AM

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

terahn avatar Nov 16 '20 19:11 terahn

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.

danielcaldas avatar Nov 17 '20 14:11 danielcaldas

Ok sounds good. I will get a pull request going then.

terahn avatar Nov 17 '20 18:11 terahn

@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

FaizanMostafa avatar Jun 19 '23 09:06 FaizanMostafa