Lays out a graph using the Fruchterman-Reingold layout.
For details on the layout algorithm, see http://www.cs.ubc.ca/rr/proceedings/spe91-95/spe/vol21/issue11/spe060tf.pdf.

If the graph has a metadata key of , only the vertices specified in the value's IVertex collection are laid out and all other vertices are completely ignored.

If the graph has a metadata key of , the previous layout is used as a starting point for the new layout. Otherwise, the locations of all unlocked vertices are randomized at the start of the layout process.

If a vertex has a metadata key of with a value of true, it is included in layout calculations but its own location is left unmodified.

If an edge has a metadata key of , the edge weight is used in the layout calculations. Edges with larger edge weights exert stronger attractive forces on their vertices. If an edge weight is zero or less, the algorithm ignores it and uses a value of 1.0 instead.

Here is sample C# code that uses a to synchronously lay out a graph. using System; using System.Drawing; using Smrf.NodeXL.Core; using Smrf.NodeXL.Layouts; namespace PopulateAndLayOutGraph { class Program { static void Main(string[] args) { // Create a graph. The graph has no visual representation; it is // just a data structure. Graph oGraph = new Graph(GraphDirectedness.Directed); IVertexCollection oVertices = oGraph.Vertices; IEdgeCollection oEdges = oGraph.Edges; // Add three vertices. IVertex oVertexA = oVertices.Add(); oVertexA.Name = "Vertex A"; IVertex oVertexB = oVertices.Add(); oVertexB.Name = "Vertex B"; IVertex oVertexC = oVertices.Add(); oVertexC.Name = "Vertex C"; // Connect the vertices with directed edges. IEdge oEdge1 = oEdges.Add(oVertexA, oVertexB, true); IEdge oEdge2 = oEdges.Add(oVertexB, oVertexC, true); IEdge oEdge3 = oEdges.Add(oVertexC, oVertexA, true); // Lay out the graph within a 100x100 rectangle. This sets the // IVertex.Location property of each vertex. ILayout oLayout = new FruchtermanReingoldLayout(); LayoutContext oLayoutContext = new LayoutContext(new Rectangle(0, 0, 100, 100)); oLayout.LayOutGraph(oGraph, oLayoutContext); // List the results. foreach (IVertex oVertex in oVertices) { Console.WriteLine("The location of {0} is {1}.", oVertex.Name, oVertex.Location); } } } }
Inheritance: LayoutBase
Ejemplo n.º 1
0
        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);
        }
 SetUp()
 {
     m_oFruchtermanReingoldLayout = new FruchtermanReingoldLayout();
 }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
    //*************************************************************************
    //  Constructor: NodeXLControl()
    //
    /// <summary>
    /// Initializes a new instance of the <see cref="NodeXLControl" /> class.
    /// </summary>
    //*************************************************************************

    public NodeXLControl()
    {
        m_oGraph = new Graph();
        CreateGraphDrawer();
        m_fEdgeBundlerStraightening = 0.15F;

        m_oLayout = new FruchtermanReingoldLayout();
        OnNewLayout(m_oLayout);

        m_oLastLayoutContext =
            new LayoutContext(System.Drawing.Rectangle.Empty);

        m_oLastGraphDrawingContext = null;

        m_eLayoutState = LayoutState.Stable;

        m_eMouseMode = MouseMode.Select;
        m_bMouseAlsoSelectsIncidentEdges = true;
        m_bAllowVertexDrag = true;

        m_oVerticesBeingDragged = null;
        m_oMarqueeBeingDragged = null;
        m_oTranslationBeingDragged = null;

        m_oSelectedVertices = new HashSet<IVertex>();
        m_oSelectedEdges = new HashSet<IEdge>();
        m_oCollapsedGroups = new Dictionary<String, IVertex>();
        m_oDoubleClickedVertexInfo = null;

        m_bShowVertexToolTips = false;
        m_oLastMouseMoveLocation = new Point(-1, -1);

        // Create a helper object for displaying vertex tooltips.

        CreateVertexToolTipTracker();
        m_oVertexToolTip = null;

        m_bGraphZoomCentered = false;

        this.AddLogicalChild(m_oGraphDrawer.VisualCollection);

        CreateTransforms();

        // Prevent a focus rectangle from being drawn around the control when
        // it captures keyboard focus.  The focus rectangle does not behave
        // properly when the layout and render transforms are applied --
        // sometimes the rectangle disappears, and sometimes it gets magnified
        // by the render layout.

        this.FocusVisualStyle = null;

        // AssertValid();
    }