[Question] How to modify node data (labels, etc)
Atlas16A opened this issue · 5 comments
I don't know if i'm just stupid or what but here goes.
I've been working on a project using the node graph and I needed to modify the labels of each node and was hoping to later add in my own data to make it more useful, however try as I might I cant seem to find a way to fully do so, I was able to gain access to the label itself through very ugly code self.g.node_mut(0.into()).unwrap().with_label("A".to_string());
However it leaves the type as Node<()>.
Im just wondering is it even possible right now to access and manipulate this data or do I need to implement it from scratch?
After some digging and trying to understand everything, I made a set_label function that seems to work, however the usage of it was not very pretty, shown below the fn.
pub fn set_label(&mut self, label: String) { self.label = label; }
self.g.node_mut(0.into()).unwrap().set_label("A".to_string());
After some testing it did appear to stay apart of the node after using this, but may be something Ive missed.
At the the moment there are 4 properties of the node you can change + payload. There is a working configurable
example in this repo which changes labels and locations of the node. The method you used in your comment is already exists in the master.
There's alot going on in that example so im not surprised i missed it but im not sure i fully get it either, so for sake of clarity ill check. It seems it uses event signal to send receive info in nodes but beyond that i kind of get lost.
I see that payload is N so are you using the structs in events to give structure to the payload then setting the value? Is using event enum structure necessary for setting payload or only because its a sim graph? Would it be possible to have a more gutted down example, like one with a button that makes half the nodes change labels or something? Idk the parts necessary for the sim are throwing me off i guess.
Thanks
Actually you don't need handling events just to change label. Event are for synchronization of the changes happened in graph with your app. Currently graph can change only:
- zoom and pan
- location of the node (if it was dragged)
- dragged status
- selected status.
As you see label is not in the list and you can change it yourself just modifying the node with .set_label
method from your app.
But request for the separate example sounds reasonable and I am going to add it shortly. Sorry if at this state API can be a little bit messy and often changes, but we are still not stable and on the way to it. I will keep this thread and link pr with label changing example to it.
Hey! I 've added simple example which demonstrates how you can change a node label. Have fun)