Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/12/17 16:00:13 (7 years ago)
Author:
mkommend
Message:

#2807: Made partial dependence plot work with constant variable values.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Controls/FactorPartialDependencePlot.cs

    r15054 r15211  
    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       }
     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;
    245252
    246253      try {
    247254        chart.ChartAreas[0].RecalculateAxesScale();
    248       } catch (InvalidOperationException) {
     255      }
     256      catch (InvalidOperationException) {
    249257        // Can occur if eg. axis min == axis max
    250258      }
     
    343351          if (yvalues[i] > max) max = yvalues[i];
    344352        }
    345         chart.Invalidate();
    346353
    347354        cancellationToken.ThrowIfCancellationRequested();
     
    358365            if (upper > max) max = upper;
    359366          }
    360           chart.Invalidate();
    361367        }
    362368
Note: See TracChangeset for help on using the changeset viewer.