Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12614


Ignore:
Timestamp:
07/06/15 18:00:54 (9 years ago)
Author:
abeham
Message:

#2274: Fixed bug in cluster visualization view and added nicer bounds in scatter plot

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.cs

    r12012 r12614  
    3737    protected List<Series> invisibleSeries;
    3838    protected Dictionary<IObservableList<Point2D<double>>, ScatterPlotDataRow> pointsRowsTable;
     39    private double xMin, xMax, yMin, yMax;
    3940
    4041    public new ScatterPlot Content {
     
    102103        AddScatterPlotDataRows(Content.Rows);
    103104        ConfigureChartArea(chart.ChartAreas[0]);
     105        RecalculateMinMaxPointValues();
    104106        RecalculateAxesScale(chart.ChartAreas[0]);
    105107      }
     
    130132      }
    131133      ConfigureChartArea(chart.ChartAreas[0]);
     134      RecalculateMinMaxPointValues();
    132135      RecalculateAxesScale(chart.ChartAreas[0]);
    133136      UpdateYCursorInterval();
     
    142145          invisibleSeries.Remove(series);
    143146      }
     147      RecalculateMinMaxPointValues();
    144148      RecalculateAxesScale(chart.ChartAreas[0]);
    145149    }
     
    193197    private void RecalculateAxesScale(ChartArea area) {
    194198      // Reset the axes bounds so that RecalculateAxesScale() will assign new bounds
    195       foreach (Axis a in area.Axes) {
    196         a.Minimum = double.NaN;
    197         a.Maximum = double.NaN;
    198       }
    199       area.RecalculateAxesScale();
     199      area.AxisX.Minimum = CalculateMinBound(xMin);
     200      area.AxisX.Maximum = CalculateMaxBound(xMax);
     201      area.AxisY.Minimum = CalculateMinBound(yMin);
     202      area.AxisY.Maximum = CalculateMaxBound(yMax);
    200203      area.AxisX.IsMarginVisible = false;
    201204
     
    204207      if (!Content.VisualProperties.YAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.YAxisMinimumFixedValue)) area.AxisY.Minimum = Content.VisualProperties.YAxisMinimumFixedValue;
    205208      if (!Content.VisualProperties.YAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.YAxisMaximumFixedValue)) area.AxisY.Maximum = Content.VisualProperties.YAxisMaximumFixedValue;
    206       if (area.AxisX.Minimum >= area.AxisX.Maximum) area.AxisX.Maximum = area.AxisX.Minimum + 1;
    207       if (area.AxisY.Minimum >= area.AxisY.Maximum) area.AxisY.Maximum = area.AxisY.Minimum + 1;
     209    }
     210
     211    private static double CalculateMinBound(double min) {
     212      double newMin;
     213      if (min < 0) {
     214        newMin = -Math.Pow(10, Math.Ceiling(Math.Log10(Math.Abs(min))));
     215        if (newMin / 1.25 < min) newMin /= 1.25;
     216        if (newMin / 1.6 < min) newMin /= 1.6;
     217        if (newMin / 2.5 < min) newMin /= 2.5;
     218        if (newMin / 2.0 < min) newMin /= 2.0;
     219      } else {
     220        newMin = Math.Pow(10, Math.Floor(Math.Log10(min)));
     221        if (newMin * 1.25 < min) newMin *= 1.25;
     222        if (newMin * 1.6 < min) newMin *= 1.6;
     223        if (newMin * 2.5 < min) newMin *= 2.5;
     224        if (newMin * 2.0 < min) newMin *= 2.0;
     225      }
     226      return newMin;
     227    }
     228
     229    private static double CalculateMaxBound(double max) {
     230      double newMax;
     231      if (max < 0) {
     232        newMax = -Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(max))));
     233        if (newMax * 1.25 > max) newMax *= 1.25;
     234        if (newMax * 1.6 > max) newMax *= 1.6;
     235        if (newMax * 2.5 > max) newMax *= 2.5;
     236        if (newMax * 2.0 > max) newMax *= 2.0;
     237      } else {
     238        newMax = Math.Pow(10, Math.Ceiling(Math.Log10(max)));
     239        if (newMax / 1.25 > max) newMax /= 1.25;
     240        if (newMax / 1.6 > max) newMax /= 1.6;
     241        if (newMax / 2.5 > max) newMax /= 2.5;
     242        if (newMax / 2.0 > max) newMax /= 2.0;
     243      }
     244      return newMax;
    208245    }
    209246
     
    286323        ConfigureSeries(series, row);
    287324        FillSeriesWithRowValues(series, row);
     325        RecalculateMinMaxPointValues();
    288326        RecalculateAxesScale(chart.ChartAreas[0]);
    289327      }
     
    310348            rowSeries.Points.Clear();
    311349            FillSeriesWithRowValues(rowSeries, row);
     350            RecalculateMinMaxPointValues();
    312351            RecalculateAxesScale(chart.ChartAreas[0]);
    313352            UpdateYCursorInterval();
     
    327366            rowSeries.Points.Clear();
    328367            FillSeriesWithRowValues(rowSeries, row);
     368            RecalculateMinMaxPointValues();
    329369            RecalculateAxesScale(chart.ChartAreas[0]);
    330370            UpdateYCursorInterval();
     
    344384            rowSeries.Points.Clear();
    345385            FillSeriesWithRowValues(rowSeries, row);
     386            RecalculateMinMaxPointValues();
    346387            RecalculateAxesScale(chart.ChartAreas[0]);
    347388            UpdateYCursorInterval();
     
    361402            rowSeries.Points.Clear();
    362403            FillSeriesWithRowValues(rowSeries, row);
     404            RecalculateMinMaxPointValues();
    363405            RecalculateAxesScale(chart.ChartAreas[0]);
    364406            UpdateYCursorInterval();
     
    401443        series.Points.Clear();
    402444        invisibleSeries.Add(series);
     445        RecalculateMinMaxPointValues();
    403446      } else {
    404447        invisibleSeries.Remove(series);
     
    409452                     select r).Single();
    410453          FillSeriesWithRowValues(series, row);
     454          RecalculateMinMaxPointValues();
    411455          this.chart.Legends[series.Legend].ForeColor = Color.Black;
    412456          RecalculateAxesScale(chart.ChartAreas[0]);
    413457          UpdateYCursorInterval();
     458        }
     459      }
     460    }
     461
     462    private void RecalculateMinMaxPointValues() {
     463      yMin = xMin = double.MaxValue;
     464      yMax = xMax = double.MinValue;
     465      foreach (var s in chart.Series.Where(x => x.Enabled)) {
     466        foreach (var p in s.Points) {
     467          double x = p.XValue, y = p.YValues[0];
     468          if (xMin > x) xMin = x;
     469          if (xMax < x) xMax = x;
     470          if (yMin > y) yMin = y;
     471          if (yMax < y) yMax = y;
    414472        }
    415473      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Clustering/ClusteringSolutionVisualizationView.cs

    r12509 r12614  
    8181
    8282      int idx = 0;
     83      var oneDim = reduced.GetLength(1) == 1;
    8384      foreach (var r in range) {
    84         rows[classes[r].Item2].Points.Add(new Point2D<double>(reduced[idx, 0], reduced[idx, 1]));
     85        Point2D<double> point;
     86        point = oneDim ? new Point2D<double>(reduced[idx, 0], 0.0) : new Point2D<double>(reduced[idx, 0], reduced[idx, 1]);
     87        rows[classes[r].Item2].Points.Add(point);
    8588        idx++;
    8689      }
     
    106109      alglib.pcabuildbasis(data, instances.Length, attributes.Length, out info, out variances, out matrix);
    107110
    108       var result = new double[instances.Length, 2];
     111      var result = new double[instances.Length, matrix.GetLength(1)];
    109112      int r = 0;
    110113      foreach (var inst in instances) {
Note: See TracChangeset for help on using the changeset viewer.