Skip to content

Commit 1d6f54d

Browse files
Add changes after review (fresh eye)
1 parent ea83bc2 commit 1d6f54d

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

Readme.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,54 @@
66

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

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.
9+
This example integrates **Microsoft Automatic Graph Layout (MSAGL)** algorithms with the WPF [`DiagramControl`](https://docs.devexpress.com/WPF/DevExpress.Xpf.Diagram.DiagramControl). The workflow extracts a graph from the diagram, processes it with an MSAGL algorithm, and applies calculated node positions to diagram items.
1010

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

1313
## Implementation Details
1414

15-
### Extract Current Graph
15+
### Extract the Graph
1616

1717
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
2020
GraphOperations.GetDiagramGraph(diagramControl);
2121
```
2222

23-
### Create Position Info
23+
### Calculate Position Information
2424

25-
For each shape, create a `PositionInfo` object that contains a reference to the shape and its calculated position:
25+
For each shape, calculate diagram shape coordinates and store them in `PositionInfo` objects:
2626

2727
```csharp
2828
layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl));
29+
30+
public virtual IEnumerable<PositionInfo<IDiagramItem>> RelayoutGraphNodesPosition(Graph<IDiagramItem> graph) {
31+
GeometryGraph = MsaglGeometryGraphHelpers.CreateGeometryGraph(graph);
32+
LayoutCalculator.CalculateLayout(GeometryGraph);
33+
return MsaglGeometryGraphHelpers.GetGetNodesPositionInfo(GeometryGraph);
34+
}
2935
```
3036

3137
### Apply Layout
3238

33-
Call the `DiagramControl.RelayoutDiagramItems` method and pass the collection of PositionInfo objects. This updates all shapes on the canvas:
39+
Update the diagram with calculated node positions:
3440

3541
```csharp
36-
diagramControl.RelayoutDiagramItems(layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl)));
42+
diagramControl.RelayoutDiagramItems(
43+
layout.RelayoutGraphNodesPosition(GraphOperations.GetDiagramGraph(diagramControl))
44+
);
3745
```
3846

39-
### Update Connectors
47+
### Update Shape Connectors
4048

41-
After shapes are repositioned, reroute connectors to reflect the new layout:
49+
After shapes are repositioned, reroute shape connectors and register a routing strategy:
4250

4351
```csharp
4452
diagramControl.Items.OfType<IDiagramConnector>().ForEach(connector => {
4553
connector.Type = layout.GetDiagramConnectorType();
4654
connector.UpdateRoute();
4755
});
48-
```
49-
50-
The controller also registers a routing strategy:
5156

52-
```csharp
5357
diagramControl.Controller.RegisterRoutingStrategy(
5458
layout.GetDiagramConnectorType(),
5559
layout.GetDiagramRoutingStrategy()
@@ -58,15 +62,15 @@ diagramControl.Controller.RegisterRoutingStrategy(
5862

5963
### Display Entire Diagram
6064

61-
Fit the view to the drawing to ensure that all elements are visible:
65+
Fit the view so that all items are visible in the viewport:
6266

6367
```csharp
6468
diagramControl.FitToDrawing();
6569
```
6670

6771
### Ribbon commands
6872

69-
Ribbon buttons load documents and apply the corresponding algorithm:
73+
Create ribbon items and handle their `ItemClick` events to apply different MSAGL algorithms:
7074

7175
```csharp
7276
void ApplySugiyama(object s, ItemClickEventArgs e) {

0 commit comments

Comments
 (0)