Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/09 22:03:41 (15 years ago)
Author:
mstoeger
Message:

Transformations on shapes are possible outside of the Draw method. (#424)

File:
1 edited

Legend:

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

    r1237 r1240  
    1212
    1313    private readonly IChartDataRowsModel model;
     14    private readonly Canvas canvas;
     15
    1416    private int maxDataRowCount;
    1517    private Boolean zoomFullView;
     
    2022    private IShape minLineShape;
    2123
    22     private readonly WorldShape root;
    2324    private readonly TextShape titleShape;
    2425    private readonly LinesShape linesShape;
     
    2829    private readonly YAxis yAxis;
    2930    private readonly Grid grid;
     31
     32    private readonly WorldShape berni;
     33    private readonly RectangleShape mousePointer;
    3034
    3135    /// <summary>
     
    4549      }
    4650
    47       //TODO: correct Rectangle to fit
    48 
    49       root = new WorldShape();
     51      minMaxLineEnabled = true;
     52
     53      canvas = canvasUI.Canvas;
    5054
    5155      grid = new Grid();
    52       minMaxLineEnabled = true;
    53       root.AddShape(grid);
     56      canvas.AddShape(grid);
    5457
    5558      linesShape = new LinesShape();
    56       root.AddShape(linesShape);
     59      canvas.AddShape(linesShape);
    5760
    5861      xAxis = new XAxis();
    59       root.AddShape(xAxis);
     62      canvas.AddShape(xAxis);
    6063
    6164      yAxis = new YAxis();
    62       root.AddShape(yAxis);
     65      canvas.AddShape(yAxis);
    6366
    6467      titleShape = new TextShape(0, 0, model.Title, 15);
    65       root.AddShape(titleShape);
     68      canvas.AddShape(titleShape);
    6669
    6770      minMaxLineShape = new MinMaxLineShape(this.minDataValue, this.maxDataValue, Color.Yellow, 4, DrawingStyle.Solid);
    68       root.AddShape(minMaxLineShape);
     71      canvas.AddShape(minMaxLineShape);
    6972
    7073      legendShape = new LegendShape();
    71       root.AddShape(legendShape);
    72 
    73       canvas.MainCanvas.WorldShape = root;
    74       canvas.Resize += delegate { UpdateLayout(); };
    75      
    76       UpdateLayout();
     74      canvas.AddShape(legendShape);
     75
     76      berni = new WorldShape();
     77      canvas.AddShape(berni);
     78
     79      mousePointer = new RectangleShape(10, 10, 20, 20, Color.Black);
     80      berni.AddShape(mousePointer);
     81
    7782      maxDataRowCount = 0;
    7883      this.model = model;
    7984      Item = model;
    8085
     86      UpdateLayout();
     87      canvasUI.Resize += delegate { UpdateLayout(); };
    8188
    8289      //The whole data rows are shown per default
     
    8895    /// </summary>
    8996    private void UpdateLayout() {
    90       root.ClippingArea = new RectangleD(0, 0, canvas.Width, canvas.Height);
    91 
    9297      titleShape.X = 10;
    93       titleShape.Y = canvas.Height - 10;
     98      titleShape.Y = canvasUI.Height - 10;
    9499
    95100      const int yAxisWidth = 100;
     
    98103      linesShape.BoundingBox = new RectangleD(yAxisWidth,
    99104                                              xAxisHeight,
    100                                               canvas.Width,
    101                                               canvas.Height);
     105                                              canvasUI.Width,
     106                                              canvasUI.Height);
     107
     108      berni.BoundingBox = linesShape.BoundingBox;
     109      berni.ClippingArea = new RectangleD(0, 0, berni.BoundingBox.Width, berni.BoundingBox.Height);
    102110
    103111      grid.BoundingBox = linesShape.BoundingBox;
     
    115123                                         linesShape.BoundingBox.Y1);
    116124
    117       legendShape.BoundingBox = new RectangleD(10, 10, 110, canvas.Height - 50);
     125      legendShape.BoundingBox = new RectangleD(10, 10, 110, canvasUI.Height - 50);
    118126      legendShape.ClippingArea = new RectangleD(0, 0, legendShape.BoundingBox.Width,
    119127                                                legendShape.BoundingBox.Height);
     
    124132      ZoomToFullView();
    125133
    126       canvas.Invalidate();
     134      canvasUI.Invalidate();
    127135    }
    128136
     
    162170      InitLineShapes(row);
    163171    }
     172
     173    private void OnDataRowRemoved(IDataRow row) {
     174      row.ValueChanged -= OnRowValueChanged;
     175      row.ValuesChanged -= OnRowValuesChanged;
     176      row.DataRowChanged -= OnDataRowChanged;
     177    }
     178
     179    #endregion
    164180
    165181    private void ZoomToFullView() {
     
    221237      ZoomToFullView();
    222238
    223       canvas.Invalidate();
    224     }
    225 
    226     private void OnDataRowRemoved(IDataRow row) {
    227       row.ValueChanged -= OnRowValueChanged;
    228       row.ValuesChanged -= OnRowValuesChanged;
    229       row.DataRowChanged -= OnDataRowChanged;
     239      canvasUI.Invalidate();
    230240    }
    231241
     
    267277      ZoomToFullView();
    268278
    269       canvas.Invalidate();
    270     }
    271 
    272 
     279      canvasUI.Invalidate();
     280    }
     281
     282    // TODO remove (see ticket #501)
    273283    public IList<IDataRow> GetRows() {
    274284      return model.Rows;
     
    286296      titleShape.Text = model.Title;
    287297
    288       Invalidate();
    289     }
    290 
    291     #endregion
     298      canvasUI.Invalidate();
     299    }
     300
     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    }
    292309
    293310    #region Begin-/EndUpdate
     
    307324
    308325      if (beginUpdateCount == 0) {
    309         canvas.Invalidate();
     326        canvasUI.Invalidate();
    310327      }
    311328    }
     
    325342
    326343        SetNewClippingArea(clippingArea);
    327         canvas.Invalidate();
     344        canvasUI.Invalidate();
    328345      }
    329346    }
     
    346363    }
    347364
     365    private void canvas_MouseMove(object sender, MouseEventArgs e) {
     366      double x = Transform.ToWorldX(e.X, berni.Viewport, berni.ClippingArea);
     367      double y = Transform.ToWorldY(e.Y, berni.Viewport, berni.ClippingArea);
     368
     369      mousePointer.Rectangle = new RectangleD(x-1, y-1, x+1, y+1);
     370      canvasUI.Invalidate();
     371    }
     372
    348373    private void canvasUI1_MouseWheel(object sender, MouseEventArgs e) {
    349374      if (ModifierKeys == Keys.Control) {
     
    353378
    354379        SetLineClippingArea(clippingArea);
    355         canvas.Invalidate();
     380        canvasUI.Invalidate();
    356381      }
    357382    }
     
    362387      zoomListener.OnMouseUp += OnZoom_MouseUp;
    363388
    364       canvas.MouseEventListener = zoomListener;
     389      canvasUI.MouseEventListener = zoomListener;
    365390
    366391      rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, Color.Blue);
     
    371396
    372397    private void OnZoom_MouseUp(object sender, MouseEventArgs e) {
    373       canvas.MouseEventListener = null;
     398      canvasUI.MouseEventListener = null;
    374399
    375400      RectangleD clippingArea = rectangleShape.Rectangle;
     
    382407      zoomFullView = false; //user wants to zoom => no full view
    383408
    384       canvas.Invalidate();
     409      canvasUI.Invalidate();
    385410    }
    386411
    387412    private void DrawRectangle(Rectangle rectangle) {
    388       rectangleShape.Rectangle = Transform.ToWorld(rectangle, canvas.ClientRectangle, linesShape.ClippingArea);
    389       canvas.Invalidate();
     413      rectangleShape.Rectangle = Transform.ToWorld(rectangle, canvasUI.ClientRectangle, linesShape.ClippingArea);
     414      canvasUI.Invalidate();
    390415    }
    391416
    392417    private void CreatePanListener(MouseEventArgs e) {
    393       PanListener panListener = new PanListener(canvas.ClientRectangle, linesShape.ClippingArea, e.Location);
     418      PanListener panListener = new PanListener(canvasUI.ClientRectangle, linesShape.ClippingArea, e.Location);
    394419
    395420      panListener.SetNewClippingArea += SetNewClippingArea;
    396421      panListener.OnMouseUp += delegate {
    397422                                 historyStack.Push(linesShape.ClippingArea);
    398                                  canvas.MouseEventListener = null;
     423                                 canvasUI.MouseEventListener = null;
    399424                               };
    400425
    401       canvas.MouseEventListener = panListener;
     426      canvasUI.MouseEventListener = panListener;
    402427    }
    403428
     
    406431
    407432      zoomFullView = false;
    408       canvas.Invalidate();
     433      canvasUI.Invalidate();
    409434    }
    410435
     
    415440      optionsdlg.ShowDialog(this);
    416441    }
    417 
    418     public void OnDataRowChanged(IDataRow row) {
    419       foreach (LineShape ls in rowToLineShapes[row]) {
    420         ls.LSColor = row.Color;
    421         ls.LSThickness = row.Thickness;
    422         ls.LSDrawingStyle = row.Style;
    423       }
    424       canvas.Invalidate();
    425     }
    426442  }
    427443}
Note: See TracChangeset for help on using the changeset viewer.