grantshandy / fdg

A Force Directed Graph Drawing Library
https://grantshandy.github.io/fdg
MIT License
183 stars 16 forks source link

Add node to names to .svg images #3

Closed wainwrightmark closed 2 years ago

wainwrightmark commented 2 years ago

Hi. I've been playing around with this package - finding it very useful.

I needed to display the node names so I hacked it in myself.

//around line 167 of gen_image/lib.rs
let text_style = TextStyle::from(("sans-serif", 20).into_font());
let coord = (node.location.x as i32, node.location.y as i32);
backend.draw_text(node.name.as_str(), &text_style, (coord.0 + 10, coord.1 - 10))?;

I think it might be a useful feature to add. Obviously with settings to control the style etc. Let me know if you agree and you'd like me to do a PR?

grantshandy commented 2 years ago

Sure this sounds like a great idea. I'd love for you to create a PR.

grantshandy commented 2 years ago

@wainwrightmark I rewrote a lot of fdg-img's coordinate-translating/finding in 1363189ffc3a9a9df7c842e3eb1cc27c5d72fc3a so it will never cut off the node text now (it did quite often before, especially when using different forces). I hope you find that useful.

Thanks for your contribution!