[Question] Is there any way to get the Node in a Graph?
knrt10 opened this issue · comments
I want to edit a node attributes inside a graph. Is there any way to get the node by name of node and edit it? Like in nodejs package JNXnetwork we can do that by
G.node.get(0).foo = 'bar';
Is there anyway in this package to do that?
Thanks
If you are using the default Graph then changing the name of a node is quite envolved, since the name is used as the identifier.
You would have to update references to the node, for example all edges made to the node.
You could use gographviz.Analyse
to parse the graph into your own structure.
If you have an idea of how to do it better, for your use case.
This structure just needs to satisfy the gographviz.Interface.
You can then write out your graph, using the gographviz Graph.
See this example
If you have an idea of how to do it better for all usecases, then let's discuss.
This might be something worthy of contributing, if you are interested.
Thanks for replying @awalterschulze . So here is my case like I have a graph that is already created. With nodes like
for _, val := range questionIDs {
_ = G.AddNode("G", val, nil)
}
here questionsIDs is just a slice of string and G
is *graph.Graph. So now I want to push another value inside my existing node inside graph G
using a simple function
pushPropertyToNode(G, target, "repeatRules", rule);
where property name is repeatRules
and target is one of questionIDs
inside G as a node and the value to insert is rule
Can you suggest how should I do that?
Thanks
How would this look in graphviz / dot syntax?
This is just for one node and edges were also added. After pushPropertyToNode
I guess like this.
digraph G {
test1 [repeatRules = somevalue]-> test2 ;
}
I don't think repeatRules is a valid attribute https://www.graphviz.org/doc/info/attrs.html
Maybe you want
digraph G {
test1 -> test2 [label = "repeatRules = somevalue"];
}
Ok, yes you are absolutely right but the main thing is I want to add it to an existing node. There is the main problem regarding that.
In this case the label is applied to the edge, not the node
G.AddEdge("test1", "test2", true, map[string]string{"label": "repeatRules = somevalue"})
Thanks