public void CalculateLayout_ReportsAllProgress() { GeometryGraph treeGraph = GraphGenerator.GenerateTree(20); var settings = new FastIncrementalLayoutSettings(); InitialLayout layout = new InitialLayout(treeGraph, settings); double progress = 0.0; EventHandler<ProgressChangedEventArgs> handler = (s, e) => progress = e.RatioComplete; try { layout.ProgressChanged += handler; layout.Run(); } finally { layout.ProgressChanged -= handler; } Assert.AreEqual(0, treeGraph.BoundingBox.Bottom); Assert.AreEqual(0, treeGraph.BoundingBox.Left); foreach (var v in treeGraph.Nodes) { Assert.IsTrue(treeGraph.BoundingBox.Contains(v.BoundingBox)); } Assert.AreEqual(1.0, progress, "Progress was never reported as 100%. Last update was at " + progress + "%"); }
public void RouteEdges_SmallGrid() { //DisplayGeometryGraph.SetShowFunctions(); Random random = new Random(1); int ntest = 20; for (int i = 0; i < ntest; i++) { GeometryGraph graph = GraphGenerator.GenerateSquareLattice(20 + random.Next(20)); AddRootCluster(graph); SetRandomNodeShapes(graph, random); int additionalEdges = random.Next(20); for (int j = 0; j < additionalEdges; j++) { Node source = graph.Nodes[random.Next(graph.Nodes.Count)]; Node target = graph.Nodes[random.Next(graph.Nodes.Count)]; Edge edge = GraphGenerator.CreateEdge(source, target); graph.Edges.Add(edge); } Layout(graph, random); //DisplayGeometryGraph.ShowGraph(graph); RouteEdges(graph, 5 * random.NextDouble()); //DisplayGeometryGraph.ShowGraph(graph); } }
public void ConstraintWithTransformation() { Random random = new Random(999); GeometryGraph graph = GraphGenerator.GenerateOneSimpleGraph(); GraphGenerator.SetRandomNodeShapes(graph, random); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); //layer direction to be left to right settings.Transformation = PlaneTransformation.Rotation(Math.PI / 2); List <Node> nodes = graph.Nodes.ToList(); settings.AddUpDownConstraint(nodes[0], nodes[1]); settings.AddLeftRightConstraint(nodes[3], nodes[4]); settings.AddUpDownVerticalConstraint(nodes[0], nodes[3]); settings.AddSameLayerNeighbors(nodes[2], nodes[4]); LayeredLayout layeredLayout = new LayeredLayout(graph, settings); layeredLayout.Run(); ShowGraphInDebugViewer(graph); SugiyamaValidation.ValidateUpDownConstraint(nodes[0], nodes[1]); SugiyamaValidation.ValidateLeftRightConstraint(nodes[3], nodes[4]); SugiyamaValidation.ValidateUpDownVerticalConstraint(nodes[0], nodes[3]); SugiyamaValidation.ValidateNeighborConstraint(graph, nodes[2], nodes[4], settings); }
public void RouteEdges_Subgraphs() { //DisplayGeometryGraph.SetShowFunctions(); Random random = new Random(1); int ntest = 20; for (int i = 0; i < ntest; i++) { int numberOfSubgraphs = 2 + random.Next(10); int numberOfNodesInSubgraphs = 2 + random.Next(10); GeometryGraph graph = GraphGenerator.GenerateGraphWithSameSubgraphs(numberOfSubgraphs, numberOfNodesInSubgraphs); AddRootCluster(graph); SetRandomNodeShapes(graph, random); int additionalEdges = random.Next(10); for (int j = 0; j < additionalEdges; j++) { Node source = graph.Nodes[random.Next(graph.Nodes.Count)]; Node target = graph.Nodes[random.Next(graph.Nodes.Count)]; Edge edge = GraphGenerator.CreateEdge(source, target); graph.Edges.Add(edge); } Layout(graph, random); //DisplayGeometryGraph.ShowGraph(graph); RouteEdges(graph, 5 * random.NextDouble()); //DisplayGeometryGraph.ShowGraph(graph); } }
protected GeometryGraph LoadGraph(string geometryGraphFileName, out LayoutAlgorithmSettings settings) { if (string.IsNullOrEmpty(geometryGraphFileName)) { throw new ArgumentNullException("geometryGraphFileName"); } GeometryGraph graph = null; settings = null; if (geometryGraphFileName.EndsWith(".geom")) { graph = GeometryGraphReader.CreateFromFile(geometryGraphFileName, out settings); SetupPorts(graph); } else if (geometryGraphFileName.EndsWith(".dot")) { int line; string msg; int col; Drawing.Graph drawingGraph = Parser.Parse(geometryGraphFileName, out line, out col, out msg); drawingGraph.CreateGeometryGraph(); graph = drawingGraph.GeometryGraph; settings = drawingGraph.CreateLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, new Random(1)); } else { Assert.Fail("Unknown graph format for file: " + geometryGraphFileName); } TestContext.WriteLine("Loaded graph: {0} Nodes, {1} Edges", graph.Nodes.Count, graph.Edges.Count); return(graph); }
public void ChainGraphDownwardConstraintTests() { GeometryGraph graph = GraphGenerator.GenerateSimpleChain(10); GraphGenerator.SetRandomNodeShapes(graph, random); LayoutAndValidate(graph, 1.5, null); }
public void RandomDotFileTests() { int line, column; string msg; string fileName = Path.Combine(this.TestContext.TestDir, "Out\\Dots\\fsm.dot"); Drawing.Graph drawGraph = Parser.Parse(fileName, out line, out column, out msg); drawGraph.CreateGeometryGraph(); GeometryGraph graph = drawGraph.GeometryGraph; GraphGenerator.SetRandomNodeShapes(graph, random); LayeredLayout layeredLayout = new LayeredLayout(graph, new SugiyamaLayoutSettings() { BrandesThreshold = 1 }); layeredLayout.Run(); string[] allFiles = Directory.GetFiles(Path.Combine(this.TestContext.TestDir, "Out\\Dots"), "*.dot"); List <int> selected = new List <int>(); for (int i = 0; i < 10; i++) { int next = random.Next(allFiles.Length); while (selected.Contains(next)) { next = random.Next(allFiles.Length); } selected.Add(next); WriteLine("Now handling dot file: " + allFiles[next]); drawGraph = Parser.Parse(allFiles[next], out line, out column, out msg); drawGraph.CreateGeometryGraph(); graph = drawGraph.GeometryGraph; GraphGenerator.SetRandomNodeShapes(graph, random); LayerDirection direction = LayerDirection.None; switch (i % 4) { case 0: direction = LayerDirection.TopToBottom; break; case 1: direction = LayerDirection.BottomToTop; break; case 2: direction = LayerDirection.LeftToRight; break; case 3: direction = LayerDirection.RightToLeft; break; } LayoutAndValidate(graph, (SugiyamaLayoutSettings)drawGraph.LayoutAlgorithmSettings, direction); } }
public void LatticeGraphTests() { GeometryGraph graph = GraphGenerator.GenerateSquareLattice(20); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Lattice Graph with Top to Down layer direction"); LayoutAndValidate(graph, settings); }
public void CircleGraphTests() { GeometryGraph graph = GraphGenerator.GenerateCircle(10); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Circle Graph with Top to Down layer direction"); LayoutAndValidate(graph, settings, 18, 10); }
public void DisjointGraphTests() { GeometryGraph graph = GraphGenerator.GenerateGraphWithSameSubgraphs(3, 6); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Disjoint Graph with Left To Right layer direction"); LayoutAndValidate(graph, settings, 32, 25, LayerDirection.LeftToRight); }
public override void Initialize() { EnableDebugViewer(); base.Initialize(); graph = GraphGenerator.GenerateOneSimpleGraph(); GraphGenerator.SetRandomNodeShapes(graph, random); allNodes = graph.Nodes.ToList(); settings = new FastIncrementalLayoutSettings(); settings.AvoidOverlaps = true; }
public void TreeGraphMdsLayout() { GeometryGraph treeGraph = GraphGenerator.GenerateTree(20); treeGraph.RootCluster = new Cluster(treeGraph.Nodes); var settings = new MdsLayoutSettings { ScaleX = 1, ScaleY = 1, RemoveOverlaps = true, PackingAspectRatio = 1.4 }; settings.EdgeRoutingSettings = new EdgeRoutingSettings { EdgeRoutingMode = EdgeRoutingMode.Spline, ConeAngle = Math.PI / 6, Padding = settings.NodeSeparation / 2.1 }; foreach (var v in treeGraph.Nodes) { v.BoundingBox = new Rectangle(0, 0, new Point(30, 30)); } var layout = new InitialLayoutByCluster(treeGraph, settings); double progress = 0.0; EventHandler <ProgressChangedEventArgs> handler = (s, e) => progress = e.RatioComplete; try { layout.ProgressChanged += handler; layout.Run(); } finally { layout.ProgressChanged -= handler; } EnableDebugViewer(); ShowGraphInDebugViewer(treeGraph); const double EdgeLengthDelta = 0.5; foreach (var e in treeGraph.Edges) { Assert.IsNotNull(e.Curve, "Edge curves not populated"); if (e.Source != e.Target) { double actualLength = (e.Source.Center - e.Target.Center).Length; double actualDesiredRatio = e.Length / actualLength; Assert.AreEqual(1, actualDesiredRatio, EdgeLengthDelta, "Edge length is not correct"); } } double aspectRatio = treeGraph.BoundingBox.Width / treeGraph.BoundingBox.Height; Assert.AreEqual(settings.PackingAspectRatio, aspectRatio, 1.4, "Aspect ratio too far from desired"); Assert.AreEqual(1.0, progress, "Progress was never reported as 100%. Last update was at " + progress + "%"); }
public void FullyConnectedGraphTests() { GeometryGraph graph = GraphGenerator.GenerateFullyConnectedGraph(20); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Fully Connected Graph with Bottom to Top layer direction"); LayoutAndValidate(graph, settings, LayerDirection.BottomToTop); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Fully Connected Graph with Left to Right layer direction"); LayoutAndValidate(graph, settings, LayerDirection.LeftToRight); }
public void TreeGraphTests() { GeometryGraph graph = GraphGenerator.GenerateFullTree(10, 3); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Tree Graph with Right to Left layer direction"); LayoutAndValidate(graph, settings, LayerDirection.RightToLeft); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Tree Graph with Bottom to Top layer direction"); LayoutAndValidate(graph, settings, LayerDirection.BottomToTop); }
public void SimpleGraphTests() { GeometryGraph graph = GraphGenerator.GenerateOneSimpleGraph(); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Simple Graph with Top to Down layer direction"); LayoutAndValidate(graph, settings); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Simple Graph with Left to Right layer direction"); LayoutAndValidate(graph, settings, LayerDirection.LeftToRight); }
public void RandomGraphTests() { GeometryGraph graph = GraphGenerator.GenerateOneGraph(new GeometryGraph(), 30, 30, true); SugiyamaLayoutSettings settings = new SugiyamaLayoutSettings(); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Kokomo Graph with bottom to top layer direction"); LayoutAndValidate(graph, settings, LayerDirection.BottomToTop); graph = GraphGenerator.GenerateOneGraph(new GeometryGraph(), 30, 40, false); GraphGenerator.SetRandomNodeShapes(graph, random); WriteLine("Trying Kokomo Graph with rigth to left layer direction"); Microsoft.Msagl.DebugHelpers.Persistence.GeometryGraphWriter.Write(graph, "wrongLayout"); LayoutAndValidate(graph, settings, LayerDirection.RightToLeft); }
public void CircleGraphDownwardConstraintTests() { GeometryGraph graph = GraphGenerator.GenerateCircle(6); ISet <Node> avoidNodes = new HashSet <Node>(graph.Nodes); Node firstNode = graph.Nodes.First(); Node lastNode = graph.Nodes.Last(); //add some non-cyclic nodes Node node1 = GraphGenerator.CreateNode(graph.Nodes.Count); Node node2 = GraphGenerator.CreateNode(graph.Nodes.Count + 1); graph.Nodes.Add(node1); graph.Nodes.Add(node2); graph.Edges.Add(GraphGenerator.CreateEdge(firstNode, node1)); graph.Edges.Add(GraphGenerator.CreateEdge(node2, lastNode)); GraphGenerator.SetRandomNodeShapes(graph, random); LayoutAndValidate(graph, 2.5, avoidNodes); }
public void RouteEdges_LargeTree() { //DisplayGeometryGraph.SetShowFunctions(); Random random = new Random(1); int ntest = 10; for (int i = 0; i < ntest; i++) { GeometryGraph graph = GraphGenerator.GenerateTree(50 + random.Next(100)); AddRootCluster(graph); SetRandomNodeShapes(graph, random); Layout(graph, random); //DisplayGeometryGraph.ShowGraph(graph); RouteEdges(graph, 5 * random.NextDouble()); //DisplayGeometryGraph.ShowGraph(graph); } }
public void RouteEdges_CallsProgress() { //DisplayGeometryGraph.SetShowFunctions(); GeometryGraph graph = GraphGenerator.GenerateTree(10); double ratioComplete = 0; EventHandler <ProgressChangedEventArgs> handler = (s, e) => ratioComplete = e.RatioComplete; SplineRouter splineRouter = null; try { splineRouter = new SplineRouter(graph, 10, 1, Math.PI / 6, null); splineRouter.ProgressChanged += handler; splineRouter.Run(); // DisplayGeometryGraph.ShowGraph(graph); } finally { splineRouter.ProgressChanged -= handler; } Assert.AreEqual(1, ratioComplete, "RouteEdges did not complete"); }
public void RouteEdges_RandomGraph() { //DisplayGeometryGraph.SetShowFunctions(); Random random = new Random(1); int ntest = 100; for (int i = 0; i < ntest; i++) { int nodeCount = 5 + random.Next(10); int edgeCount = 10 + random.Next(20); GeometryGraph graph = GraphGenerator.GenerateRandomGraph(nodeCount, edgeCount, random); AddRootCluster(graph); SetRandomNodeShapes(graph, random); Layout(graph, random); //DisplayGeometryGraph.ShowGraph(graph); RouteEdges(graph, 5 * random.NextDouble()); //DisplayGeometryGraph.ShowGraph(graph); } }
static GeometryGraph GenerateGraphWithGroups(Random random, int multiplier) { int clusterCount = (2 + random.Next(5)) * multiplier; int nodeCount = (clusterCount + random.Next(20)) * multiplier; int edgeCount = (10 + random.Next(20)) * multiplier; //tree of clusters var parent = GenerateClusterTree(clusterCount, random); GeometryGraph graph = new GeometryGraph(); //create nodes for (int i = 0; i < nodeCount; i++) { Node node = GraphGenerator.CreateNode(i); graph.Nodes.Add(node); } //create clusters var clusters = new Cluster[clusterCount]; for (int i = 0; i < clusterCount; i++) { clusters[i] = new Cluster(); clusters[i].BoundaryCurve = CurveFactory.CreateRectangle(30, 30, new Point(15, 15)); clusters[i].RectangularBoundary = new RectangularClusterBoundary { LeftMargin = 5, RightMargin = 5, BottomMargin = 5, TopMargin = 5 }; } //set cluster hiearchy graph.RootCluster = clusters[0]; for (int i = 1; i < clusterCount; i++) { clusters[parent[i]].AddChild(clusters[i]); } //put nodes to clusters for (int i = 0; i < nodeCount; i++) { clusters[random.Next(clusterCount)].AddChild(graph.Nodes[i]); } for (int i = 0; i < clusterCount; i++) { if (clusters[i].Nodes.Count() == 0 && clusters[i].Clusters.Count() == 0) { Node node = GraphGenerator.CreateNode(i); graph.Nodes.Add(node); clusters[i].AddChild(node); nodeCount++; } } //adding edges for (int i = 0; i < edgeCount; i++) { int s = random.Next(nodeCount + clusterCount - 1); Node snode = (s < nodeCount ? graph.Nodes[s] : clusters[s - nodeCount + 1]); int t = random.Next(nodeCount + clusterCount - 1); Node tnode = (t < nodeCount ? graph.Nodes[t] : clusters[t - nodeCount + 1]); if (EdgeIsValid(snode, tnode)) { var edge = new Edge(snode, tnode); edge.LineWidth = 0.5 + 3 * random.NextDouble(); graph.Edges.Add(edge); } else { i--; } } SetupPorts(graph); return(graph); }