The Omni Group Forums

The Omni Group Forums (
-   OmniGraffle General (
-   -   Script: clearer layout for orthogonal trees (

RobTrew 2011-10-28 11:55 PM

Script: clearer layout for orthogonal trees
[This script has now been replaced by a [URL=""]more general-purpose tool[/URL], which does not require Launchbar]

The hierarchical option in Automatic Layout currently bunches parents towards each other, skewing them artificially and asymmetrically away from the centres of their child ranges.

For hierarchies with straight-line connections between nodes, this may give a pleasingly unbuttoned 'botanical' style.

For orthogonal connections, however, it simply damages the signal-to-noise ratio:[LIST=1][*]Introducing artifacts like jagged three stage connections between a parent and a single child,[*]imposing asymmetries which are not present in the user's data,[*]sometimes even making connectors overlap, so that it becomes unclear which parent is attached to which child.[/LIST]This draft script aims to make orthogonal hierarchies clearer and more legible by properly centring parents over their child ranges, eliminating spurious asymmetries, and ensuring that the link between a parent and a single child is always a simple straight line.

[B]Automatic Layout's standard result[/B] the noise, asymmetries and ambiguities are rooted in the fact that this is a non-orthogonal layout merely decorated with orthogonal connectors a diagram in drag:


[B]Converted (by the script) to a true orthogonal layout[/B] the structure of the user's data is revealed clearly, without noise, distortion or ambiguity:


The script first runs the built-in Automatic Layout, so that it can discover the order of siblings (the OG Applescript library doesn't offer us this information).
The layout of the tree is then improved by moving shapes to left or right (up and down in the case of a left-to-right tree), to eliminate the unfortunate 'bunching', artifacts, occasional ambiguity, and imposed asymmetry introduced by the Graphviz layout engine.

(Note that OmniGraffle has a bug in which connectors are not always automatically updated after shapes have been moved by applescript - the final flickering is a nudging of each shape to force OG to update all the connectors. This can be switched off by editing:
[I]property pblnUpdateLinks : true[/I]
[I]property pblnUpdateLinks : false[/I]

To force an update manually - use Cmd A to select the whole diagram, and move it slightly with the mouse. Any misplaced connectors will then jump to their correct position).

Still a draft script, and it has only been tested on the templates and styles which I work with personally, so it's important to back up your diagrams before testing it.


If the script is selected in LaunchBar, you can speed up tree-work by tapping the space bar and entering one or more commands, using the following syntax to:[LIST=1][*]Adjust the [B]width and/or height[/B] of all shapes in visible layers,[*]switch [B]link updating[/B] on or off (i.e. override the default value of [I]pblnUpdateLinks[/I]),[*]adjust the amount of [B]space between rows[/B] (rank separation) (in points, not inches),[*]adjust the [B]object separation[/B] (also in points),[*]change the [B]direction[/B] of the layout from top, left, right, or bottom,[*]change the [B]type of all lines[/B] in visible layers, e.g. switch between straight lines and orthogonal links,[*]change the [B]magnets[/B] of all shapes in visible layers (magnets are adjusted automatically by the script when orthogonal trees switch between vertical and horizontal directions).[/LIST]
[I]s={150,100}[/I] or[I] size={150,100} [/I]
[I]w=150[/I] or [I]width=150[/I]
[I]h=100[/I] or [I]height=100[/I]

[I]u=f[/I] or [I]updatelinks=false[/I]
[I]u=t[/I] or [I]updatelinks=true[/I]

[B]rank separation[/B]: [I]r=30[/I] or [I]rank=30[/I] (NB in points, not inches)
[B]object separation[/B]: [I]o=15[/I] or [I]object=15[/I] (ditto)

[B]link type[/B]: [I]l=[b|c|o|s][/I] or [I]links=[bezier|curved|orthogonal|straight][/I]

[B]direction[/B] of layout [I]d=t|l|r|b[/I] or [I]direction=[/I](from) [I]top|left|right|bottom[/I]

[B]magnets[/B]: [I]m={}[/I] or just [I]m=[/I] will clear all magnets from all shapes in the visible layers.
[I]m=[ns|ew|nsew|corners|c|8][/I] will set magnets of shapes in visible layers to North-South, East-West, NSEW, all four corners, or all corners + all sides.

[B]arrow heads[/B] on the lines in the visible layers:
[I]a=[h|t|b|n][/I] or [I]arrows=[head|tail|both|none][/I]

multiple commands should be separated by a single space
e.g.[INDENT][I]d=l l=o r=30 o=0[/I][/INDENT]
[B]Relative values[/B]:

Values for the w, h, r, and o commands can be prefixed with "+" or "-" to make them relative.
To increase the rank separation by 10 points:[INDENT][I]r=+10[/I][/INDENT]or to shrink the height of all shapes (in visible layers) by 10 points:[INDENT][I]h=-10[/I][/INDENT]


RobTrew 2011-10-29 03:32 AM

A more complex before and after.

For some more complex trees, centring parents over children can even make the diagram marginally more compact, as well as simpler and more legible. (The script preserves [I]automatic layout[/I]'s object separation settings).

Before (as generated by OG's built-in Automatic Layout):


After (with parents centred over children by the script):


RobTrew 2011-10-29 02:33 PM

Quickly scanning material on the Graphviz engine which OmniGraffle is using, I get the impression that simple trees with parents centred over their children really [B]are[/B] beyond the scope of that engine :-)

I hope that this is a misapprehension ...

( but if a clean and compact orthogonal layout can be hacked with a simple applescript by a non-programmer, then I am sure it is not beyond the enormous wisdom of OmniGroup's esteemed collectivity of creative engineers and brilliant wizards :-)

Worth requesting a "Centre parents over children" option for Automatic Layout through OG [B]Help > Send Feedback[/B], I think ...


RobTrew 2011-10-31 01:10 PM

Added a LaunchBar parameter syntax for making absolute or relative adjustments to the shape sizes and gaps of a tree more rapidly (bypassing the inspector dialogs).

Also allows rapid rotation of the tree around the four possible directions (root at top, left, right or bottom) automating magnet changes when these are required to maintain a well-formed orthogonal tree.

(connector types, arrow directions, and general magnet options can also be rapidly changed through combinations of LaunchBar switches).


All times are GMT -8. The time now is 02:47 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2020, vBulletin Solutions, Inc.