Graph layout algorithm allowing manual adjustments?

Julia packages like GraphPlot and NetworkLayout can automatically choose the positions of graph vertices to make the graph look nice. However, sometimes I want to manually adjust the positions of the vertices to make the layout more “perfect”, for presentation purposes. Is there any package which allows me to use the mouse to drag the vertices around after the graph is plotted? Alternatively, can I type in the desired coordinates of a subset of points (e.g. I may want several points to lie on a circle) and ask the graph layout algorithm to choose the positions of the remaining points in a way that’s “compatible” with the manual choices already made?

Suggestions outside the Julia ecosystem are also welcome. I’m desperate to get this functionality from anywhere.

1 Like

GraphMakie.jl does I think :wink:

2 Likes

Yes you can! More detail on how to do this in GraphMakie:

fig, ax, p = graphplot(g)

you can access the node positions as an Observable via p[:node_pos].

So you can allways tweak them by setting

p[:node_pos][] = #any array of Point2f or Point3f

or adjust just a single node pos by

p[:node_pos][][4] = Point2f(0,0)
notify(p[:node_pos]) # trigger the update of the plot

You could also use the node drag interaction, arrange the nodes by hand and call p[:node_pos][] afterwards to copy-past the final coordinates.

2 Likes

Thanks, that works nicely in the terminal and VSCode, but in Jupyter notebook I only get a static image embedded into the notebook. Is there a way to tell Jupyter that I want the figure to be displayed in a standalone window that supports the UI interactions like dragging?

I’ve never tried jupyter with julia so I am not sure how it works. Maybe you’re on CairoMakie? You could try

using GLMakie
GLMakie.activate!()

or maybe the same with WGLMakie?