Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1242


Ignore:
Timestamp:
03/03/09 20:10:48 (15 years ago)
Author:
dwagner
Message:

Changed Behaviour of Single value lines; They are now shown without bounds.
OptionsDialog now modifies the model and not the view; (#501 and #502)

Location:
trunk/sources/HeuristicLab.Visualization
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/HorizontalLineShape.cs

    r1240 r1242  
    22
    33namespace HeuristicLab.Visualization {
    4   public class MinMaxLineShape : WorldShape {
    5     private readonly LineShape minLineShape;
    6     private readonly LineShape maxLineShape;
    7 
     4  public class HorizontalLineShape : LineShape {
    85    /// <summary>
    9     /// Initializes the HorizontalLineShape.
     6    /// Initializes the LineShape.
    107    /// </summary>
     8    /// <param name="x1">x coordinate of left lineEndPoind</param>
     9    /// <param name="y1">y coordinate of left lineEndPoind</param>
     10    /// <param name="x2">x coordinate of right lineEndPoind</param>
     11    /// <param name="y2">y coordinate of right lineEndPoind</param>
    1112    /// <param name="color">color for the LineShape</param>
    12     /// <param name="yMin">y value for lower line</param>
    13     /// <param name="yMax">y value for upper line</param>
    14     /// <param name="thickness">line thickness</param>
    15     /// <param name="style">line style</param>
    16     public MinMaxLineShape(double yMin, double yMax, Color color, int thickness, DrawingStyle style) {
    17       minLineShape = new LineShape(0, yMin, 1, yMin, color, thickness, style);
    18       maxLineShape = new LineShape(0, yMax, 1, yMax, color, thickness, style);
    19       AddShape(minLineShape);
    20       AddShape(maxLineShape);
    21     }
     13    /// <param name="thickness">tickness of the line in pixels</param>
     14    /// <param name="drawingStyle">drawing style of the line (solid, dashed, dotted,...)</param>
     15    public HorizontalLineShape(double x1, double y1, double x2, double y2, Color color, int thickness,
     16                               DrawingStyle drawingStyle) : base(x1, y1, x2, y2, color, thickness, drawingStyle) {}
    2217
    2318    public override void Draw(Graphics graphics) {
    24       minLineShape.X1 = ClippingArea.X1;
    25       minLineShape.X2 = ClippingArea.X2;
    26       maxLineShape.X1 = ClippingArea.X1;
    27       maxLineShape.X2 = ClippingArea.X2;
     19      X1 = Parent.ClippingArea.X1;
     20      X2 = Parent.ClippingArea.X2;
     21      Y2 = Y1;
    2822      base.Draw(graphics);
    29     }
    30 
    31 
    32     public double YMin {
    33       set {
    34         minLineShape.Y1 = value;
    35         minLineShape.Y2 = value;
    36       }
    37     }
    38 
    39     public double YMax {
    40       set {
    41         maxLineShape.Y1 = value;
    42         maxLineShape.Y2 = value;
    43       }
    4423    }
    4524  }
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r1240 r1242  
    1010  public partial class LineChart : ViewBase {
    1111    internal class LinesShape : WorldShape {}
    12 
    1312    private readonly IChartDataRowsModel model;
    1413    private readonly Canvas canvas;
     
    1817    private double minDataValue;
    1918    private double maxDataValue;
    20     private bool minMaxLineEnabled;
    21     private MinMaxLineShape minMaxLineShape;
    22     private IShape minLineShape;
     19 
    2320
    2421    private readonly TextShape titleShape;
     
    4946      }
    5047
    51       minMaxLineEnabled = true;
    52 
     48   
    5349      canvas = canvasUI.Canvas;
    5450
     
    6864      canvas.AddShape(titleShape);
    6965
    70       minMaxLineShape = new MinMaxLineShape(this.minDataValue, this.maxDataValue, Color.Yellow, 4, DrawingStyle.Solid);
    71       canvas.AddShape(minMaxLineShape);
     66      //  horizontalLineShape = new HorizontalLineShape(this.maxDataValue, Color.Yellow, 4, DrawingStyle.Solid);
     67      //  root.AddShape(horizontalLineShape);
    7268
    7369      legendShape = new LegendShape();
     
    111107      grid.BoundingBox = linesShape.BoundingBox;
    112108
    113       minMaxLineShape.BoundingBox = linesShape.BoundingBox;
    114109
    115110      yAxis.BoundingBox = new RectangleD(0,
     
    135130    }
    136131
     132    private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
     133      var optionsdlg = new OptionsDialog(this.model);
     134      optionsdlg.ShowDialog(this);
     135    }
     136
     137    public void OnDataRowChanged(IDataRow row) {
     138      foreach (LineShape ls in rowToLineShapes[row]) {
     139        ls.LSColor = row.Color;
     140        ls.LSThickness = row.Thickness;
     141        ls.LSDrawingStyle = row.Style;
     142      }
     143      canvasUI.Invalidate();
     144    }
     145
    137146    #region Add-/RemoveItemEvents
     147
     148    private readonly IDictionary<IDataRow, List<LineShape>> rowToLineShapes =
     149      new Dictionary<IDataRow, List<LineShape>>();
    138150
    139151    protected override void AddItemEvents() {
     
    164176      if (row.Count > maxDataRowCount) {
    165177        maxDataRowCount = row.Count;
     178        //   UpdateSingleValueRows();
    166179      }
    167180
     
    183196        return;
    184197      }
    185       RectangleD newClippingArea = new RectangleD(-0.1,
    186                                                   minDataValue - ((maxDataValue - minDataValue)*0.05),
    187                                                   maxDataRowCount - 0.9,
    188                                                   maxDataValue + ((maxDataValue - minDataValue)*0.05));
     198      var newClippingArea = new RectangleD(-0.1,
     199                                           minDataValue - ((maxDataValue - minDataValue)*0.05),
     200                                           maxDataRowCount - 0.9,
     201                                           maxDataValue + ((maxDataValue - minDataValue)*0.05));
    189202
    190203      SetLineClippingArea(newClippingArea);
     
    201214      grid.ClippingArea = linesShape.ClippingArea;
    202215
    203       minMaxLineShape.ClippingArea = linesShape.ClippingArea;
     216      // horizontalLineShape.ClippingArea = linesShape.ClippingArea;
     217
    204218
    205219      xAxis.ClippingArea = new RectangleD(linesShape.ClippingArea.X1,
     
    215229
    216230    private void InitLineShapes(IDataRow row) {
    217       List<LineShape> lineShapes = new List<LineShape>();
     231      var lineShapes = new List<LineShape>();
    218232      if (rowToLineShapes.Count == 0) {
    219233        minDataValue = Double.PositiveInfinity;
    220234        maxDataValue = Double.NegativeInfinity;
    221235      }
    222       if (row.Count > 0) {
     236      if ((row.Count > 0)) {
    223237        maxDataValue = Math.Max(row[0], maxDataValue);
    224238        minDataValue = Math.Min(row[0], minDataValue);
    225239      }
    226       for (int i = 1; i < row.Count; i++) {
    227         LineShape lineShape = new LineShape(i - 1, row[i - 1], i, row[i], row.Color, row.Thickness, row.Style);
    228         lineShapes.Add(lineShape);
    229         // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
    230         linesShape.AddShape(lineShape);
    231         maxDataValue = Math.Max(row[i], maxDataValue);
    232         minDataValue = Math.Min(row[i], minDataValue);
    233       }
    234       minMaxLineShape.YMax = maxDataValue;
    235       minMaxLineShape.YMin = minDataValue;
     240      if ((row.LineType == DataRowType.SingleValue)) {
     241        if (row.Count > 0) {
     242          LineShape lineShape = new HorizontalLineShape(0, row[0], double.MaxValue, row[0], row.Color, row.Thickness,
     243                                                        row.Style);
     244          lineShapes.Add(lineShape);
     245          // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
     246          linesShape.AddShape(lineShape);
     247        }
     248      }
     249      else {
     250        for (int i = 1; i < row.Count; i++) {
     251          var lineShape = new LineShape(i - 1, row[i - 1], i, row[i], row.Color, row.Thickness, row.Style);
     252          lineShapes.Add(lineShape);
     253          // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
     254          linesShape.AddShape(lineShape);
     255          maxDataValue = Math.Max(row[i], maxDataValue);
     256          minDataValue = Math.Min(row[i], minDataValue);
     257        }
     258      }
     259      //horizontalLineShape.YVal = maxDataValue;
    236260      rowToLineShapes[row] = lineShapes;
    237261      ZoomToFullView();
     
    239263      canvasUI.Invalidate();
    240264    }
    241 
    242     private readonly IDictionary<IDataRow, List<LineShape>> rowToLineShapes =
    243       new Dictionary<IDataRow, List<LineShape>>();
    244265
    245266    // TODO use action parameter
     
    248269      maxDataValue = Math.Max(value, maxDataValue);
    249270      minDataValue = Math.Min(value, minDataValue);
    250       minMaxLineShape.YMax = maxDataValue;
    251       minMaxLineShape.YMin = minDataValue;
    252       if (index > lineShapes.Count + 1) {
    253         throw new NotImplementedException();
    254       }
    255 
    256       // new value was added
    257       if (index > 0 && index == lineShapes.Count + 1) {
    258         if (maxDataRowCount < row.Count) {
    259           maxDataRowCount = row.Count;
    260         }
    261         LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], row.Color, row.Thickness,
    262                                             row.Style);
    263         lineShapes.Add(lineShape);
    264         // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
    265         linesShape.AddShape(lineShape);
    266       }
    267 
    268       // not the first value
    269       if (index > 0) {
    270         lineShapes[index - 1].Y2 = value;
    271       }
    272 
    273       // not the last value
    274       if (index > 0 && index < row.Count - 1) {
    275         lineShapes[index].Y1 = value;
    276       }
     271      if (row.LineType == DataRowType.SingleValue) {
     272        if (action == Action.Added) {
     273          LineShape lineShape = new HorizontalLineShape(0, row[0], double.MaxValue, row[0], row.Color, row.Thickness,
     274                                                        row.Style);
     275          lineShapes.Add(lineShape);
     276          // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
     277          linesShape.AddShape(lineShape);
     278        }
     279        else {
     280          // lineShapes[0].X2 = maxDataRowCount;
     281          lineShapes[0].Y1 = value;
     282          lineShapes[0].Y2 = value;
     283        }
     284      }
     285      else {
     286        //  horizontalLineShape.YVal = maxDataValue;
     287        if (index > lineShapes.Count + 1) {
     288          throw new NotImplementedException();
     289        }
     290
     291        // new value was added
     292        if (index > 0 && index == lineShapes.Count + 1) {
     293          if (maxDataRowCount < row.Count) {
     294            maxDataRowCount = row.Count;
     295            //  UpdateSingleValueRows();
     296          }
     297          var lineShape = new LineShape(index - 1, row[index - 1], index, row[index], row.Color, row.Thickness,
     298                                        row.Style);
     299          lineShapes.Add(lineShape);
     300          // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
     301          linesShape.AddShape(lineShape);
     302        }
     303
     304        // not the first value
     305        if (index > 0) {
     306          lineShapes[index - 1].Y2 = value;
     307        }
     308
     309        // not the last value
     310        if (index > 0 && index < row.Count - 1) {
     311          lineShapes[index].Y1 = value;
     312        }
     313      }
     314
    277315      ZoomToFullView();
    278 
    279316      canvasUI.Invalidate();
    280317    }
     
    299336    }
    300337
    301     public void OnDataRowChanged(IDataRow row) {
    302       foreach (LineShape ls in rowToLineShapes[row]) {
    303         ls.LSColor = row.Color;
    304         ls.LSThickness = row.Thickness;
    305         ls.LSDrawingStyle = row.Style;
    306       }
    307       canvasUI.Invalidate();
    308     }
    309 
     338 
    310339    #region Begin-/EndUpdate
    311340
    312     private int beginUpdateCount = 0;
     341    private int beginUpdateCount;
    313342
    314343    public void BeginUpdate() {
     
    349378      Focus();
    350379      if (e.Button == MouseButtons.Right) {
    351      
    352           this.contextMenuStrip1.Show(PointToScreen(e.Location));
    353      
     380        contextMenuStrip1.Show(PointToScreen(e.Location));
    354381      }
    355382      else {
     
    383410
    384411    private void CreateZoomListener(MouseEventArgs e) {
    385       ZoomListener zoomListener = new ZoomListener(e.Location);
     412      var zoomListener = new ZoomListener(e.Location);
    386413      zoomListener.DrawRectangle += DrawRectangle;
    387414      zoomListener.OnMouseUp += OnZoom_MouseUp;
     
    436463    #endregion
    437464
    438     private void optionsToolStripMenuItem_Click(object sender, EventArgs e) {
    439       OptionsDialog optionsdlg = new OptionsDialog(this);
    440       optionsdlg.ShowDialog(this);
    441     }
     465   
    442466  }
    443467}
  • trunk/sources/HeuristicLab.Visualization/LineShape.cs

    r1240 r1242  
    3232    public RectangleD BoundingBox {
    3333      get { return boundingBox; }
     34      set { boundingBox = value; }
    3435    }
    3536
     
    7172    /// </summary>
    7273    /// <param name="graphics">graphics handle to draw to</param>
    73     public void Draw(Graphics graphics) {
     74    public virtual void Draw(Graphics graphics) {
    7475      Rectangle screenRect = Transform.ToScreen(boundingBox, Parent.Viewport, Parent.ClippingArea);
    7576
  • trunk/sources/HeuristicLab.Visualization/Options/OptionsDialog.cs

    r1237 r1242  
    55namespace HeuristicLab.Visualization.Options {
    66  public partial class OptionsDialog : Form {
    7     private readonly LineChart lc;
     7    private readonly IChartDataRowsModel model;
    88
    9     public OptionsDialog(LineChart lc) {
     9    public OptionsDialog(IChartDataRowsModel model) {
    1010      InitializeComponent();
    11       this.lc = lc;
     11      this.model = model;
    1212    }
    1313
     
    2727
    2828    private void OptionsDialog_Load(object sender, EventArgs e) {
    29       if (lc.GetRows().Count != 0) {
    30         LineSelectCB.DataSource = lc.GetRows();
     29      if (model.Rows.Count != 0) {
     30        LineSelectCB.DataSource = model.Rows;
    3131        LineSelectCB.DisplayMember = "Label";
    3232
Note: See TracChangeset for help on using the changeset viewer.