System.Windows.Forms.DataVisualization.Charting.Utilities.HistogramChartHelper.RoundInterval C# (CSharp) 메소드

RoundInterval() 개인적인 메소드

Helper method which rounds specified axsi interval.
private RoundInterval ( double interval ) : double
interval double Calculated axis interval.
리턴 double
        internal double RoundInterval( double interval )
        {
            // If the interval is zero return error
            if( interval == 0.0 )
            {
                throw( new ArgumentOutOfRangeException("interval", "Interval can not be zero."));
            }

            // If the real interval is > 1.0
            double	step = -1;
            double	tempValue = interval;
            while( tempValue > 1.0 )
            {
                step ++;
                tempValue = tempValue / 10.0;
                if( step > 1000 )
                {
                    throw( new InvalidOperationException( "Auto interval error due to invalid point values or axis minimum/maximum." ) );
                }
            }

            // If the real interval is < 1.0
            tempValue = interval;
            if( tempValue < 1.0 )
            {
                step = 0;
            }

            while( tempValue < 1.0 )
            {
                step --;
                tempValue = tempValue * 10.0;
                if( step < -1000 )
                {
                    throw( new InvalidOperationException( "Auto interval error due to invalid point values or axis minimum/maximum." ) );
                }
            }

            double tempDiff = interval / Math.Pow( 10.0, step );
            if( tempDiff < 3.0 )
            {
                tempDiff = 2.0;
            }
            else if( tempDiff < 7.0 )
            {
                tempDiff = 5.0;
            }
            else
            {
                tempDiff = 10.0;
            }

            // Make a correction of the real interval
            return  tempDiff * Math.Pow( 10.0, step );
        }