Changeset 8840 for trunk/sources
- Timestamp:
- 10/23/12 15:06:22 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.Designer.cs
r7967 r8840 1 namespace HeuristicLab.Problems.DataAnalysis.Views { 1 using System.Windows.Forms.DataVisualization.Charting; 2 namespace HeuristicLab.Problems.DataAnalysis.Views { 2 3 partial class DiscriminantFunctionClassificationSolutionThresholdView { 3 4 /// <summary> … … 53 54 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 54 55 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 56 this.chart.PostPaint += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs>(chart_PostPaint); 55 57 // 56 58 // JitterTrackBar … … 92 94 93 95 } 94 95 96 #endregion 96 97 -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs
r8550 r8840 40 40 private const string TestLabelText = "Test Samples"; 41 41 42 private const double ClassNameLeftOffset = 10.0; 43 private const double ClassNameBottomOffset = 5.0; 44 42 45 public new IDiscriminantFunctionClassificationSolution Content { 43 46 get { return (IDiscriminantFunctionClassificationSolution)base.Content; } … … 47 50 private Dictionary<double, Series> classValueSeriesMapping; 48 51 private Random random; 49 private bool updateInProgress ;52 private bool updateInProgress, updateThresholds; 50 53 51 54 public DiscriminantFunctionClassificationSolutionThresholdView() … … 126 129 FillSeriesWithDataPoints(series); 127 130 } 128 AddThresholds();131 updateThresholds = true; 129 132 } 130 133 chart.ChartAreas[0].RecalculateAxesScale(); … … 166 169 } 167 170 171 private void chart_PostPaint(object sender, ChartPaintEventArgs e) { 172 if (updateThresholds) { 173 AddThresholds(); 174 updateThresholds = false; 175 } 176 } 177 168 178 private void AddThresholds() { 169 179 chart.Annotations.Clear(); 170 180 int classIndex = 1; 181 SizeF textSizeInPixel; 182 IClassificationProblemData problemData = Content.ProblemData; 183 var classValues = Content.Model.ClassValues.ToArray(); 184 Graphics g = chart.CreateGraphics(); 185 Axis y = chart.ChartAreas[0].AxisY; 186 Axis x = chart.ChartAreas[0].AxisX; 187 string name; 171 188 foreach (double threshold in Content.Model.Thresholds) { 172 189 if (!double.IsInfinity(threshold)) { … … 176 193 annotation.LineWidth = 2; 177 194 annotation.LineColor = Color.Red; 178 179 195 annotation.IsInfinitive = true; 180 196 annotation.ClipToChartArea = chart.ChartAreas[0].Name; 181 197 annotation.Tag = classIndex; //save classIndex as Tag to avoid moving the threshold accross class bounderies 182 183 198 annotation.AxisX = chart.ChartAreas[0].AxisX; 184 annotation.AxisY = chart.ChartAreas[0].AxisY;199 annotation.AxisY = y; 185 200 annotation.Y = threshold; 186 201 202 name = problemData.GetClassName(classValues[classIndex - 1]); 203 TextAnnotation beneathLeft = CreateTextAnnotation(name, classIndex, x, y); 204 beneathLeft.Y = threshold; 205 beneathLeft.X = x.Minimum; 206 TextAnnotation beneathRigth = CreateTextAnnotation(name, classIndex, x, y); 207 beneathRigth.Y = threshold; 208 textSizeInPixel = g.MeasureString(beneathRigth.Text, beneathRigth.Font); 209 double textWidthPixelPos = x.ValueToPixelPosition(x.Maximum) - textSizeInPixel.Width - ClassNameLeftOffset; 210 //check if position is within the position boundary 211 beneathRigth.X = textWidthPixelPos < 0 || textWidthPixelPos > chart.Width ? double.NaN : x.PixelPositionToValue(textWidthPixelPos); 212 213 name = problemData.GetClassName(classValues[classIndex]); 214 TextAnnotation aboveLeft = CreateTextAnnotation(name, classIndex, x, y); 215 textSizeInPixel = g.MeasureString(aboveLeft.Text, aboveLeft.Font); 216 double textHeightPixelPos = y.ValueToPixelPosition(threshold) - textSizeInPixel.Height - ClassNameBottomOffset; 217 //check if position is within the position boundary 218 aboveLeft.Y = textHeightPixelPos < 0 || textHeightPixelPos > chart.Height ? double.NaN : y.PixelPositionToValue(textHeightPixelPos); 219 aboveLeft.X = x.Minimum; 220 TextAnnotation aboveRight = CreateTextAnnotation(name, classIndex, x, y); 221 aboveRight.Y = aboveLeft.Y; 222 textWidthPixelPos = x.ValueToPixelPosition(x.Maximum) - textSizeInPixel.Width - ClassNameLeftOffset; 223 //check if position is within the position boundary 224 aboveRight.X = textWidthPixelPos < 0 || textWidthPixelPos > chart.Width ? double.NaN : x.PixelPositionToValue(textWidthPixelPos); 225 187 226 chart.Annotations.Add(annotation); 227 chart.Annotations.Add(beneathLeft); 228 chart.Annotations.Add(aboveLeft); 229 chart.Annotations.Add(beneathRigth); 230 chart.Annotations.Add(aboveRight); 188 231 classIndex++; 189 232 } 190 233 } 234 } 235 236 private TextAnnotation CreateTextAnnotation(string name, int classIndex, Axis x, Axis y) { 237 TextAnnotation annotation = new TextAnnotation(); 238 annotation.Text = name; 239 annotation.AllowMoving = true; 240 annotation.AllowResizing = false; 241 annotation.AllowSelecting = false; 242 annotation.ClipToChartArea = chart.ChartAreas[0].Name; 243 annotation.Tag = classIndex; 244 annotation.AxisX = chart.ChartAreas[0].AxisX; 245 annotation.AxisY = y; 246 return annotation; 191 247 } 192 248
Note: See TracChangeset
for help on using the changeset viewer.