- Timestamp:
- 04/03/12 15:33:08 (13 years ago)
- 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
r7700 r7701 49 49 this.chart.TabIndex = 0; 50 50 this.chart.Text = "chart"; 51 this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);52 51 this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.Chart_MouseDoubleClick); 53 52 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 54 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);55 53 // 56 54 // label1 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionErrorCharacteristicsCurveView.cs
r7700 r7701 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing;25 24 using System.Linq; 26 25 using System.Windows.Forms; … … 28 27 using HeuristicLab.MainForm; 29 28 using HeuristicLab.MainForm.WindowsForms; 29 30 30 namespace HeuristicLab.Problems.DataAnalysis.Views { 31 31 [View("Error Characteristics Curve")] … … 37 37 protected const string AllSamples = "All Samples"; 38 38 39 protected Dictionary<string, List<double>> seriesResiduals = new Dictionary<string, List<double>>();40 41 39 public RegressionSolutionErrorCharacteristicsCurveView() 42 40 : base() { … … 102 100 protected virtual void UpdateChart() { 103 101 chart.Series.Clear(); 104 seriesResiduals.Clear();105 102 chart.Annotations.Clear(); 106 103 if (Content == null) return; … … 117 114 Series baselineSeries = new Series("Baseline"); 118 115 baselineSeries.ChartType = SeriesChartType.FastLine; 119 seriesResiduals[baselineSeries.Name] = baselineResiduals;120 116 UpdateSeries(baselineResiduals, baselineSeries); 121 117 baselineSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(baselineSeries); … … 133 129 solutionSeries.ChartType = SeriesChartType.FastLine; 134 130 var estimatedValues = GetResiduals(GetOriginalValues(), GetEstimatedValues(solution)); 135 seriesResiduals[solutionSeries.Name] = estimatedValues;136 131 UpdateSeries(estimatedValues, solutionSeries); 137 132 solutionSeries.ToolTip = "Area over Curve: " + CalculateAreaOverCurve(solutionSeries); … … 235 230 } 236 231 237 #region events232 #region Baseline 238 233 private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) { 239 234 HitTestResult result = chart.HitTest(e.X, e.Y); 240 235 if (result.ChartElementType != ChartElementType.LegendItem) return; 241 if (result.Series.Name != constantModel.Name) return;242 236 243 237 MainFormManager.MainForm.ShowContent((IRegressionSolution)result.Series.Tag); 244 238 } 239 240 private IRegressionSolution CreateConstantModel() { 241 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average(); 242 var solution = new ConstantRegressionModel(averageTrainingTarget).CreateRegressionSolution(ProblemData); 243 solution.Name = "Baseline"; 244 return solution; 245 } 246 #endregion 247 245 248 private void chart_MouseMove(object sender, MouseEventArgs e) { 246 249 HitTestResult result = chart.HitTest(e.X, e.Y); … … 250 253 Cursor = Cursors.Default; 251 254 } 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 #endregion264 265 private IRegressionSolution CreateConstantModel() {266 double averageTrainingTarget = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndizes).Average();267 var solution = new ConstantRegressionModel(averageTrainingTarget).CreateRegressionSolution(ProblemData);268 solution.Name = "Baseline";269 return solution;270 }271 272 private void ToggleSeriesData(Series series) {273 if (series.Points.Count > 0) { //checks if series is shown274 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-performance288 private static void ClearPointsQuick(DataPointCollection points) {289 points.SuspendUpdates();290 while (points.Count > 0)291 points.RemoveAt(points.Count - 1);292 points.ResumeUpdates();293 }294 255 } 295 256 }
Note: See TracChangeset
for help on using the changeset viewer.