Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/06/16 14:50:17 (8 years ago)
Author:
bburlacu
Message:

#2594: Added chart util method to calculate the "optimal" axis interval (reducing the number of fractional digits to make it look nice). Modified the regression solution line chart and scatter plot to use the new scaling method.

File:
1 edited

Legend:

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

    r14007 r14008  
    4343    }
    4444
     45    // this method tries to find an axis interval with as few fractional digits as possible (because it looks nicer)
     46    // we only try between 3 and 5 ticks (inclusive) because it wouldn't make sense to exceed this interval
     47    public static void CalculateOptimalAxisInterval(double min, double max, out double axisMin, out double axisMax, out double axisInterval) {
     48      CalculateAxisInterval(min, max, 5, out axisMin, out axisMax, out axisInterval);
     49      int bestLsp = int.MaxValue;
     50      for (int ticks = 3; ticks <= 5; ++ticks) {
     51        double aMin, aMax, aInterval;
     52        CalculateAxisInterval(min, max, ticks, out aMin, out aMax, out aInterval);
     53        var x = aInterval;
     54        int lsp = 0; // position of the least significant fractional digit
     55        while (x - Math.Floor(x) > 0) {
     56          ++lsp;
     57          x *= 10;
     58        }
     59        if (lsp <= bestLsp) {
     60          axisMin = aMin;
     61          axisMax = aMax;
     62          axisInterval = aInterval;
     63          bestLsp = lsp;
     64        }
     65      }
     66    }
     67
    4568    private static int Decimals(this double x) {
    4669      if (x.IsAlmost(0) || double.IsInfinity(x) || double.IsNaN(x))
     
    4871
    4972      var v = Math.Abs(x);
    50       int d = 0;
     73      int d = 1;
    5174      while (v < 1) {
    5275        v *= 10;
Note: See TracChangeset for help on using the changeset viewer.