Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the overlapping problem of drawing self-loops #694

Closed
ljt10086 opened this issue Jul 9, 2023 · 14 comments
Closed

About the overlapping problem of drawing self-loops #694

ljt10086 opened this issue Jul 9, 2023 · 14 comments
Assignees
Labels
good first issue Candidates for first-time contributors who are already familiar with C plotting Issues related to plotting graphs in igraph in general stale

Comments

@ljt10086
Copy link

ljt10086 commented Jul 9, 2023

As for python-igraph when drawing a self-loop, it does not seem to be able to change the orientation of the self-loop by modifying edge.loop.angle like r version. After reading your code, I find that you use the draw_loop_edge function when drawing the self-loop, and use pi/4 angle, which makes it impossible to modify edge.loop.angle. Eventually, there will be self-loop edges that overlap with other edges when drawing.

@ljt10086 ljt10086 closed this as completed Jul 9, 2023
@ljt10086 ljt10086 reopened this Jul 9, 2023
@iosonofabio iosonofabio self-assigned this Jul 9, 2023
@ljt10086
Copy link
Author

ljt10086 commented Jul 9, 2023

1

@iosonofabio
Copy link
Member

I wrote that bit. Happy to add this option, just didn't think about it at the time.

There is a big PR related to plotting in the queue. As soon as that one's send, I can quickly fix this one.

@iosonofabio iosonofabio added plotting Issues related to plotting graphs in igraph in general good first issue Candidates for first-time contributors who are already familiar with C labels Jul 9, 2023
@szhorvat
Copy link
Member

szhorvat commented Jul 9, 2023

@iosonofabio This was fixed at some point in the past, but then it broke again, see #321.

@iosonofabio
Copy link
Member

Yep, remember the discussion.

@iosonofabio
Copy link
Member

@ljt10086 I can't find a place in the docs where we allow users to change the angle of loops, what you call loop.angle. Can you please paste a link to the relevant section in the docs?

@szhorvat I didn't realize #321 is still open. Well a good chance to fix it again.

I'll add this on top of #669 which should make it into 0.11. Unfortunately, I don't think I currently have bandwidth to also fix it in 0.10.X

@ljt10086
Copy link
Author

In this page there is some description of loop.angle in R-igraph:https://igraph.org/r/doc/plot.common.html
And I saw that in the r version of the implementation someone solved the self-loop orientation problem by setting loop.angle:
https://stackoverflow.com/questions/52410379/r-igraph-orientation-of-edge-beginning-and-ending-from-same-vertex

@iosonofabio
Copy link
Member

Thank you. @szhorvat @ntamas any opinion? Implement the user angle would definitely be easier than the auto detection, and consistent with R.

Btw at some point we should try to harmonize most of these arguments across our interfaces perhaps.

@szhorvat
Copy link
Member

I am not too worried about harmonizing visualization across interfaces. Each interface has separately implemented visualization that works with the very different native visualization capabilities of the host language.

IMO loop.angle is a crutch, and the proper solution is automatic adjustment of self-loops, similar to how Mathematica does it and to how it used to work in py-igraph 0.9.

Here are a bunch of random graphs to show how Mathematica plots multi-self-loops in various positions:

image

@szhorvat
Copy link
Member

szhorvat commented Jul 10, 2023

Issue for R interface is at igraph/rigraph#407

@ntamas
Copy link
Member

ntamas commented Jul 11, 2023

I agree with @szhorvat that finding the right angles for loops is not something that the user should be dealing with, but I don't know what the best algorithm would be. My idea is something like this:

  1. Calculate the angles to all neighbors of the vertex.
  2. Sort the angles in ascending order.
  3. Find the largest difference between consecutive angles in the sorted list, taking into account "wrapping around" at the end of the list. (Of course everything should be mod 360). Take the angles at both sides of the largest interval that we've found here -- this is the interval in which the layout is likely to be the least crowded.
  4. Place the loop edges spaced out equally in this interval. If there is only one loop edge to be placed, orient it towards the angle halfway between the lower and upper bounds. If there are two edges, place them at 1/3 and 2/3 and so on.

@szhorvat
Copy link
Member

Exactly.

I'm pretty sure this is what Mathematica does, i.e. find the largest gap between non-loop edges and place the self-loops there.

The self-loops have an effective angular size, defined through Bezier curves. If this does not fit in the gap, then reduce this size.

image

Special case: Isolated vertices where there are no non-loop edges to set a reference for the angle. Mathematica uses a fixed horizontal angle here. An alternative solution is to orient away from the centre.


What we do need a parameter for (and I'm not sure if we have it) is self-loop size. Non-loop edges have a natural size: the distance between endpoints. But for loops it is sometimes useful to adjust the size.

@iosonofabio
Copy link
Member

Let's continue this discussion on #669

I've implemented the algo as suggested by both of you and will now add a new documented argument for loop size. There's currently a discussion about arrows in self loops.

@stale
Copy link

stale bot commented Sep 18, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 18, 2023
@szhorvat
Copy link
Member

I think this is fixed now (reopen if I'm mistaken).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Candidates for first-time contributors who are already familiar with C plotting Issues related to plotting graphs in igraph in general stale
Projects
None yet
Development

No branches or pull requests

4 participants