anvaka / ngraph

Beautiful Graphs
MIT License
1.42k stars 131 forks source link

Lazily add edges #37

Open strarsis opened 2 years ago

strarsis commented 2 years ago

When an edge is added, non-existing nodes are added automatically.

However, sometimes the edges of a node are added while the other nodes, including those to be connected, haven't been added yet. Therefore it would be very helpful if those edges were added without creating non-existing nodes. Even better: An event is emitted when those yet non-existing nodes are queries, so they can be dynamically added (e.g. by network request).

anvaka commented 1 year ago

Edges by definition connect nodes - I can't think of a scenario where edge exists without nodes. So this does seem to work as designed.

Yet I feel like I'm missing something in your use case. Tell me more what were you trying to do and what was missing?

strarsis commented 1 year ago

From an API a list of nodes (each has an individual ID) is fetched, each node has a list of connections with other node IDs. The nodes list is iterated over and each node is added to the ngraph as graph node, and each connections list of the node is also iterated over and each connection should also be added as graph edge - and here is the underlying issue: The graph edge needs the target node to be existing. One would need multiple iterations over all the nodes and their connections to avoid this.