Changeset 8868


Ignore:
Timestamp:
11/05/12 12:59:44 (10 years ago)
Author:
sforsten
Message:

#1949:

  • TextAnnotations are now placed in an easier way
  • Y axis doesn't start at zero any more
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 {
     1namespace HeuristicLab.Problems.DataAnalysis.Views {
    32  partial class DiscriminantFunctionClassificationSolutionThresholdView {
    43    /// <summary>
     
    5453      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    5554      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);
    5755      //
    5856      // JitterTrackBar
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r8840 r8868  
    4040    private const string TestLabelText = "Test Samples";
    4141
    42     private const double ClassNameLeftOffset = 10.0;
    43     private const double ClassNameBottomOffset = 5.0;
    44 
    4542    public new IDiscriminantFunctionClassificationSolution Content {
    4643      get { return (IDiscriminantFunctionClassificationSolution)base.Content; }
     
    5047    private Dictionary<double, Series> classValueSeriesMapping;
    5148    private Random random;
    52     private bool updateInProgress, updateThresholds;
     49    private bool updateInProgress;
    5350
    5451    public DiscriminantFunctionClassificationSolutionThresholdView()
     
    6865
    6966      this.chart.ChartAreas[0].AxisY.Title = "Estimated Values";
     67      this.chart.ChartAreas[0].AxisY.IsStartedFromZero = false;
    7068      this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
    7169      this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
     
    129127            FillSeriesWithDataPoints(series);
    130128          }
    131           updateThresholds = true;
     129          AddThresholds();
    132130        }
    133131        chart.ChartAreas[0].RecalculateAxesScale();
     
    169167    }
    170168
    171     private void chart_PostPaint(object sender, ChartPaintEventArgs e) {
    172       if (updateThresholds) {
    173         AddThresholds();
    174         updateThresholds = false;
    175       }
    176     }
    177 
    178169    private void AddThresholds() {
    179170      chart.Annotations.Clear();
    180171      int classIndex = 1;
    181       SizeF textSizeInPixel;
    182172      IClassificationProblemData problemData = Content.ProblemData;
    183173      var classValues = Content.Model.ClassValues.ToArray();
    184       Graphics g = chart.CreateGraphics();
    185174      Axis y = chart.ChartAreas[0].AxisY;
    186175      Axis x = chart.ChartAreas[0].AxisX;
     
    201190
    202191          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);
    212194
    213195          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);
    225198
    226199          chart.Annotations.Add(annotation);
    227200          chart.Annotations.Add(beneathLeft);
    228201          chart.Annotations.Add(aboveLeft);
    229           chart.Annotations.Add(beneathRigth);
     202          chart.Annotations.Add(beneathRight);
    230203          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
    231215          classIndex++;
    232216        }
     
    234218    }
    235219
    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) {
    237221      TextAnnotation annotation = new TextAnnotation();
    238222      annotation.Text = name;
     
    240224      annotation.AllowResizing = false;
    241225      annotation.AllowSelecting = false;
     226      annotation.IsSizeAlwaysRelative = true;
    242227      annotation.ClipToChartArea = chart.ChartAreas[0].Name;
    243228      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;
    246234      return annotation;
    247235    }
Note: See TracChangeset for help on using the changeset viewer.