Example #1
0
        OnRender
        (
            DrawingContext oDrawingContext,
            Double dAdjustedNearValue,
            Double dAdjustedNearOffset,
            Double dAdjustedFarValue,
            Double dAdjustedFarOffset
        )
        {
            Debug.Assert(oDrawingContext != null);
            Debug.Assert(dAdjustedNearOffset >= 0);
            Debug.Assert(dAdjustedFarOffset >= 0);
            AssertValid();

            Rect oClientRectangle =
                new Rect(0, 0, this.ActualWidth, this.ActualHeight);

            Double dAxisLength = m_bIsXAxis ? this.ActualWidth : this.ActualHeight;

            if (dAxisLength == 0)
            {
                return;
            }

            // If the pen is not one pixel wide, gridlines drawn on a large-font
            // machine vary in width, depending on their position.

            Pen oPen = WpfGraphicsUtil.CreateOnePixelPen(this,
                                                         SystemColors.WindowTextBrush);

            WpfGraphicsUtil.FreezeIfFreezable(oPen);

            DrawBackground(oDrawingContext, oClientRectangle, dAdjustedNearOffset,
                           dAdjustedFarOffset);

            DrawAxisLine(oDrawingContext, oClientRectangle, oPen);

            if (dAdjustedFarValue == dAdjustedNearValue)
            {
                // This is a degenerate case.  Draw just one gridline.

                DrawMajorGridlineAndValue(oDrawingContext, oClientRectangle, oPen,
                                          dAdjustedNearValue, dAdjustedNearOffset, "N");

                return;
            }

            if (dAdjustedNearOffset + dAdjustedFarOffset > dAxisLength)
            {
                return;
            }

            DrawLabel(oDrawingContext, oClientRectangle);

            Double [] adMajorGridlineValues;
            Int32     iDecimalPlacesToShow;

            ChartUtil.GetAxisGridlineValues(dAdjustedNearValue, dAdjustedFarValue,
                                            out adMajorGridlineValues, out iDecimalPlacesToShow);

            String sFormatSpecifier = GetFormatSpecifier(adMajorGridlineValues,
                                                         iDecimalPlacesToShow);

            // Use the point-slope equation of a line to get the major gridline
            // coordinates.

            Double dX1 = dAdjustedNearValue;
            Double dY1 = dAdjustedNearOffset;
            Double dX2 = dAdjustedFarValue;
            Double dY2 = dAxisLength - dAdjustedFarOffset;

            Debug.Assert(dX1 != dX2);
            Double dM = (dY1 - dY2) / (dX1 - dX2);

            Double dPreviousMajorGridlineOffset = Double.NaN;

            foreach (Double dMajorGridlineValue in adMajorGridlineValues)
            {
                // Compute the major gridline's offset, then draw it.

                Double dMajorGridlineOffset =
                    dY1 + dM * (dMajorGridlineValue - dX1);

                DrawMajorGridlineAndValue(oDrawingContext, oClientRectangle, oPen,
                                          dMajorGridlineValue, dMajorGridlineOffset, sFormatSpecifier);

                if (!Double.IsNaN(dPreviousMajorGridlineOffset))
                {
                    // Draw minor gridlines between the major gridlines.

                    DrawMinorGridlines(oDrawingContext, oClientRectangle, oPen,
                                       dMajorGridlineOffset, dPreviousMajorGridlineOffset);
                }

                dPreviousMajorGridlineOffset = dMajorGridlineOffset;
            }
        }