Visio Insights
The official blog of the Microsoft Visio product team

  • Visio Insights

    Make Your Own Bubble Chart, part 2


    This post is part of a series examining Bubble Chart diagrams.  We are building a Bubble Chart stencil from scratch to make diagram creation easy for the user.  You can get the completed stencil from the first post in the series.  In the previous post, we started working on the Bubble Chart master shape.  It captures configuration information from the user when the shape is dropped on the page.  The information along with the chart shape's boundaries are stored in properties on the page.  Now we will complete the shape by adding the chart labels.




    Double-click on the Bubble Chart shape in the stencil to edit it again.  There are seven labels on the chart: the title, two axis labels and four axis range boundaries.  Visio only allows one text block per shape, so we need seven shapes to display all the text.  Our rectangle will hold the text for the title.  The remaining shapes will be added as separate text boxes.  Select the rectangle and type some default text such as "Bubble Chart".  The text is centered horizontally and vertically by default.  We want the text to appear above the shape.


    Shape text is positioned according to the Text Transform section of the Shapesheet.  Go to Window > Show Shapesheet to open the Shapesheet window.  Then go to Insert > Section, choose Text Transform and click OK.  We need to change the properties associated with the Y coordinate of the text block.  To put the text at the top of the chart, set the TxtPinY cell equal to the shape height.  To make multi-line text grow away from the shape, set the TxtLocPinY cell to zero (note the way this is represented in the picture).  Finally, to keep the text box sized according to its text contents, set the TxtHeight cell equal to the height of the text.  Enter the formulas as shown in the picture below.




    The default text size can be set in the Shapesheet as well.  Find the Character section and set the Size cell to 24 pt.




    Next we need to add more shapes for the other labels.  The rectangle will be a group shape and the other shapes added as sub-shapes.  First, we need to lock the rectangle so that it does not change shapes are added.  Find the Protection section and set LockCalcWH to 1.  When shapes are added to a group, Visio will recalculate the boundaries of the group to encompass the new shapes.  We want our rectangle to define the group boundary and place the labels outside.  LockCalcWH prevents Visio from redefining the group boundary.  Also lock the rectangle from rotation since our formulas assume no rotation.




    Now we can make the group.  Close the Shapesheet window.  Then choose Shape > Grouping > Convert to Group.  Go to Insert > Text Box and draw a text box on the page.  Visio will enter text edit mode and display a flashing caret.  Go to Insert > Field and click on the Custom Formula category.  Enter a formula referencing the minimum X value of the chart.  Sheet.5 is the reference for the rectangle shape.  Prop.ChartMinX is the reference for the Shape Data value.  Press OK to close the dialog and click away from the shape to exit text edit mode.




    Select the rectangle and then Shift+click the text box to select it as well.  Go to Shape > Grouping > Add to Group.  The order of selection is important.  Now the text box is part of the group.  Sub-select the text box and go to Window > Show Shapesheet.  We need to lock the text box into the correct position around the rectangle.  Also the text box should grow to fit its contents.  Fill in the Shape Transform section as shown in the picture below.  Note the change to the LocPinX and LocPinY to make the text box grow down and to the right.




    We need to repeat this process five more times to add the remaining text labels.  Here are the remaining field formulas and Shape Transform sections:



    Field formula = Sheet.5!Prop.ChartMinY





    Field formula = Sheet.5!Prop.ChartMaxX





    Field formula = Sheet.5!Prop.ChartMaxY





    Field formula = Sheet.5!Prop.ChartXAxisLabel





    Field formula = Sheet.5!Prop.ChartYAxisLabel




    As a final touch, apply a fill color to the rectangle to make it work with the Theme feature in Visio 2007.  Choose a very light color such as 5% Gray or 35% Tint on an Accent Color.  The Bubble Chart shape needs to contrast with the Bubble Data shapes we will place on top. 




    This completes the Bubble Chart shape.  We will build the Bubble Data shape in the next post.


  • Visio Insights

    Make Your Own Bubble Chart, part 1


    In the previous post we introduced the Bubble Chart diagram and demonstrated a quick way to create one using the BubbleChart.vss stencil.  This stencil was custom-built for the blog, so grab the file attachment from the previous post.  Now we build the stencil from scratch to understand how to integrate Visio 2007's Data Connectivity features with shape design.


    Bubble chart 


    There are two shapes in the BubbleChart.vss stencil: Bubble Chart and Bubble Data.  Bubble Chart is the background shape that defines all the parameters of the chart.  Bubble Data is the circle shape added for each row of data displayed.  There's a third player that is critical to making the bubble chart work without the need for code - the Page.  In this solution the Bubble Data shapes do not have to know anything about the Bubble Chart shape.  The page acts as the central property store for the chart, avoiding any messy configuration between the chart and the bubbles.


    First, we create the stencil.  Launch Visio and create a new blank page.  Then create a new blank stencil.  Right-click in the Shapes window and choose New Master.  Enter Bubble Chart and click OK.  Right-click again to create a new master shape called Bubble Data.  Go ahead and save the stencil to name it BubbleChart.vss.




    Now we flesh out the Bubble Chart master shape.  Double-click the shape in the Shapes window.  We start with the page itself.  The page will store all the parameters needed for the chart.  Any page properties added here will be replicated on the drawing page once the master shape gets dropped.  Go to Window > Show Shapesheet to edit the Pagesheet - the Shapesheet for the page.  Next go to Insert > Section.  Choose User-defined cells then click OK.




    Scroll down to find the newly added section.  We need to store nine property values.  Right-click and choose Insert Row eight times.  Now we can name each property by clicking on the red row heading and typing.  Enter the nine property names and some default values as shown in the picture.




    Let's look at the properties we're defining.  The chart has an X axis and a Y axis.  For each axis there is a minimum value and a maximum value.  The first four properties will be set by the user.  These are the ranges that will correspond to their data.  The second four properties describe the location of the chart on the page.  They are set by the BubbleChart shape.  Note that the values of these properties have a measurement unit.  Both sets of four properties describe the same points - one from the user's perspective and one from Visio's.  The last property is the size factor.  We need to know how big to make each bubble on the chart.  The size factor is a simple way to record a scale.  Using the default value 10 as an example, a bubble with a Size of 10 in the data set will have a diameter of 1 inch in the chart.


    Now that the page is set up, let's make the chart shape itself.  Close the Shapesheet window for the page and draw a rectangle.  Then go to Window > Show Shapesheet to open the rectangle's Shapesheet.  There are several things to do here.  We need to capture some chart information from the user.  This will be done through Shape Data.  Other information comes from the shape itself.  We'll use User-defined cells to track this information.  Go to Insert > Section and check the User-defined and Shape Data boxes, then click OK.




    We need four User-defined cells to store the page coordinates related to the chart boundaries.  Add three more rows using right-click > Insert Row.  We'll use the same row names as in the Pagesheet.  Next we need to enter formulas to calculate the values from the shape transform.  The bottom left corner of a shape can be found by taking the shape's Pin and subtracting its LocPin.  This is done for both X and Y.  The upper right corner can then be found by adding the shape's Width or Height the minimum values.  So we know the page coordinates for the chart, but we need these to be stored in the page not the chart shape.  We use the function SETF to push the values to the matching User-defined cells in the Pagesheet.  SETF takes two parameters.  First comes a reference to the target cell, which is retrieved using the GETREF function.  Second is the value to be pushed, which is the chart page coordinates.  Enter the row names and formulas as shown in the picture.




    The remaining properties are stored in seven Shape Data rows.  Right-click in a Shape Data row and choose Insert Row six times.  The first four rows will match the Pagesheet names for the data ranges.  Then we add two new rows for X and Y axis labels.  The final row matches the size factor property from the page.  In the Shape Data section, the Label column stores the friendly text that appears in the Shape Data dialog.  The Type column specifies the data type.  Enter 2 for the numeric properties and 0 for the string properties.  Again we need to push the values to the User-defined cell s in the Pagesheet.  In this case SETATREF is a good choice.  The function essentially forwards any value entered to the cell referenced in the function.  Enter the Shape Data information as shown in the picture.




    To prompt the user to fill in the Shape Data properties when the shape is dropped, we use a little trick involving the SETF function.  Normally you just need to set the Ask property in a Shape Data row to pop up the Shape Data dialog on drop.  However, Ask will display the dialog when the shape is either dropped or copied.  In our case, we would prefer not to see the dialog on a copy because the properties are already set.  An alternate mechanism is to put a formula in the EventDrop cell of the shape.  Scroll down to find the EventDrop cell in the Events section.  DOCMD(1312) is the command code for the Shape Data dialog.  This command will fire when the shape is dropped.  To prevent further events from triggering the dialog, SETF is called.  We set a zero in the EventDrop cell itself.  Thus the formula can wipe itself out.




    At this point we have all the functionality of the Bubble Chart shape defined.  In the next post, we complete the master shape by adding labeling.



  • Visio Insights

    Introducing the Bubble Chart


      A Bubble Chart is a diagram that presents multi-dimensional data in a graphical form.  Each data field is tied to a particular visualization.  Most often data controls the Size and Position of elements in the chart.  Thus the diagrams often resemble a bunch of bubbles.  Taken to an extreme, data can be visualized in almost any way such as Color, Shape, Line Thickness, Shadow or any other formatting.  As the data grows more complex, it becomes more important to find effective ways to present it.  Bubble charts offer a compact graphical way to present information.


      Bubble Chart 


      Over the next few posts we will build our very own Bubble Chart stencil.  Using the custom Bubble Chart shapes in combination with the Data Link and Data Graphics features of Visio 2007, it is possible to generate Bubble charts from data in just a few steps.  In this post we look at the finished solution from a user perspective.  The Bubble Chart stencil is included as a file attachment to the post.  In subsequent posts, we create the stencil from scratch.  Understanding the details of construction will let you customize the solution if you desire.


      Using the Bubble Chart stencil

      To make a bubble chart, you need the BubbleChart.vss stencil and a data source with data in specially labeled fields.  Here is an Excel spreadsheet with the data we will use.  Note the column headings: Label, X, Y and Size.  Our bubble chart shapes are designed to pull information from fields with these names.




      To begin, start a new blank drawing and open the BubbleChart.vss stencil.  Go to Data > Link Data to Shapes to import the data from Excel.  In the Data Selector wizard, choose Microsoft Excel Workbook.  Then browse to the Excel file and click Finish.  The data appears in the External Data window.




      Next drag the Bubble Chart shape onto the page.  This shape forms the chart background.  It includes labels for the title and axes.  The chart shape defines the space where bubble shapes will be placed.  As the chart is moved or resized, the bubble shapes will reposition accordingly.  Dropping the shape automatically triggers the Shape Data dialog.  Fill in the ranges and labels for each axis.  The last Shape Data field is Max Size.  Enter the largest Size value you expect in your data.  Visio will scale the bubbles to make the largest size equal to 1 inch on the page.




      Now we are ready to add the bubbles.  Select the Bubble Data shape in the Shapes window, but do not drag it onto the page.  Instead click on a row in the External Data window and press Ctrl+A to select all the data rows.  Then drag the rows onto the page.  Data Link drops new Bubble Data shapes and automatically links them to the data.  The bubble shapes are placed into the chart according to their data values.  The Label and Size fields are displayed as data graphics.  The diagram is complete!  You can even use the Data Refresh feature to quickly update the diagram when the Excel data changes.


      Connect to your data set.  Add the Bubble Chart shape.  Select the Bubble Data shape and drag out all the data rows.  Instant diagram.  Next time we'll see how to build the BubbleChart.vss stencil to make it happen.


  • Visio Insights

    Working with ResizeMode


      In this post, we take a break from Visio 2007 information and explore a peculiar shape design issue.  If you have worked with Groups in Visio, you have probably encountered a situation where the shapes inside of a group just don't behave properly during resize.  Sometimes you want shapes inside a group to resize with the group.  Sometimes you don't.  Visio provides a setting to control the resize behavior, but you may be surprised how it works.  Enter ResizeMode.


      ResizeMode is the name of the Shapesheet cell that controls shape resize within groups.  This is presented as Resize Behavior in the Format > Behavior dialog.  There are three possible settings for the resize behavior: Scale with group, Reposition only and Use group's setting.


      Format > Behavior dialog 


      A shape inside a group will have one of these three settings.  Really there are just two behaviors (scale & reposition), with the third setting just deferring up to the group for its value.  The default setting is Use group, which in turn defaults to Scale.  So how does Scale and Reposition affect the resizing of shapes inside a group?


      Resize behaviors 


      Scale allows the shapes inside the group to stretch as the group stretches.  Reposition maintains the original size of the shapes but moves their center as the group stretches.  Sounds straightforward enough, so what's the catch?


      The catch is that ResizeMode only works when used BEFORE a shape is grouped.  When a shape is put into a group, Visio uses ResizeMode to determine what formulas get applied to the shape to make it resize with the group.  Changing ResizeMode later on has no effect on the resize behavior.  Thus it is quite likely that users change the setting and then get frustrated when nothing happens.  It's just not a good design.


      Here is the Shapesheet view of what is happening.  ResizeMode is a cell in the Shape Transform section.  The default is 0 (Use group's setting).  Reposition only is 1.  Scale with group is 2.  Below is the Shapesheet for a shape before it is grouped.




      Below is the Shapesheet of a shape with ResizeMode = 1 that is then grouped.  Notice that the Width and Height formulas are untouched, but the PinX and PinY depend on the group.  This is the Reposition behavior.


      Shapesheet - Reposition 


      Below is the Shapesheet of a shape with ResizeMode = 2 that is then grouped.  Notice that Width and Height now depend on the group.  This is the Scale behavior.


      Shapesheet - Resize 


      Changing ResizeMode in the Shapesheet and in the Format > Behavior dialog has no effect on these formulas.  The setting only comes into play at the time the shape is added to a group.  Visio has some work to do to clean up both the design and the documentation for ResizeMode.  Hopefully this article explains what is really happening.


  • Visio Insights

    Insert Text Box


      Every once in a while a new feature idea comes along that is so unique and compelling that it revolutionizes the way people work.  Insert Text Box is not such a feature.  Adding text to a diagram is nothing new in Visio.  However, usability studies have shown that adding text is one of the more challenging tasks for new users.  Thus we added Insert Text Box to Visio 2007 to make diagramming a little more approachable.


      Insert Text Box command 


      Insert Text Box is a menu command that invokes Visio's Text tool.  Choosing the command is the equivalent of clicking on the Text tool in the Standard toolbar.  We found that new users were not aware of the little 'A' toolbar button.  In contrast, most users were aware of PowerPoint's Insert Text Box command, and many would look for a similar command in Visio.  Now that command exists.


      One significant difference between the Insert Text Box command and the Text tool is that you can only insert one text box at a time with the command.  Once the text box is created, Visio automatically switches back to the Pointer tool.  With the Text tool you remain in text mode until you manually switch back to the Pointer tool.  The one-shot method solves another problem for new users - not knowing about the Pointer tool.  Even after users discovered the Text tool, they did not always realize that they had to switch back to the Pointer tool at some point.


      Microsoft Office Visio 2007 - now with text box insertion technology.  Buy it today.


  • Visio Insights

    Menu Changes in Visio 2007


    A new release of Visio means changes both large and small to the application.  The menu system has a number of changes in it.  There are some new additions such as Remove Hidden Information, Publish to PDF / XPS and the Data menu.  This post focuses on changes to the existing menu items.  Hopefully we can help you locate that feature you were looking for.

    View menu

    Shape Custom Properties are renamed to Shape Data, so the Custom Properties Window is now called the Shape Data Window.

    Format menu

    Three commands are now hidden by default.  Format > Special, Format > Style and Format > Define Styles are only visible if you enable Developer Mode.  Do this by going to Tools > Options > Advanced > Run in Developer Mode.  Styles are superceded by Themes in Visio 2007, and these three commands are targeted at shape designers more than standard users.

    Format menu 

    Tools menu

    Shared Workspace is now called Document Management (an Office-wide change).  Online Collaboration has been removed from the product.  This is now done externally through Microsoft LiveMeeting. 

    Custom Property Sets are now called Shape Data Sets and no longer live in this menu.  You can find the command by right-clicking in the Shape Data Window.  The new Data Link feature accomplishes some of the same tasks as Shape Data Sets, so the feature gets less visibility in Visio 2007.

    Shape Data Sets

    Reports has been moved to the new Data menu.  Export to Database has been moved to Tools > Add-Ons > Visio Extras where the other Database Wizard features are located.  Macros is now called Macro - go figure.  The Add-Ons sub-menu has been reorganized to align with the new diagram categories in the Getting Started pane.  Thus Building Plan is now Maps and Floor Plans, and Organization Chart is now Business.

    Tools > Add-Ons 

    Shape menu

    As mentioned above, Custom Properties are now called Shape Data.  The menu item has been moved to the new Data menu.  Also the Lay Out Shapes command has been split into a Configure Layout command and a Re-layout Shapes command.

    Help menu

    The Getting Started Tutorial has been replaced by training materials on Office Online.  You'll find a larger and better assortment of training courses there.  Diagram Gallery is replaced by the revised Getting Started pane, where you can see large thumbnails illustrating each of Visio's diagram types.  Detect and Repair is now called Office Diagnostics, and Customer Feedback Options is now Privacy Options.

    Page context menu

    Right-clicking on the drawing page, you'll find the View sub-menu removed.  All the commands in this sub-menu can be found in the main View menu up top.

    Shape context menu

    Right-clicking on a shape, you'll also find the View sub-menu removed.  In the Shape sub-menu, Custom Properties has been renamed Shape Data and moved to the Data sub-menu.  Rotate and flip commands have been removed in favor of expanding the z-order commands like Bring Forward and Move Backward.


    Overall there are quite a few changes.  Some of these changes related to the new Data menu and our focus on data connectivity.  Others were related to Office-wide feature changes.  If you have thoughts on the organization of Visio's commands or the drawing workspace, please leave us a comment.


  • Visio Insights

    Sharing Diagrams on a Server


    Hi Everyone,

    Our Product Planning team would like to hear from those who share diagrams by putting them on a Web site, SharePoint site or file server.  Are you sharing diagrams connected to data sources (perhaps through the new Data Link and Data Graphics features in Visio 2007)?  We'd like to better understand how our customers share diagrams inside their organizations.

    If you would like to help us with this area, please contact us.

    Visio Team

  • Visio Insights

    DXF, DWG & Visio


    Hi Everyone,

    Do you ever open, save or use AutoCAD files (DXF/DWG) with Visio? If so, the Visio product team would like to talk to you. Please contact us, and we’ll be in touch.

    Visio Team

  • Visio Insights

    Remove Hidden Information


      In a previous post we discussed the fact that a Visio document can become bloated over time by accumulating masters, styles, layers, fonts and colors that are no longer used in the diagram.  Often the file size impact is minimal, but not always.  Visio 2007 includes a new feature called Remove Hidden Information that lets users purge these unused items from their documents.  You can find this feature in the File menu.



      Remove Hidden Information actually provides two services.  First, Visio will offer to remove personal or sensitive information such as comments, reviewer markup and referenced file paths.  Visio can also strip out cached data recordsets.  Removing personal information is a good thing to do before publishing a document outside your organization.



      Second, Visio will offer several ways to reduce the file size by deleting unused items.  The preview picture may not be essential to your document.  Master shapes can account for the most significant size impacts in the document.  Themes and data graphics are new to Visio 2007 but are based on master shapes.  Styles can be large in quantity if not also size.  This doesn't cover every type of item that can bloat a document, but these are the critical items.



      For those designing shapes or solutions, you may find it desirable to exclude your masters from deletion.  Some solutions count on their master shapes existing in a document whether currently in use or not.  Visio allows shapes to set a flag to prevent Remove Hidden Information from deleting them.  Add the User-defined cell User.msvRHIPreventRemoval to the page sheet in the master and set the value to 1.


      We've been hoping to add this feature to Visio for some time, and it is great to see it included with Visio 2007.




  • Visio Insights

    Customizing Data Graphics


      One of the new features in Visio 2007 Professional is Data Graphics - the ability to display data on shapes in rich, visual ways.  Many of you have already experimented with this feature and are looking for ways to create custom visualizations.  There is an MSDN article that covers the full spectrum of customizations possible for Data Graphics.  In this post we'll work through a specific example - changing the text size in callouts.



      In the flowchart above, a data graphic is applied to the three process steps.  The data graphic has two text callouts displaying the Cost and Duration shape data fields.  The default text size for the flowchart shapes and the text callouts is 8 points.  What happens if we do a Select All and change the text size to 12 points?



      The flowchart shape text has increased in size, but the callout text has not.  Normally when you apply formatting to a group shape, Visio automatically pushes that formatting to all sub-shapes as well.  However, Data Graphics callouts are designed to prevent this automatic propagation.  There are many scenarios where it is desirable to maintain separate formatting for the shapes and the callouts.  Visio 2007 introduces a new protection on shapes to prevent group formatting from propagating to sub-shapes.



      Group formatting protection does not prevent all formatting changes on a shape - just those pushed from groups.  You can directly select (or sub-select) a shape and still format it.  Data Graphics callout work this way.  Not all Visio shapes allow selection of sub-shapes.  This is controlled by the group selection behavior property found in the Format > Behavior dialog.  If the selection property is set to Group Only, you will have to go to Edit > Open Group to make any formatting changes.


      Thus it is possible to customize the formatting on individual data graphic callouts, but what about making a global change to the data graphic?  The MSDN article explains more about the way that data graphics are structured, but essentially the callouts used in a data graphic derive from Visio callout masters.  By editing the callout master, all the data graphic callouts can be changed.  You may be accustomed to opening the Document Stencil to edit masters, but Data Graphic callouts are hidden masters.  Go to View > Drawing Explorer to find them.



      In the Drawing Explorer, you will find masters for the flowchart shapes in the diagram.  There are also masters for the data graphics and the callouts used in the data graphics.  For our example, we want to edit the Text callout master to update the text font size.  You can right click on the master name, choose Edit Master Shape and make the desired formatting changes.    Once you close the edit window and save the changes, all the data graphics in the diagram are updated. 



      It is a good idea to rename this callout master.  Because this version of the text callout master is different from the built-in one, Visio will offer both in the Edit Data Graphic dialog.  Assigning a new name will allow you to distinguish between the two.



      You may want to make your custom data graphic callout available in all your documents.  Visio 2007 does not offer a central storage location, so the recommended practice is to put the data graphic and callout masters into a template that you can use as you start each new diagram.  You can use the custom callout in a data graphic on a shape in the diagram.  Then copy that shape to another document.  Visio will copy over all necessary data graphic and callout masters.  We're interested to find out what types of custom data graphics you create to visualize information.  Be sure to let us know how you use the feature.



  • Visio Insights

    Visio 2007 Standard and Professional


    The most common set of questions in the newsgroups asks about the difference between Visio Standard and Visio Professional.  For Visio 2007, Microsoft has published a handy guide detailing the differences between the two editions.  There are breakdowns by feature and by diagram type.

    There are a couple points worth making here.  First, for those using the Visio that ships with Visual Studio for Enterprise Architects or Visual Studio Team System, there is no Visio 2007-based version as of yet.  The latest Visual Studio offering includes Visio 2003.

    Second, this is the first release where some features of the Visio engine are only available in Visio Professional.  For those unfamiliar with Visio's archictecture, the product consists of a drawing engine plus lots of content (shapes and templates and add-ons) that work with the drawing engine.  Historically, the drawing engine is the same in every edition and only the content varies by edition.  In Visio 2007, the features related to data connectivity (Data Link, Data Graphics, Data Refresh) are only supported in the Professional edition.  As in previous versions the Professional edition also has additional content.

    Visio 2007 Standard can open files created in Visio 2007 Professional, but the data features are disabled.  This delineation extends to Visio's programming interface.  Automation related to the new data features will not function on Visio 2007 Standard.  This behavior is somewhat akin to opening files in Visio 2003.  While Visio 2003 and Visio 2007 share the same file format, Visio 2003 does not have the new data connectivity features.  For example, in Visio 2003 you can work with a 2007 diagram that contains Data Graphics, but you cannot apply a data graphic to another shape or manipulate the existing data graphics.

    Thanks to all our MVPs and newsgroup responders who answer questions about Visio's product editions.  Now you can point them to the new Office Online link.



  • Visio Insights

    Microsoft Office Visio 2007 Released


    Yesterday Visio 2007 was made available to business customers along with the rest of the 2007 Office System.  Retail availability for Visio 2007 will be January 30, 2007.

    What’s so great about Visio 2007? 

    Our primary investment focuses on visualizing business information.  We’ve made it significantly easier to bring your business data into Visio and visualize it in a diagram.  Data Link is a new feature that imports data from external sources and associates that data with individual shapes in the drawing.  Data Graphics is a new feature that surfaces your data in graphical ways.  Combined with the ability to refresh from the data source, these features turn your Visio diagram into a living document.

     Data Link and Data Graphics


    While Data Link helps you add data to your existing diagram, Visio 2007 introduces a new drawing type called PivotDiagrams.  Similar in concept to Excel PivotTables, PivotDiagrams dynamically present tabular data in a hierarchical form.  By pivoting on different columns in the data, the diagram changes to aggregate information based on the breakdown specified.   PivotDiagrams are a great way to explore large data sets and present meaningful information visually.



    Visio 2007 also makes it easy to communicate with your audience.  A new Themes feature provides one click formatting to drawings, giving them a professional appearance.  Publish as PDF or XPS lets you distribute diagrams in a fixed format.  Also Outlook 2007 has the Visio Viewer built right in.  Sharing Visio drawings has never been easier.


    Links to More Information

    There’s much more to this release, and there are a number of resources already available to showcase what’s new.  Start with Microsoft Office Online and then look at MSDN and the other Visio blogs.

    Visio page on Office Online -


    There are some great videos on the site demonstrating many of the new features:

    Video demos -


    For shape designers and developers, look for information on MSDN.  There are some good technical articles explaining what is new in automation and how to make use of the new features.

    MSDN Visio site –

    Visio 2007 SDK -


    Eric Rockey, Lead Program Manager for Visio 2007, has a blog previewing many of the new Visio 2007 features.

    Eric Rockey’s Visio 12 blog -


    Bill Morein, Program Manager for Visio 2007, has a blog covering data visualization for Visio and includes several posts about the Visio 2007 feature set.

    Bill Morein’s Data Visualization blog -


    Finally, stay tuned to Visio Insights for more information about Visio 2007.  There’s quite a bit to cover.


  • Visio Insights

    Smarter Paste between Pages


    The Visio Product Team uses Visio for a number of tasks.  A common task is creating storyboards to show how a user might construct a diagram.  If you’ve ever seen one of those “behind the scenes” documentaries for a movie, you’ve seen the storyboarding process.  Each step the user takes is captured on a separate page in a Visio drawing.  Then the entire document is shown as a presentation to replay the construction of the diagram.

    It seems that quite a few people use Visio for this sort of task.  Visio is a pretty good tool for mocking up application or web interfaces.  One common request is to make copying between pages work better.  In these types of documents, each page is almost identical to the one before it.  One of the nicer touches in PowerPoint is that objects copied from one page (slide) to another are pasted in exactly the same position.  In Visio objects are pasted to the center of the screen making repositioning a chore.  Visio needs a smarter paste behavior.

    A little bit of code can solve the problem for Visio.  Actually, there are two ways to solve the problem.  You could write your own procedures to perform copy and paste with better logic for positioning.  Alternatively, you could handle the event notifications from Visio when copy and paste occur and fix up the positioning after the fact.  The attached Visio document has VBA code to illustrate both methods.

    Create your own copy / paste commands

    When invoking Visio’s Copy and Paste command through automation, Visio allows you to specify whether the position of the selection on the page should be preserved using the visCopyPasteNoTranslate flag.  Thus you can create your own macros that do copy and paste:

    Public Sub CopyNoTranslate()


        Application.ActiveWindow.Selection.Copy (visCopyPasteNoTranslate)


    End Sub


    Public Sub PasteNoTranslate()


        Application.ActivePage.Paste (visCopyPasteNoTranslate)


    End Sub

    In fact you can assign Ctrl-C and Ctrl-V as the accelerator keys for these macros to override Visio’s copy / paste.  If the real goal is to support copying to a new page, this macro will perform the necessary steps:

    Public Sub CopyToNewPage()


        Dim vsoSelection As Visio.Selection


        'Make sure we are in a drawing window

        If Application.ActiveWindow.Type = Visio.VisWinTypes.visDrawing Then


            'If there is no selection, select all shapes on the page

            Set vsoSelection = Application.ActiveWindow.Selection

            vsoSelection.IterationMode = 0

            If vsoSelection.Count = 0 Then


            End If


            'Copy selection to new page

            vsoSelection.Copy Visio.visCopyPasteNoTranslate


            Application.ActivePage.Paste Visio.visCopyPasteNoTranslate


        End If


    End Sub

    Respond to Visio’s copy / paste events

    This method uses an event handler to detect copy and paste actions.  The position of the selection is read during the copy action.  The new position of the selection (which will be placed in the center of the window) is read during the paste action.  The current page is recorded during each action as well.  If the copy and paste actions occur on different pages, the code moves the selection back to its previous coordinates following the paste action.

    Private Sub vsoApp_EnterScope(ByVal app As IVApplication, ByVal nScopeID As Long, ByVal bstrDescription As String)


        'Check for Copy action in a drawing window

        If nScopeID = 1021 And app.ActiveWindow.Type = Visio.VisWinTypes.visDrawing Then


            Dim vsoSelection As Visio.Selection

            Set vsoSelection = app.ActiveWindow.Selection


            If vsoSelection.Count > 0 Then


                'Find the shape in the selection at the bottom of the z-order

                Dim bottomShape As Integer

                bottomShape = GetBottomShape(vsoSelection)


                'Record scope ID and selection information

                nCopyScopeID = nScopeID

                gCopyPageID = app.ActivePage.PageSheet.UniqueID(Visio.visGetOrMakeGUID)

                dShapePosX = vsoSelection(bottomShape).CellsU("PinX").ResultIU

                dShapePosY = vsoSelection(bottomShape).CellsU("PinY").ResultIU


            End If


        End If


    End Sub


    Private Sub vsoApp_ExitScope(ByVal app As IVApplication, ByVal nScopeID As Long, ByVal bstrDescription As String, ByVal bErrOrCancelled As Boolean)


        'Check for Paste action in a drawing window

        If nScopeID = 1022 And app.ActiveWindow.Type = Visio.VisWinTypes.visDrawing Then


            If nCopyScopeID <> 0 Then


                Dim vsoSelection As Visio.Selection

                Set vsoSelection = app.ActiveWindow.Selection


                Dim activePageID As String

                activePageID = app.ActivePage.PageSheet.UniqueID(Visio.visGetOrMakeGUID)


                If vsoSelection.Count > 0 And gCopyPageID <> activePageID Then


                    'Find the shape in the selection at the bottom of the z-order

                    Dim bottomShape As Integer

                    bottomShape = GetBottomShape(vsoSelection)


                    'Fix up position of selection by offsetting from the bottom shape

                    Dim posX As Double, posY As Double

                    posX = vsoSelection(bottomShape).CellsU("PinX").ResultIU

                    posY = vsoSelection(bottomShape).CellsU("PinY").ResultIU


                    vsoSelection.Move dShapePosX - posX, dShapePosY - posY


                End If


            End If


        End If


    End Sub

    The full code for this method is found in the attached document.  We use the EnterScope and ExitScope events to detect the copy and paste actions.  The key problem to solve is recording the current position of the selected shapes.  Visio selections do not have coordinates associated with them, so the coordinates of one of the shapes within the selection must be used.  The trick is to make sure that the same shape is scanned in both the copy and paste actions.  Visio does not necessarily preserve the order of shapes in the selection during paste.  This code finds the bottommost shape in the z-order (layering order) to ensure that the same shape is scanned each time.

    To use this method, open the SmartPaste.vsd file in Visio along with the other documents you are working on.  Once you enable macros for the file, SmartPaste will work with your regular Copy  and Paste actions.

    If you find this type of behavior useful or find it counter-productive, please let us know.

  • Visio Insights

    Hyperlink Problem in Internet Explorer 7


    We’re seeing quite a few reports in the newsgroups about a new issue involving hyperlinks in Visio’s HTML output and Internet Explorer 7. Basically, clicking a hyperlink in a drawing saved as HTML from Visio 2003 results in an error that says “Internet Explorer cannot open the Internet site. Operation aborted.”




    In this post, we’ll talk about why this happens and some ways to work around it.


    The problem occurs only with Visio 2003 (not with earlier versions or with Visio 2007, which will soon be available) and only when the Web output format is VML. Essentially, the way Visio 2003 structures the hyperlinks in VML output is not supported in IE 7, and hyperlinks that worked fine in IE 6 will fail in IE 7. Here are a couple of ways to work around the problem:


    Workaround 1: Edit the hyperlinks in the Web output so they will work in IE 7

    Look for the VML_1.HTM file in the set of supporting files included with the main .HTM file saved from Visio. (If there is more than one page in the Visio drawing, there will be one of these files for each page: VML_1.HTM, VML_2.HTM, VML_3.HTM, etc.)  Open it in a text editor such as Notepad and find the block of HTML that represents each hyperlink. Here is an example of an uncorrected hyperlink to


    [Edit #2:  Because the blog software keeps trying to interpret our HTML as real code, we've turned the HTML into a picture.]



    Tip: Use search & replace in Notepad to accomplish this quickly for all the hyperlinks at once.


    Workaround 2: Use an output format other than VML

    While VML is the default output format when Visio drawings are saved as HTML, you can use one of the other formats, such as JPG or GIF, to work around this problem. The downside is that you won’t get some of the enhanced functionality provided with VML, such as the ability to pan and zoom the drawing on the Web page.


    To save the Visio drawing in a Web format other than VML:

    1.       Go to File>Save As Web Page.

    2.       Click the Publish button in the Save As dialog box.

    3.       In the Save As Web Page dialog box, click the Advanced tab.

    4.       Pick a different format in the Output Formats drop-down list.

    5.       Click OK.




  • Visio Insights

    Flattening Groups


    To continue our exploration of best practices for shape development we will look at grouping in this post.  Grouping is a convenient way of packaging shapes and is the mechanism for creating many complex shapes.  Visio offers a number of capabilities for groups, from special interaction behaviors to shape transform changes.  It's not surprising to see groups used extensively in master shapes.  However, grouping can easily be taken too far, and you can encounter serious performance issues when that happens.  Let's look at the issues in detail.

    First, a group in Visio is a shape.  Prior to Visio 2000 groups were special objects that were not quite the same as shapes.  They were containers for shapes but could not have their own text or geometry.  Beginning with Visio 2000 groups became full-fledged shapes.  Today a group can have geometry and text just like any other shape.  A group can be either 1-D or 2-D.  It is important to note that groups are shapes too because this is one of the simplest and best optimations to make in shape design.  Visio's overall performance is highly dependent on the total number of shapes being managed.  A group containing two sub-shapes is three shapes to Visio.  If you are using the group merely as a container, you are wasting one shape.  Convert one of the sub-shapes into a group and stick the other sub-shape inside.  Now you only have two shapes to provide the same functionality.

    Second, there is a penalty for using groups in Visio.  Every group defines a new coordinate system for the contents of the group.  There is overhead required to compute the transforms for these coordinate systems to display shapes on a page.  The deeper the nesting of groups the more coordinate transformation that Visio must do.  Thus if you must use groups, it is better to keep the structure as flat as possible.  We recommend avoiding making any shapes with more than two levels of nested groups.

    The most common problem we see in custom shapes (and in some of the ones in the Visio box) is that groups are used where they are convenient, not just where they are required.  This results in too many shapes being used in a master.  When you are designing your custom master shape, determine the minimum number of shapes required to do the job.  An additional shape is necessary when you need another piece of text separate from the shape text you already have or when you need a portion of the shape to have different line or fill formatting than the rest.  These are the two conditions: more text or different formatting.  You do not need a new shape for more geometry.  Visio supports multiple geometry sections per shape.  As long as these sections can use the same formatting, this is much more efficient than creating a group.

    Let's look at an example to see the difference between grouping and geometry sections.  Imagine a master consisting of 16 squares.  It's easy to create this shape by drawing one square in Visio, then duplicating it 15 times.  If you group all 16 squares together, you now have a group with 16 sub-shapes.  (A colored box is drawn around the group just for illustration purposes.)  Some basic performance testing shows that Visio takes 74 milliseconds to create 50 instances of the master on a page.  Each instance requires 64.4 kilobytes of memory.

    Compare that master to an similar one that uses multiple geometry sections to accomplish the same task.  After duplicating the square to make 16 squares total, a Combine shape operation was run to make a single shape with 16 geometry sections.  Because there is only one shape, no group is required.  Performance testing shows that 50 instances take 31 milliseconds to create, and Visio requires 36.6 kilobytes of memory for each instance.  Thus you get better than twice the performance and almost half the memory consumption as the group shape.  The differences are more dramatic as you apply local formatting as we saw in a previous post.  In this example, there is no reason to use a group because a single shape can accommodate all the necessary geometry.  Additional shapes are only required if multiple pieces of text or different sets of formatting are needed.

    When you do use groups make sure to keep things flat.  Additional nested levels add more shapes and more overhead.  Pretend that our example master was created by drawing two squares, then grouping them, then duplicating the group, then grouping that, then duplicating and grouping by two until a single group remained.  The original 16 squares have become a 31 shape master.

    Over the years we have received many customer drawings where performance, memory and file size are severely impacted because of too much grouping.  Often it is too late to tell customers to redesign their masters to economize on shape use.  Where customers have made changes, the results can be dramatic.  Improvements from 2x to 10x are typical.  A common excuse heard from shape designers is that they use nested groups because the masters are assemblies of standard components.  The shape designers want to keep the components contained within their own groups to facilitate maintainability.  Before commiting to this structure we recommend testing the performance of the shapes to know whether the tradeoff in inefficiency is acceptable.

    For those that are interested in real-world examples of complex but efficient group shapes, look at the Data Graphics callouts in the new Visio 2007 Professional product.  These shapes follow the strict rules for when an additional shape is required, but they have some impressive graphical looks as well.

  • Visio Insights

    More on Inheritance and Performance


    In the previous post we looked at the difference between using instances of master shapes versus using masterless shapes.  Visio masters store shape information centrally, reducing memory and increasing performance.  Shapes on the page inherit their properties from the master shape until the user makes a local change to override the inherited values.  Today we want to analyze another aspect of inheritance and its impact on performance.

    User-defined cells are a great way for shape designers and solution developers to add intelligence to a Visio shape.  Unlike Scratch cells they support custom row names, making the Shapesheet more readable and understandable.  The section name "User-defined" is a misnomer since these are designer / developer defined cells.  They can be used to store information that does not need to be directly exposed to the users of the shape.

    Suppose we have a solution that adds a new User-defined cell to store a timestamp recording when the shape was dropped.  We might have some code that responds to the ShapeAdded event from Visio by inserting a User-defined section, adding a new named row and then setting the cell value.  Alternatively, we could redesign our master shape to already have a User-defined section and the necessary named row in it.  Our code only needs to set the cell value.

    The first approach relies on working exclusively through the Visio API.  The second approach relies on inheritance to provide the User-defined row.  What are the performance implications here?  We ran a little experiment programmatically dropping 100 shapes on the page.  Each shape had 20 User-defined rows in each.  In the first test, the User-defined rows were generated through code.  The test took 688 milliseconds and the resulting memory usage was 41 kilobytes for the document.  Compare that data to the inheritance scenario where the User-defined rows already existed and the code only needed to set cell values.  This test took 360 milliseconds and the resulting memory usage was 36 kilobytes for the document.

    The difference is that the inheritance scenario is almost twice as fast as the non-inheritance scenario.  Most of this performance delta is caused by the additional work Visio must do to add new rows to the Shapesheet.  Using inheritance lets Visio skip this step.  Some of the performance delta is related to the increased memory consumption caused by having local copies of the User-defined rows in each shape.  In the inheritance scenario, the User-defined rows are inherited but there are local values in the Value cell for each row.  In the non-inheritance scenario, the rows themselves are also local.

    There is an important issue to be aware of when working with User-defined rows - or any Shapesheet section with nameable rows.  Adding a new row to the section breaks the inheritance of all existing rows in the section.  The rows and cell values are forced to become local.  This can adversely affect performance, memory consumption and file size because one addition can ruin the party for every other row.  In our testing, this has added a 2% - 5% performance penalty to shapes with existing inherited User-defined rows.  The penalty is caused by the increased memory requirements for the local row and cell data.

    To summarize, programmatically adding new rows to the Shapesheet is a fairly expensive operation.  It is far more efficient to pre-build the rows you need into your master shapes.  Also adding a new row to a shape causes all the rows in that Shapesheet section to become local.  This creates an ongoing performance impact because of the greater memory usage for the local data.  Next time we'll look at the benefits of shallow nesting for group shapes as we continue to explore performance optimizations in Visio.


  • Visio Insights

    Master Benefits


    One of the things we'd like to accomplish with this blog is to highlight some performance optimizations that shape designers and developers should consider adopting as best practices.  Unfortunately designing highly efficient shapes and solutions is a bit of a black art in Visio.  Today we will look at the fundamental issue of using masters.

    Master shapes and instance shapes are described in this post.  A master shape allows Visio to store a single copy of a shape definition and only manage the information that is different for each instance of a shape.  For many shapes, only the Shape Transform section of the Shapesheet is specific (or "local" as we call it) to each instance.  That section contains the PinX and PinY coordinates for the shape's location on the page.  As you modify a shape on the page, more Shapesheet cells take on custom values rather than inherit their values from the master shape.  Thus Visio requires more memory to manage this information.

    A masterless shape, such as a line or rectangle drawn with the drawing tools is essentially 100% local values.  That means Visio must store the complete set of Shapesheet properties for each and every shape on the page.  Let's compare Visio's performance when working with instances of masters versus masterless shapes.  We'll just create a master that consists of a plain rectangle for the master shape.  We'll draw a plain rectangle using the drawing tools for a masterless shape.  Then to get a better reading on the incremental costs of working with these shapes, we duplicate each 100 times.  The numbers below are based on some tests done with Visio 2003.

    When comparing memory consumption, the masterless rectangle requires about 11,700 bytes per shape.  The master instance rectangle requires about 3,600 bytes per shape.  The difference gets larger if you apply formatting to the rectangles.  The masterless rectangle with custom line, fill and text colors set requires about 33,000 bytes per shape.  The master instance rectangle only uses 6,300 bytes per shape.  Note that Undo was enabled for this, which would exaggerate the numbers a bit.

    These differences also impact the file size of the Visio document.  A blank Visio document uses about 18 kilobytes of space.  A document with 100 masterless rectangles uses about 52 kilobytes.  The 100 master instance rectangles use about 45 kilobytes.  Thus when you subtract out the document overhead, masterless requires 26% more space.

    Finally, we can look at the time it takes Visio to create 100 shapes on the page.  This was measured with Undo disabled and a little automation script to drop the shapes.  100 masterless rectangles were created in about 95 milliseconds.  100 master instance rectangles were created in about 47 milliseconds.  Much of the performance differences relates to the extra memory footprint required for the masterless rectangles.

    Hopefully this gets you thinking about the efficiency of your own content and code.  Do you generate large diagrams by drawing lots of lines and rectangles?  You should think about masters.  Do you work with masters but heavily customize the shape instances once they are on the page?  Perhaps you can consolidate the customizations into a few masters that can be instanced.  Or perhaps you can place many of the customizations into a Visio style and apply that to your shape instances.  Do a little measurement with Windows Task Manager yourself to understand what the per shape memory costs are.

    We'll take a look at additional performance optimizations in some future posts.



  • Visio Insights

    Staying in Bounds


    In the previous two posts we looked at the capabilities of the SetAtRef function in the Shapesheet.  This function along with the helper functions SetAtRefExpr and SetAtRefEval allows a shape designer to keep one or more cells synchronized.  One important detail that was omitted was the fact that all three functions were introduced in Visio 2003.


    Today we explore another Visio 2003 function that provides advanced shape behavior capabilities: the Bound function.  Bound has two basic characteristics.  First, the function takes any value and ensures that it lies within a set of boundary limits for the cell.  If the value is within the boundary limits, Bound returns the value directly.  If the value is not within the boundary limits, Bound returns the closest limit value.  The second characteristic is that the Visio drawing window is aware of cells with the Bound formula and can visually enforce the boundary limits.


    Here is the syntax for the Bound function:


    BOUND (value, type, ignore, value1, value2 [,ignore(n), value1(n), value2(n),...])


    value    The current value being constrained.

    type      Whether the constraint is inclusive (0), exclusive (1), or disabled (2).

    ignore  TRUE to ignore the range; FALSE to constrain the value of the cell to the range.

    value1  First value in a range.

    value2  Second value in a range.


    Let’s look at some examples to better understand this function.  A Visio document with these examples is attached to this post for you use with Visio 2003.  It is helpful to see firsthand how Visio enforces Bound as you manipulate the shape.



    In the first example we want to keep the Width of the shape between 1 and 3 inches.  This is an example of an inclusive type.  As long as the incoming cell value is between 1 and 3 inches, the Bound function will return that value.  If the incoming cell value is less than 1 inch, the function returns 1 inch.  If the incoming cell value is greater than 3 inches, the function returns 3 inches.  If you resize this shape in Visio, you will see that Visio acknowledges the Bound and prevents resizing outside the allowable range.


    In this respect, Bound behaves similarly to SetAtRef.  Any change made to the cell through the drawing window does not blast the formula already in the shape.  Instead, Visio places the incoming cell value into the first argument of the Bound function.  The first argument is in fact an implicit SetAtRefExpr function.  We don’t show “SetAtRefExpr” to keep the Bound function syntax from getting too confusing, but that is what Visio is doing behind the scenes.  Any shape Width that you attempt to set in the drawing window is pushed into the first argument.



    The second example demonstrates the use of multiple ranges in Bound.  The incoming cell value must fall within one of these ranges.  The value1 and value2 arguments are set to the same value in this example to force the shape Width to a specific set of values.  When working with multiple ranges, it may be desirable for some of the ranges to be disabled under specific conditions.  The ignore argument prior to each range supports disabling of individual ranges.



    The third example applies Bound to a control handle (you'll have to see this one in Visio).  You can constrain the position of the control handle to stay within the bounding box of the shape.



    The final example forces a control handle to remain outside the bounding box of a shape (you'll have to see this one in Visio).  This is an example of an exclusive type.  The control handle must not be within the range limits.  There are some complications that must be addressed, however.  It is okay for the horizontal position of the control handle to be within the limits if the vertical position is not within the limits.  Likewise it is okay for the vertical position of the control handle to be within the limits if the horizontal position is not within the limits.  This extra logic is placed into the ignore argument for the range limits.  Note that these functions create a circular reference, but Visio can work through the circularity to produce the correct results.


    Like SetAtRef, the Bound function opens a whole new set of opportunities for shape behavior.  Shape designers can incorporate this behavior to create Smart Shapes with sensible restrictions on the way they can be manipulated.


  • Visio Insights

    More on SetAtRef


    In the previous post we examined how the SetAtRef function could be used to keep two Shapesheet cells synchronized.  Today we will explore a few advanced capabilities of SetAtRef for manipulating cell values.


    Our scenario is a shape with a custom property called Size.  We would like this property to control the Width of the shape.  Also changes to the Width should update the Size property.  A text field displays the current value of the Size property as well.



    Notice that the cell values for Width and Prop.Size are not the same.  Our previous solution using SetAtRef to synchronize the cells will not work.  One unit of Size should correspond with 0.25 inches of Width.  What we need is a way to convert between Size and Width as we are synchronizing the cells.


    A first attempt might look like this:



    We adjust the Width formula to take the Size value and convert it to a width.  This works properly whenever the Size changes, but any change to the Width will push the wrong value back to Size.  We need to take the incoming Width value and perform a conversion on it before that value is pushed to the Prop.Size cell.


    Fortunately, the SetAtRef function supports this capability.  You can provide an optional second argument to the function that tells Visio how to transform the incoming value.  Our goal is to take the incoming Width value and divide it by the proper conversion factor to calculate the Size.  To specify this as an expression in the SetAtRef function, we need a way of referencing the incoming cell value.  Visio provides the SetAtRefExpr function for this purpose.  SetAtRefExpr starts with no function arguments.  Then Visio places the incoming cell value into the function.  Like SetAtRef, for recalc SetAtRefExpr evaluates to its function argument:  SetAtRefExpr(x) = x.



    This almost solves the problem.  However, if you look below at the resulting value put in the Prop.Size cell, you can see that Visio is putting the literal expression in the cell rather than the calculated result of the expression.  The formula in Prop.Size does evaluate to 4, but we would prefer to have just the final result.



    There is another function available to force Visio to evaluate the SetAtRef expression before a value is put in the cell.  SetAtRefEval can be used on the entire second argument in SetAtRef or on one or more portions of the expression.



    This completely solves our problem.  The shape now is able to keep the Width and Size properties synchronized while converting between the two.  Our final formula for the Width cell is:


    SETATREF(Prop.Size,SETATREFEVAL(SETATREFEXPR(1.25 in)/0.25 in))*0.25 in


    Here is a verbose description of this formula.  When the Width of the shape changes, do not overwrite the contents of this cell.  Place the new Width value into the SetAtRefExpr function argument.  Then take the new value and divide it by 0.25 inches.  Evaluate that result and place the it in the Prop.Size cell.  Then recalculate the Width cell.  For recalculation take the current value of Prop.Size and multiply it by 0.25 inches.  This is the final value of the Width cell.


    As you can see SetAtRef and its related functions allow fairly sophisticated manipulations of cell contents.  The result for the user is simply intelligent shape behavior.  Next time we’ll look at a few more ways that SetAtRef can be used.


  • Visio Insights

    Text Control Handles


    Shape control handles offer users convenient ways to take advantage of the intelligence built into the shape by a designer.  Perhaps the most common use for a control handle is to link it to the text on a shape.  While Visio provides the Text Block Tool for manipulating shape text, this tool is not very discoverable (it’s underneath the Text tool in the Standard toolbar) and is cumbersome.  A control handle is a very convenient alternative.  In fact, Visio 2003 has a text control handle built into the default dynamic connector.



    The dynamic connector incorporates a couple of behaviors that you may find helpful in the design of your own shapes:

    ·         The control handle is not shown unless there is actual text in the shape

    ·         The user can use either the control handle or the text block to reposition the text

    Let’s look at the Shapesheet for a dynamic connector to see how these behaviors are implemented.


    The visibility of the control handle is determined by the X Behavior cell.  This cell describes how the control handle should resize with the shape, whether it can be moved at all and whether the control handle is visible.  An IF statement sets the behavior to 5 to hide the handle or 0 to show it.  The conditional statement verifies that the shape has no text or that it is currently not visible.  Note the use of the STRSAME function to check for text.  This is the recommended practice.



    The synchronization of the control handle and text block is accomplished using the SETATREF function.  This is a very powerful and complicated function that needs some introduction.  We’ll look at the basic capability as it is used in the text control handle here, but there is quite a bit more to cover in a future post.

    Consider a typical formula dependency where cell A depends on cell B.  As long as the user modifies cell B, then A and B will both be up to date.  What happens if the user modifies cell A?  This change would blast the formula in cell A, decoupling it from cell B.  You could GUARD the formula in cell A to preserve the dependency on cell B, but now the user cannot manipulate cell A at all.  SETATREF solves this problem by preserving dependencies and forwarding inputs to the independent cell.  SETATREF allows cell A to depend on cell B while also allowing the user to change either A or B.

    In the case of the text control handle, the position of the text block is dependent on the position of the control handle.  Thus the TxtPinX and TxtPinY cells have formulas with references to Controls.TextPosition and Controls.TextPosition.Y respectively.  These references are then wrapped by a SETATREF formula.  To understand how SETATREF works, we need to separate what happens during recalculation versus what happens during cell input.

    Because TxtPinX and TxtPinY have formulas with references to the control handle position, these cells must be recalculated whenever the control handle position changes.  During the recalc operation, the SETATREF function is transparent.  SETATREF(x) = x.  In other words, the result of the recalc is just like if there were no SETATREF wrapped around the cell references.  On the other hand, when the user directly manipulates the TxtPinX or TxtPinY cells (by using the Text Block Tool), SETATREF influences how the new value updates the Shapesheet.  Rather than letting the new cell value replace the SETATREF formula, Visio forwards the value to the cell referenced in the SETATREF function.  Thus any change to the TxtPinX or TxtPinY cell is actually made to the Controls.TextPosition or Control.TextPosition.Y cell instead.  Then the TxtPinX and TxtPinY cells pick up the change through recalculation.

    This ability to preserve dependencies and forward input values is extremely versatile for shape development.  We’ll look at some more sophisticated uses for SETATREF in a future post.


  • Visio Insights

    New Visio Resource and More


    There are several housekeeping items in today's post.

    New resource

    Chris Roth, a Visio MVP, has begun a new Visio blog:

    Check out articles on creating flowcharts from code and hiding parts of shapes.


    Recruiting Visio & CAD users

    Do you use Visio to view, draw on top of, convert or export CAD drawings?  We'd like to hear from you as we plan the next release of Visio.  If you are willing to tell us about the way you use Visio with CAD or have some thoughts about what's good or bad about Visio's functionality, please contact us.


    Suggest a blog topic

    Is there something you would like to see covered by this blog?  Send us a suggestion for a topic.  We try to hit the most frequently asked questions from the newsgroups.  Please let us know what is important to you.


  • Visio Insights

    Better Layout Using Dynamic Glue


    Visio makes it easy for users to place shapes anywhere and provides connectors for maintaining connections between shapes.  However, as diagrams get more complicated, users often look to Visio for help organizing shape placement and connector routing on the page.  Unfortunately, while Visio's automatic layout functionality is quite powerful, many times the results are not good enough without tweaking the layout settings.  In this post we'll look at one such scenario and try making a few changes to improve the final results.

    Here is a custom shape with several connection points on each side.  Connectors are intended to glue to these points on the shape.

    A diagram is created using this shape and connectors are added.

    We now would like Visio to rearrange the shapes and reroute the connectors to create a cleaner, more readable diagram.  Choosing Shape > Re-layout Shapes gives this result:

    This result is not ideal.  There are still overlapping connectors and too many bends.  Visio is actually constrained by the way the connectors were glued to the shapes.  The traditional way to glue connectors is to drag the end of the line to a connection point on the shape.  This creates what is known as static glue in Visio.  The connector remains associated with that connection point.  Static glue has drawbacks for layout because it prevents Visio from routing to the nearest side of the shape.  An alternative is using dynamic glue.  To glue using dynamic glue, drag the end of the line to the center of the shape.  A red outline rectangle will appear to indicate dynamic glue.  The resulting red glue square has a slightly different look as well.

    By switching all the connections over to dynamic glue, Visio can choose more efficient routes for the connectors.  However, now Visio routes to locations on the shapes that we do not want.  Our custom shape is not supposed to allow connections on the top or bottom.

    There is a Shapesheet cell that allows us to set some restrictions on dynamic glue so that Visio will not choose any arbitrary location to connect.  The Shape Layout section has a cell named ShapeFixedCode that determines how connections can be made to a shape.  By setting ShapeFixedCode to 64 on the custom shape we can force Visio to connect at connection points.

    Now the automatic layout keeps the connectors glued to the connection points.  Note that the glue style is still dynamic glue.  Visio is free to choose which connection point is used for each connection.  The result is better but still not ideal.  There are still too many bends in the connectors as Visio must work in and around the shapes.

    One final change can clean this layout up.  Each drawing page has a default layout spacing, but the shapes you use in the drawing may not be suitable for that default.  In this example, the default drawing spacing is 0.375 in. while the custom shape size is 1.25 in. x 1 in.  That pushes the shapes too close together.  By increasing the spacing between shapes, Visio can find better routes for the connectors.  This is done in the Shape > Configure Layout dialog.

    The end result is a much simpler arrangement with clean connector routes.

    Dynamic glue adds flexibility to Visio's layout and routing optimizations and will result in a better looking diagram.  The tradeoff is the inability to specify particular connection points for connectors.  Visio assumes all connection points are equally valid.  Hopefully the techniques presented in this post help you get better layout results.  It is unfortunate that Visio's automatic layout needs this much tweaking to get good results, but it is challenging for a layout engine to produce optimal results across a huge variety of drawing types.  As always, tell us your pain points, and we will try to address them in the future.


  • Visio Insights

    How Far Can I Zoom In?


    Here’s a recent question on the newsgroups that has come up several times in the past.  It seems that the larger you make a page in Visio, the less you can zoom in to see the details.  This is true.  There is a maximum zoom limit in Visio, and this maximum depends on the size of your page.


    The limitation on zoom is tied to the way Visio uses Windows’ GDI display component to render pages.  A Visio page is one big surface that is clipped to fit in the drawing window.  This allows capabilities such as smooth panning / scrolling and rapid zoom changes because the rendered image does not need to be constantly reconstructed.  In Windows 9x systems this display surface was limited to a maximum size of 32767 x 32767 pixels - basically a 16-bit system limitation.


    To calculate the maximum zoom level, Visio uses this basic formula:

    Max Zoom = (32767 / (Page size in inches * Screen pixels per inch)) * 100%

    Take an example drawing with the largest page dimension equal to 34 inches and a standard monitor pixel density of 96 DPI.  This formula evaluates to 1004%.  If the page size increases, the maximum zoom decreases proportionally.


    More recent versions of Windows support larger ranges in GDI.  Starting with the latest service pack of Visio 2003, we have updated our zoom logic to take advantage of this headroom.  At a minimum, you can zoom into your drawing at 1000% regardless of page size.  The formula above is still used to determine the maximum zoom.  Thus the zoom limit is the larger of the formula result or 1000%.


    Hopefully this addresses most of the situations where zooming was restricted with large pages.


  • Visio Insights

    Printing Comments


    Visio 2003 introduced a new Reviewer & Markup feature that allows users to add comments to diagrams.  A typical question we are asked is “How do I print the comments?”  This capability was not included in the markup feature, but our Product Support team has published a solution in a Knowledge Base article:


    The solution is a VBA macro that you can add to your document to programmatically collect the comment information and put it into a new shape in the diagram.  Please follow the link for detailed instructions and the code.  The shape is placed off the page at first.  You can resize the shape, format the text to your liking and then move the shape into the printed page region.



    The code operates on the current page and also any reviewer pages that may overlay it.  Comments are found in the Annotation section of the page’s ShapeSheet.



    This “comment report” is one way of addressing the need for printing comments.  If you use comments in your diagrams, please tell us how you surface them or how you would like to see Visio display and print them.



  • Visio Insights

    Seeing While You Drag


    There have been several recent newsgroup questions relating to dragging shapes around on the page.  Sometimes you get to see the geometry you are dragging around.  Other times you only see an outline rectangle.  A similar issue is that dragging is quite choppy such that you often don't see what you drag.  Both issues deal with performance in Visio.  Let's look at each one.


    Drag image generation

    When you drag a shape around, Visio generates a drag image to display.  This is basically a bitmap representation of your shape.  Seeing the actual geometry of your shape helps with positioning and alignment.  If you select a bunch of shapes to drag around, the drag image that Visio must generate is more complex.  This takes more time, which then makes Visio feel sluggish. 


    To avoid this situation, Visio has a cut-off point of 25 shapes.  This 25 shape limit includes any sub-shapes of groups in the selection.  If you drag around more than 25 shapes at a time, Visio will only show an outline rectangle for the drag image.  You can still pause while dragging, and Visio will go ahead and generate the full image.


    An interesting side effect of this threshold is that it causes 2-D glue operations to fail as well.  (2-D glue means gluing a 2-D shape to another 2-D shape, while 1-D glue is the normal connector to 2-D shape operation.)  2-D glue only works when the drag image is shown.  Even pausing to generate the drag image does not work around the problem.  Shapes that have outward connection points on them thus need to be kept simple.


    For those that would like to eliminate this threshold entirely, there is a registry key. For Visio 2003 set ‘HKCU\Software\Microsoft\Office\11.0\Visio\Application\DragBitmap’ to “2”. For Visio 2007 set ‘HKCU\Software\Microsoft\Office\12.0\Visio\Application\DragBitmap’ to “2”.  The downside is that you will encounter degraded performance as you begin to drag more complex shapes around.  This may or may not be noticeable on your computer.


    Dragging performance

    Once you begin dragging and the drag image has been generated, a second issue affects whether you can drag it around smoothly.  Visio must update the rendered drawing as you drag this image across it.  This involves creating a mask out of the drag image and then doing XOR operations against pixels as things move around.  Depending on how complicated the drawing page is behind the drag image, this process can take some time.  The longer it takes to re-render, the choppier the drag behavior appears to be in Visio.  With some really complicated drawings like inserted CAD objects, it may take more than a second for any update to occur.


    Dragging performance really depends on the computer's video card, but many users have reported that dragging is actually slower on their new computers versus their older computers.  How can performance be worse on a faster video card?  It turns out that Visio's masking code is really old.  The code makes specific calls to the video card that are no longer in use today.  The cards now support much more efficient ways of doing things.  In fact, video card manufacturers likely no longer optimize the legacy calls.  Since Visio still does things the old-fashioned way, performance goes down on the newer cards.


    There is nothing a user can do to address this second problem.  The good news is that Visio 2007 has replaced it's old masking code with newer, mainstream calls to the video cards.  The results are dramatic.  We measured drag performance to be 150 times faster in Visio 2007!  This results in very smooth dragging for even the most complex Visio diagrams.



    Keep in mind that both of the two drag issues here impact what you see on the screen.  One is a hard-coded limit based on shape count.  The other is dependent on the performance of the video card (when used with legacy calls).  If the first issue is annoying, you can use the registry fix.  If the second issue is frustrating, you will need to wait for Visio 2007.


Page 6 of 8 (181 items) «45678