# Changeset 14155

Ignore:
Timestamp:
07/21/16 15:13:08 (11 months ago)
Message:

#2594: Improved axis scaling.

File:
1 edited

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

 r14152 var range = max - min; var minLog = Math.Log10(Math.Abs(min)); var maxLog = Math.Log10(Math.Abs(max)); var rangeLog = Math.Log10(range); var dMin = (int)Math.Floor(minLog); var dMax = (int)Math.Floor(maxLog); var dRange = (int)Math.Floor(rangeLog); int decimalRank; if (dMin == dMax && dMax == dRange) decimalRank = dMin - 1; else decimalRank = Math.Min(Math.Min(dMin, dMax), dRange); var dRange = (int)Math.Round(Math.Log10(range)); int decimalRank = dRange - 1; var aMin = min.RoundDown(decimalRank); var aMax = max.RoundUp(decimalRank); } // this method 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 /// /// 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. /// public static void CalculateOptimalAxisInterval(double min, double max, out double axisMin, out double axisMax, out double axisInterval) { CalculateAxisInterval(min, max, 5, out axisMin, out axisMax, out axisInterval); var floor = (int)Math.Floor(value); var pow = (int)Math.Pow(10, decimalRank); // round down to nearest multiple of 5 or 10 var mod = Math.Min(floor % pow, floor % (pow / 2)); var mod = floor % pow; if (mod < 0) mod += pow; return floor - mod; } var ceil = (int)Math.Ceiling(value); var pow = (int)Math.Pow(10, decimalRank); // round up to nearest multiple of 5 or 10 var mod = ceil % (pow / 2) == 0 || ceil % pow == 0 ? 0 : Math.Min(pow / 2 - ceil % (pow / 2), pow - ceil % pow); return ceil + mod; var mod = ceil % pow; if (mod < 0) mod += pow; return ceil - mod + pow; } return value.Ceil(Math.Abs(decimalRank));
Note: See TracChangeset for help on using the changeset viewer.