Is it possible to remove a node?
keevitaja opened this issue · 8 comments
Is it possible to remove a node from graph?
Not currently. But it's a nice addition to the library!
I'll try to work on in this week.
Released with v2.3.0
😄
Adding to this: is this possible to remove an edge?
@barocsi there is no API to do that, however if you call addNode
on the same node, it'll replace it.
graph.addNode('A', { B: 10, C: 20 });
Say you want to remove the edge C from A:
graph.addNode('A', { B: 10 });
Should do the trick.
That works fine, thanks!
Some additional and last question: how can I get a reference to a node by its key?
route.addNode('A', { B:1 })
route.addNode('B', { A:1, C:2, D: 4 })
route.addNode('C', { B:2, D:1 })
route.addNode('D', { C:1, B:4 })
for example before I modify the edges of A i need to get a hold of its current edges.
Just found it,
route.graph.get('A')
@barocsi beware of two things while doing that:
-
You're accessing and internal class property. If you don't treat the returned value as pure and accidentally modify it, you might have unexpected results.
-
The returned value will be a deep
Map
, not an object.