Skip to content
  • Home
  • Work
  • About
  • Blog
  • Contact

Building a labelled dynamic connector in Visio

John Goldsmith's profile image

John Goldsmith

29 April 2015
  • General Use
  • ShapeSheet

LabelledDynamicConnectorInVisio

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:

VisioConnectorsWithLines

…to one that looks like this:

VisioConnectorsWithoutLines

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:

VisioConnectorsWithColorByValue

So if you'd like to try out the shape you can download it here:

  • Labelled Dynamic Connectors.zip

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.

VisioGeometrySections

There are a number of things to calculate, but the main work happens in the User section:

VisioUserSection

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:

    User.Label_Start_Side =

    RECTSECT(1,1, PNTX(User.Label_StartPnt), PNTY(User.Label_StartPnt), 0)

    User.fx_LocPinXFactor =

    INDEX(ARG("Sect"),"0.5;0.0;0.5;1.0;0.5",";",0.5)

  • 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: VisioScratchCell

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!

Microsoft MVP Logo

John has been a Microsoft MVP, in the award categories of Visio and M365, since 2008.

Visio Blogs

  • Bill Morein (via Wayback Machine)
  • Chris Castillo (via Wayback Machine)
  • Chris Hopkins (via Wayback Machine)
  • David Parker
  • Eric Rockey
  • Jesse Phillips-Mead
  • John Marshall
  • Michel LAPLANE (FR)
  • Nikolay Belyh
  • Saveen Reddy (via Wayback Machine)
  • Visio Guy
  • Visio [Product] Blog
  • Visio Insights (via Wayback Machine)

Visio Resources

  • Developing Microsoft Visio Solutions
  • Visio Stencils at ShapeSource
  • Microsoft Visio YouTube Playlist
  • Visio (Product site)
  • Office 2010 Engineering
  • Visio 2016 SDK (Download)
  • Visio JavaScript API reference
  • VisioMVPs.org
Contact

visualSignals ltd
31 Riverview Grove
London, W4 3QL
United Kingdom

+44 (0) 208 078 9120

Around the Web

Copyright © visualSignals ltd 2025

Mastodon