Changeset 14155
 Timestamp:
 07/21/16 15:13:08 (13 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ChartUtil.cs
r14152 r14155 31 31 32 32 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; 47 35 var aMin = min.RoundDown(decimalRank); 48 36 var aMax = max.RoundUp(decimalRank); … … 60 48 } 61 49 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> 64 53 public static void CalculateOptimalAxisInterval(double min, double max, out double axisMin, out double axisMax, out double axisInterval) { 65 54 CalculateAxisInterval(min, max, 5, out axisMin, out axisMax, out axisInterval); … … 101 90 var floor = (int)Math.Floor(value); 102 91 var pow = (int)Math.Pow(10, decimalRank); 103 // round down to nearest multiple of 5 or 10104 var mod = Math.Min(floor % pow, floor % (pow / 2));92 var mod = floor % pow; 93 if (mod < 0) mod += pow; 105 94 return floor  mod; 106 95 } … … 112 101 var ceil = (int)Math.Ceiling(value); 113 102 var pow = (int)Math.Pow(10, decimalRank); 114 // round up to nearest multiple of 5 or 10115 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; 117 106 } 118 107 return value.Ceil(Math.Abs(decimalRank));
Note: See TracChangeset
for help on using the changeset viewer.