Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15239


Ignore:
Timestamp:
07/13/17 17:48:57 (7 years ago)
Author:
mkommend
Message:

#2807: Merged r15211, r15213, r15222 into stable.

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.DataAnalysis.Views

  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/FactorPartialDependencePlot.cs

    r15148 r15239  
    7373        if (value != yAxisTicks) {
    7474          yAxisTicks = value;
    75           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     75          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    7676          RecalculateInternalDataset();
    7777        }
     
    8484        if ((value.HasValue && fixedYAxisMin.HasValue && !value.Value.IsAlmost(fixedYAxisMin.Value)) || (value.HasValue != fixedYAxisMin.HasValue)) {
    8585          fixedYAxisMin = value;
    86           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     86          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    8787        }
    8888      }
     
    9494        if ((value.HasValue && fixedYAxisMax.HasValue && !value.Value.IsAlmost(fixedYAxisMax.Value)) || (value.HasValue != fixedYAxisMax.HasValue)) {
    9595          fixedYAxisMax = value;
    96           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     96          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    9797        }
    9898      }
     
    209209      try {
    210210        var limits = await UpdateAllSeriesDataAsync(cancellationToken);
     211        chart.Invalidate();
    211212
    212213        yMin = limits.Lower;
     
    214215        // Set y-axis
    215216        if (resetYAxis)
    216           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     217          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    217218
    218219        calculationPendingTimer.Stop();
     
    220221        if (updateOnFinish)
    221222          Update();
    222       } catch (OperationCanceledException) { } catch (AggregateException ae) {
     223      }
     224      catch (OperationCanceledException) { }
     225      catch (AggregateException ae) {
    223226        if (!ae.InnerExceptions.Any(e => e is OperationCanceledException))
    224227          throw;
     
    235238    }
    236239
    237     private void SetupAxis(Axis axis, double minValue, double maxValue, int ticks, double? fixedAxisMin, double? fixedAxisMax) {
    238       if (minValue < maxValue) {
    239         double axisMin, axisMax, axisInterval;
    240         ChartUtil.CalculateAxisInterval(minValue, maxValue, ticks, out axisMin, out axisMax, out axisInterval);
    241         axis.Minimum = fixedAxisMin ?? axisMin;
    242         axis.Maximum = fixedAxisMax ?? axisMax;
    243         axis.Interval = (axis.Maximum - axis.Minimum) / ticks;
    244       }
    245 
    246       try {
    247         chart.ChartAreas[0].RecalculateAxesScale();
    248       } catch (InvalidOperationException) {
    249         // Can occur if eg. axis min == axis max
    250       }
     240    private static void SetupAxis(EnhancedChart chart, Axis axis, double minValue, double maxValue, int ticks, double? fixedAxisMin, double? fixedAxisMax) {
     241      //guard if only one distinct value is present
     242      if (minValue.IsAlmost(maxValue)) {
     243        minValue = minValue - 0.5;
     244        maxValue = minValue + 0.5;
     245      }
     246
     247      double axisMin, axisMax, axisInterval;
     248      ChartUtil.CalculateAxisInterval(minValue, maxValue, ticks, out axisMin, out axisMax, out axisInterval);
     249      axis.Minimum = fixedAxisMin ?? axisMin;
     250      axis.Maximum = fixedAxisMax ?? axisMax;
     251      axis.Interval = (axis.Maximum - axis.Minimum) / ticks;
     252
     253      chart.ChartAreas[0].RecalculateAxesScale();
    251254    }
    252255
     
    343346          if (yvalues[i] > max) max = yvalues[i];
    344347        }
    345         chart.Invalidate();
    346348
    347349        cancellationToken.ThrowIfCancellationRequested();
     
    358360            if (upper > max) max = upper;
    359361          }
    360           chart.Invalidate();
    361362        }
    362363
  • stable/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/PartialDependencePlot.cs

    r15137 r15239  
    8282        if (value != xAxisTicks) {
    8383          xAxisTicks = value;
    84           SetupAxis(chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
     84          SetupAxis(chart, chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
    8585          RecalculateInternalDataset();
    8686        }
     
    9393        if ((value.HasValue && fixedXAxisMin.HasValue && !value.Value.IsAlmost(fixedXAxisMin.Value)) || (value.HasValue != fixedXAxisMin.HasValue)) {
    9494          fixedXAxisMin = value;
    95           if (trainingMin < trainingMax) {
    96             SetupAxis(chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
    97             RecalculateInternalDataset();
    98             // set the vertical line position
    99             if (VerticalLineAnnotation.X <= fixedXAxisMin) {
    100               var axisX = chart.ChartAreas[0].AxisX;
    101               var step = (axisX.Maximum - axisX.Minimum) / drawingSteps;
    102               VerticalLineAnnotation.X = axisX.Minimum + step;
    103             }
     95          SetupAxis(chart, chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
     96          RecalculateInternalDataset();
     97          // set the vertical line position
     98          if (VerticalLineAnnotation.X <= fixedXAxisMin) {
     99            var axisX = chart.ChartAreas[0].AxisX;
     100            var step = (axisX.Maximum - axisX.Minimum) / drawingSteps;
     101            VerticalLineAnnotation.X = axisX.Minimum + step;
    104102          }
    105103        }
     
    112110        if ((value.HasValue && fixedXAxisMax.HasValue && !value.Value.IsAlmost(fixedXAxisMax.Value)) || (value.HasValue != fixedXAxisMax.HasValue)) {
    113111          fixedXAxisMax = value;
    114           if (trainingMin < trainingMax) {
    115             SetupAxis(chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
    116             RecalculateInternalDataset();
    117             // set the vertical line position
    118             if (VerticalLineAnnotation.X >= fixedXAxisMax) {
    119               var axisX = chart.ChartAreas[0].AxisX;
    120               var step = (axisX.Maximum - axisX.Minimum) / drawingSteps;
    121               VerticalLineAnnotation.X = axisX.Maximum - step;
    122             }
     112          SetupAxis(chart, chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
     113          RecalculateInternalDataset();
     114          // set the vertical line position
     115          if (VerticalLineAnnotation.X >= fixedXAxisMax) {
     116            var axisX = chart.ChartAreas[0].AxisX;
     117            var step = (axisX.Maximum - axisX.Minimum) / drawingSteps;
     118            VerticalLineAnnotation.X = axisX.Maximum - step;
    123119          }
    124120        }
     
    132128        if (value != yAxisTicks) {
    133129          yAxisTicks = value;
    134           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     130          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    135131          RecalculateInternalDataset();
    136132        }
     
    143139        if ((value.HasValue && fixedYAxisMin.HasValue && !value.Value.IsAlmost(fixedYAxisMin.Value)) || (value.HasValue != fixedYAxisMin.HasValue)) {
    144140          fixedYAxisMin = value;
    145           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     141          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    146142        }
    147143      }
     
    153149        if ((value.HasValue && fixedYAxisMax.HasValue && !value.Value.IsAlmost(fixedYAxisMax.Value)) || (value.HasValue != fixedYAxisMax.HasValue)) {
    154150          fixedYAxisMax = value;
    155           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    156         }
    157       }
    158     }
    159 
    160     private double trainingMin = 1;
    161     private double trainingMax = -1;
     151          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     152        }
     153      }
     154    }
     155
     156    private double trainingMin = -1;
     157    private double trainingMax = 1;
    162158
    163159    private int drawingSteps = 1000;
     
    293289      if (IsDisposed
    294290        || sharedFixedVariables == null || !solutions.Any() || string.IsNullOrEmpty(freeVariable)
    295         || trainingMin.IsAlmost(trainingMax) || trainingMin > trainingMax || drawingSteps == 0)
     291        || trainingMin > trainingMax || drawingSteps == 0)
    296292        return;
    297293
     
    307303      try {
    308304        var limits = await UpdateAllSeriesDataAsync(cancellationToken);
     305        chart.Invalidate();
    309306
    310307        yMin = limits.Lower;
     
    312309        // Set y-axis
    313310        if (resetYAxis)
    314           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     311          SetupAxis(chart, chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    315312
    316313        UpdateOutOfTrainingRangeStripLines();
     
    320317        if (updateOnFinish)
    321318          Update();
    322       } catch (OperationCanceledException) { } catch (AggregateException ae) {
     319      }
     320      catch (OperationCanceledException) { }
     321      catch (AggregateException ae) {
    323322        if (!ae.InnerExceptions.Any(e => e is OperationCanceledException))
    324323          throw;
     
    335334    }
    336335
    337     private void SetupAxis(Axis axis, double minValue, double maxValue, int ticks, double? fixedAxisMin, double? fixedAxisMax) {
    338       if (minValue < maxValue) {
    339         double axisMin, axisMax, axisInterval;
    340         ChartUtil.CalculateAxisInterval(minValue, maxValue, ticks, out axisMin, out axisMax, out axisInterval);
    341         axis.Minimum = fixedAxisMin ?? axisMin;
    342         axis.Maximum = fixedAxisMax ?? axisMax;
    343         axis.Interval = (axis.Maximum - axis.Minimum) / ticks;
    344       }
    345 
    346       try {
    347         chart.ChartAreas[0].RecalculateAxesScale();
    348       } catch (InvalidOperationException) {
    349         // Can occur if eg. axis min == axis max
    350       }
     336    private static void SetupAxis(EnhancedChart chart, Axis axis, double minValue, double maxValue, int ticks, double? fixedAxisMin, double? fixedAxisMax) {
     337      //guard if only one distinct value is present
     338      if (minValue.IsAlmost(maxValue)) {
     339        minValue = minValue - 0.5;
     340        maxValue = minValue + 0.5;
     341      }
     342
     343      double axisMin, axisMax, axisInterval;
     344      ChartUtil.CalculateAxisInterval(minValue, maxValue, ticks, out axisMin, out axisMax, out axisInterval);
     345      axis.Minimum = fixedAxisMin ?? axisMin;
     346      axis.Maximum = fixedAxisMax ?? axisMax;
     347      axis.Interval = (axis.Maximum - axis.Minimum) / ticks;
     348
     349      chart.ChartAreas[0].RecalculateAxesScale();
    351350    }
    352351
     
    357356      if (initializeAxisRanges) {
    358357        double xmin, xmax, xinterval;
    359         ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval);
     358        //guard if only one distinct value is present
     359        if (trainingMin.IsAlmost(trainingMax))
     360          ChartUtil.CalculateAxisInterval(trainingMin - 0.5, trainingMax + 0.5, XAxisTicks, out xmin, out xmax, out xinterval);
     361        else
     362          ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval);
     363
    360364        FixedXAxisMin = xmin;
    361365        FixedXAxisMax = xmax;
     
    369373      // we expand the range in order to get nice tick intervals on the x axis
    370374      double xmin, xmax, xinterval;
    371       ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval);
     375      //guard if only one distinct value is present
     376      if (trainingMin.IsAlmost(trainingMax))
     377        ChartUtil.CalculateAxisInterval(trainingMin - 0.5, trainingMin + 0.5, XAxisTicks, out xmin, out xmax, out xinterval);
     378      else
     379        ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval);
    372380
    373381      if (FixedXAxisMin.HasValue) xmin = FixedXAxisMin.Value;
     
    470478          if (yvalues[i] > max) max = yvalues[i];
    471479        }
    472         chart.Invalidate();
    473480
    474481        cancellationToken.ThrowIfCancellationRequested();
     
    485492            if (upper > max) max = upper;
    486493          }
    487           chart.Invalidate();
    488494        }
    489495
Note: See TracChangeset for help on using the changeset viewer.