Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Operator Architecture Refactoring/HeuristicLab.Charting.Data/Datachart.cs @ 1708

Last change on this file since 1708 was 550, checked in by gkronber, 16 years ago

fixed #267 (DataRowType.Bars is not implemented in DataChart).
Bars can be specified by adding two data points for the lower left and upper right corner.

File size: 4.1 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;
26using HeuristicLab.Charting;
27
28namespace HeuristicLab.Charting.Data {
29  public class Datachart : Chart {
30    private IList<DataRowType> dataRowTypes;
31
32    private string myTitle;
33    public string Title {
34      get { return myTitle; }
35      set {
36        if(myTitle != value) {
37          myTitle = value;
38          OnUpdate();
39        }
40      }
41    }
42
43    public Datachart(PointD lowerLeft, PointD upperRight)
44      : base(lowerLeft, upperRight) {
45      dataRowTypes = new List<DataRowType>();
46    }
47    public Datachart(double x1, double y1, double x2, double y2)
48      : this(new PointD(x1, y1), new PointD(x2, y2)) {
49    }
50
51    public void AddDataRow(DataRowType dataRowType, Pen pen, Brush brush) {
52      Group group = new Group(this);
53      group.Pen = pen;
54      group.Brush = brush;
55      Group.Add(group);
56      dataRowTypes.Add(dataRowType);
57      if(dataRowType == DataRowType.Lines) {
58        Group lines = new Group(this);
59        group.Add(lines);
60        Group points = new Group(this);
61        group.Add(points);
62      }
63    }
64    public void RemoveDataRow(int index) {
65      Group.Remove(Group.Primitives[index]);
66      dataRowTypes.RemoveAt(index);
67    }
68
69    public void AddDataPoint(int dataRowIndex, PointD point) {
70      DataRowType dataRowType = dataRowTypes[dataRowIndex];
71      Group group = (Group)Group.Primitives[dataRowIndex];
72
73      switch(dataRowType) {
74        case DataRowType.Lines:
75          Group lines = (Group)group.Primitives[1];
76          Group points = (Group)group.Primitives[0];
77          if(points.Primitives.Count > 0) {
78            FixedSizeRectangle lastRect = (FixedSizeRectangle)points.Primitives[0];
79            Line line = new Line(this, lastRect.Point, point, group.Pen);
80            lines.Add(line);
81          }
82          FixedSizeRectangle rect = new FixedSizeRectangle(this, point, new Size(5, 5), group.Pen, group.Brush);
83          rect.ToolTipText = "(" + point.X.ToString() + " ; " + point.Y.ToString() + ")";
84          points.Add(rect);
85          break;
86        case DataRowType.Bars:
87          if(group.Primitives.Count < 2) {
88            group.Add(new FixedSizeRectangle(this, point, new Size(0, 0), group.Pen, group.Brush));
89            if(group.Primitives.Count == 2) {
90              PointD p = ((FixedSizeRectangle)group.Primitives[0]).Point;
91              PointD q = ((FixedSizeRectangle)group.Primitives[1]).Point;
92              double y0 = Math.Min(p.Y, q.Y);
93              double y1 = Math.Max(p.Y, q.Y);
94              double x0 = Math.Min(p.X, q.X);
95              double x1 = Math.Max(p.X, q.X);
96              Rectangle bar = new Rectangle(this, x0, y0, x1, y1, group.Pen, group.Brush);
97              bar.ToolTipText = "Height=" + (y1 - y0);
98              group.Add(bar);
99            }
100          }
101          break;
102        case DataRowType.Points:
103          FixedSizeRectangle r = new FixedSizeRectangle(this, point, new Size(5, 5), group.Pen, group.Brush);
104          r.ToolTipText = "(" + point.X.ToString() + " ; " + point.Y.ToString() + ")";
105          group.Add(r);
106          break;
107      }
108    }
109    public void AddDataPoint(int dataRowIndex, double x, double y) {
110      AddDataPoint(dataRowIndex, new PointD(x, y));
111    }
112  }
113}
Note: See TracBrowser for help on using the repository browser.