Skip to content

Commit

Permalink
Merge branch 'Brains-per_cluster_settings_for_sugiyama'
Browse files Browse the repository at this point in the history
  • Loading branch information
levnach committed May 27, 2022
2 parents e95bca6 + 5e7b59a commit 47d30d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions GraphLayout/MSAGL/Layout/Layered/SugiyamaLayoutSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,5 +437,9 @@ public double GridSizeByX
set { gridSizeByX = value; }
}

/// <summary>
/// Settings per Cluster for InitialLayoutByCluster used by LayoutHelpers.ProcessSugiamaLayout
/// </summary>
public Dictionary<object, LayoutAlgorithmSettings> ClusterSettings { get; set; } = new Dictionary<object, LayoutAlgorithmSettings>();
}
}
8 changes: 7 additions & 1 deletion GraphLayout/MSAGL/Miscellaneous/LayoutHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ public static class LayoutHelpers {

if (geometryGraph.RootCluster.Clusters.Any()) {
PrepareGraphForInitialLayoutByCluster(geometryGraph, sugiyamaLayoutSettings);
var initialBc = new InitialLayoutByCluster(geometryGraph, a => sugiyamaLayoutSettings);
var initialBc =
new InitialLayoutByCluster(
geometryGraph,
//use different settings per each Cluster if available
c => sugiyamaLayoutSettings.ClusterSettings.ContainsKey(c.UserData)
? sugiyamaLayoutSettings.ClusterSettings[c.UserData]
: sugiyamaLayoutSettings);
initialBc.Run(cancelToken);
//route the rest of the edges, those between the clusters
var edgesToRoute = sugiyamaLayoutSettings.EdgeRoutingSettings.EdgeRoutingMode == EdgeRoutingMode.SplineBundling ? geometryGraph.Edges.ToArray() : geometryGraph.Edges.Where(e => e.Curve == null).ToArray();
Expand Down
16 changes: 12 additions & 4 deletions GraphLayout/Samples/WpfApplicationSample/WpfApplicationSample.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -8,8 +8,10 @@
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using Microsoft.Msagl.Core.Geometry.Curves;
using Microsoft.Msagl.Core.Routing;
using Microsoft.Msagl.Drawing;
using Microsoft.Msagl.Layout.Layered;
using Microsoft.Msagl.WpfGraphControl;
using Microsoft.Win32;
using Color = Microsoft.Msagl.Drawing.Color;
Expand Down Expand Up @@ -295,8 +297,7 @@ void SetFileMenu(Menu mainMenu)


var subgraph = new Subgraph("subgraph1");
subgraph.Label.Text = "Outer Subgraph";
subgraph.Attr.ClusterLabelMargin = LabelPlacement.Bottom;
subgraph.Label.Text = "Outer";
graph.RootSubgraph.AddSubgraph(subgraph);
subgraph.AddNode(graph.FindNode("47"));
subgraph.AddNode(graph.FindNode("58"));
Expand All @@ -305,14 +306,21 @@ void SetFileMenu(Menu mainMenu)
subgraph2.Label.Text = "Inner";
subgraph2.Attr.Color = Color.Black;
subgraph2.Attr.FillColor = Color.Yellow;
subgraph2.Attr.ClusterLabelMargin = LabelPlacement.Left;
subgraph2.Attr.ClusterLabelMargin = LabelPlacement.Bottom;
subgraph2.AddNode(graph.FindNode("70"));
subgraph2.AddNode(graph.FindNode("71"));
subgraph.AddSubgraph(subgraph2);
graph.AddEdge("58", subgraph2.Id);

graph.Attr.LayerDirection = LayerDirection.LR;
//graph.LayoutAlgorithmSettings.EdgeRoutingSettings.EdgeRoutingMode = EdgeRoutingMode.Rectilinear;

var global = (SugiyamaLayoutSettings) graph.LayoutAlgorithmSettings;
var local = (SugiyamaLayoutSettings) global.Clone();
local.Transformation = PlaneTransformation.Rotation(-Math.PI / 2);
subgraph2.LayoutSettings = local; // for Collapsing\Expanding
global.ClusterSettings.Add(subgraph2, local);

graphViewer.Graph = graph;
}
catch (Exception e)
Expand Down

0 comments on commit 47d30d6

Please sign in to comment.