Skip to content

Commit

Permalink
enable node separation in MDS packing
Browse files Browse the repository at this point in the history
Signed-off-by: Lev Nachmanson <levnach@hotmail.com>
  • Loading branch information
levnach committed Jul 28, 2021
1 parent c8f65b9 commit 62ce41e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
5 changes: 3 additions & 2 deletions GraphLayout/MSAGL/Core/Layout/GraphConnectedComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void CreateComponent(Edge e)
/// result in the Node InEdges and OutEdges lists containing duplicates.
/// </remarks>
/// <returns></returns>
public static IEnumerable<GeometryGraph> CreateComponents(IList<Node> nodes, IEnumerable<Edge> edges) {
public static IEnumerable<GeometryGraph> CreateComponents(IList<Node> nodes, IEnumerable<Edge> edges, double nodeSeparation) {
ValidateArg.IsNotNull(nodes, "nodes");
ValidateArg.IsNotNull(edges, "edges");
var nodeIndex = new Dictionary<Node, int>();
Expand All @@ -124,7 +124,8 @@ public static IEnumerable<GeometryGraph> CreateComponents(IList<Node> nodes, IEn
var nodeToGraph = new Dictionary<Node, GeometryGraph>();
var graphs = new List<GeometryGraph>();
foreach (var c in components) {
var g = new GeometryGraph();
var g = new GeometryGraph() { Margins = nodeSeparation/2 };

foreach (var i in c) {
var v = nodes[i];
g.Nodes.Add(v);
Expand Down
6 changes: 3 additions & 3 deletions GraphLayout/MSAGL/Layout/Initial/InitialLayoutByCluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void LayoutCluster(Cluster cluster) {
foreach (var cl in cluster.Clusters)
LayoutCluster(cl);

List<GeometryGraph> components = (List<GeometryGraph>)GetComponents(cluster, settings.LiftCrossEdges);
List<GeometryGraph> components = (List<GeometryGraph>)GetComponents(cluster, settings.LiftCrossEdges, settings.NodeSeparation);

//currentComponentFraction = (1.0 / clusterCount) / components.Count;

Expand Down Expand Up @@ -353,7 +353,7 @@ static bool IsDescendant(Node node, Cluster root) {
/// <param name="cluster">cluster to break into components</param>
/// <param name="liftCrossEdges">set this to consider lower-level edges while arranging subclusters</param>
/// <returns>GeometryGraphs that are each a connected component</returns>
static IEnumerable<GeometryGraph> GetComponents(Cluster cluster, bool liftCrossEdges) {
static IEnumerable<GeometryGraph> GetComponents(Cluster cluster, bool liftCrossEdges, double nodeSeparation) {
// Create a copy of the cluster's nodes. Some or all of these may also be clusters. We call these "top nodes".
Dictionary<Node, Node> originalToCopyNodeMap = ShallowNodeCopyDictionary(cluster);
var copiedEdges = new List<Edge>();
Expand Down Expand Up @@ -387,7 +387,7 @@ static IEnumerable<GeometryGraph> GetComponents(Cluster cluster, bool liftCrossE
}
}

return GraphConnectedComponents.CreateComponents(originalToCopyNodeMap.Values.ToArray(), copiedEdges);
return GraphConnectedComponents.CreateComponents(originalToCopyNodeMap.Values.ToArray(), copiedEdges, nodeSeparation);
}

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion GraphLayout/MSAGL/Layout/MDS/MDSGraphLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal static void LayoutGraphWithMds(GeometryGraph geometryGraph, MdsLayoutSe
/// the layouts for connected components together.
/// </summary>
internal void LayoutConnectedComponents() {
GeometryGraph[] graphs = GraphConnectedComponents.CreateComponents(graph.Nodes, graph.Edges).ToArray();
GeometryGraph[] graphs = GraphConnectedComponents.CreateComponents(graph.Nodes, graph.Edges, this.settings.NodeSeparation).ToArray();
// layout components, compute bounding boxes

if (settings.RunInParallel) {
Expand Down Expand Up @@ -170,6 +170,8 @@ void LayoutConnectedGraphWithMds(GeometryGraph compGraph)
{
GTreeOverlapRemoval.RemoveOverlaps(compGraph.Nodes.ToArray(), settings.NodeSeparation);
}


compGraph.BoundingBox = compGraph.PumpTheBoxToTheGraphWithMargins();
}

Expand Down
2 changes: 1 addition & 1 deletion GraphLayout/MSAGL/Miscellaneous/Ranking/RankingLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void SetNodePositionsAndMovedBoundaries(GeometryGraph graph) {
/// </summary>
protected override void RunInternal()
{
GeometryGraph[] graphs = GraphConnectedComponents.CreateComponents(graph.Nodes, graph.Edges).ToArray();
GeometryGraph[] graphs = GraphConnectedComponents.CreateComponents(graph.Nodes, graph.Edges, this.settings.NodeSeparation).ToArray();
// layout components, compute bounding boxes

for (int i = 0; i < graphs.Length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ private void SetGraph() {

var geomGraph=graph.GeometryGraph;

var geomGraphComponents = GraphConnectedComponents.CreateComponents(geomGraph.Nodes, geomGraph.Edges);
var settings = new SugiyamaLayoutSettings();
var geomGraphComponents = GraphConnectedComponents.
CreateComponents(geomGraph.Nodes, geomGraph.Edges, 0 );
foreach (var subgraph in geomGraphComponents) {

var layout=new LayeredLayout(subgraph, settings);
Expand Down
16 changes: 15 additions & 1 deletion GraphLayout/Test/MSAGLTests/DelaunayTriangulation/CdtTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Microsoft.Msagl.Routing.Spline.Bundling;
using Microsoft.Msagl.GraphViewerGdi;



namespace Microsoft.Msagl.UnitTests.DelaunayTriangulation {
[TestClass]
public class CdtTests {
Expand Down Expand Up @@ -108,7 +110,19 @@ public void CdtTriangleCreationTest() {
Assert.IsTrue(tri0.Edges[0] == tri.Edges[1]);
Assert.IsTrue(tri.Edges[1].CcwTriangle != null && tri.Edges[1].CwTriangle != null);
}

[Ignore]
[TestMethod]
public void FlatLine() {
#if TEST_MSAGL
GraphViewerGdi.DisplayGeometryGraph.SetShowFunctions();
#endif
var points = new List<Point> { new Point(0, 0), new Point(100, 0), new Point(300, 0) };
var cdt = new Cdt(points, null, null);
cdt.Run();
#if TEST_MSAGL
CdtSweeper.ShowFront(cdt.GetTriangles(), null, null, null);
#endif
}
[TestMethod]
public void SmallTriangulation() {
#if TEST_MSAGL
Expand Down

0 comments on commit 62ce41e

Please sign in to comment.