Beispiel #1
0
        /// <summary>
        /// Draw the value labels, tic marks, and grid lines as
        /// required for this <see cref="Axis"/>.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the
        /// PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or
        /// owner of this object.
        /// </param>
        /// <param name="baseVal">
        /// The first major tic value for the axis
        /// </param>
        /// <param name="nTics">
        /// The total number of major tics for the axis
        /// </param>
        /// <param name="topPix">
        /// The pixel location of the far side of the ChartRect from this axis.
        /// This value is the ChartRect.Height for the XAxis, or the ChartRect.Width
        /// for the YAxis and Y2Axis.
        /// </param>
        /// <param name="shift">The number of pixels to shift this axis, based on the
        /// value of <see cref="Axis.Cross"/>.  A positive value is into the ChartRect relative to
        /// the default axis position.</param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and
        /// passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust
        /// font sizes, etc. according to the actual size of the graph.
        /// </param>
        internal override void DrawLabels(Graphics g, GraphPane pane, double baseVal, int nTics,
                                          float topPix, float shift, float scaleFactor)
        {
            int lNtics = Percentages.Length;

            MajorTic tic = _ownerAxis._majorTic;
            //			MajorGrid grid = _ownerAxis._majorGrid;

            double dVal;
            float  pixVal;
            float  scaledTic = tic.ScaledTic(scaleFactor);

            using (Pen ticPen = tic.GetPen(pane, scaleFactor))
            //			using ( Pen gridPen = grid.GetPen( pane, scaleFactor ) )
            {
                // get the Y position of the center of the axis labels
                // (the axis itself is referenced at zero)
                SizeF maxLabelSize = GetScaleMaxSpace(g, pane, scaleFactor, true);
                float charHeight   = _fontSpec.GetHeight(scaleFactor);
                float maxSpace     = maxLabelSize.Height;

                float  edgeTolerance = Default.EdgeTolerance * scaleFactor;
                double rangeTol      = (_maxLinTemp - _minLinTemp) * 0.001;

                int firstTic = 0;

                // save the position of the previous tic
                float lastPixVal = -10000;

                // loop for each major tic
                for (int i = firstTic; i < lNtics + firstTic; i++)
                {
                    dVal = CalcMajorTicValue(baseVal, i);
                    double linVal = dVal; // Linearize(dVal);

                    // If we're before the start of the scale, just go to the next tic
                    if (linVal < _minLinTemp)
                    {
                        continue;
                    }
                    // if we've already past the end of the scale, then we're done
                    if (linVal > _maxLinTemp + rangeTol)
                    {
                        break;
                    }

                    // convert the value to a pixel position
                    pixVal = LocalTransform(linVal);

                    tic.Draw(g, pane, ticPen, pixVal, topPix, shift, scaledTic);

                    // draw the grid
                    //					grid.Draw( g, gridPen, pixVal2, topPix );

                    bool isMaxValueAtMaxPix = ((_ownerAxis is XAxis || _ownerAxis is Y2Axis) &&
                                               !IsReverse) ||
                                              (_ownerAxis is Y2Axis && IsReverse);

                    bool isSkipZone = (((_isSkipFirstLabel && isMaxValueAtMaxPix) ||
                                        (_isSkipLastLabel && !isMaxValueAtMaxPix)) &&
                                       pixVal < edgeTolerance) ||
                                      (((_isSkipLastLabel && isMaxValueAtMaxPix) ||
                                        (_isSkipFirstLabel && !isMaxValueAtMaxPix)) &&
                                       pixVal > _maxPix - _minPix - edgeTolerance);

                    bool isSkipCross = _isSkipCrossLabel && !_ownerAxis._crossAuto &&
                                       Math.Abs(_ownerAxis._cross - dVal) < rangeTol * 10.0;

                    isSkipZone = isSkipZone || isSkipCross;

                    if (_isVisible && !isSkipZone)
                    {
                        // For exponential scales, just skip any label that would overlap with the previous one
                        // This is because exponential scales have varying label spacing
                        if (IsPreventLabelOverlap &&
                            Math.Abs(pixVal - lastPixVal) < maxLabelSize.Width)
                        {
                            continue;
                        }

                        DrawLabel(g, pane, i, dVal, pixVal, shift, maxSpace, scaledTic, charHeight, scaleFactor);

                        lastPixVal = pixVal;
                    }
                }
            }
        }