Changeset 8868
- Timestamp:
- 11/05/12 12:59:44 (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
r8840 r8868 1 using System.Windows.Forms.DataVisualization.Charting; 2 namespace HeuristicLab.Problems.DataAnalysis.Views { 1 namespace HeuristicLab.Problems.DataAnalysis.Views { 3 2 partial class DiscriminantFunctionClassificationSolutionThresholdView { 4 3 /// <summary> … … 54 53 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 55 54 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);57 55 // 58 56 // JitterTrackBar -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs
r8840 r8868 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 45 42 public new IDiscriminantFunctionClassificationSolution Content { 46 43 get { return (IDiscriminantFunctionClassificationSolution)base.Content; } … … 50 47 private Dictionary<double, Series> classValueSeriesMapping; 51 48 private Random random; 52 private bool updateInProgress , updateThresholds;49 private bool updateInProgress; 53 50 54 51 public DiscriminantFunctionClassificationSolutionThresholdView() … … 68 65 69 66 this.chart.ChartAreas[0].AxisY.Title = "Estimated Values"; 67 this.chart.ChartAreas[0].AxisY.IsStartedFromZero = false; 70 68 this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 71 69 this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true; … … 129 127 FillSeriesWithDataPoints(series); 130 128 } 131 updateThresholds = true;129 AddThresholds(); 132 130 } 133 131 chart.ChartAreas[0].RecalculateAxesScale(); … … 169 167 } 170 168 171 private void chart_PostPaint(object sender, ChartPaintEventArgs e) {172 if (updateThresholds) {173 AddThresholds();174 updateThresholds = false;175 }176 }177 178 169 private void AddThresholds() { 179 170 chart.Annotations.Clear(); 180 171 int classIndex = 1; 181 SizeF textSizeInPixel;182 172 IClassificationProblemData problemData = Content.ProblemData; 183 173 var classValues = Content.Model.ClassValues.ToArray(); 184 Graphics g = chart.CreateGraphics();185 174 Axis y = chart.ChartAreas[0].AxisY; 186 175 Axis x = chart.ChartAreas[0].AxisX; … … 201 190 202 191 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); 192 TextAnnotation beneathLeft = CreateTextAnnotation(name, classIndex, x, y, x.Minimum, threshold, ContentAlignment.TopLeft); 193 TextAnnotation beneathRight = CreateTextAnnotation(name, classIndex, x, y, x.Maximum, threshold, ContentAlignment.TopRight); 212 194 213 195 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); 196 TextAnnotation aboveLeft = CreateTextAnnotation(name, classIndex, x, y, x.Minimum, threshold, ContentAlignment.BottomLeft); 197 TextAnnotation aboveRight = CreateTextAnnotation(name, classIndex, x, y, x.Maximum, threshold, ContentAlignment.BottomRight); 225 198 226 199 chart.Annotations.Add(annotation); 227 200 chart.Annotations.Add(beneathLeft); 228 201 chart.Annotations.Add(aboveLeft); 229 chart.Annotations.Add(beneathRig th);202 chart.Annotations.Add(beneathRight); 230 203 chart.Annotations.Add(aboveRight); 204 205 beneathLeft.ResizeToContent(); 206 beneathRight.ResizeToContent(); 207 aboveLeft.ResizeToContent(); 208 aboveRight.ResizeToContent(); 209 210 beneathRight.Width = -beneathRight.Width; 211 aboveLeft.Height = -aboveLeft.Height; 212 aboveRight.Height = -aboveRight.Height; 213 aboveRight.Width = -aboveRight.Width; 214 231 215 classIndex++; 232 216 } … … 234 218 } 235 219 236 private TextAnnotation CreateTextAnnotation(string name, int classIndex, Axis x, Axis y) {220 private TextAnnotation CreateTextAnnotation(string name, int classIndex, Axis axisX, Axis axisY, double x, double y, ContentAlignment alignment) { 237 221 TextAnnotation annotation = new TextAnnotation(); 238 222 annotation.Text = name; … … 240 224 annotation.AllowResizing = false; 241 225 annotation.AllowSelecting = false; 226 annotation.IsSizeAlwaysRelative = true; 242 227 annotation.ClipToChartArea = chart.ChartAreas[0].Name; 243 228 annotation.Tag = classIndex; 244 annotation.AxisX = chart.ChartAreas[0].AxisX; 245 annotation.AxisY = y; 229 annotation.AxisX = axisX; 230 annotation.AxisY = axisY; 231 annotation.Alignment = alignment; 232 annotation.X = x; 233 annotation.Y = y; 246 234 return annotation; 247 235 }
Note: See TracChangeset
for help on using the changeset viewer.