Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Charting.Grid/Grid.cs @ 2

Last change on this file since 2 was 2, checked in by swagner, 17 years ago

Added HeuristicLab 3.0 sources from former SVN repository at revision 52

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Drawing;
26
27namespace HeuristicLab.Charting.Grid {
28  public class Grid : Group {
29    private int rows;
30    public int RowCount {
31      get { return rows; }
32    }
33
34    private int columns;
35    public int ColumnCount {
36      get { return columns; }
37    }
38
39    private PointD myLowerLeft;
40    public virtual PointD LowerLeft {
41      get { return myLowerLeft; }
42    }
43
44    private PointD myUpperRight;
45    public virtual PointD UpperRight {
46      get { return myUpperRight; }
47    }
48
49    public virtual SizeD Size {
50      get { return new SizeD(UpperRight.X - LowerLeft.X, UpperRight.Y - LowerLeft.Y); }
51    }
52
53    private void UpdateLines() {
54      if (Primitives.Count > 0) {
55        this.Clear();
56      }
57      if ((rows == 0) || (columns == 0)) {
58        return;
59      }
60      double width = Size.Width / ColumnCount;
61      double height = Size.Height / RowCount;
62      PointD ll = LowerLeft;
63      PointD ur = UpperRight;
64      for(int col = 0; col <= ColumnCount; col++) {
65        ur.X = ll.X;
66        this.Add(new Line(Chart, ll, ur, this.Pen));
67        ll.X += width;
68      }
69      ll = LowerLeft;
70      ur = UpperRight;
71      for(int row = 0; row <= RowCount; row++) {
72        ur.Y = ll.Y;
73        this.Add(new Line(Chart, ll, ur, this.Pen));
74        ll.Y += height;
75      }
76    }
77
78    public Grid(IChart chart, PointD lowerLeft, PointD upperRight, int rows, int cols) : base(chart) {
79      SetPosition(lowerLeft, upperRight);
80      this.rows = rows;
81      this.columns = cols;
82      UpdateLines();
83      // UpdateEnabled = false; // vielleicht doch besser net?
84    }
85
86    public virtual void SetPosition(PointD lowerLeft, PointD upperRight) {
87      if((lowerLeft.X > upperRight.X) || (lowerLeft.Y > upperRight.Y))
88        throw new ArgumentException("Lower left point is greater than upper right point");
89      myLowerLeft = lowerLeft;
90      myUpperRight = upperRight;
91      UpdateLines();
92      OnUpdate();
93    }
94
95    public virtual void SetRowsCols(int rows, int columns) {
96      this.rows = rows;
97      this.columns = columns;
98      UpdateLines();
99      OnUpdate();
100    }
101
102    public override void Move(Offset delta) {
103      // do nothing
104    }
105
106    public override bool ContainsPoint(PointD point) {
107      // throw new Exception("The method or operation is not implemented.");
108      return false;
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.