/// <summary>
 /// Gives each label a size.
 /// By default they don't have a size so we must fill it in.
 /// </summary>
 private static void AddLabelSizes(GeometryGraph graph)
 {
     foreach (Label label in graph.CollectAllLabels())
     {
         label.Width  = 30;
         label.Height = 15;
     }
 }
        /// <summary>
        /// Verifies that the graph conforms to the correct aspect ratio.
        /// </summary>
        private static void VerifyAspectRatio(GeometryGraph graph, double aspectRatio)
        {
            double ratioTolerance = aspectRatio * 0.2;

            // Verify the graph is the correct size
            Assert.AreEqual(aspectRatio, (graph.Width - (graph.Margins * 2)) / (graph.Height - (graph.Margins * 2)), ratioTolerance, "The graph does not conform to the aspect ratio.");

            // Verify the nodes were spread apart to fill the space
            IEnumerable <Rectangle> nodeBoxes  = graph.Nodes.Select(n => n.BoundingBox);
            IEnumerable <Rectangle> edgeBoxes  = graph.Edges.Select(e => e.BoundingBox);
            IEnumerable <Rectangle> labelBoxes = graph.CollectAllLabels().Select(l => l.BoundingBox);

            Rectangle itemBounds = new Rectangle(nodeBoxes.Concat(edgeBoxes).Concat(labelBoxes));

            Assert.AreEqual(aspectRatio, itemBounds.Width / itemBounds.Height, ratioTolerance, "The graph's nodes do not conform to the aspect ratio.");
        }
        public void LabelsNearEdges()
        {
            // Setup
            string filePath = Path.Combine(this.TestContext.TestDir, "Out\\Dots", "chat.dot");

            GeometryGraph graph = this.LoadGraph(filePath);

            AddLabelSizes(graph);
            Assert.IsTrue(graph.CollectAllLabels().Count > 0, "The loaded graph has no labels.");

            // Execute
            LayeredLayout layeredLayout = new LayeredLayout(graph, new SugiyamaLayoutSettings());

            layeredLayout.Run();

            // Verify
            foreach (Edge edge in graph.Edges)
            {
                VerifyLabelIsNearEdges(edge);

                // We do not verify that labels don't overlap other edges,
                // since that is not gauranteed by sugiyama layout.
            }
        }