Changeset 6784 for branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs
- Timestamp:
- 09/16/11 12:00:36 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs
r6647 r6784 20 20 #endregion 21 21 using System; 22 using System.Collections.Generic; 22 23 using System.Drawing; 23 24 using System.Linq; … … 34 35 private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Values (training)"; 35 36 private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Values (test)"; 37 private const string ESTIMATEDVALUES_ALL_SERIES_NAME = "Estimated Values (all samples)"; 36 38 37 39 public new IRegressionSolution Content { … … 65 67 this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine; 66 68 this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(), 67 Content.ProblemData.Dataset.Get VariableValues(Content.ProblemData.TargetVariable));69 Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray()); 68 70 69 71 this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME); 70 72 this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME; 71 73 this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType = SeriesChartType.FastLine; 72 this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), 73 Content.EstimatedTrainingValues.ToArray()); 74 this.chart.DataManipulator.InsertEmptyPoints(Content.ProblemData.Dataset.Rows, IntervalType.Number, ESTIMATEDVALUES_TRAINING_SERIES_NAME); 74 this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray()); 75 75 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 76 80 77 81 this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME); 78 82 this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME; 79 83 this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType = SeriesChartType.FastLine; 80 this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), 81 Content.EstimatedTestValues.ToArray()); 84 this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), Content.EstimatedTestValues.ToArray()); 82 85 this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content; 86 87 88 int[] allIndizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndizes).Except(Content.ProblemData.TestIndizes).ToArray(); 89 var estimatedValues = Content.EstimatedValues.ToArray(); 90 List<double> allEstimatedValues = allIndizes.Select(index => estimatedValues[index]).ToList(); 91 92 this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME); 93 this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME; 94 this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType = SeriesChartType.FastLine; 95 this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndizes, allEstimatedValues); 96 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; 100 this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]); 101 83 102 UpdateCursorInterval(); 84 103 this.UpdateStripLines(); … … 109 128 } 110 129 111 private void Content_ProblemDataChanged(object sender, EventArgs e) {112 RedrawChart();113 }114 115 private void Content_ModelChanged(object sender, EventArgs e) {116 UpdateEstimatedValuesLineChart();117 }118 119 130 protected override void OnContentChanged() { 120 131 base.OnContentChanged(); 121 132 RedrawChart(); 122 133 } 123 124 private void UpdateEstimatedValuesLineChart() { 125 if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart); 126 else { 127 if (this.chart.Series.Count > 0) { 128 Series s = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME]; 129 if (s != null) { 130 s.Points.DataBindXY(Content.ProblemData.TrainingIndizes.ToArray(), Content.EstimatedTrainingValues.ToArray()); 131 s.LegendText = ESTIMATEDVALUES_TRAINING_SERIES_NAME; 132 } 133 s = this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME]; 134 if (s != null) { 135 s.Points.DataBindXY(Content.ProblemData.TestIndizes.ToArray(), Content.EstimatedTestValues.ToArray()); 136 s.LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME; 137 } 138 this.UpdateStripLines(); 139 UpdateCursorInterval(); 140 } 141 } 142 } 134 private void Content_ProblemDataChanged(object sender, EventArgs e) { 135 RedrawChart(); 136 } 137 private void Content_ModelChanged(object sender, EventArgs e) { 138 RedrawChart(); 139 } 140 141 143 142 144 143 private void Chart_MouseDoubleClick(object sender, MouseEventArgs e) { … … 201 200 this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine); 202 201 } 202 203 private void ToggleSeriesData(Series series) { 204 if (series.Points.Count > 0) { //checks if series is shown 205 if (this.chart.Series.Any(s => s != series && s.Points.Count > 0)) { 206 series.Points.Clear(); 207 } 208 } else if (Content != null) { 209 string targetVariableName = Content.ProblemData.TargetVariable; 210 211 IEnumerable<int> indizes = null; 212 IEnumerable<double> predictedValues = null; 213 switch (series.Name) { 214 case ESTIMATEDVALUES_ALL_SERIES_NAME: 215 indizes = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndizes).Except(Content.ProblemData.TestIndizes).ToArray(); 216 var estimatedValues = Content.EstimatedValues.ToArray(); 217 predictedValues = indizes.Select(index => estimatedValues[index]).ToList(); 218 break; 219 case ESTIMATEDVALUES_TRAINING_SERIES_NAME: 220 indizes = Content.ProblemData.TrainingIndizes.ToArray(); 221 predictedValues = Content.EstimatedTrainingValues.ToArray(); 222 break; 223 case ESTIMATEDVALUES_TEST_SERIES_NAME: 224 indizes = Content.ProblemData.TestIndizes.ToArray(); 225 predictedValues = Content.EstimatedTestValues.ToArray(); 226 break; 227 } 228 series.Points.DataBindXY(indizes, predictedValues); 229 chart.DataManipulator.InsertEmptyPoints(1, IntervalType.Number, series.Name); 230 chart.Legends[series.Legend].ForeColor = Color.Black; 231 UpdateCursorInterval(); 232 chart.Refresh(); 233 } 234 } 235 236 private void chart_MouseMove(object sender, MouseEventArgs e) { 237 HitTestResult result = chart.HitTest(e.X, e.Y); 238 if (result.ChartElementType == ChartElementType.LegendItem && result.Series.Name != TARGETVARIABLE_SERIES_NAME) 239 Cursor = Cursors.Hand; 240 else 241 Cursor = Cursors.Default; 242 } 243 private void chart_MouseDown(object sender, MouseEventArgs e) { 244 HitTestResult result = chart.HitTest(e.X, e.Y); 245 if (result.ChartElementType == ChartElementType.LegendItem && result.Series.Name != TARGETVARIABLE_SERIES_NAME) { 246 ToggleSeriesData(result.Series); 247 } 248 } 249 250 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 251 if (chart.Series.Count != 4) return; 252 e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black; 253 e.LegendItems[1].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black; 254 e.LegendItems[2].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black; 255 e.LegendItems[3].Cells[1].ForeColor = this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black; 256 } 203 257 } 204 258 }
Note: See TracChangeset
for help on using the changeset viewer.