Changeset 7700


Ignore:
Timestamp:
Apr 3, 2012, 2:32:24 PM (2 years ago)
Author:
sforsten
Message:

#1811:

  • added toggle of series
  • changed existing MouseDown event to MouseDoubleClick
  • renamed "Mean Model" to "Baseline". For consistence some variable names also have been renamed
Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression
Files:
2 edited

Legend:

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

    r7043 r7700  
    4949      this.chart.TabIndex = 0; 
    5050      this.chart.Text = "chart"; 
     51      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend); 
     52      this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Chart_MouseDoubleClick); 
     53      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 
    5154      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 
    5255      //  
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs

    r7259 r7700  
    2222using System; 
    2323using System.Collections.Generic; 
     24using System.Drawing; 
    2425using System.Linq; 
    2526using System.Windows.Forms; 
     
    3637    protected const string AllSamples = "All Samples"; 
    3738 
     39    protected Dictionary<string, List<double>> seriesResiduals = new Dictionary<string, List<double>>(); 
     40 
    3841    public RegressionSolutionErrorCharacteristicsCurveView() 
    3942      : base() { 
     
    99102    protected virtual void UpdateChart() { 
    100103      chart.Series.Clear(); 
     104      seriesResiduals.Clear(); 
    101105      chart.Annotations.Clear(); 
    102106      if (Content == null) return; 
     
    104108      var originalValues = GetOriginalValues().ToList(); 
    105109      constantModel = CreateConstantModel(); 
    106       var meanModelEstimatedValues = GetEstimatedValues(constantModel); 
    107       var meanModelResiduals = GetResiduals(originalValues, meanModelEstimatedValues); 
    108  
    109       meanModelResiduals.Sort(); 
    110       chart.ChartAreas[0].AxisX.Maximum = Math.Ceiling(meanModelResiduals.Last()); 
    111       chart.ChartAreas[0].CursorX.Interval = meanModelResiduals.First() / 100; 
    112  
    113       Series meanModelSeries = new Series("Mean Model"); 
    114       meanModelSeries.ChartType = SeriesChartType.FastLine; 
    115       UpdateSeries(meanModelResiduals, meanModelSeries); 
    116       meanModelSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(meanModelSeries); 
    117       meanModelSeries.Tag = constantModel; 
    118       chart.Series.Add(meanModelSeries); 
     110      var baselineEstimatedValues = GetEstimatedValues(constantModel); 
     111      var baselineResiduals = GetResiduals(originalValues, baselineEstimatedValues); 
     112 
     113      baselineResiduals.Sort(); 
     114      chart.ChartAreas[0].AxisX.Maximum = Math.Ceiling(baselineResiduals.Last()); 
     115      chart.ChartAreas[0].CursorX.Interval = baselineResiduals.First() / 100; 
     116 
     117      Series baselineSeries = new Series("Baseline"); 
     118      baselineSeries.ChartType = SeriesChartType.FastLine; 
     119      seriesResiduals[baselineSeries.Name] = baselineResiduals; 
     120      UpdateSeries(baselineResiduals, baselineSeries); 
     121      baselineSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(baselineSeries); 
     122      baselineSeries.Tag = constantModel; 
     123      chart.Series.Add(baselineSeries); 
    119124 
    120125      AddRegressionSolution(Content); 
     
    128133      solutionSeries.ChartType = SeriesChartType.FastLine; 
    129134      var estimatedValues = GetResiduals(GetOriginalValues(), GetEstimatedValues(solution)); 
     135      seriesResiduals[solutionSeries.Name] = estimatedValues; 
    130136      UpdateSeries(estimatedValues, solutionSeries); 
    131137      solutionSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(solutionSeries); 
     
    200206    } 
    201207 
    202     protected IEnumerable<double> GetMeanModelEstimatedValues(IEnumerable<double> originalValues) { 
     208    protected IEnumerable<double> GetbaselineEstimatedValues(IEnumerable<double> originalValues) { 
    203209      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average(); 
    204210      return Enumerable.Repeat(averageTrainingTarget, originalValues.Count()); 
     
    229235    } 
    230236 
    231     #region Mean Model 
    232     private void chart_MouseDown(object sender, MouseEventArgs e) { 
    233       if (e.Clicks < 2) return; 
     237    #region events 
     238    private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) { 
    234239      HitTestResult result = chart.HitTest(e.X, e.Y); 
    235240      if (result.ChartElementType != ChartElementType.LegendItem) return; 
     
    238243      MainFormManager.MainForm.ShowContent((IRegressionSolution)result.Series.Tag); 
    239244    } 
     245    private void chart_MouseMove(object sender, MouseEventArgs e) { 
     246      HitTestResult result = chart.HitTest(e.X, e.Y); 
     247      if (result.ChartElementType == ChartElementType.LegendItem) 
     248        Cursor = Cursors.Hand; 
     249      else 
     250        Cursor = Cursors.Default; 
     251    } 
     252    private void chart_MouseDown(object sender, MouseEventArgs e) { 
     253      HitTestResult result = chart.HitTest(e.X, e.Y); 
     254      if (result.ChartElementType == ChartElementType.LegendItem) { 
     255        ToggleSeriesData(result.Series); 
     256      } 
     257    } 
     258    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 
     259      foreach (LegendItem legend in e.LegendItems) { 
     260        legend.Cells[1].ForeColor = this.chart.Series[legend.SeriesName].Points.Count == 0 ? Color.Gray : Color.Black; 
     261      } 
     262    } 
     263    #endregion 
    240264 
    241265    private IRegressionSolution CreateConstantModel() { 
    242266      double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average(); 
    243267      var solution = new ConstantRegressionModel(averageTrainingTarget).CreateRegressionSolution(ProblemData); 
    244       solution.Name = "Mean Model"; 
     268      solution.Name = "Baseline"; 
    245269      return solution; 
    246270    } 
    247     #endregion 
     271 
     272    private void ToggleSeriesData(Series series) { 
     273      if (series.Points.Count > 0) {  //checks if series is shown 
     274        if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) { 
     275          ClearPointsQuick(series.Points); 
     276        } 
     277      } else if (Content != null) { 
     278        List<double> residuals; 
     279        if (seriesResiduals.TryGetValue(series.Name, out residuals)) { 
     280          UpdateSeries(residuals, series); 
     281          chart.Legends[series.Legend].ForeColor = Color.Black; 
     282          chart.Refresh(); 
     283        } 
     284      } 
     285    } 
     286 
     287    // workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance 
     288    private static void ClearPointsQuick(DataPointCollection points) { 
     289      points.SuspendUpdates(); 
     290      while (points.Count > 0) 
     291        points.RemoveAt(points.Count - 1); 
     292      points.ResumeUpdates(); 
     293    } 
    248294  } 
    249295} 
Note: See TracChangeset for help on using the changeset viewer.