LayOutComponentInBin ( IGraph oGraph, ICollection <IVertex> oVerticesInComponent, Rectangle oBinRectangle ) { Debug.Assert(oGraph != null); Debug.Assert(oVerticesInComponent != null); AssertValid(); oGraph.SetValue(ReservedMetadataKeys.LayOutTheseVerticesOnly, oVerticesInComponent); // Force the FruchtermanReingoldLayout class to randomize the vertices. LayoutMetadataUtil.MarkGraphAsNotLaidOut(oGraph); ILayout oLayout = new FruchtermanReingoldLayout(); oLayout.Margin = BinMargin; LayoutContext oLayoutContext = new LayoutContext(oBinRectangle); oLayout.LayOutGraph(oGraph, oLayoutContext); }
LayOutSmallerComponentsInBins ( IGraph graph, ICollection <IVertex> verticesToLayOut, LayoutContext layoutContext, out ICollection <IVertex> remainingVertices, out Rectangle remainingRectangle ) { AssertValid(); remainingVertices = null; remainingRectangle = Rectangle.Empty; // This method modifies some of the graph's metadata. Save the // original metadata. Boolean bOriginalGraphHasBeenLaidOut = LayoutMetadataUtil.GraphHasBeenLaidOut(graph); ICollection <IVertex> oOriginalLayOutTheseVerticesOnly = (ICollection <IVertex>)graph.GetValue( ReservedMetadataKeys.LayOutTheseVerticesOnly, typeof(ICollection <IVertex>)); // Split the vertices into strongly connected components, sorted in // increasing order of vertex count. ConnectedComponentCalculator oConnectedComponentCalculator = new ConnectedComponentCalculator(); IList <LinkedList <IVertex> > oComponents = oConnectedComponentCalculator.CalculateStronglyConnectedComponents( verticesToLayOut, graph, true); Int32 iComponents = oComponents.Count; // This object will split the graph rectangle into bin rectangles. RectangleBinner oRectangleBinner = new RectangleBinner( layoutContext.GraphRectangle, m_iBinLength); Int32 iComponent = 0; for (iComponent = 0; iComponent < iComponents; iComponent++) { LinkedList <IVertex> oComponent = oComponents[iComponent]; Int32 iVerticesInComponent = oComponent.Count; if (iVerticesInComponent > m_iMaximumVerticesPerBin) { // The vertices in the remaining components should not be // binned. break; } Rectangle oBinRectangle; if (!oRectangleBinner.TryGetNextBin(out oBinRectangle)) { // There is no room for an additional bin rectangle. break; } // Lay out the component within the bin rectangle. LayOutComponentInBin(graph, oComponent, oBinRectangle); } // Restore the original metadata on the graph. if (bOriginalGraphHasBeenLaidOut) { LayoutMetadataUtil.MarkGraphAsLaidOut(graph); } else { LayoutMetadataUtil.MarkGraphAsNotLaidOut(graph); } if (oOriginalLayOutTheseVerticesOnly != null) { graph.SetValue(ReservedMetadataKeys.LayOutTheseVerticesOnly, oOriginalLayOutTheseVerticesOnly); } else { graph.RemoveKey(ReservedMetadataKeys.LayOutTheseVerticesOnly); } if (oRectangleBinner.TryGetRemainingRectangle( out remainingRectangle)) { remainingVertices = GetRemainingVertices(oComponents, iComponent); return(remainingVertices.Count > 0); } return(false); }