[1350] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
[1458] | 3 | using System.Drawing;
|
---|
[1996] | 4 | using System.Xml;
|
---|
| 5 | using HeuristicLab.Core;
|
---|
[1350] | 6 | using HeuristicLab.Visualization.LabelProvider;
|
---|
[1457] | 7 | using HeuristicLab.Visualization.Test;
|
---|
[1350] | 8 |
|
---|
| 9 | namespace HeuristicLab.Visualization {
|
---|
| 10 | public delegate void YAxisDescriptorChangedHandler(YAxisDescriptor sender);
|
---|
| 11 |
|
---|
[1996] | 12 | public class YAxisDescriptor : StorableBase {
|
---|
| 13 | private ILabelProvider labelProvider = new ContinuousLabelProvider("0.##");
|
---|
[1350] | 14 | private readonly List<IDataRow> dataRows = new List<IDataRow>();
|
---|
| 15 | private bool showYAxis = true;
|
---|
[1462] | 16 | private bool showYAxisLabel = true;
|
---|
[1350] | 17 | private string label = "";
|
---|
[1969] | 18 | private bool clipChangeable = true;
|
---|
[1457] | 19 | private AxisPosition position = AxisPosition.Left;
|
---|
[1350] | 20 |
|
---|
[1458] | 21 | private bool showGrid = true;
|
---|
| 22 | private Color gridColor = Color.LightBlue;
|
---|
| 23 |
|
---|
[1350] | 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 |
|
---|
[1462] | 44 | public bool ShowYAxisLabel {
|
---|
| 45 | get { return showYAxisLabel; }
|
---|
| 46 | set {
|
---|
| 47 | showYAxisLabel = value;
|
---|
| 48 | OnYAxisDescriptorChanged();
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[1996] | 52 | public ILabelProvider LabelProvider {
|
---|
| 53 | get { return labelProvider; }
|
---|
[1350] | 54 | set {
|
---|
[1996] | 55 | labelProvider = value;
|
---|
[1350] | 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 |
|
---|
[1460] | 92 | public bool ClipChangeable {
|
---|
| 93 | get { return clipChangeable; }
|
---|
| 94 | set { clipChangeable = value; }
|
---|
[1390] | 95 | }
|
---|
| 96 |
|
---|
[1457] | 97 | public AxisPosition Position {
|
---|
| 98 | get { return position; }
|
---|
[1458] | 99 | set {
|
---|
| 100 | position = value;
|
---|
| 101 | OnYAxisDescriptorChanged();
|
---|
| 102 | }
|
---|
[1457] | 103 | }
|
---|
| 104 |
|
---|
[1458] | 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 |
|
---|
[1350] | 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 | }
|
---|
[1996] | 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 | }
|
---|
[1350] | 169 | }
|
---|
| 170 | } |
---|