[2] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using HeuristicLab.Charting;
|
---|
| 27 |
|
---|
| 28 | namespace 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 {
|
---|
[550] | 36 | if(myTitle != value) {
|
---|
[2] | 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);
|
---|
[550] | 57 | if(dataRowType == DataRowType.Lines) {
|
---|
[2] | 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 |
|
---|
[550] | 73 | switch(dataRowType) {
|
---|
[2] | 74 | case DataRowType.Lines:
|
---|
| 75 | Group lines = (Group)group.Primitives[1];
|
---|
| 76 | Group points = (Group)group.Primitives[0];
|
---|
[550] | 77 | if(points.Primitives.Count > 0) {
|
---|
[2] | 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:
|
---|
[550] | 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 | }
|
---|
[2] | 101 | break;
|
---|
| 102 | case DataRowType.Points:
|
---|
[550] | 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);
|
---|
[2] | 106 | break;
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | public void AddDataPoint(int dataRowIndex, double x, double y) {
|
---|
| 110 | AddDataPoint(dataRowIndex, new PointD(x, y));
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|