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

Notes on algorithm used #114

Open
theRealSuperMario opened this issue Apr 8, 2021 · 5 comments
Open

Notes on algorithm used #114

theRealSuperMario opened this issue Apr 8, 2021 · 5 comments

Comments

@theRealSuperMario
Copy link

Hi,

I would like to ask if there is a section that describes the algorithm used or in general the methodology so that I do not have to go through the code and figure it out from there.

I am asking this because I am looking for the specific algorithm used when comparing projects, but could not find any notes on this here.

Besides that, very nice project !!!

@Phlya
Copy link
Owner

Phlya commented Apr 8, 2021

Hi, a very reasonable request, but I don't have a description at the moment, sorry! ggrepel has a better description, and I loosely based this project on that, without actually looking at the code there though (I don't know R anyway).

A brief description is:

  1. Iteratively try all alignment options for each text object, to minimize overlaps
  2. Force all text objects to not overlap axes bounds
  3. Then, iteratively calculate where to move each text object, based on its overlaps with other text objects, points, and objects, apply the move, ensuring the texts are not going outside axes bound. Repeat until
  • no overlaps remain
  • or until limit of number of iterations is reached.
  • or - a tricky part - until certain "precision" is achieved (i.e. combined length of overlaps is lower than certain fraction of combined lengths/widths of all text objects).
  • finally - if there is a sign that the process is not converging, and the overlap has increased over one of the previous 10 steps of the iterations.

You'll have to check the code for the details of the implementation unfortunately, sorry!

@theRealSuperMario
Copy link
Author

Thanks for clarifying. That is all I needed.

If you find the time, it might be nice to update the docs and add a section à la "how it works", just to clarify that it is not some standard algorithm you use.

@Phlya
Copy link
Owner

Phlya commented Apr 11, 2021

Thanks, you are right!

Are there any standard algorithms for this, that are actually implemented somewhere and work reasonably well?

@theRealSuperMario
Copy link
Author

Yeah so I think Graphviz has some nice algorithms that could be useful.

But it is not straight forward to get this into MPL.

@Phlya
Copy link
Owner

Phlya commented Apr 22, 2021

Something like this, from networkx?
https://stackoverflow.com/a/34697108/1304161

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants