Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/06/12 17:50:17 (13 years ago)
Author:
gkronber
Message:

#1081: merged r7266:7459 from the trunk into the time series prognosis branch.

Location:
branches/HeuristicLab.TimeSeries
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.TimeSeries

  • branches/HeuristicLab.TimeSeries/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r7268 r7460  
    2626using System.Windows.Forms.DataVisualization.Charting;
    2727using HeuristicLab.MainForm;
    28 using HeuristicLab.MainForm.WindowsForms;
    2928
    3029namespace HeuristicLab.Problems.DataAnalysis.Views {
     
    6867        this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
    6968          Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
    70 
     69        // training series
    7170        this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
    7271        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
    7372        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType = SeriesChartType.FastLine;
     73        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Color;
    7474        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]);
    7576        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
    76         this.chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, ESTIMATEDVALUES_TRAINING_SERIES_NAME);
    77         this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.BorderWidth = 0;
    78         this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.MarkerStyle = MarkerStyle.None;
    79 
    80 
     77        // test series
    8178        this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
    8279        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
    8380        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    8481        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]);
    8583        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;
    86 
    87 
     84        // series of remaining points
    8885        int[] allIndizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndizes).Except(Content.ProblemData.TestIndizes).ToArray();
    8986        var estimatedValues = Content.EstimatedValues.ToArray();
    9087        List<double> allEstimatedValues = allIndizes.Select(index => estimatedValues[index]).ToList();
    91 
    9288        this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
    9389        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
    9490        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    9591        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndizes, allEstimatedValues);
     92        this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
    9693        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Tag = Content;
    97         this.chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, ESTIMATEDVALUES_ALL_SERIES_NAME);
    98         this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.BorderWidth = 0;
    99         this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.MarkerStyle = MarkerStyle.None;
    10094        this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
    10195
    10296        UpdateCursorInterval();
    10397        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;
    104118      }
    105119    }
     
    204218      if (series.Points.Count > 0) {  //checks if series is shown
    205219        if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) {
    206           series.Points.Clear();
     220          ClearPointsQuick(series.Points);
    207221        }
    208222      } else if (Content != null) {
     
    227241        }
    228242        series.Points.DataBindXY(indizes, predictedValues);
    229         chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, series.Name);
     243        this.InsertEmptyPoints(series);
    230244        chart.Legends[series.Legend].ForeColor = Color.Black;
    231245        UpdateCursorInterval();
    232246        chart.Refresh();
    233247      }
     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();
    234256    }
    235257
Note: See TracChangeset for help on using the changeset viewer.