Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8840 for trunk


Ignore:
Timestamp:
10/23/12 15:06:22 (12 years ago)
Author:
sforsten
Message:

#1949: class names are displayed on the left and right side of the diagram, above and beneath every threshold

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 {
     1using System.Windows.Forms.DataVisualization.Charting;
     2namespace HeuristicLab.Problems.DataAnalysis.Views {
    23  partial class DiscriminantFunctionClassificationSolutionThresholdView {
    34    /// <summary>
     
    5354      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    5455      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);
    5557      //
    5658      // JitterTrackBar
     
    9294
    9395    }
    94 
    9596    #endregion
    9697
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r8550 r8840  
    4040    private const string TestLabelText = "Test Samples";
    4141
     42    private const double ClassNameLeftOffset = 10.0;
     43    private const double ClassNameBottomOffset = 5.0;
     44
    4245    public new IDiscriminantFunctionClassificationSolution Content {
    4346      get { return (IDiscriminantFunctionClassificationSolution)base.Content; }
     
    4750    private Dictionary<double, Series> classValueSeriesMapping;
    4851    private Random random;
    49     private bool updateInProgress;
     52    private bool updateInProgress, updateThresholds;
    5053
    5154    public DiscriminantFunctionClassificationSolutionThresholdView()
     
    126129            FillSeriesWithDataPoints(series);
    127130          }
    128           AddThresholds();
     131          updateThresholds = true;
    129132        }
    130133        chart.ChartAreas[0].RecalculateAxesScale();
     
    166169    }
    167170
     171    private void chart_PostPaint(object sender, ChartPaintEventArgs e) {
     172      if (updateThresholds) {
     173        AddThresholds();
     174        updateThresholds = false;
     175      }
     176    }
     177
    168178    private void AddThresholds() {
    169179      chart.Annotations.Clear();
    170180      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;
    171188      foreach (double threshold in Content.Model.Thresholds) {
    172189        if (!double.IsInfinity(threshold)) {
     
    176193          annotation.LineWidth = 2;
    177194          annotation.LineColor = Color.Red;
    178 
    179195          annotation.IsInfinitive = true;
    180196          annotation.ClipToChartArea = chart.ChartAreas[0].Name;
    181197          annotation.Tag = classIndex;  //save classIndex as Tag to avoid moving the threshold accross class bounderies
    182 
    183198          annotation.AxisX = chart.ChartAreas[0].AxisX;
    184           annotation.AxisY = chart.ChartAreas[0].AxisY;
     199          annotation.AxisY = y;
    185200          annotation.Y = threshold;
    186201
     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
    187226          chart.Annotations.Add(annotation);
     227          chart.Annotations.Add(beneathLeft);
     228          chart.Annotations.Add(aboveLeft);
     229          chart.Annotations.Add(beneathRigth);
     230          chart.Annotations.Add(aboveRight);
    188231          classIndex++;
    189232        }
    190233      }
     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;
    191247    }
    192248
Note: See TracChangeset for help on using the changeset viewer.