Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/YAxisDescriptor.cs @ 2594

Last change on this file since 2594 was 1996, checked in by mstoeger, 15 years ago

implemented IStorable and made use of the PersistenceManager wherever possible. #639

File size: 5.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4using System.Xml;
5using HeuristicLab.Core;
6using HeuristicLab.Visualization.LabelProvider;
7using HeuristicLab.Visualization.Test;
8
9namespace HeuristicLab.Visualization {
10  public delegate void YAxisDescriptorChangedHandler(YAxisDescriptor sender);
11
12  public class YAxisDescriptor : StorableBase {
13    private ILabelProvider labelProvider = new ContinuousLabelProvider("0.##");
14    private readonly List<IDataRow> dataRows = new List<IDataRow>();
15    private bool showYAxis = true;
16    private bool showYAxisLabel = true;
17    private string label = "";
18    private bool clipChangeable = true;
19    private AxisPosition position = AxisPosition.Left;
20
21    private bool showGrid = true;
22    private Color gridColor = Color.LightBlue;
23
24    public event YAxisDescriptorChangedHandler YAxisDescriptorChanged;
25
26    private void OnYAxisDescriptorChanged() {
27      if (YAxisDescriptorChanged != null) {
28        YAxisDescriptorChanged(this);
29      }
30    }
31
32    public List<IDataRow> DataRows {
33      get { return dataRows; }
34    }
35
36    public bool ShowYAxis {
37      get { return showYAxis; }
38      set {
39        showYAxis = value;
40        OnYAxisDescriptorChanged();
41      }
42    }
43
44    public bool ShowYAxisLabel {
45      get { return showYAxisLabel; }
46      set {
47        showYAxisLabel = value;
48        OnYAxisDescriptorChanged();
49      }
50    }
51
52    public ILabelProvider LabelProvider {
53      get { return labelProvider; }
54      set {
55        labelProvider = value;
56        OnYAxisDescriptorChanged();
57      }
58    }
59
60    public double MinValue {
61      get {
62        double min = double.MaxValue;
63
64        foreach (IDataRow row in dataRows) {
65          min = Math.Min(min, row.MinValue);
66        }
67
68        return min;
69      }
70    }
71
72    public double MaxValue {
73      get {
74        double max = double.MinValue;
75
76        foreach (IDataRow row in dataRows) {
77          max = Math.Max(max, row.MaxValue);
78        }
79
80        return max;
81      }
82    }
83
84    public string Label {
85      get { return label; }
86      set {
87        label = value;
88        OnYAxisDescriptorChanged();
89      }
90    }
91
92    public bool ClipChangeable {
93      get { return clipChangeable; }
94      set { clipChangeable = value; }
95    }
96
97    public AxisPosition Position {
98      get { return position; }
99      set {
100        position = value;
101        OnYAxisDescriptorChanged();
102      }
103    }
104
105    public bool ShowGrid {
106      get { return showGrid; }
107      set {
108        showGrid = value;
109        OnYAxisDescriptorChanged();
110      }
111    }
112
113    public Color GridColor {
114      get { return gridColor; }
115      set {
116        gridColor = value;
117        OnYAxisDescriptorChanged();
118      }
119    }
120
121    public void AddDataRow(IDataRow row) {
122      if (row.YAxis != null) {
123        row.YAxis.DataRows.Remove(row);
124      }
125      this.DataRows.Add(row);
126      OnYAxisDescriptorChanged();
127    }
128
129    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
130      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
131
132      XmlSupport.SetAttribute("Label", this.Label, node);
133      XmlSupport.SetAttribute("GridColor", this.GridColor.ToArgb().ToString(), node);
134      XmlSupport.SetAttribute("Position", this.Position.ToString(), node);
135      XmlSupport.SetAttribute("ShowGrid", this.ShowGrid ? "true" : "false", node);
136      XmlSupport.SetAttribute("ShowYAxis", this.ShowYAxis ? "true" : "false", node);
137      XmlSupport.SetAttribute("ShowYAxisLabel", this.ShowYAxisLabel ? "true" : "false", node);
138      XmlSupport.SetAttribute("ClipChangeable", this.ClipChangeable ? "true" : "false", node);
139
140      node.AppendChild(PersistenceManager.Persist("LabelProvider", this.LabelProvider, document, persistedObjects));
141
142      foreach (IDataRow row in dataRows) {
143        node.AppendChild(PersistenceManager.Persist("DataRow", row, document, persistedObjects));
144      }
145
146      return node;
147    }
148
149    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
150      base.Populate(node, restoredObjects);
151
152      this.Label = XmlSupport.GetAttribute("Label", "", node);
153      this.GridColor = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("GridColor", Color.LightBlue.ToArgb().ToString(), node)));
154      this.Position = (AxisPosition)Enum.Parse(typeof(AxisPosition), XmlSupport.GetAttribute("Position", "Left", node));
155      this.ShowGrid = XmlSupport.GetAttribute("ShowGrid", "true", node) == "true";
156      this.ShowYAxis = XmlSupport.GetAttribute("ShowYAxis", "true", node) == "true";
157      this.ShowYAxisLabel = XmlSupport.GetAttribute("ShowYAxisLabel", "true", node) == "true";
158      this.ClipChangeable = XmlSupport.GetAttribute("ClipChangeable", "true", node) == "true";
159
160      XmlNode labelProviderNode = node.SelectSingleNode("LabelProvider");
161      if (labelProviderNode != null)
162        this.labelProvider = (ILabelProvider)PersistenceManager.Restore(labelProviderNode, restoredObjects);
163
164      foreach (XmlNode dataRowNode in node.SelectNodes("DataRow")) {
165        IDataRow row = (IDataRow)PersistenceManager.Restore(dataRowNode, restoredObjects);
166        AddDataRow(row);
167      }
168    }
169  }
170}
Note: See TracBrowser for help on using the repository browser.