Beispiel #1
0
        GetEdgeEndpoint
        (
            VertexDrawingHistory otherVertexDrawingHistory,
            out Point edgeEndpoint
        )
        {
            AssertValid();

            GetEdgeEndpointOnRectangle(this.VertexLocation, this.Rectangle,
                                       otherVertexDrawingHistory.VertexLocation, out edgeEndpoint);
        }
        GetEdgeEndpoint
        (
            VertexDrawingHistory otherVertexDrawingHistory,
            out Point edgeEndpoint
        )
        {
            AssertValid();

            GetEdgeEndpointOnCircle(this.VertexLocation, this.Radius,
                                    otherVertexDrawingHistory.VertexLocation, out edgeEndpoint);
        }
Beispiel #3
0
        DrawLabel
        (
            DrawingContext drawingContext,
            GraphDrawingContext graphDrawingContext,
            VertexDrawingHistory vertexDrawingHistory,
            Rect vertexBounds,
            FormattedText formattedText
        )
        {
            Debug.Assert(drawingContext != null);
            Debug.Assert(graphDrawingContext != null);
            Debug.Assert(vertexDrawingHistory != null);
            Debug.Assert(formattedText != null);
            AssertValid();

            DrawLabel(drawingContext, graphDrawingContext, vertexDrawingHistory,
                      vertexBounds, GetLabelPosition(vertexDrawingHistory.Vertex),
                      formattedText);
        }
Beispiel #4
0
        GetEdgeEndpoint
        (
            VertexDrawingHistory otherVertexDrawingHistory,
            out Point edgeEndpoint
        )
        {
            AssertValid();

            Point oVertexLocation = this.VertexLocation;

            // A diamond is just a rotated square, so the
            // VertexDrawingHistory.GetEdgePointOnRectangle() can be used if the
            // diamond and the other vertex location are first rotated 45 degrees
            // about the diamond's center.

            Double dHalfSquareWidth = m_dHalfWidth / Math.Sqrt(2.0);

            Rect oRotatedDiamond = new Rect(
                oVertexLocation.X - dHalfSquareWidth,
                oVertexLocation.Y - dHalfSquareWidth,
                2.0 * dHalfSquareWidth,
                2.0 * dHalfSquareWidth
                );

            Matrix oMatrix = WpfGraphicsUtil.GetRotatedMatrix(oVertexLocation, 45);

            Point oRotatedOtherVertexLocation =
                oMatrix.Transform(otherVertexDrawingHistory.VertexLocation);

            Point oRotatedEdgeEndpoint;

            GetEdgeEndpointOnRectangle(oVertexLocation, oRotatedDiamond,
                                       oRotatedOtherVertexLocation, out oRotatedEdgeEndpoint);

            // Now rotate the computed edge endpoint in the other direction.

            oMatrix = WpfGraphicsUtil.GetRotatedMatrix(oVertexLocation, -45);

            edgeEndpoint = oMatrix.Transform(oRotatedEdgeEndpoint);
        }
Beispiel #5
0
        DrawLabel
        (
            DrawingContext drawingContext,
            GraphDrawingContext graphDrawingContext,
            VertexDrawingHistory vertexDrawingHistory,
            Rect vertexBounds,
            VertexLabelPosition labelPosition,
            FormattedText formattedText
        )
        {
            Debug.Assert(drawingContext != null);
            Debug.Assert(graphDrawingContext != null);
            Debug.Assert(vertexDrawingHistory != null);
            Debug.Assert(formattedText != null);
            AssertValid();

            Double        dHalfVertexBoundsWidth  = vertexBounds.Width / 2.0;
            Double        dHalfVertexBoundsHeight = vertexBounds.Height / 2.0;
            Double        dLabelHeight            = formattedText.Height;
            Double        dHalfLabelHeight        = dLabelHeight / 2.0;
            Double        dLabelWidth             = formattedText.Width;
            Double        dHalfLabelWidth         = dLabelWidth / 2.0;
            TextAlignment eTextAlignment          = TextAlignment.Left;

            formattedText.MaxLineCount = 1;

            // This is the point where the label will be drawn.  It initially
            // assumes a text height of zero with no margin, but that will be
            // adjusted within the switch statement below.

            Point  oDraw  = vertexDrawingHistory.GetLabelLocation(labelPosition);
            Double dDrawX = oDraw.X;
            Double dDrawY = oDraw.Y;

            // These are the bounds of the label text.

            Double dLabelBoundsLeft  = 0;
            Double dLabelBoundsRight = 0;

            switch (labelPosition)
            {
            case VertexLabelPosition.TopLeft:

                eTextAlignment = TextAlignment.Right;

                dDrawY           -= (dLabelHeight + VerticalMargin);
                dLabelBoundsLeft  = dDrawX - dLabelWidth;
                dLabelBoundsRight = dDrawX;

                break;

            case VertexLabelPosition.TopCenter:

                eTextAlignment = TextAlignment.Center;

                dDrawY           -= (dLabelHeight + VerticalMargin);
                dLabelBoundsLeft  = dDrawX - dHalfLabelWidth;
                dLabelBoundsRight = dDrawX + dHalfLabelWidth;

                break;

            case VertexLabelPosition.TopRight:

                // eTextAlignment = TextAlignment.Left;

                dDrawY           -= (dLabelHeight + VerticalMargin);
                dLabelBoundsLeft  = dDrawX;
                dLabelBoundsRight = dDrawX + dLabelWidth;

                break;

            case VertexLabelPosition.MiddleLeft:

                eTextAlignment = TextAlignment.Right;

                dDrawX           -= HorizontalMargin;
                dDrawY           -= dHalfLabelHeight;
                dLabelBoundsLeft  = dDrawX - dLabelWidth;
                dLabelBoundsRight = dDrawX;

                break;

            case VertexLabelPosition.MiddleCenter:

                eTextAlignment = TextAlignment.Center;

                dDrawY           -= dHalfLabelHeight;
                dLabelBoundsLeft  = dDrawX - dHalfLabelWidth;
                dLabelBoundsRight = dDrawX + dHalfLabelWidth;

                break;

            case VertexLabelPosition.MiddleRight:

                // eTextAlignment = TextAlignment.Left;

                dDrawX           += HorizontalMargin;
                dDrawY           -= dHalfLabelHeight;
                dLabelBoundsLeft  = dDrawX;
                dLabelBoundsRight = dDrawX + dLabelWidth;

                break;

            case VertexLabelPosition.BottomLeft:

                eTextAlignment = TextAlignment.Right;

                dDrawY           += VerticalMargin;
                dLabelBoundsLeft  = dDrawX - dLabelWidth;
                dLabelBoundsRight = dDrawX;

                break;

            case VertexLabelPosition.BottomCenter:

                eTextAlignment = TextAlignment.Center;

                dDrawY           += VerticalMargin;
                dLabelBoundsLeft  = dDrawX - dHalfLabelWidth;
                dLabelBoundsRight = dDrawX + dHalfLabelWidth;

                break;

            case VertexLabelPosition.BottomRight:

                // eTextAlignment = TextAlignment.Left;

                dDrawY           += VerticalMargin;
                dLabelBoundsLeft  = dDrawX;
                dLabelBoundsRight = dDrawX + dLabelWidth;

                break;

            default:

                Debug.Assert(false);
                break;
            }

            // Don't let the text exceed the bounds of the graph rectangle.

            Double dLabelBoundsTop    = dDrawY;
            Double dLabelBoundsBottom = dDrawY + dLabelHeight;

            Rect oGraphRectangleMinusMargin =
                graphDrawingContext.GraphRectangleMinusMargin;

            dDrawX += Math.Max(0,
                               oGraphRectangleMinusMargin.Left - dLabelBoundsLeft);

            dDrawX -= Math.Max(0,
                               dLabelBoundsRight - oGraphRectangleMinusMargin.Right);

            dDrawY += Math.Max(0,
                               oGraphRectangleMinusMargin.Top - dLabelBoundsTop);

            dDrawY -= Math.Max(0,
                               dLabelBoundsBottom - oGraphRectangleMinusMargin.Bottom);

            formattedText.TextAlignment = eTextAlignment;

            drawingContext.DrawText(formattedText, new Point(dDrawX, dDrawY));
        }
Beispiel #6
0
 GetEdgeEndpoint
 (
     VertexDrawingHistory otherVertexDrawingHistory,
     out Point edgeEndpoint
 );
Beispiel #7
0
        GetEdgeEndpoint
        (
            VertexDrawingHistory otherVertexDrawingHistory,
            out Point edgeEndpoint
        )
        {
            AssertValid();

            Point oVertexLocation      = this.VertexLocation;
            Point oOtherVertexLocation = otherVertexDrawingHistory.VertexLocation;

            // Instead of doing geometry calculations similar to what is done in
            // VertexDrawingHistory.GetEdgePointOnRectangle(), make use of that
            // method by making the triangle look like a rectangle.  First, figure
            // out how to rotate the triangle about the vertex location so that the
            // side containing the endpoint is vertical and to the right of the
            // vertex location.

            Double dEdgeAngle = WpfGraphicsUtil.GetAngleBetweenPoints(
                oVertexLocation, oOtherVertexLocation);

            Double dEdgeAngleDegrees = MathUtil.RadiansToDegrees(dEdgeAngle);

            Double dAngleToRotateDegrees;

            if (dEdgeAngleDegrees >= -30.0 && dEdgeAngleDegrees < 90.0)
            {
                dAngleToRotateDegrees = 30.0;
            }
            else if (dEdgeAngleDegrees >= -150.0 && dEdgeAngleDegrees < -30.0)
            {
                dAngleToRotateDegrees = 270.0;
            }
            else
            {
                dAngleToRotateDegrees = 150.0;
            }

            // Now create a rotated rectangle that is centered on the vertex
            // location and that has the vertical, endpoint-containing triangle
            // side as the rectangle's right edge.

            Double dWidth = 2.0 * m_dHalfWidth;

            Rect oRotatedRectangle = new Rect(
                oVertexLocation.X,
                oVertexLocation.Y - m_dHalfWidth,
                dWidth * WpfGraphicsUtil.Tangent30Degrees,
                dWidth
                );

            Matrix oMatrix = WpfGraphicsUtil.GetRotatedMatrix(oVertexLocation,
                                                              dAngleToRotateDegrees);

            // Rotate the other vertex location.

            Point oRotatedOtherVertexLocation =
                oMatrix.Transform(oOtherVertexLocation);

            // GetEdgeEndpointOnRectangle will compute an endpoint on the
            // rectangle's right edge.

            Point oRotatedEdgeEndpoint;

            GetEdgeEndpointOnRectangle(oVertexLocation, oRotatedRectangle,
                                       oRotatedOtherVertexLocation, out oRotatedEdgeEndpoint);

            // Now rotate the edge endpoint in the other direction.

            oMatrix = WpfGraphicsUtil.GetRotatedMatrix(oVertexLocation,
                                                       -dAngleToRotateDegrees);

            edgeEndpoint = oMatrix.Transform(oRotatedEdgeEndpoint);
        }