igraph / rigraph

igraph R package
https://r.igraph.org
549 stars 200 forks source link

plot(g, layout=layout_with_sugiyama) does not work #496

Open szhorvat opened 2 years ago

szhorvat commented 2 years ago

Even though it is named similarly to other layout functions, layout_with_sugiyama does not interoperate with other functions such as plot. It is not possible to use plot(g, layout=layout_with_sugiyama) because layout_with_sugiyama returns its result in a different format from other layout_... functions. This is necessary because the Sugiyama layout will not only position vertices, it will also route edges along curved paths.

In the long term, we should think about how to unify layout handling and support arbitrary layouts, even those that use curved edges. Apart from Sugiyama, another example of such a layout is hierarchical edge bundling. Incidentally, both Sugiyama and hierarchical edge bundling achieve edge routing by creating a new graph with "dummy nodes". This might or might not work as a general approach.

ntamas commented 2 years ago

This is going to be more complicated than it seems; essentially we need to end up plotting a different graph and not what the user really wants to plot, and the dummy vertices of the extended graph must not be visible on the plot.

I think that the presence of this "extended" graph is a hack on its own; basically we needed a way to associate the extra coordinates of the edges (that could be used as control points) back to the edges themselves, and this was the easiest way to do it in the C layer. I don't see it clearly yet how we could improve it for higher-level interfaces. The cleanest solution would be to attach the extra control points of the edges as an edge attribute to the edges themselves, and let the plotting backend handle them nicely (i.e. by drawing a smooth cubic spline that passes through all control points, including the start and end of the edge). But this is a bigger task.

As a stopgap measure I've added an extra step to plot() that checks whether the object returned from the layout function is a named vector and whether it has an extra layout item. If it does, then the layout item is used, so it is now compatible with the output of layout_with_sugiyama but it does not use the extra control points lyet.

iosonofabio commented 2 years ago

rephrasing @ntamas in a positive light: We already have cubic splines in both Cairo and mpl, perhaps even plotly. Adding infra to support a few more waypoints is definitely doable, if a task in its own right

ntamas commented 1 year ago

Yup, but note that this is R where we don't have Cairo and matplotlib :)