Skip to content

Commit ea83bc2

Browse files
Update after review (support)
1 parent 2ae2c7f commit ea83bc2

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

Readme.md

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,39 @@
66

77
# WPF Diagram Control - Microsoft Automatic Graph Layout (MSAGL) Algorithms
88

9-
This example connects the [Microsoft Automatic Graph Layout (MSAGL)](https://github.com/Microsoft/automatic-graph-layout) library to [`DiagramControl`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Diagram.DiagramControl). This technic allows you apply advanced algorithms such as **Sugiyama**, **Ranking**, **PhyloTree**, **MDS**, or **Disconnected Graphs** with one click.
9+
This example integrates custom layout algorithms with [`DiagramControl`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Diagram.DiagramControl). You can extract a graph from the diagram, process the graph with an external algorithm, and apply calculated positions back to diagram items. This technic allows you apply advanced or custom algorithms with one click.
1010

1111
![Diagram Control - Microsoft Automatic Graph Layout (MSAGL) Algorithms](./Images/diagram-layouts.jpg)
1212

1313
## Implementation Details
1414

15-
### Load Sample Graph
15+
### Extract Current Graph
1616

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**.
17+
Use the `GraphOperations.GetDiagramGraph` method to extract the current diagram. The method returns a `Graph` object that contains the collections of nodes and edges represented by diagram items:
1818

1919
```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
20+
GraphOperations.GetDiagramGraph(diagramControl);
2721
```
2822

29-
### Extract and Arrange Nodes
23+
### Create Position Info
3024

31-
The `GraphOperations.GetDiagramGraph` extracts nodes and edges from the diagram. The selected MSAGL calculator computes positions, which are then applied to the diagram:
25+
For each shape, create a `PositionInfo` object that contains a reference to the shape and its calculated position:
3226

3327
```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-
}
28+
layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl));
29+
```
30+
31+
### Apply Layout
32+
33+
Call the `DiagramControl.RelayoutDiagramItems` method and pass the collection of PositionInfo objects. This updates all shapes on the canvas:
34+
35+
```csharp
36+
diagramControl.RelayoutDiagramItems(layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl)));
4837
```
4938

5039
### Update Connectors
5140

52-
After shapes are repositioned, connectors update routs. The code example sets connector types and updates their routes:
41+
After shapes are repositioned, reroute connectors to reflect the new layout:
5342

5443
```csharp
5544
diagramControl.Items.OfType<IDiagramConnector>().ForEach(connector => {
@@ -69,7 +58,7 @@ diagramControl.Controller.RegisterRoutingStrategy(
6958

7059
### Display Entire Diagram
7160

72-
The `DiagramControl` adjusts its viewport to display the entire diagram:
61+
Fit the view to the drawing to ensure that all elements are visible:
7362

7463
```csharp
7564
diagramControl.FitToDrawing();

0 commit comments

Comments
 (0)