visio conference 2008

52

Upload: david-parker

Post on 26-May-2015

2.152 views

Category:

Technology


2 download

DESCRIPTION

Presentation given by David Parker (MVP) at the Visio Conference 2008 introducing Link Data to Shapes and Data Graphics ... still relevant for Visio 2010

TRANSCRIPT

Page 1: Visio Conference 2008
Page 2: Visio Conference 2008

Visualizing Information the Smart (Diagram) WayDavid J ParkerMVP (Visio)bVisual ltd

Page 3: Visio Conference 2008

Who am I?Microsoft MVP (Visio)Microsoft MCP (Visio, SQL)

Pre-Microsoft acquisitionVisio Business Partner, 1996-8Speaker at Visio Conferences 1997 &1998Started bVisual in 1998

Post-Microsoft acquisitionMicrosoft Visio Solution Provider since 1999Speaker at Microsoft Office Visio Conferences 2006Visio Solution Provider Training for Microsoft EMEA

Visualizing Information with Microsoft Office Visio 2007 McGraw-Hill, 2007

• http://www.visualizinginformation.com

DataLegends – Visio add-in to add Data Graphic legends• http://www.visiotoolbox.com/productdetail.aspx?productid=9

WBS Modeler for Visio and Projectwww.wbsmodeler.com

Visio Examples• http://www.bvisual.net/examples.htm

Page 4: Visio Conference 2008

Business Data Visualized

Page 5: Visio Conference 2008

Data Features in Visio

Visio Drawing

Shape

Data Source

On-line

Prints

Reports

odc

Import Link Display> > > Communicate

Data

Graphics

Page 6: Visio Conference 2008

Microsoft Office Visio 2007 StandardDatabase Wizard

Microsoft Office Visio 2007 Professional

Database WizardDatabase reverse engineeringUML modelsLink Data To Shapes *PivotDiagrams *Data Graphics *

Visio 2007 EditionsVisual data

Page 7: Visio Conference 2008

Visible DataVisio Professional 2007

Shape DataRenamed from Custom Properties

Link Data to ShapesMultiple data sources per shapeRead onlyUses Office Data Connections (*.odc files)

PivotDiagramsDiagrammatic version of PivotTablesUses Office Data Connections (*.odc files)

Data GraphicsData sensitive text and graphics on shapes

Page 8: Visio Conference 2008

Visio Development Platform

Vis

io V

iew

er

Vis

ioD

raw

ings

Data

Dia

gra

mm

ing

ML

SaveAs

Web

Visio Engine

Vis

io S

DK

Sh

ap

eS

tud

ioTo

ols

& W

izard

sS

am

ple

cod

e

ShapeSheet, Smart Shapes

.NET Primary Interoperability Assemblies (PIAs)

Visio Object Model (COM)

Visio DrawingControl (ActiveX)

Full VisioClient App

Extensibility Support

VSTO Add-in

COM Add-in

Add-ons

VBA

Page 9: Visio Conference 2008

Importing Linked Data

DataConnection and DataRecordsetsVisio 12.0 Type LibAdd, AddFromConnectionFile, AddFromXML

UI and code links to:Microsoft Office Excel & AccessSharePoint Services ListsSQL Server Tables and ViewsOLEDB & ODBC

Can also create link in code to :SQL Server stored proceduresXML files

Page 10: Visio Conference 2008

Link to SQL Server Stored ProcDeclarations & Connection String

Dim dds As Visio.DataRecordset 'The data recordsetDim ary() As String ‘Array to hold the p key columnsDim SQLConnStr As String 'The connection stringDim SQLCommStr As String 'The Command stringDim datasetName As String 'The dataset name

SQLConnStr = "Provider=SQLOLEDB.1;" & _ "Integrated Security=SSPI;" & _ "Persist Security Info=True;" & _ "Data Source=.;" & _ "Initial Catalog=AdventureWorks;" & _ "Use Procedure for Prepare=1“

Page 11: Visio Conference 2008

Link to SQL Server Stored ProcCommand String & Adding DataRecordset SQLCommStr = "EXEC uspGetEmployees 1" ary() = Split("EmployeeID", ";") datasetName = "Employees“

Set dds = Visio.ActiveDocument.DataRecordsets.Add( _ SQLConnStr, SQLCommStr, _ VisDataRecordsetAddOptions.visDataRecordsetDelayQuery, _ datasetName)

dds.SetPrimaryKey VisPrimaryKeySettings.visKeySingle, ary() dds.Refresh

Visio.ActiveWindow.Windows.ItemFromID( _visWinIDExternalData).Visible = True

Page 12: Visio Conference 2008

Link to XML fileConnection String

Dim doc As Visio.DocumentDim dst As Visio.DataRecordsetDim xmlFile As StringDim dom As New MSXML2.DOMDocumentDim OK As Boolean

Set doc = Visio.ActiveDocument xmlFile = “MyXMLFile.xml" OK = dom.Load(xmlFile)

Set dst = doc.DataRecordsets.AddFromXML( _ dom.XML, 0, “Any Name")

Page 13: Visio Conference 2008

Refreshing Linked Data

UI and code refreshing of DataRecordset

.Refresh

.GetAllRefreshConflicts

.GetMatchingRowsForRefreshConflict

.RemoveRefreshConflictXML files can only be refreshed in code

.RefreshUsingXMLAutomation requires assigned name and file

Page 14: Visio Conference 2008

Refreshing from XML file

Dim doc As Visio.DocumentDim dst As Visio.DataRecordsetDim xmlFile As StringDim dom As New MSXML2.DOMDocumentDim OK As Boolean

Set doc = Visio.ActiveDocument xmlFile = “MyXMLFile.xml" OK = dom.Load(xmlFile)

For Each dst In Visio.ActiveDocument.DataRecordsets If dst.Name = “Any Name" Then dst.RefreshUsingXML dom.XML Exit For End If Next

Page 15: Visio Conference 2008

Linking Shapes in the UIExternal Data Window

Select a Master – Drag data row(s)Drag a data row onto any shapeShape Data key field(s) contain values - AutoLink

Page 16: Visio Conference 2008

External Data on ShapesWhat the user sees

Shape Data automatically added to shapesBasic Data Graphics usually added by default

Page 17: Visio Conference 2008

External Data on ShapesBehind the scenes

User-defined CellsShape Data

_VisDM_ prefixes column namesUnless already exist!

Page 18: Visio Conference 2008

Importing Data

demo

Page 19: Visio Conference 2008

Create Linked Shapes in CodeDefinitionDropManyLinkedU

ObjectsToInstance() array of variants

XYs() array of doubles

DataRecordsetID long

DataRowIDs() array of longs

ApplyDataGraphicAfterLink boolean

ShapeIDs() out array of longs

Page 20: Visio Conference 2008

Create Linked Shapes in CodeExample'Retrieve the row ids from the datarecordsetDim aryRowIDs() As Long aryRowIDs = drs.GetDataRowIDs("")

'Drop the master in random co-ords, and linked to the'datarecordset, applying a DataGraphicDim aryShapeIDs() As LongDim applyDataGraphics As Boolean Visio.ActiveDocument.DocumentSheet.Cells( _ "User.msvLastAppliedDataGraphic").FormulaU = _

"=""Data - Employees""" applyDataGraphics = True Visio.ActivePage.DropManyLinkedU _ aryMsts, aryXYs, drs.ID, aryRowIDs, _

applyDataGraphics , aryShapeIDs

Page 21: Visio Conference 2008

Linking Data to ShapesDrop Many...

demo

Page 22: Visio Conference 2008

Connecting Shapes from DataUsing DataRecordsets in codeMany types of diagrams require

shapes to be connectedOrganization Charts, Network diagrams, Process

Connecting shapes example codeConnectSubordinatesConnectDottedLineManagers

Can then use different layouts for display

LayoutPage... example codeLayoutSelection... example code

Page 23: Visio Conference 2008

ConnectSubordinatesCode excerpt

For iEmp = 0 To UBound(aryShapeIDs) 'Get the potential manager row Set shpEmp = Visio.ActivePage.Shapes.ItemFromID(aryShapeIDs(iEmp)) rowID = shpEmp.GetLinkedDataRow(drs.ID) varRowData = drs.GetRowData(rowID) 'Arrays are zero based empID = CLng(varRowData(empColumn - 1)) 'Filter the rows to get sub-ordinates of the current employee aryRowIDs = drs.GetDataRowIDs("ManagerID = " & CStr(empID)) 'Iterate thru the subordinate datarecordset rows For iSub = 0 To UBound(aryRowIDs) v = drs.GetRowData(aryRowIDs(iSub)) 'Get the subordinate shapes Visio.ActivePage.GetShapesLinkedToDataRow drs.ID, aryRowIDs(iSub), arySubShapeIDs 'Check that there is actually something in the array If IsArrayAllocated(arySubShapeIDs) = True Then 'Iterate thru the subordinate shapes For iSubShape = 0 To UBound(arySubShapeIDs) Set shpSub = Visio.ActivePage.Shapes.ItemFromID(arySubShapeIDs(iSubShape)) 'Create a dynamic connection from manager to subordinate shpEmp.AutoConnect shpSub, visAutoConnectDirUp Next iSubShape End If Next iSub Next iEmp

Page 24: Visio Conference 2008

Hierachichal Layouts

Standard Hierachy Org Chart Page LayoutModified with Selection Layout

cf Org Chart Wizard

Page 25: Visio Conference 2008

Alternative Layouts

Other Page Layouts may also be suitable

Compact TreeRadialCircular

Page 26: Visio Conference 2008

Connecting Shapes from DataReading Data and Layouts

demo

Page 27: Visio Conference 2008

Using the Connection to Write

'Get the DataRecordsetDim drs As DataRecordset Set drs = Visio.ActiveWindow.Windows.ItemFromID( _

Visio.visWinIDExternalData).SelectedDataRecordset...‘Get the connection stringDim conStr As String conStr = drs.DataConnection.ConnectionString‘Use the connection string to create a connectionDim dbCnxn As New ADODB.Connection dbCnxn.ConnectionString = conStr dbCnxn.Open dbCnxn.BeginTrans...

Page 28: Visio Conference 2008

Writing Data from Shapes

demo

Page 29: Visio Conference 2008

Data GraphicsOverview

Color By ValueTextData BarIcon Set

Page 30: Visio Conference 2008

DataGraphic MastersWhat the user sees

Document stencil only shows visible mastersDrawing Explorer displays all (but not type)

Page 31: Visio Conference 2008

DataGraphic MastersBehind the scenes

Public Sub EnumMasters()Dim mst As Visio.Master Debug.Print "ID", "Hidden", "Type", "IsDGCallout", "Name" For Each mst In Visio.ActiveDocument.Masters Debug.Print mst.ID, mst.Hidden, mst.Type, _

mst.Shapes(1).IsDataGraphicCallout, mst.name Next mstEnd Sub

Page 32: Visio Conference 2008

Master and Instances

Document Stencil Document Page

Normal Master

GraphicItem Master

DataGraphic Master

Master instance with DataGraphic

Page 33: Visio Conference 2008

Creating DataGraphics in code

Create a new DataGraphic masterDocument.Masters.AddEx(visTypeDataGraphic)

Open the new MasterMaster.Open

Copy an existing GraphicItem to it.GraphicItems.AddCopy(existingGI)

Amend GraphicItems.HorizontalPosition & .VerticalPosition.SetExpression VisGraphicField, string

Close Master

Page 34: Visio Conference 2008

Min & Max Values for Data BarsSetDataBarMinMaxValues codeA Data Bar graphic item can be

Multiple times in same Data GraphicIn multiple Data GraphicsEach instance has different value ranges

Min and max values read from shape instances

Prop. msvCalloutFieldData Bar can have multiple fields

E.g. Multi-bar graphProp. msvCalloutPropFieldn where n=2 to 5

Update master using .Open

Page 35: Visio Conference 2008

Setting Min & Max Values

Document Stencil Document Page

5. Update DataGraphic Master Data Bar GraphicItem Min/Max Values2. Collect Data Bar GraphicItems

1. Get Active DataGraphic Master

4. Read Min/Max of Data Bar Graphic Items

3. Create Selection

Page 36: Visio Conference 2008

SetMinMaxDatabarValuesStart Part

Const UserType As String = "User.msvCalloutType“Const UserDGID As String = "User.visDGItemID "Const PropMax As String = "Prop.msvCalloutPropMax"Const PropMin As String = "Prop.msvCalloutPropMin“

'Get the active Data GraphicDim mstDG As Master Set mstDG = GetActiveDataGraphic

im dicDataBarShapes As New DictionaryDim gi As Visio.GraphicItem 'Create a dictionary of data bars For Each gi In mstDG.GraphicItems If gi.Type = visTypeDataBar Then dicDataBarShapes.Add CStr(gi.ID), 0 End If Next gi

Page 37: Visio Conference 2008

SetMinMaxDatabarValuesMiddle Part

Dim colDataBarShapes As New CollectionDim itmGraphic As Visio.shapeDim gID As String 'Update the data bars dictionary with shape pseudo-index For Each itmGraphic In mstDG.Shapes(1).Shapes If itmGraphic.IsDataGraphicCallout = True Then If itmGraphic.Cells(UserType).ResultStr("") = "Data Bar" Then gID = CStr(itmGraphic.Cells(UserDGID).ResultInt("", 0)) dicDataBarShapes.Item(gID) = itmGraphic.NameU colDataBarShapes.Add gID End If End If Next itmGraphic 'Iterate thru each page to collect min/max values For Each pag In Visio.ActiveDocument.Pages 'Get all shapes that use this data graphic master Set sel = pag.CreateSelection(visSelTypeByDataGraphic, 0, mstDG) ... Next shp Next pag

Page 38: Visio Conference 2008

SetMinMaxDatabarValuesEnd Part

...'Finally - update the ItemGraphic in the DataGraphic MasterDim mstCopy As Visio.Master Set mstCopy = mstDG.Open For Each itmGraphic In mstCopy.Shapes(1).Shapes If itmGraphic.IsDataGraphicCallout = True Then If itmGraphic.Cells(UserType).ResultStr("") = "Data Bar" Then

gID = CStr(itmGraphic.Cells(UserDGID).ResultInt("", 0)) itmGraphic.Cells(PropMax).FormulaU = "=" & dicMaxVal.Item(gID) itmGraphic.Cells(PropMin).FormulaU = "=" & dicMinVal.Item(gID) End If End If Next itmGraphic 'Close the copy to update all instances mstCopy.Close

Page 39: Visio Conference 2008

Data GraphicsUpdating DataBar Minimum and Maximum Values automatically

demo

Page 40: Visio Conference 2008

PivotDiagramBreakdown

Breakdown data into CategoriesSortMergePromoteCollapse

Page 41: Visio Conference 2008

PivotDiagramBreakdown

PivotDiagram is an add-onNot an API extensionOnly launched in code from SharePoint Services List (soon to be published MSDN article)

Use code to select in various waysAids in applying DataGraphics and extra DataRecordsetsE.g. SelectSameBreakdownName sample

Page 42: Visio Conference 2008

SelectSameBreakdownName...Set vsoWindow = Visio.Application.ActiveWindow

If vsoWindow.Selection.Count > 0 Then Set shp = vsoWindow.Selection.PrimaryItem If IsPivotNode(shp) = True Then breakdownName = _

GetGroupNameByID(GetBreakdownID(shp)) SelectByBreakdownName breakdownName End IfEnd If

Page 43: Visio Conference 2008

IsPivotNode & isPivotShapeTypeIsPivotNode = isPivotShapeType(shape, ePivotShapeType.Node)

Private Function isPivotShapeType(ByVal shape As Visio.shape, _ ByVal pivotShapeType As ePivotShapeType) As Boolean

If Not shape.CellExists(UserDDShapeType, _ Visio.VisExistsFlags.visExistsAnywhere) = 0 Then If shape.Cells(UserDDShapeType).ResultIU = pivotShapeType Then isPivotShapeType = True Else isPivotShapeType = False End If Else isPivotShapeType = False End IfEnd Function

Page 44: Visio Conference 2008

PivotDiagramsCustom Selections

demo

Page 45: Visio Conference 2008

CustomisationDataLegends

Legends for Icon Sets & Color By Value

Page 46: Visio Conference 2008

DataLegends

demo

Page 47: Visio Conference 2008

Thankyou!

David J ParkerMicrosoft MVP (Visio)http://www.bVisual.net

Bookhttp://www.visualizinginformation.com

[email protected]

Page 48: Visio Conference 2008

Visio Development Resources

Visio 2007 SDKhttp://msdn2.microsoft.com/en-us/library/ms409183.aspx

Visio 2007 Solution Development Workshop

http://www.microsoft.com/downloads/details.aspx?FamilyID=332c211e-581e-4029-9839-8f45de10b4c2&DisplayLang=en

Visio Developer Portalhttp://msdn2.microsoft.com/en-us/office/aa905478.aspx

Visio Insight bloghttp://blogs.msdn.com/visio/

Visio MVP web sitehttp://visio.mvps.org/

My Visio Bloghttp://bvisual.spaces.live.com/

Page 49: Visio Conference 2008

Book Discount Vouchers(visit my booth)

announcing

Page 50: Visio Conference 2008

Visualizing Information the Smart (Diagram) Way

Q & A

Page 51: Visio Conference 2008

Upcoming PresentationsTime End User Track

(Lassen Room)Solution Developer Track(Kodiak Room)

1:45pm - 2:45pmYesterday

Integrating Visio 2007 with Other Office Applications

Visio 2007 as a Solutions Development Platform

3:00pm - 4:00pmYesterday

Get Creative with Data in Visio 2007

Developing Visio Solutions with Visual Studio Tools for Office

4:30pm - 5:30pmYesterday

Understanding and Demystifying Visio Shapes

Visio Solution Developer Pain Points

10:45am - 11:45amToday

Visio Futures - API Insights

1:15pm - 2:15pmToday

Visualizing Information the Smart (Diagram) Way

2:30pm - 3:30pmToday

Going Further with Data Connectivity

Page 52: Visio Conference 2008

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.

The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after

the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.