Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14155


Ignore:
Timestamp:
07/21/16 15:13:08 (8 years ago)
Author:
bburlacu
Message:

#2594: Improved axis scaling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ChartUtil.cs

    r14152 r14155  
    3131
    3232      var range = max - min;
    33       var minLog = Math.Log10(Math.Abs(min));
    34       var maxLog = Math.Log10(Math.Abs(max));
    35       var rangeLog = Math.Log10(range);
    36 
    37       var dMin = (int)Math.Floor(minLog);
    38       var dMax = (int)Math.Floor(maxLog);
    39       var dRange = (int)Math.Floor(rangeLog);
    40 
    41       int decimalRank;
    42       if (dMin == dMax && dMax == dRange)
    43         decimalRank = dMin - 1;
    44       else
    45         decimalRank = Math.Min(Math.Min(dMin, dMax), dRange);
    46 
     33      var dRange = (int)Math.Round(Math.Log10(range));
     34      int decimalRank = dRange - 1;
    4735      var aMin = min.RoundDown(decimalRank);
    4836      var aMax = max.RoundUp(decimalRank);
     
    6048    }
    6149
    62     // this method tries to find an axis interval with as few fractional digits as possible (because it looks nicer)
    63     // we only try between 3 and 5 ticks (inclusive) because it wouldn't make sense to exceed this interval
     50    /// <summary>
     51    /// Tries to find an axis interval with as few fractional digits as possible (because it looks nicer).  we only try between 3 and 5 ticks (inclusive) because it wouldn't make sense to exceed this interval.
     52    /// </summary>
    6453    public static void CalculateOptimalAxisInterval(double min, double max, out double axisMin, out double axisMax, out double axisInterval) {
    6554      CalculateAxisInterval(min, max, 5, out axisMin, out axisMax, out axisInterval);
     
    10190        var floor = (int)Math.Floor(value);
    10291        var pow = (int)Math.Pow(10, decimalRank);
    103         // round down to nearest multiple of 5 or 10
    104         var mod = Math.Min(floor % pow, floor % (pow / 2));
     92        var mod = floor % pow;
     93        if (mod < 0) mod += pow;
    10594        return floor - mod;
    10695      }
     
    112101        var ceil = (int)Math.Ceiling(value);
    113102        var pow = (int)Math.Pow(10, decimalRank);
    114         // round up to nearest multiple of 5 or 10
    115         var mod = ceil % (pow / 2) == 0 || ceil % pow == 0 ? 0 : Math.Min(pow / 2 - ceil % (pow / 2), pow - ceil % pow);
    116         return ceil + mod;
     103        var mod = ceil % pow;
     104        if (mod < 0) mod += pow;
     105        return ceil - mod + pow;
    117106      }
    118107      return value.Ceil(Math.Abs(decimalRank));
Note: See TracChangeset for help on using the changeset viewer.