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.

Comments (1)

  1. McScooter says:

    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.