コード例 #1
0
        private void IntervalFromRange(Range range, double minInterval, out DecomposedNumber interval, out DecomposedNumber firstTick)
        {
            // Exponent of the least significant figure of the interval.
            int intervalExponent       = (int)Math.Floor(Math.Log10(minInterval));
            int intervalIntCoefficient = (int)Math.Floor(minInterval / Math.Pow(10, intervalExponent) + fractionalTolerance);

            // LSF must be either 1, 2, 5 or 10, whichever is directly above the current value.
            if (intervalIntCoefficient > 5)
            {
                intervalIntCoefficient = 1; intervalExponent++;
            }
            else if (intervalIntCoefficient > 2)
            {
                intervalIntCoefficient = 5;
            }
            else if (intervalIntCoefficient > 1)
            {
                intervalIntCoefficient = 2;
            }
            else
            {
                intervalIntCoefficient = 1;
            }
            //
            interval = new DecomposedNumber(intervalIntCoefficient * Math.Pow(10, intervalExponent), (double)intervalIntCoefficient, intervalExponent);
            //
            // Now get the first tick
            double firstTickValue;
            double absoluteTolerance = fractionalTolerance * interval.Value;

            if ((range.Min - absoluteTolerance) < 0)
            {
                firstTickValue = (range.Min - absoluteTolerance) - ((range.Min - absoluteTolerance) % interval.Value);
            }
            else
            {
                firstTickValue = interval.Value - ((range.Min - absoluteTolerance) % interval.Value) + (range.Min - absoluteTolerance);
            }
            int firstTickExp = (firstTickValue == 0) ? interval.Exponent : (int)Math.Floor(Math.Log10(Math.Abs(firstTickValue)));

            firstTick = new DecomposedNumber(firstTickValue, firstTickValue / Math.Pow(10, firstTickExp), firstTickExp);
        }
コード例 #2
0
ファイル: Axis.cs プロジェクト: goutkannan/ironlab
        private void IntervalFromRange(Range range, double minInterval, out DecomposedNumber interval, out DecomposedNumber firstTick) 
        {
            // Exponent of the least significant figure of the interval.
            int intervalExponent = (int)Math.Floor(Math.Log10(minInterval));
            int intervalIntCoefficient = (int)Math.Floor(minInterval / Math.Pow(10, intervalExponent) + fractionalTolerance);

            // LSF must be either 1, 2, 5 or 10, whichever is directly above the current value.      
            if (intervalIntCoefficient > 5) { intervalIntCoefficient = 1; intervalExponent++; }
            else if (intervalIntCoefficient > 2) { intervalIntCoefficient = 5; }
            else if (intervalIntCoefficient > 1) { intervalIntCoefficient = 2; }
            else { intervalIntCoefficient = 1; }
            //
            interval = new DecomposedNumber(intervalIntCoefficient * Math.Pow(10, intervalExponent), (double)intervalIntCoefficient, intervalExponent);
            //
            // Now get the first tick
            double firstTickValue;
            double absoluteTolerance = fractionalTolerance * interval.Value;
            if ((range.Min - absoluteTolerance) < 0)
            {
                firstTickValue = (range.Min - absoluteTolerance) - ((range.Min - absoluteTolerance) % interval.Value);
            }
            else
            {
                firstTickValue = interval.Value - ((range.Min - absoluteTolerance) % interval.Value) + (range.Min - absoluteTolerance);
            }
            int firstTickExp = (firstTickValue == 0) ? interval.Exponent : (int)Math.Floor(Math.Log10(Math.Abs(firstTickValue)));
            firstTick = new DecomposedNumber(firstTickValue, firstTickValue / Math.Pow(10, firstTickExp), firstTickExp);
        }