Volume 3: Programming with the Visio Object Model disclaimer


Lesson 1: Data Graphics Concepts



Download 0.78 Mb.
Page22/36
Date29.01.2017
Size0.78 Mb.
#11974
1   ...   18   19   20   21   22   23   24   25   ...   36

Lesson 1: Data Graphics Concepts


Microsoft Visio offers tools for visualizing information. Data can be connected from external sources and linked to individual shapes. A variety of graphics can be applied to the shapes to display information about the data they contain. The data can be refreshed from the external source and the graphics can update automatically based on the values stored in the data.

Data Graphics lets you present information in a concise, understandable format. Text, geometry, formatting, and graphics are combined to help users identify issues, illustrate patterns in data, and communicate status. Data Graphics can be expressed in many different ways to give the user a wide variety of options for visualizing his data.

This lesson covers that full range of options for creating and customizing Data Graphics.

Lesson Objectives

After completing this lesson you will be able to:

  • Create new data graphics and customize existing data graphics

  • Apply text, data-bar, and icon set callouts and use color-by-value to visualize data

  • Create new text, data-bar, and icon-set callouts

  • Manage Data Graphics objects in a document

  • Go beyond the basics and customize your own data graphic items

14.Overview of Objects / Methods / Properties


Included in this section is a description of the objects, methods, and properties related to creating and managing data graphics in Visio. There are other objects, properties, and methods that come into play when developing solutions with data graphics. These will be covered as they are needed.

Where appropriate, there are bits of sample code sprinkled throughout this lesson which illustrate how to use these features programmatically.


Data Graphics


A GraphicItem is responsible for a single adornment such as a data bar or text callout shown on a Data Graphic. A GraphicItems collection of these make up a single Data Graphic which is held in Visio in the form of a hidden Master on a stencil. The master is of type visTypeDataGraphic.

The relationship of the data graphic objects to other portions of the Visio object model is shown in the graphic below.




Methods

GraphicItem object

Description

GetExpression

Returns the current expression for the primary key column corresponding to the specified field.

SetExpression

Sets the value of the expression string that is part of a GraphicItem object's rule, against which shape data is evaluated.




GraphicItems object

Description

AddCopy

Adds a copy of a GraphicItem object to the GraphicItems collection.




Master object

Description

DataGraphicDelete

Deletes the Master object of type visTypeDataGraphic from the Masters collection of the document.




Masters object

Description

AddEx

Adds a master of the specified VisMasterTypes object to the Masters collection.



Properties

GraphicItem object

Description

DataGraphic

Returns the Master object of type visTypeDataGraphic that is the parent of the GraphicItem object, the GraphicItems collection, the Selection object, or the Shape object.

HorizontalPosition

Gets or sets the horizontal position of a graphic item relative to a container or shape, as VisGraphicPositionHorizontal.

PositionRelativeTo

Gets or sets whether the graphic item is positioned relative to a container or to a primary shape, as VisGraphicPositionRelativeTo.

Tag

Gets or sets an expression that stores extra data needed for your program. For example, the name you want to apply to a graphic item. Not used by Visio.

UseDataGraphicPosition

Gets or sets whether a GraphicItem object inherits the DataGraphicHorizontalPosition property setting and DataGraphicVerticalPosition property setting of the data graphic master to which it belongs (when set to True), or whether to apply the GraphicItem object's own HorizontalPosition setting and Vertical Position setting (when set to False).

VerticalPosition

Gets or sets the vertical position of the graphic item relative to a container or shape, as VisGraphicPositionVertical.




GraphicItems object

Description

DataGraphic

See GraphicItem object.




Master object

Description

DataGraphicHidden

Determines whether the data graphic is visible in the Data Graphics task pane.

DataGraphicHidesText

If set to True, hides the text of the primary shape when a data graphic master is applied. The default is False.

DataGraphicHorizontalPosition

Gets or sets the horizontal position of a data graphic relative to the shape it is applied to, based on the specified VisGraphicPositionHorizontal value.

DataGraphicShowBorder

Gets or sets whether a border appears around GraphicItem objects whose UseDataGraphicPosition property is set to True, or that occupy the same position as the data graphic of which they are a part.

DataGraphicVerticalPosition

Gets or sets the vertical position of a data graphic relative to the shape it is applied to, based on the specified VisGraphicPositionVertical value.

GraphicItems

Returns the GraphicItems collection of the Master object. Read-only.



15.Creating Data Graphics Masters


Data graphics can be added to a drawing at any time. They may already be part of a drawing if the template used to create the drawing contained data graphics or if shapes dropped on a page had a data graphic associated with them.

Data graphics can be created from scratch or can be copied from existing data graphics and then modified.


Basics of creating a Data Graphics Master


A new data graphic can be created easily using the Visio interface that is presented in the Data tab (Data > Data Graphics). Within the task pane completely new data graphics can be created using the command New Data Graphic. To create a data graphic from an existing data graphic, right-click the data graphic and choose Duplicate. To modify any data graphic, right-click the data graphic and choose Edit Data Graphic…





Try it!

  1. From the Samples folder open Viewing Data Graphics.vsd

  2. Display the Document Stencil and note which masters are displayed.

  3. Display the Drawing Explorer window and note which masters are displayed. Are they the same?

  4. Create a new data graphic (Data > Data Graphics > Create New Data Graphic…). Give it a meaningful name that you will recognize. Does it show in the Document Stencil? Does it show in the Drawing Explorer?

Viewing a data graphics master


Once a new data graphic has been created, it can be viewed in the Drawing Explorer window. Don’t look for it in the Document Stencil because the data graphics master is “hidden”. There is a property of the master object, the Hidden property, that is used to control the display of the master in the stencil window. However, this property is ignored by the Drawing Explorer, which shows every master regardless of the Hidden property value.
Try it!

  1. Open the VBA window. Make sure the Immediate window is displayed.

  2. In Visio use File > Options > Advanced to check the number of Undo levels. Set the number to at least 30.

  3. Run the macro “ListMasters”. All masters, along with their Hidden property are displayed in the Immediate window.

  4. Run the macro “MakeAllMastersShow”. This changes the value of the Hidden property of all masters to False so that they will show in the Document Stencil window.

  5. Note the data graphics masters in the Document Stencil and then Undo (Ctrl-Z) the results of running the macro to again hide the data graphics masters.

Creation with automation





Note:

When Visio’s macro recorder is turned on the Data Graphics menu is deactivated. Thus recording anything that happens in the data graphics task pane is not possible.

The file Working with Data Graphics.vsd in the Sample folder has the following sample code in it for creating a data graphic master.

Public Sub AddEx_Example()

‘Create an empty data graphic master

Dim vsoMaster As Visio.Master

Set vsoMaster = Visio.ActiveDocument.Masters.AddEx(visTypeDataGraphic)

Debug.Print vsoMaster.Name

End Sub

Try it!

  1. Open Working with Data Graphics.vsd from the Samples folder. Run the macro (View > Macros > InterestingMacros.AddEx_Example).

  2. A new master can be seen in the Drawing Explorer window. The name of the new master is displayed in VBA’s Immediate window.

  3. The empty data graphic also shows in the Data Graphic task pane, but does not show in the Document Stencil. The AddEx method makes it hidden automatically.

  4. There is a data graphic called DGDisposition included in this file. Run the macro DuplicateDataGraphic to copy this data graphic.

  5. The new data graphic shows in the Data Graphic task pane.

The code for DuplicateDataGraphic is below.

Sub DuplicateDataGraphic()

'Copy the data graphic named "DGDisposition"

ActiveDocument.Masters.Drop _

ActiveDocument.Masters.Item("DGDisposition"), 86, 121

End Sub


16.Creating Data Graphics Items

Overview of Data Graphics


A data graphic is a collection of data presented in a diagram either as a set of graphical widgets or by formatting shapes that contain data. The widgets are known as callouts. These callouts are placed on or next to a shape that contains data, referred to as the target shape in this document. The data displayed is typically Shape Data, but other shape information and custom expressions can also be displayed.

Note:

Don’t confuse the data graphics term callout with the new Callout shapes that are introduced with Visio 2010. These are two separate entities.

Visio provides three types of callouts, as listed in Table .

Table . Data Graphics callout types

Type

Description

Text callouts

Display data as text.

Data-bar callouts

Display data by modifying some visual aspect of the callout, such as the amount filled in a progress bar.

Icon-set callouts

Display data by using icons that appear or disappear based on conditional statements.

A fourth way of displaying data in a shape is by using Color by Value. This method applies conditional formatting to the shape itself rather than displaying information in a callout.



Figure . Data Graphic applied to regular shape




Figure . Data Graphic applied to pivot node

A data graphic consists of the set of callouts and Color by Value rules used to display data on a shape. Each shape can have only one data graphic applied at a time, but a data graphic can consist of many callouts and Color by Value rules. You apply data graphics in the Data Graphics task pane.




More Information:

On the drawing page, a data graphic is a set of special shapes added to a target shape that contains the data to be displayed. When you apply a data graphic, the target shape becomes a group (if it is not already a group) and the data graphic shapes are added as subshapes of that group. Data graphic shapes usually appear on top of any existing subshapes that are included in target shapes.



Create Data Graphics Item with the Visio user interface


There are many built-in text, data-bar, and icon-set callouts available with Visio. As built in callouts, they do not show in the Masters collection of the Drawing Explorer window. However, once one of these callouts is added to a data graphic it is added to the Masters collection.

Visio recognizes a shape as a data graphics callout if the topmost shape in the master contains the user-defined cell User.msvCalloutType.


Text callouts and Data bar callouts

There are eight built-in text callouts provided with Visio. These are shown in the graphic below.

There are eleven built-in data bar callouts in Visio. Most of them are shown in the graphic below.



These callouts can be added to any data graphic. Once they are added, they show in the Masters collection in the Drawing Explorer window. Once in the Masters collection of the drawing they can be edited and renamed to form a customized callout.



Working with Text callouts and Data bar callouts are very similar.
Try it!

  1. Create a new blank drawing.

  2. Create a new data graphic (Data > Data Graphics > Create New Data Graphic…). The New Data Graphic dialog is displayed.

  3. Select new Item.

  4. For Data field: choose More Fields… and then select Geometry and Width.

  5. For Displayed as: choose Text. The New Text dialog is displayed.

  6. Select the Text callout.

  7. Under Details > Value Format choose the browse button and then General and check Show Units.

  8. Under Details set Label to “Width”.

  9. Close the dialog. In the Drawing Explorer note that two new masters are added, Data Graphic and Text callout.

  10. Draw a rectangle and apply the data graphic to it. It will display the shape’s width.



  1. In the Drawing Explorer window click the Text callout and change its name to My Text callout.

  2. Right click My Text callout and choose Edit Master shape. Change the line color and the text color in the master. Close the master editing window. (Note: you may have to force a redraw in the drawing for the results to be seen. Moving the shape should do it or reapply the data graphic).



  1. In the Data Graphics work area choose Edit Data Graphic and choose New Item. Choose any field for the data then choose Text. Note that the My Text callout is in the list as well as the original built-in Text callout. Close the Edit Data Graphic dialog.

    Note:

    The built-in callouts cannot be changed. If you use one in a data graphic and modify it as was done above, but don’t rename it, you will see two versions of the callout in the callout list, the one you modified and the original built in version. It is best to rename a callout if it is being modified so that it can be more easily identified in the callout list.

  2. Select the My Text callout master in the Masters collection of the Drawing Explorer window. Right click and choose Edit Master Shape.

  3. In the master drawing window right click the shape and choose Show ShapeSheet. The first user-defined cell is shown below. Note that the callout type is set to “Text Callout”.



  1. In the same ShapeSheet look at the Shape Data section. Note that the first seven Prop.msv… rows correspond to the elements in the Details section of the New Text dialog we saw when editing the data graphic. The last row Prop.msvCalloutField holds the value of the data element being displayed.

The Shape Data rows define the presentation in the Details section of the New Text dialog. The Label specifies the label displayed. The Type field controls the type of data (boolean, string, list, etc.). Format specifies list elements.

A very important column, not seen in this figure, is the Invisible column. Note that Visio uses Shape Data rows in callouts in highly specialized ways and that these rows are not intended to be used as standard Shape Data properties. For this reason, the Invisible cell should always be set to True to hide these rows from the user.

Put a custom formula in a callout

It is easy to modify a data graphic to display Shape Data from a shape. It is also possible to display other information about a shape, such as its Width or a user-defined cell. It is even possible to display calculated data that is derived from several data elements.

To create and display a custom formula choose More Fields… in the Data field section of the Text or Data bar callout. The following dialog is presented. Note that it is very similar to the dialog for a Text Field and it is used in exactly the same way. In the image below Geometry is chosen as a category and then Width is chosen as the Field name. Note that there are several other categories and each of them contains several fields that can be chosen.



The real power in this dialog comes from the last Category Custom Formula. From here one can create calculated fields and format the data using the Format function.


Try it!

  1. Create a new data graphic.

  2. Add a New Item…

  3. For Data field choose More Fields…

  4. Choose Custom Formula. The Custom formula field at the bottom becomes active.

  5. Enter into the Custom formula field

="Aspect Ratio = "&Format(Width/Height,"0.0")

Let’s take this formula apart from the inside out. Width and Height are references to the shape’s Width and Height cells. Width divided by Height is commonly referred to as the aspect ratio. Format is a function that takes a value and formats it based on a formatting string which in this case is the string “0.0”. This says to display a number to one decimal place. On the left side of the formula is the constant string “Aspect Ratio” followed by & which is the concatenation operator for putting strings together.



  1. For Displayed as: choose Text and choose callout Heading 3.

  2. Select OK to close this dialog.

  3. In the New Data Graphic dialog set the Callout position to Left and Above Shape.

  4. Select OK to close the dialogs.

  5. Draw a rectangle and apply the data graphic. Resize the rectangle and observe that the aspect ratio value changes.


Add a field to a data graphic

In this lesson we will add a new field to an existing data graphic that will be used to control the fill color of the header bar within the data graphic.

Visio recognizes a shape as a data graphic through the user-defined cell User.msvCalloutType. This is set to “Text Callout” or “Heading” for a text callout, “Data Bar” for a data bar callout and “Icon Set” for an Icon set callout.

You can define properties for text callouts or data bars to expose in the Edit Item dialog. Shape Data rows are used to define the fields to be displayed when editing a data graphic.

Important:

The names of the Shape Data rows used to display fields in a callout must begin with Prop.msvCalloutProp…



Try it!

Start from the data graphic used in the last section to display the aspect ratio in a Heading 3 callout.

  1. In the Drawing Explorer window rename the Heading 3 callout to My Heading.

  2. Right-click My Heading and choose Edit Master Shape.

  3. Right-click the shape and choose Show ShapeSheet.

  4. In the ShapeSheet for the My Heading master add a row to the Shape Data section.

  5. Fill in the following cell values for the new row.

    • Name the row Prop.msvCalloutPropColor. Don’t type “Prop.” This will be added automatically.

    • Label = “Heading Color”

    • Prompt = “List”

    • Type = 1

    • Format = “Red;Green;Blue”

    • Value = Index(1,Prop.msvCalloutPropColor.Format)

    • Invisible = True

  6. Close the ShapeSheet and the master drawing window. Choose Yes to update My Heading.

  7. Check what has been done so far in the Data Graphics task pane. Edit the data graphic and edit the Text callout and look for the new properties. The changes may not update automatically. Force a refresh by changing the Callout to something different and then back again. You should now see the new row Heading Color and be able to choose between the colors Red, Green, and Blue.

  8. Close the dialogs for editing the data graphic.

  9. In the Drawing Explorer window right-click My Heading, choose Edit Master Shape, and then select the shape and choose Show ShapeSheet.

  10. Set the FillForegnd cell in the Fill Format section to

=GUARD(LOOKUP(Prop.msvCalloutPropColor,Prop.msvCalloutPropColor.Format)+2)

This formula returns the values 2, 3, and 4 which correspond to the colors Red, Green, and Blue when used in the FillForegnd cell.



  1. Close the ShapeSheet and close the master drawing window. Choose Yes to update My Heading.

  2. Edit the Data Graphics (Data > Data Graphics > Edit Data Graphic…) by changing the color in the field Heading Color. Below is the result when the color Red is chosen.


Icon-set callouts

You can use existing icon sets or create your own either as Visio geometry or by using image files.

An icon-set callout is a shape that can display up to five different images, depending on a value provided by the Data Graphics feature. Icon-set callouts are different from text callouts and data-bar callouts because the icon-set callout does not use the data-field value directly. In the Edit Icon Set dialog box, you can define a set of conditional statements for icon-set data that determines which icon should be displayed. From the conditional statements, Visio creates a single ShapeSheet formula that returns a number that corresponds to a particular icon.

Visio recognizes a shape as a data-graphics callout if the topmost shape in the master contains the user-defined cell User.msvCalloutType whose value is set to "Icon Set" (quotation marks required).

A second user-defined cell named User.msvCalloutIconCount tells Visio how many icons the callout supports. This cell should have an integer value of 1, 2, 3, 4, or 5.

A third user-defined cell named User.msvCalloutIconNumber receives the formula from Visio that determines which icon to display. This formula evaluates to -1 when none of the user's conditional statements are true. Otherwise, the formula evaluates to an integer of 0, 1, 2, 3, or 4.

icon-set callout user-defined cells

Figure . Icon set callout user defined cells

The code sample below will add the three user-defined cells and set their values.

Sub AddUserCellsForIconSet()

'Add the user-defined cells required for an icon set to the currently

'selected shape

If ActiveWindow.Selection.Count = 0 Then

MsgBox "Select a shape before using this macro"

Exit Sub


End If

Dim fExistsLocally As Boolean

fExistsLocally = False

With ActiveWindow.Selection(1)

'Check to see if the cell already exists. If so, don't add it again.

If Not (.CellExists("User.msvCalloutType", fExistsLocally)) _

Then .AddNamedRow visSectionUser, "msvCalloutType", visTagDefault

If Not (.CellExists("User.msvCalloutIconCount", fExistsLocally)) _

Then .AddNamedRow visSectionUser, "msvCalloutIconCount", _

visTagDefault

If Not (.CellExists("User.msvCalloutIconNumber", fExistsLocally)) _

Then .AddNamedRow visSectionUser, "msvCalloutIconNumber", _

visTagDefault

'Set the values into the cells

.Cells("user.msvCalloutType").Formula = """Icon Set"""

.Cells("user.msvCalloutIconCount").Result(visNumber) = 5

.Cells("user.msvCalloutIconNumber").Result(visNumber) = 0

End With


End Sub
Try it!

  1. Open from the Samples folder the file Working with Data Graphics.vsd

  2. Use the drawing tools to create a shape on the page.

  3. Select the shape just created and run the macro AddUserCellsForIconSet

  4. Check the ShapeSheet to verify that the user cells were added

  5. Running this macro again on this same shape will still work because the macro checks to see if the cells already exist before attempting to add them.

By convention, you should hide the callout shape when User.msvCalloutIconNumber is -1, although it would be possible to use this state to display another graphic. To hide a shape completely, you must hide all of its geometry, text, and images.
Using geometry

A common way to draw an icon is by using shape geometry. A shape can have multiple geometry sections in it, and you can show or hide each section independently, depending on the value you set in the User.msvCalloutIconNumber cell. Similarly, a shape can be a group containing additional subshapes, and you can show or hide the geometry in those subshapes independently.

Figure provides an example of an icon-set callout that has two geometry sections.



icon-set callout geometry example

Figure . Icon set callout geometry example

The circle is shown for icon values 0, 2, and 4 (displaying the numbers 1, 3, and 5). The square is shown for icon values 1 and 3 (displaying the numbers 2 and 4). Figure shows a geometry section.

icon set callout geometry section

Figure . Icon set callout geometry section

The NoShow cell in each geometry section controls the visibility of the section. Table lists the complete formulas for the NoShow cells.

Table . Icon set callout NoShow formulas



Cell

Formula

Geometry1.NoShow

IF(OR(User.msvCalloutIconNumber=0,User.msvCalloutIconNumber=2, User.msvCalloutIconNumber=4),FALSE,TRUE)

Geometry2.NoShow

IF(OR(User.msvCalloutIconNumber=1,User.msvCalloutIconNumber=3),FALSE,TRUE)

Note that when User.msvCalloutIconNumber is -1, both formulas evaluate to TRUE and no geometry is shown.


Using image files

Another way to show an icon is by using a picture image, such as a bitmap or a metafile. In this case, the callout shape must be a group shape that contains the image or images as subshapes. Put the user-defined cells for the icon set into the group shape. You can show or hide the images by specifying the value in the group's User.msvCalloutIconNumber cell.

When working with images, it is easier if all the pictures are the same size. Also, the images should be combined into an image strip—a single picture that contains the images arranged in an evenly spaced row. You can perform these manipulations either in Visio or in another graphics editor, such as Paint.

Figure shows an example of an icon set based on images.

Figure . Icon set callout image example

To create this icon set, draw a rectangle to the final callout size you want. Convert the rectangle to a group and add the required user-defined cells for the icon set. Then add the image strip to the page, and lock its aspect ratio. Resize the image strip until it is exactly 5 times the width of the rectangle (or a different multiple if there are fewer icons in the set).



Figure . Icon set callout image example: Step 1

Using the Crop tool, crop the image strip down to the width of the rectangle. Align the image strip on top of the rectangle and add it to its group. You can delete or permanently hide the rectangle's geometry section.





Figure . Icon set callout image example: Step 2

The final step is to tie the image strip to the group's icon number. In the ShapeSheet of the image strip, the Foreign Image Info section controls the size and position of the picture. Only a portion of the picture is visible in the shape, and the rest is cropped out of view. The ImgOffsetX cell controls what portion of the image is seen. This cell moves the image based on the icon value of the group.



The formula in the ImgOffsetX cell refers to Sheet.5. This is the group shape that contains the images.

icon-set callout foreign image info section

Figure . Icon set callout Foreign Image Info section


Note:

There are significant differences when working with image strips created as bitmaps vs. those created as enhanced metafiles. For bitmaps, if the image does not completely fill the frame, then the background must be of some color (let’s assume white). When these images are applied in an icon set, the icons will have a white border around the image. If the user puts a color on the page other than white, the icon doesn’t look so good. Second, the image quality may degrade. Image strips created as enhanced metafiles have a transparent region around the shape and the image quality does not degrade. Using enhanced metafiles instead of bitmaps for the image strip creates a much better looking icon set.



Try it!

  1. Open the file Working with Data Graphics.vsd. An example of creating the icon set described above is covered in this drawing on page “The making of an icon set”.

  2. Edit a data graphic and add a new graphic item. The new Icon Set is displayed along with the other icon sets.

  3. Choose the icon set (its name is not displayed) in the New Icon Set dialog.

Working with data graphics using automation


Data graphics can be managed through the Visio user interface. But what about doing some these same tasks or accessing the information about data graphics and graphic items through automation? In the file Working with Data Graphics.vsd in the Samples folder there is VBA code for the following.
Return a data graphic assigned to a shape

Through automation you can get the data graphic assigned to a shape. The information is in the DataGraphic property of the shape.
Try it!

  1. Open Working with Data Graphics.vsd from the Samples folder.

  2. Select a shape that has a data graphic assigned to it and run the macro WhichDataGraphicAssigned from the Tools menu.

  3. The data graphic assigned to the shape is displayed in a message box.

  4. View the code.
Apply a data graphic to a shape

You can also set the data graphic for a shape through code.
Try it!

  1. Open Working with Data Graphics.vsd from the Samples folder.

  2. Go to the page named Data Graphics. Right-click one of the shapes and choose Set to next DG. This runs the procedure SetDGToNextInList which finds the current data graphic assigned to the shape and then searches all of the data graphics in the document to find the next data graphic. It then assigns this data graphic to the shape.

  3. View the code.



Interrogate Graphic Items

You can interrogate properties for graphic items.
Try it!

  1. Open Working with Data Graphics.vsd from the Samples folder.

  2. Go to the page named Data Graphics.

  3. Select a shape that has a data graphic assigned to it. Run the macro ListDataGraphic. This will write information about the data graphic and each of the graphic items that make up the data graphic to VBA’s Immediate window.

  4. View the code.
Set information into a data graphic

  1. Right click one of the shapes and choose SetDGToNextHorizontalPosition. This runs the procedure SetDGToNextHorizontalPosition which increments the horizontal position of the data graphic.




Note:

Editing a data graphic in the Data Graphic task pane is equivalent to editing the master in the Drawing Explorer window. To do the equivalent operation in code you must edit the master. This requires that 1) the master be Opened (which creates a copy), 2) edits are made to the copy, and 3) close the copy. On close the changes are copied back to the master and the update happens in the drawing.




  1. View the code.

  2. There is also a procedure SetDGToNextVerticalPosition.
Set information into a data graphic item

  1. On the page named Data Graphics make sure there is a data graphic assigned to one of the shapes.

  2. Edit this data graphic and edit the item within it so that it does NOT use the default position of the data graphic (uncheck the box Use default position) and then reposition the Text callout or Data Bar callout.

  3. Select the shape that has the data graphic just modified and run the macro ResetGraphicItemsToDefaultPosition. This macro steps through each of the graphic items for the data graphic assigned to the shape and sets the property UseDataGraphicPosition to True. This is equivalent to editing the graphic item and checking the checkbox Use default position.

  4. View the code




Note:

Like editing a data graphic, editing a graphic item is equivalent to editing a master. We therefore need to open the master, edit the copy, and close the master.
Other things to do with a data graphic

There are two check boxes in the Edit Data Graphic dialog

  • Show border around items at default position. Get or set the property DataGraphicShowBorder.

  • Hide shape text when data graphic is applied. Get or set the property DataGraphicHidesText.
Other things to do with a data graphic item

  • Set details as in the Edit Item dialog. The details fields come from the Shape Data rows in the master. Setting the Shape Data cells through automation is equivalent to opening the Edit Item dialog and changing details values.

  • Set data field as in the Edit Item dialog. Use the SetExpression method of the GraphicItem.

Guidelines for constructing data graphic callout shapes


Use of common design practices helps ensure consistency and ease of use for callout shapes.
Callout Name

For text callouts and data bars, the name assigned to the callout master is the name displayed in the Callout drop-down list in the Edit Item dialog. Icon sets are only displayed graphically.
Sample Values

Visio uses the callout master shape as a thumbnail in the Edit Item dialog. The master shape also appears in the Data Graphics viewing area as part of the data graphic thumbnails. To help your users understand how your callout displays information, choose an appropriate sample data value for the shape.
Controlling callout size

Visio applies special formulas to your callout shape to control its size and position relative to the parent shape in the drawing. In general, these formulas size the callout to match the width and height of the parent shape. To specify a fixed size or a size controlled by logic within the callout, place GUARD expressions in the Width cell or in the Height cell in the callout, or in both cells. In Figure , in the first example, the Width cell value is matched to the width of the parent shape, but the Height cell value is determined by the callout. Also in Figure , in the second example, both the width and height remain fixed.

callout sizing examples

Figure . Callout sizing examples


Controlling margins

Callout shapes are often stacked together or aligned along the edges of the parent shape. This may make the geometry or graphical images in the callouts appear crowded. It is often helpful to build a margin into the callout shape's geometry or image strip. The icon set example, discussed previously, includes a margin to inset the geometry of the callout, as shown in Figure .

callout margin example geometry sections

Figure . Callout margin example Geometry sections

In this example, a user-defined cell named Margin was created to specify the spacing to be used. When you use fixed dimensions in a shape, include a factor for the page scale so that the shape is usable in scaled drawings. You can do this by multiplying the fixed dimension by the value of the DropOnPageScale cell.

callout margin example user-defined section

Figure . Callout margin example user-defined section

Protection cells

When you design callout shapes, you must decide what you want to allow your users to manipulate in the callout after they apply it to a parent shape. The Protection section in the ShapeSheet enables you to lock down specific behaviors or properties in the callout shape.

This is an example of changing the text size in callouts.

 

http://officeblogs.net/visio/callouttext1-010207.png

 

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?



 

http://officeblogs.net/visio/callouttext2-010207.png

 

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 introduced a new protection on shapes to prevent group formatting from propagating to sub-shapes.



 

http://officeblogs.net/visio/callouttext3-010207.png

 

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 callouts work this way. Not all Visio shapes allow selection of sub-shapes. This is controlled by the group selection behavior property found in the Developer > Behavior dialog. If the Selection property is set to Group Only, you will have to right click the shape and choose Group > Open Group to make any formatting changes.



As was shown earlier, the master callout can be edited to effect global callout changes.

The following table shows Protection section cells useful for controlling callout behavior.



Cell

Explanation

LockAspect

Useful for icon sets if the Width cell and the Height cell are not protected with the Guard function.

LockFormat

Prevents users from making formatting changes to the callout.

LockCustProp

Prevents users from deleting Shape Data properties from the callout.

LockGroup

Prevents users from deleting subshapes that make up the callout.

LockFromGroupFormat

Prevents formatting changes made by users to the target shape from also being applied to the callout. Direct formatting of the callout shape is still allowed.

LockThemeColors

Prevents color themes from changing the formatting of the callout.

LockThemeEffects

Prevents effect themes from change the formatting of the callout.



Performance, memory, and file size

Because data-graphics callouts are Visio shapes and can contain complex graphics, they can significantly affect the size and responsiveness of a Visio drawing. If an average callout shape includes two subshapes and an average data graphic includes three callouts, Visio adds nine shapes to the document every time you apply a data graphic to a target shape. For some drawing types, such as flowcharts, the data-graphics shapes are far more complex than the shapes that constitute the drawing itself. The file size and memory requirements for a drawing that contains data graphics might be an order of magnitude larger than those of a drawing without data graphics. This affects the performance of the document.

The most important factor that influences performance, memory, and file size is the number of shapes per callout. Ideally, each callout should be a single shape. If you must combine multiple callout shapes into a group, ensure that the group itself is used for its geometry or text. Shapes support multiple geometry sections, so an additional shape is often not necessary. You can individually show or hide each geometry section based on the configuration of the callout. Additional shapes are necessary when a callout needs multiple formats or pieces of text, but try to keep the total number of shapes to a minimum. Also, avoid creating groups nested inside other groups.

Another performance factor is the time required for Visio to add new ShapeSheet cells to the callout when you use it in a drawing. Visio generates several additional user-defined cells to implement some of the data graphics behavior in the callout. Including these cells in the callout master shape saves time and file size. Table lists named rows that you must add to callout masters.

Table . Callout user-defined cells used by data graphics



Row

Value

User.visDGCalloutItem

blank

User.visDGDefaultPos

blank

User.visDGStackHeight

blank

If you design target shapes to work with data graphics, you can add some of the named rows listed in Table to target masters.

Table . Target shape user-defined cells used by data graphics

Row

Value

User.visDGDisplayFormat

blank

User.visDGDefaultPos

blank

User.visDGCBVFill

blank

User.visDGOldColors

blank

User.msvThemeColors

blank

User.msvThemeEffects

blank

By pre-creating the user-defined cells needed by data graphics, you can reduce the time needed to apply data graphics to shapes.

One final performance issue to be aware of is the use of the ShapeSheet functions TEXTWIDTH and TEXTHEIGHT. These functions calculate the geometric boundary of shape text—which is useful information for precisely arranging text and geometry together. However, they require Visio to fully compose and lay out the shape text each time the function is evaluated. These functions are very expensive relative to other ShapeSheet expressions, so use them sparingly.

17.Managing Data Graphic Masters

Where are they stored and how do you see them?


There are a number of built-in data graphics, callouts, and icon sets. These do not show anywhere in the user interface except in the data graphics viewing area on the ribbon.

Once assigned to a shape, these data graphics, callouts, and icon sets are added to the masters collection of the drawing and can be seen using the Drawing Explorer window. As masters, they have a Hidden property that is set to True. This prevents them from be displayed in the Document Stencil window, but not in the Drawing Explorer.


Making a data graphic part of a document


The built-in data graphics are always included in any Visio document. Other data graphics can be added and saved with a document.
Add a data graphic to a document

To copy a data graphic from one document to another, apply the data graphic to a shape in the current drawing. Then copy the shape and paste it into the other document. This action copies the data graphic definition to the other document, and it copies the callouts used by the data graphic. You can then delete the shape from the first document, but the data graphic remains available in the second document.
Try it!

  1. Open a drawing from the Visio Samples. File > New > Sample Diagrams > Process Improvement.

  2. Create a new drawing that has no data graphics in the template. File > New > General > Basic Diagram.

  3. Look at the Masters in the Drawing Explorer for each drawing. There shouldn’t be any in the second drawing.

  4. In the first drawing select a process shape that has a data graphic applied to it. Paste it into the second drawing.

  5. Check the masters collection after pasting the process shape. Depending on the shape chosen there may be several masters added. For example, the masters collection will look something like this:

    • Bubble callout

    • Data bar 2

    • Process

    • Process 2

    • Status icons

    • Text callout

  6. Check the Document Stencil. The Process shape should be there.

  7. Within the new document delete the process shape. There should be no shapes left on the drawing page. The Masters collection and the Document Stencil are unchanged meaning that the data graphic is still part of this drawing. Check the Data Graphic task pane to verify this.

  8. Delete the Process shape from the Document Stencil. Check the Masters collection and the Data Graphics task pane. The Data Graphics remain.
Make a data graphic part of a template

The process above can also be used to add any data graphic to a template. Open the template for editing, add the data graphic, and save the template. When a drawing is created from the template the data graphic will show in the Data Graphics task pane.


More Information:

It is not possible to define a data graphic in a central location for use in all documents, so building the data graphic into the template is the best approach.



Make a master with a data graphic already applied.

One additional option is to pre-associate a data graphic with a master shape. This method is useful for diagrams in which data graphics are an integral part of the drawing and in which each shape can use the same data graphic to display information. To build a data graphic into a master shape, apply the data graphic to a shape on the page and then drag the shape to a stencil to create a master. Note that, by doing this, you remove the association that the shape had with its previous master. Visio makes a new master from this union of shape and data graphic. Visio also places a copy of the data graphic and any callout masters in the stencil.
Try it!

  1. Open a drawing from the Visio Samples, File > New. Choose Samples Diagrams and then open Process Improvement.

  2. Create a new stencil.

  3. Drag one of the process shapes that has a data graphic applied to it into the blank stencil

  4. Create a new drawing that has no data graphics in the template. File > New > General > Basic Diagram.

  5. Tile the windows so that both windows can be seen.

  6. Drag the master from the new stencil into the new basic diagram drawing.

  7. Check the masters collection and the Data Graphic task pane. The data graphic is there!

  8. Use the Drawing Explorer to review the shape. Note that it is a group shape and that each of the data graphic items are also members of the group.

Hidden masters and removing hidden information


Normally, unused masters can be removed using the Remove Hidden Information tool of Visio. However, some custom solutions include data graphic masters in the document and the solution depends on these graphics being present.

To protect a hidden data graphic (or any master) from removal by the RHI tool, create a user-defined cell User.msvRHIPreventRemoval to the master’s PageSheet and set its value to 1. The Remove Hidden Information tool will then ignore this master and NOT remove it.





Download 0.78 Mb.

Share with your friends:
1   ...   18   19   20   21   22   23   24   25   ...   36




The database is protected by copyright ©ininet.org 2024
send message

    Main page