Smrf.NodeXL.Visualization.Wpf.CollapsedGroupDrawingManager.MoveVertexBoundsIfNecessary C# (CSharp) Method

MoveVertexBoundsIfNecessary() public method

public MoveVertexBoundsIfNecessary ( GraphDrawingContext graphDrawingContext, Double graphScale, Rect &vertexBounds ) : void
graphDrawingContext GraphDrawingContext
graphScale Double
vertexBounds System.Windows.Rect
return void
    MoveVertexBoundsIfNecessary
    (
        GraphDrawingContext graphDrawingContext,
        Double graphScale,
        ref Rect vertexBounds
    )
    {
        Debug.Assert(graphDrawingContext != null);
        Debug.Assert(graphScale >= GraphDrawer.MinimumGraphScale);
        Debug.Assert(graphScale <= GraphDrawer.MaximumGraphScale);
        AssertValid();

        // Additional elements are drawn only for the fan motif.

        String sType;

        if (
            m_oCollapsedGroupVertex != null
            &&
            m_oCollapsedGroupAttributes.TryGetValue(
                CollapsedGroupAttributeKeys.Type, out sType)
            &&
            sType == CollapsedGroupAttributeValues.FanMotifType
            )
        {
            // Move the fan bounds within the bounds of the graph rectangle's
            // margin.

            Rect oFanBounds = GetCircleSegment(vertexBounds,
                GetFanMotifAngleRadians(), graphScale).Bounds;

            Rect oMovedFanBounds = WpfGraphicsUtil.MoveRectangleWithinBounds(
                oFanBounds, graphDrawingContext.GraphRectangleMinusMargin,
                false);

            // Now move the vertex bounds by the same amount.

            vertexBounds = Rect.Offset(vertexBounds,
                oMovedFanBounds.Left - oFanBounds.Left,
                oMovedFanBounds.Top - oFanBounds.Top
                );
        }
    }

Usage Example

    MoveVertexIfNecessary
    (
        IVertex oVertex,
        GraphDrawingContext oGraphDrawingContext,
        CollapsedGroupDrawingManager oCollapsedGroupDrawingManager,
        ref Rect oVertexBounds
    )
    {
        Debug.Assert(oVertex != null);
        Debug.Assert(oGraphDrawingContext != null);
        Debug.Assert(oCollapsedGroupDrawingManager != null);
        AssertValid();

        if (!m_bLimitVerticesToBounds ||
            oGraphDrawingContext.GraphRectangleMinusMarginIsEmpty)
        {
            // The vertex shouldn't be moved.

            return;
        }

        // First, assume that this is a normal vertex and not a vertex that
        // represents a collapsed group.  Move the vertex bounds within the
        // bounds of the graph rectangle's margin.

        Rect oMovedVertexBounds = WpfGraphicsUtil.MoveRectangleWithinBounds(
            oVertexBounds, oGraphDrawingContext.GraphRectangleMinusMargin,
            false);

        // If the vertex actually represents a collapsed group, move it further
        // if necessary to accomodate the additional elements that
        // CollapsedGroupmanager.PostDrawVertex() may draw on top of the
        // vertex.

        oCollapsedGroupDrawingManager.MoveVertexBoundsIfNecessary(
            oGraphDrawingContext, m_dGraphScale, ref oMovedVertexBounds);

        oVertex.Location = System.Drawing.PointF.Add( oVertex.Location,
            new System.Drawing.SizeF(
                (Single)(oMovedVertexBounds.X - oVertexBounds.X),
                (Single)(oMovedVertexBounds.Y - oVertexBounds.Y)
                ) );

        oVertexBounds = oMovedVertexBounds;
    }