abulka / pynsource

Reverse engineer Python source code into UML
http://pynsource.com
287 stars 40 forks source link

Layout UML Optimally generates different layout every time #53

Closed ejudgie closed 5 years ago

ejudgie commented 5 years ago

How come selecting "Layout UML Optimally" alway generates a new layout. I was assuming it would alway reorganize the same way.

abulka commented 5 years ago

Layout is based on the "spring layout" algorithm which uses random numbers in certain parts of the algorithm.

"Layout UML Optimally" runs multiple "normal" layouts and then chooses the one with the least line and shape overlaps (plus other criteria) before sending that best layout to the shape overlap removal stage.

See perhaps

https://stackoverflow.com/questions/29825508/how-to-get-the-same-node-positions-in-d3s-force-layout-graph

It might be possible to get deterministic results by force seeding the random number generator before each layout. That approach would have to be weighed against the benefit of being able to run layout a few times (whether normal or optimal) to get possible improved layouts.

There is a menu command (and hot key) to save and restore the current layout, which is handy when running layouts, just in case the new layout is not as good as the one you already have.

Sent from my iPad

On 16 May 2019, at 5:43 am, Edward Judge notifications@github.com wrote:

How come selecting "Layout UML Optimally" alway generates a new layout. I was assuming it would alway reorganize the same way.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

ejudgie commented 5 years ago

Thanks for the quick reply. Are these the "Remember/Restore Layout" options?
Does the layout already get saved when you save to file or do you need to "Remember Layout" first?

abulka commented 5 years ago

Are these the "Remember/Restore Layout" options?

Yes. Does the layout already get saved when you save to file or do you need to "Remember Layout" first?

Your diagrams get saved as they appear when you select save. No need to select Remember layout.

Layouts also are preserved as much as possible when importing the same source code again. This is useful when updating UML classes with the latest changes in source code, which might add, rename or remove methods, attributes.

ejudgie commented 5 years ago

Thanks.