Connected diagrams can often get a little crowded with various dynamic connectors running between multiple nodes and so it can be useful to hide some of the connecting lines. Of course you still need to make sense of what’s connected to what so adding labels to a connector can be helpful. The challenge is positioning those labels in what is, by definition, a truly dynamic shape.
When you use a Dynamic Connector, which is the default when you use the connector tool (Ctrl+3), Visio manages the geometry of the line as you move its endpoints to route the line around various placeable shapes that it encounters. As you change the style of the connector between right-angled, straight and curved, the Geometry1 ShapeSheet section gets changed on the fly.
While there have been ways around this (most notably Graham Wideman’s directed arrows example – see page 194 of his 2003 book), a number of newer ShapeSheet functions that were introduced in Visio 2010 that allow you to interrogate the path of a geometry section and provide an alternative method. I thought I’d take a look.
The idea is to get from a diagram like this:
…to one that looks like this:
Feature-wise, the shape allows you to do a number of things:
- you can set the text on its two label sub-shapes via Shape Data
- the label text can be synchronized (ie the end label will match the start) or be independent
- the middle section of the connector can be hidden or visible and this applies to all of the three styles (right-angle, straight or curved)
- the visibility of the middle connector section can be set at page or shape levels (via the connector context menu)
- label text defaults to a single line but supports carriage returns (shift + enter) via Shape Data
- label formatting can be applied to the whole shape (including the label sub-shapes) or you can sub-select the labels individually
Other aspects of this shape that might be worth exploring are the ability to link the label text to Data Recordsets and drive their values in that way, or by using Color by Value to set the line and fill accordingly. For example, here’s Color by Value with the target value being set to the connectors ‘Label start text’, which in this case happens to be numbers:
So if you’d like to try out the shape you can download it here:
In the ShapeSheet
From a shape building perspective, you basically start with a dynamic connector and add a second geometry section. While, Visio merrily adds and removes rows from Geometry1, it leaves any other sections untouched, so Geometry2 is there to display:
- the line from the start of the connector to the start label
- and the line from the end label to the end of the connector
Once you've got your label coordinates you convert the connector shape to a group and add two sub-shapes for the labels themselves.
There are a number of things to calculate, but the main work happens in the User section:
The most interesting parts are as follows:
- Label position – Here I’m using the POINTALONGPATH and PATHLENGTH functions to get a point along the Geometry1 path, which works with all connector styles [see User.Label_StartPnt]
- LocPinXY label alignment – The labels need to expand in the opposite direction of their respective endpoints. To calculate this I’m using the RECTSECT function to get the corresponding sector of the endpoint relative to the label’s position and then getting an factor to multiply the LocPinX and Y using and INDEX function:
- Lock X or Y label position depending on sector – When the connector uses the right-angle style you expect the labels to be positioned perpendicular to the side of the shape they’re glued to. However, if the connector’s first leg turns a corner before the label’s offset then this places the label at an angle instead. To combat this I’m coercing the X and Y values, depending on a) which side (sector) the associated endpoint is, and b) whether the style is right-angle. As this involves a number of calculations I’ve pushed this work out to a couple of Scratch section rows. Here’s an example of the of the X value for the start label:
The remaining cells are either helpers or minor properties.
I’ve tried to make the connector as flexible as possible but if there are modifications that suit your scenario better, then by all means drop a comment at the bottom and let me know how you made it better!