Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/24/12 16:50:51 (13 years ago)
Author:
bburlacu
Message:

#1756: Fixed line chart behavior for cases when the data point series are not continuous (some indices are not consecutive).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r7335 r7406  
    2626using System.Windows.Forms.DataVisualization.Charting;
    2727using HeuristicLab.MainForm;
    28 using HeuristicLab.MainForm.WindowsForms;
    2928
    3029namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    6665        this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable;
    6766        this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    68         this.chart.Series[TARGETVARIABLE_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Color;
    6967        this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
    7068          Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
     
    7573        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Color;
    7674        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray());
     75        this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME]);
    7776        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
    7877        // test series
     
    8079        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
    8180        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    82         this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Color;
    8381        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), Content.EstimatedTestValues.ToArray());
     82        this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME]);
    8483        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;
    8584        // series of remaining points
     
    8786        var estimatedValues = Content.EstimatedValues.ToArray();
    8887        List<double> allEstimatedValues = allIndizes.Select(index => estimatedValues[index]).ToList();
    89 
    9088        this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
    9189        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
    9290        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    93         this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Color;
    9491        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndizes, allEstimatedValues);
     92        this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
    9593        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Tag = Content;
    9694        this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
     
    9896        UpdateCursorInterval();
    9997        this.UpdateStripLines();
     98      }
     99    }
     100
     101    private void InsertEmptyPoints(Series series) {
     102      int i = 0;
     103      while (i < series.Points.Count - 1) {
     104        if (series.Points[i].IsEmpty) {
     105          ++i;
     106          continue;
     107        }
     108
     109        var p1 = series.Points[i];
     110        var p2 = series.Points[i + 1];
     111        // check for consecutive indices
     112        if ((int)p2.XValue - (int)p1.XValue != 1) {
     113          // insert an empty point between p1 and p2 so that the line will be invisible (transparent)
     114          var p = new DataPoint((int)((p1.XValue + p2.XValue) / 2), 0.0) { IsEmpty = true };
     115          series.Points.Insert(i + 1, p);
     116        }
     117        ++i;
    100118      }
    101119    }
     
    200218      if (series.Points.Count > 0) {  //checks if series is shown
    201219        if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) {
    202           series.Points.Clear();
     220          ClearPointsQuick(series.Points);
    203221        }
    204222      } else if (Content != null) {
     
    223241        }
    224242        series.Points.DataBindXY(indizes, predictedValues);
     243        this.InsertEmptyPoints(series);
    225244        chart.Legends[series.Legend].ForeColor = Color.Black;
    226245        UpdateCursorInterval();
    227246        chart.Refresh();
    228247      }
     248    }
     249
     250    // workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance
     251    private static void ClearPointsQuick(DataPointCollection points) {
     252      points.SuspendUpdates();
     253      while (points.Count > 0)
     254        points.RemoveAt(points.Count - 1);
     255      points.ResumeUpdates();
    229256    }
    230257
Note: See TracChangeset for help on using the changeset viewer.