Steve Cook's WebLog

Speeding up auto-layout

I've been trying to speed up the way that DSL Tools lays out a bunch of lines and shapes when you start with a model file and no diagram.

By default the shape layout takes a long time to layout the shapes in a rectangular grid, and doesn’t leave enough space for the lines to route efficiently.  There is a straightforward workaround for this, which is to do your own shape layout, leaving enough space for the lines.  This can speed it up by 1-2 orders of magnitude.  This is what I did:

  • Overrode the diagram to set ShouldAutoPlaceChildShapes to false.  This stops the shape layout.  Just doing this will put all the shapes on top of each other at the top left.
  • Overrode OnBoundsFixup on my shapes class(es) to do a rather simple rectangular layout, bearing in mind that setting the AbsoluteBounds of a shape goes through the BoundsRules, which will apply gridding and margins.  There's a parameter createdDuringViewFixup for this method: you only want to do the layout when this is true.
  • Because I was laying our compartment shapes, I set the default expanded state to be collapsed, because the size calculations are done on the collapsed shapes.

To do the overrides you have to set IsDoubleDerived to true, which causes the Generation Gap pattern  to be generated.

Published Thursday, June 07, 2007 6:02 PM by Steve Cook
Filed under:

Comments

 

McScooter said:

Hey Steve, have you looked at specialist layout algorithms, e.g. those in Graphviz (www.graphviz.org)?  gv is impressively fast, even for large networks.

- Scoot.

June 7, 2007 3:34 PM
New Comments to this post are disabled

This Blog

Syndication

News

Locations of visitors to this page
Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the author’s discretion. All code samples are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker