vasturiano / react-force-graph

React component for 2D, 3D, VR and AR force directed graphs
https://vasturiano.github.io/react-force-graph/example/large-graph/
MIT License
2.24k stars 284 forks source link

API should not allow duplicate node IDs [or at least ignore them] #439

Open dearlordylord opened 1 year ago

dearlordylord commented 1 year ago

Describe the bug having the structure

const graphData = {
  nodes: [{
    id: '1',
  }, {
    id: '2',
  }, {
    id: '2',
  }],
  links: [{
    source: '1',
    target: '2',
  }]
};

calling the component as

 <ForceGraph3D
        graphData={graphData}
        linkDirectionalArrowLength={3.5}
        linkDirectionalArrowRelPos={1}
        linkCurvature={0.25}
      />

I experience it creating an extra node for id: 2 and not linking it to the node of id: 1, instead linking only the first node with id: 2

Expected behavior

Ideally, I'd expect it to handle duplicated IDs and ignoring the extra nodes

Ideally ideally, I'd expect it to handle duplicated IDs, throwing an error

Ideally ideally ideally, I'd expect it to make duplicated IDs unrepresentable accepting the structure


const graphData = {
  nodes: {'1': {/*...*/}, '2': {/*...*/}}
  links: [{
    source: '1',
    target: '2',
  }]
};

which seems to be more reasonable than an array

vasturiano commented 1 year ago

@Firfi thanks for reaching out.

This module really adopted the convention that came from d3-force forceLink.

Overall, it's better if you sanitize your data before you pass it on to react-force-graph.