Partager via


Browse and rearrange dependency graphs

You can rearrange items on dependency graphs to make them easier to read and improve rendering performance.

Requirements

In this topic

  • Managing large graphs

  • Changing the graph layout

  • Browsing the graph

  • Examining nodes and links

  • Hiding or showing nodes and links

  • Grouping nodes

For more ways to browse the graph by using the mouse or keyboard, choose the help link on a blank graph.

Managing Large Graphs

When you generate a dependency graph the first time, Visual Studio creates a code index for all the dependencies it finds. Though this process might take some time, especially for large solutions or graphs with many links, this index improves performance of later operations. If the code changes later, then Visual Studio reindexes the updated code only.

If you don't want to wait for the graph to finish generating, you can cancel the generation process at any time and try the following suggestions:

After you generate the graph, try the following suggestions:

  • On the graph toolbar, choose Quick ClustersQuick Clusters button on graph toolbar so that you can see natural dependency clusters in the code. See Changing the graph layout.

    Dependency graph - Quick Clusters layout

  • Organize the graph into smaller areas by grouping related nodes. Collapse those groups to see only the intergroup dependencies, which appear automatically. See Grouping nodes.

  • Edit the graph manually to remove nodes and links you don't need. Changing the graph doesn't affect the underlying code. See Edit and customize dependency graphs.

Changing the Graph Layout

To

On the graph toolbar or the graph shortcut menu

Arrange the dependency flow for the entire graph in a specific direction. This can help you see architectural layers in the code.

Choose one of the following to show the graph as a tree:

  • Left to rightLeft to Right layout button

  • Right to leftRight to Left graph button

  • Top to bottomTop to Bottom graph button

  • Bottom to topBottom to Top graph button

See natural dependency clusters in the code.

Choose Quick ClustersQuick Clusters button on graph toolbar to see the most dependent nodes at the center of the clusters and the least dependent nodes at the outside of those clusters.

Dependency graph - Quick Clusters layout

To move specific nodes on the graph, drag them. To move other nodes and links out of the way as you drag nodes, press and hold the SHIFT key as you drag nodes. To change the layout inside a group independently of the graph by selecting one of the tree layouts, Quick Clusters, or List View, which arranges the group's contents into a list. See Grouping nodes.

Note

The following functionality is not available in this release: Neighborhood Browse Mode, Butterfly Mode, Advanced Selection, and Dependency Matrix View.

Browsing the Graph

To

Perform these steps

Scan the graph

Drag the graph in any direction.

Zoom in or out of the graph

Rotate the mouse wheel.

- or -

Choose the plus sign (+) or the minus sign (-) on the graph toolbar.

- or -

To zoom in on a specific area, use the right mouse button to draw a rectangle around the area.

Resize and fit the graph in its window

On the graph toolbar, choose Zoom to Fit.

- or -

Double-click an empty area of the graph.

Resize and center the graph on a specific node

Expand the node. Double-click inside an empty area of the node.

Visual Studio resizes the graph so the entire group fits inside the graph window.

If you double-click a collapsed namespace, class, or its members, Visual Studio shows you the code definition.

Change focus independently of the currently selected node

Press TAB.

A dotted line appears around the node that is currently in focus.

Find a node on the graph by its name.

Tip

To find items in the solution but not on the graph, find them in Solution Explorer, and then drag them to the graph.

Dependency graph search box
  1. Press CTRL+F.

    A search box appears in the upper right corner of the graph.

  2. Type the item name. To customize your search, choose a search option.

    The first item that matches your search appears selected on the graph.

  3. To see another match, choose Find Next (press F3).

    - or -

    To select all matches, open the drop-down list. Choose Select All.

Important

You can use the search box to find matches in collapsed groups only if those groups were expanded previously. To find these matches and expand their parent groups automatically, choose this option under the search box.

Find the source or target of a link

Use this method when there are too many links to easily see the source or target of a specific link.

  1. Change the graph layout to tree layout or Quick ClustersQuick Clusters button on graph toolbar layout.

    See Changing the Graph Layout.

  2. Move the mouse pointer on top of the link, or select the link.

    Visual Studio shows two arrows and a tooltip that lists the source and target of the link and other link details.

  3. Choose the arrow that points in the direction that you want to follow.

    The source or target appears selected, depending on the direction you selected.

Select all unselected nodes

Open the shortcut menu for the selected nodes. Choose Select, Invert Selection.

Select additional nodes that link to the selected ones

Open the shortcut menu for the selected nodes. Choose Select and one of the following:

  • To select additional nodes that link directly to the selected node, choose Incoming Dependencies.

  • To select additional nodes that link directly from the selected node, choose Outgoing Dependencies.

  • To select additional nodes that link directly to and from the selected node, choose Both.

  • To select all nodes that link to and from the selected node, choose Connected Subgraph.

  • To select all children of the selected node, choose Children.

Dependency graphs show the following kinds of links:

  • An individual link represents a single relationship between two nodes.

  • A cross-group link represents a relationship between two nodes in different groups.

  • An aggregate link represents all the relationships that point in the same direction between two groups.

Tip

By default, the graph shows cross-group links only for selected nodes. To show these links at all times, on the graph toolbar, open the Change how links are rendered on the graph list Change how links are rendered on the graph button. Choose Show All Cross-Group Links.

This hides aggregated links between groups.

To

Perform these steps

See more information about a node or a link

Move the mouse pointer on top of the node or link until a tooltip appears.

The tooltip for an aggregated link lists the individual dependencies that it represents.

- or -

Open the shortcut menu for the node or the link. Choose Properties.

Show or hide the contents of a group

  • To expand a group, open the shortcut menu for the node. Choose Group, Expand.

    - or -

    Move the mouse pointer on top of the node until the chevron (^) button appears. Choose the chevron (^) button to expand the group.

    (Keyboard: To expand or collapse a selected group, choose the PLUS key (+) or the MINUS key (-).

    To expand or collapse everything in a selected group, press and hold the SHIFT key while you choose the PLUS key (+) or the MINUS key (-).)

  • To expand all groups, open the shortcut menu for the graph. Choose Group, Expand All.

    Note

    This command is not available if expanding all groups generates an unusable graph or memory issues. It is recommended that you expand the graph only to the level of detail that you care about.

  • To collapse a single group, open the shortcut menu for the node. Choose Group, Collapse.

    - or -

    Move the mouse pointer on top of a group until the chevron (^) button appears. Choose the chevron (^) button to collapse the group.

  • To collapse all groups, open the shortcut menu for the graph. Choose Group, Collapse All.

See the code definition for a namespace, type, or member

Open the shortcut menu for the node. Choose Goto, Go To Definition.

-or-

Double-click the node. For expanded groups, double-click the header on the group.

-or-

Select the node. Press F12.

For example:

  • For a namespace, the code file for the first alphabetical class in that namespace opens to show the definition of that class.

    Note

    When you perform this task on a Visual Basic .NET namespace, the code file behind the namespace does not open. This issue also occurs when you perform this task on a group of selected nodes that include a Visual Basic .NET namespace. To work around this issue, browse manually to the code file behind the namespace, or omit the node for the namespace from your selection.

  • For a class or a partial class, the code file for that class opens to show the class definition.

  • For a method, the code file for the parent class opens to show the method definition.

Find the source or target of a link

Use this method when there are too many links to easily see the source or target of a specific link.

  1. On the graph toolbar, change the graph layout to tree layout or Quick ClustersQuick Clusters button on graph toolbar layout.

  2. Move the mouse pointer on top of the link, or select the link.

    Visual Studio shows two arrows and a tooltip that lists the source and target of the link and other link details.

  3. Choose the arrow that points in the direction that you want to follow.

    The source or target appears selected, depending on the direction that you selected.

Examine dependencies and items that participate in an aggregate link

For a single link:

  1. Select the link.

  2. Move the mouse pointer on top of the link. When Visual Studio shows two arrows with a plus sign (+) between them, choose the plus sign (+).

    To create a new graph, press and hold the SHIFT key while you choose the plus sign (+).

    - or -

    Open the shortcut menu for your selection. Choose Show, Contributing links in current diagram or Contributing links in a new diagram.

For multiple links:

  1. Select the links.

  2. Open the shortcut menu for your selection. Choose Show, Contributing links in current diagram or Contributing links in a new diagram.

Visual Studio expands the groups at both ends of the link and shows only those items and dependencies that participate in the link.

Note

When you examine dependencies between items in partial groups, you might see the following behavior:

  • Links to items that don’t participate in your examination disappear from the graph, even though those links still exist.

  • Suppose you examine a link to an item in a partial group, and then later examine a different link to the same item. During your second examination, the target partial group shows only items from your first examination. Links and target items that didn’t participate in your first examination but participate in your second examination don’t appear.

To see missing items from a group, choose Refetch ChildrenRefetch Children Icon, which indicates that not all members of a group appear on the graph. You can also try undoing your actions (Keyboard: choose CTRL+Z) and examine the dependencies on a new graph.

Examine dependencies across multiple nodes in different groups

  1. Expand the groups so you can see all their children.

  2. Select all the nodes that interest you, including their children.

    To select all nodes in a group, press and hold the left mouse button while you draw a rectangle around that group. To select all nodes on a graph, press CTRL+A.

    The graph shows the cross-group links between the selected nodes.

    Tip

    To show cross-group links at all times, on the graph toolbar, open the Change how links are rendered on the graph list Change how links are rendered on the graph button. Choose Show All Cross-Group Links.

See the items that a node or link references

Note

This applies only when the Reference attribute is set for the node or link in the graph's .dgml file.

To add references to items from nodes or links, see Edit and customize dependency graphs.

Open the shortcut menu for the node. Choose Goto and the item.

Hiding nodes keeps them from participating in layout algorithms. By default, cross-group links are hidden. Cross-group links are individual links that connect nodes across groups. When groups are collapsed, the graph aggregates all cross-group links into single links between groups. When you expand a group and select nodes inside the group, cross-group links appear and show the dependencies in that group.

Warning

Before you share a graph that was created in Visual Studio Ultimate with those who use Visual Studio Premium or Visual Studio Professional, make sure to unhide any nodes or cross-group links that you want others to see. Otherwise, those users won't be able to unhide those items.

To hide or show nodes

To

Perform these steps

Hide selected nodes

  1. Select nodes you want to hide.

  2. Open the shortcut menu for the selected nodes or for the graph. Choose Select, Hide Selected.

Hide unselected nodes

  1. Select nodes you want to stay visible.

  2. Open the shortcut menu for the selected nodes or for the graph. Choose Select, Hide Unselected.

Show hidden nodes

  • To show all hidden nodes inside a group, make sure the group is expanded first. Choose Unhide ChildrenUnhide Children Icon in the upper left corner of the group.

  • To show all hidden nodes, open the shortcut menu for the graph. Choose Select, Unhide All.

Hide nodes by editing the .dgml file

  1. Open the shortcut menu for the graph surface. Choose Goto, DGML.

    Visual Studio opens the graph's .dgml file.

  2. In the <Node/> element, add the following attribute to hide the node:

    Visibility="Hidden"

    For example:

    <Nodes>
       <Node Id="MyNode" Visibility="Hidden"/>
    </Nodes>

To show or hide links

To

On the graph toolbar, open the Change how links are rendered on the graph list or open the graph shortcut menu. Choose:

Show cross-group links at all times

Show All Cross-Group Links

This hides aggregated links between groups.

Show only cross-group links for selected nodes

Show Cross-Group Links On Selected Nodes

Hide cross-group links at all times

Hide All Cross-Group Links

Hide all links (or show all links)

Hide All Links

To show all links, choose Hide All Links again to turn off this mode.

Grouping Nodes

To

Perform these steps

Show container nodes as group nodes or leaf nodes

To show container nodes as leaf nodes, select the nodes. Open the shortcut menu for your selection. Choose Group, Convert To Leaf.

To show container nodes as group nodes, select the nodes. Open the shortcut menu for your selection. Choose Group, Convert To Group.

To show all leaf nodes as group nodes, open the shortcut menu for the graph. Choose Group, Turn On Grouping.

To show all group nodes as leaf nodes, open the shortcut menu for the graph. Choose Group, Turn Off Grouping.

Change the layout inside a group

  1. Select the group.

    The group toolbar starts to appear.

    Dependency graph - group toolbar

  2. Open the Change the layout style of the group list Dependency graph - group toolbar - layout. Choose the layout you want.

    List View rearranges the group's members into list. Graph Default resets the group layout to the graph default layout. For other options, see Changing the graph layout.

Add a node to a group

Drag the node onto the group.

While you drag the node, Visual Studio displays an indicator to show that you are moving the node.

You can also drag nodes out of a group.

Add a node to a non-group node

You can convert any node into a group. Drag the node onto the target node.

Group selected nodes

  1. Select the nodes that you want to group.

    A toolbar starts to appear above the last selected node.

    Dependency graph toolbar

  2. On the toolbar, choose Group the selected nodesGraph toolbar - Group selected.

    - or -

    Open the shortcut menu for your selection. Choose Group, Add Parent Group.

  3. Open the shortcut menu for the new group. Choose Properties. In the Label property, rename the group.

Group nodes that have specific categories or properties

  1. Select the nodes that have the specific category or property.

  2. Open the shortcut menu for your selection. Choose Group, Add Parent Group.

  3. Open the shortcut menu for the new group. Choose Properties. In the Label property, rename the group.

Group nodes according to their containers

  1. On the Architecture menu, choose Windows, Architecture Explorer.

  2. Use Architecture Explorer to find and select all the nodes that you want to group.

    See Find code with Architecture Explorer.

  3. On the right side of the current column, choose the collapsed action column to expand it. (Keyboard: Press Tab to move focus until the collapsed action column expands.)

    Note

    The action column appears highlighted when you move the pointer, or focus, on top of it.

  4. In the action column, choose Contained By. (Keyboard: Press Tab to move focus and then use the arrow keys until the Contained By relationship is selected.)

  5. From next column, drag the container groups to the graph.

  6. Open the shortcut menu for the graph surface, choose Group, Turn On Grouping.

Group nodes according to their property values

  1. Save the graph as a .dgml file on disk.

  2. On the Architecture menu, choose Windows, Architecture Explorer.

  3. In Architecture Explorer, under File System, choose Select Files.

  4. In the next column, select your saved .dgml file.

  5. Use Architecture Explorer to find and select all the nodes that you want to group.

    See Find code with Architecture Explorer.

  6. On the right side of the current column, choose the collapsed action column to expand it. (Keyboard: Press Tab to move focus until the collapsed action column expands.)

    Note

    The action column appears highlighted when you move the pointer over it.

  7. In the action column, under Grouping, choose Group by Properties. (Keyboard: Press Tab to move focus and then use the arrow keys until the Group by Properties command is selected.)

  8. In the next column, select the properties that you want to use as groups.

    The next column appears and shows the available property values.

  9. From the next column, drag the property value groups to the graph.

  10. Open the shortcut menu for the graph surface. Choose Group, Turn On Grouping.

Remove groups

Select the group or groups that you want to remove. Open the shortcut menu for your selection. Choose Group, Remove Group.

Remove nodes from their parent group up to their grandparent, or outside a group, if they have no grandparent group

Select the nodes that you want to move. Open the shortcut menu for your selection. Choose Group, Remove From Parent.

You can also organize nodes into groups by editing the graph's .dgml file.

To convert a node to a group or add a new group

  1. To convert a node to a group, open the shortcut menu for the node. Choose Goto, DGML.

    Visual Studio opens the graph's .dgml file and highlights the <Node/> element for that node.

    - or -

    To add a new group:

    1. Open the shortcut menu for a blank area of the graph. Choose Goto, DGML.

    2. In the <Nodes> section, add a new <Node/> element.

  2. In the <Node/> element, add a Group attribute to specify whether the group appears expanded or collapsed. For example:

    <Nodes>
       <Node Id="MyFirstGroup" Group="Expanded" />
       <Node Id="MySecondGroup" Group="Collapsed" />
    </Nodes>
    
  3. In the <Links> section, make sure that a <Link/> element that has the following attributes exist for each relationship between a group node and its child nodes:

    • A Source attribute that specifies the group node

    • A Target attribute that specifies the child node

    • A Category attribute that specifies a Contains relationship between the group node and its child node

    For example:

    <Links>
       <Link Category="Contains" Source="MyFirstNewGroup" Target="FirstGroupChildOne" />
       <Link Category ="Contains" Source="MyFirstNewGroup" Target="FirstGroupChildTwo" />
       <Link Category ="Contains" Source="MySecondNewGroup" Target="SecondGroupChildOne" />
       <Link Category="Contains" Source="MySecondNewGroup" Target="SecondGroupChildTwo" />
    </Links>
    

    For more information about the Category attribute, see Assign Categories to Nodes and Links in Edit and customize dependency graphs.

See Also

Concepts

Edit and customize dependency graphs

Map dependencies across your code on dependency graphs