Skip to content

Commit 2ae2c7f

Browse files
Update implementation details
1 parent ed3e71d commit 2ae2c7f

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

Readme.md

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,90 @@ This example connects the [Microsoft Automatic Graph Layout (MSAGL)](https://git
1212

1313
## Implementation Details
1414

15-
...
15+
### Load Sample Graph
16+
17+
The application loads a diagram from an XML file before applying a layout. This example includes five datasets: **Sugiyama**, **Ranking**, **PhyloTree**, **MDS**, and **Disconnected Graphs**.
18+
19+
```csharp
20+
void LoadSugiyama(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
21+
diagramControl.LoadDocument("Data/SugiyamaLayout.xml");
22+
}
23+
void LoadMDS(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) {
24+
diagramControl.LoadDocument("Data/MDSLayout.xml");
25+
}
26+
// … similar for Ranking, PhyloTree, DisconnectedGraphs
27+
```
28+
29+
### Extract and Arrange Nodes
30+
31+
The `GraphOperations.GetDiagramGraph` extracts nodes and edges from the diagram. The selected MSAGL calculator computes positions, which are then applied to the diagram:
32+
33+
```csharp
34+
void ApplyLayout(GraphLayout layout) {
35+
try {
36+
diagramControl.RelayoutDiagramItems(
37+
layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl))
38+
);
39+
diagramControl.Items.OfType<IDiagramConnector>().ForEach(connector => {
40+
connector.Type = layout.GetDiagramConnectorType();
41+
connector.UpdateRoute();
42+
});
43+
diagramControl.FitToDrawing();
44+
} catch(Exception e) {
45+
DXMessageBox.Show(string.Format("Error message: '{0}'", e.Message), "Error has been occurred");
46+
}
47+
}
48+
```
49+
50+
### Update Connectors
51+
52+
After shapes are repositioned, connectors update routs. The code example sets connector types and updates their routes:
53+
54+
```csharp
55+
diagramControl.Items.OfType<IDiagramConnector>().ForEach(connector => {
56+
connector.Type = layout.GetDiagramConnectorType();
57+
connector.UpdateRoute();
58+
});
59+
```
60+
61+
The controller also registers a routing strategy:
62+
63+
```csharp
64+
diagramControl.Controller.RegisterRoutingStrategy(
65+
layout.GetDiagramConnectorType(),
66+
layout.GetDiagramRoutingStrategy()
67+
);
68+
```
69+
70+
### Display Entire Diagram
71+
72+
The `DiagramControl` adjusts its viewport to display the entire diagram:
73+
74+
```csharp
75+
diagramControl.FitToDrawing();
76+
```
77+
78+
### Ribbon commands
79+
80+
Ribbon buttons load documents and apply the corresponding algorithm:
81+
82+
```csharp
83+
void ApplySugiyama(object s, ItemClickEventArgs e) {
84+
ApplyLayout(new GraphLayout(new SugiyamaLayoutCalculator()));
85+
}
86+
void ApplyRanking(object s, ItemClickEventArgs e) {
87+
ApplyLayout(new GraphLayout(new RankingLayoutCalculator()));
88+
}
89+
void ApplyPhyloTree(object s, ItemClickEventArgs e) {
90+
ApplyLayout(new PhyloTreeLayout(new PhyloTreeLayoutCalculator()));
91+
}
92+
void ApplyMDS(object s, ItemClickEventArgs e) {
93+
ApplyLayout(new GraphLayout(new MDSLayoutCalculator()));
94+
}
95+
void ApplyDisconnectedGraphs(object s, ItemClickEventArgs e) {
96+
ApplyLayout(new GraphLayout(new DisconnectedGraphsLayoutCalculator()));
97+
}
98+
```
1699

17100
## Files to Review
18101

@@ -47,7 +130,6 @@ This example connects the [Microsoft Automatic Graph Layout (MSAGL)](https://git
47130
* [WPF DiagramControl - Create Custom Context Menus](https://github.com/DevExpress-Examples/wpf-diagram-custom-context-menu)
48131
* [WPF Diagram Control - Track and Restrict Drag Actions](https://github.com/DevExpress-Examples/wpf-diagram-track-and-restrict-drag-actions)
49132

50-
51133
<!-- feedback -->
52134
## Does this example address your development requirements/objectives?
53135

0 commit comments

Comments
 (0)