- Timestamp:
- 06/04/09 00:41:56 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/3.2/ChartDataRowsModel.cs
r1993 r1996 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Drawing;4 using System.Globalization;5 3 using System.Xml; 6 4 using HeuristicLab.Core; 7 5 using HeuristicLab.Visualization.Options; 8 using HeuristicLab.Visualization.Test;9 6 10 7 namespace HeuristicLab.Visualization{ … … 16 13 private string title = "Title"; 17 14 private ViewSettings viewSettings = new ViewSettings(); 18 private readonly XAxisDescriptor xAxisDescriptor = new XAxisDescriptor();15 private XAxisDescriptor xAxisDescriptor; 19 16 private YAxisDescriptor defaultYAxisDescriptor = new YAxisDescriptor(); 20 17 private readonly List<IDataRow> rows = new List<IDataRow>(); 21 18 22 19 public ChartDataRowsModel() { 23 this.XAxis .XAxisDescriptorChanged += delegate { OnModelChanged(); };20 this.XAxis = new XAxisDescriptor(); 24 21 } 25 22 … … 38 35 public XAxisDescriptor XAxis { 39 36 get { return xAxisDescriptor; } 37 private set { 38 this.xAxisDescriptor = value; 39 this.xAxisDescriptor.XAxisDescriptorChanged += delegate { OnModelChanged(); }; 40 } 40 41 } 41 42 … … 125 126 126 127 XmlSupport.SetAttribute("Title", title, node); 127 128 List<YAxisDescriptor> yAxes = new List<YAxisDescriptor>();129 yAxes.Add(defaultYAxisDescriptor);130 foreach (IDataRow row in rows) {131 if (!yAxes.Contains(row.YAxis)) {132 yAxes.Add(row.YAxis);133 }134 }135 136 foreach (YAxisDescriptor yAxis in yAxes) {137 XmlNode yAxisElement = document.CreateElement("YAxis");138 139 XmlSupport.SetAttribute("Label", yAxis.Label, yAxisElement);140 XmlSupport.SetAttribute("GridColor", yAxis.GridColor.ToArgb().ToString(), yAxisElement);141 XmlSupport.SetAttribute("Position", yAxis.Position.ToString(), yAxisElement);142 XmlSupport.SetAttribute("ShowGrid", yAxis.ShowGrid ? "true" : "false", yAxisElement);143 XmlSupport.SetAttribute("ShowYAxis", yAxis.ShowYAxis ? "true" : "false", yAxisElement);144 XmlSupport.SetAttribute("ShowYAxisLabel", yAxis.ShowYAxisLabel ? "true" : "false", yAxisElement);145 XmlSupport.SetAttribute("ClipChangeable", yAxis.ClipChangeable ? "true" : "false", yAxisElement);146 147 if (yAxis == defaultYAxisDescriptor)148 XmlSupport.SetAttribute("Default", "true", yAxisElement);149 150 node.AppendChild(yAxisElement);151 }152 153 XmlNode xAxisElement = document.CreateElement("XAxis");154 XmlSupport.SetAttribute("Color", xAxisDescriptor.Color.ToArgb().ToString(), xAxisElement);155 XmlSupport.SetAttribute("GridColor", xAxisDescriptor.GridColor.ToArgb().ToString(), xAxisElement);156 XmlSupport.SetAttribute("Label", xAxisDescriptor.Label, xAxisElement);157 XmlSupport.SetAttribute("ShowGrid", xAxisDescriptor.ShowGrid ? "true" : "false", xAxisElement);158 XmlSupport.SetAttribute("ShowLabel", xAxisDescriptor.ShowLabel ? "true" : "false", xAxisElement);159 node.AppendChild(xAxisElement);160 128 161 129 foreach (IDataRow row in rows) { 162 node.AppendChild( row.ToXml(document));130 node.AppendChild(PersistenceManager.Persist("DataRow", row, document, persistedObjects)); 163 131 } 164 165 node.AppendChild( XAxis.LabelProvider.GetLabelProviderXmlNode(document));132 node.AppendChild(PersistenceManager.Persist("DefaultYAxis", this.DefaultYAxis, document, persistedObjects)); 133 node.AppendChild(PersistenceManager.Persist("XAxis", this.XAxis, document, persistedObjects)); 166 134 167 135 return node; … … 173 141 title = XmlSupport.GetAttribute("Title", "", node); 174 142 175 List<YAxisDescriptor> yAxes = new List<YAxisDescriptor>(); 176 foreach (XmlNode yAxisNode in node.SelectNodes("YAxis")) { 177 YAxisDescriptor yAxis = new YAxisDescriptor(); 178 yAxis.Label = XmlSupport.GetAttribute("Label", "", yAxisNode); 179 yAxis.GridColor = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("GridColor", Color.LightBlue.ToArgb().ToString(), yAxisNode))); 180 yAxis.Position = (AxisPosition)Enum.Parse(typeof(AxisPosition), XmlSupport.GetAttribute("Position", "Left", yAxisNode)); 181 yAxis.ShowGrid = XmlSupport.GetAttribute("ShowGrid", "true", yAxisNode) == "true"; 182 yAxis.ShowYAxis = XmlSupport.GetAttribute("ShowYAxis", "true", yAxisNode) == "true"; 183 yAxis.ShowYAxisLabel = XmlSupport.GetAttribute("ShowYAxisLabel", "true", yAxisNode) == "true"; 184 yAxis.ClipChangeable = XmlSupport.GetAttribute("ClipChangeable", "true", yAxisNode) == "true"; 185 yAxes.Add(yAxis); 186 187 if (XmlSupport.GetAttribute("Default", null, yAxisNode) != null) 188 defaultYAxisDescriptor = yAxis; 143 foreach (XmlNode dataRowNode in node.SelectNodes("DataRow")) { 144 IDataRow dataRow = (IDataRow)PersistenceManager.Restore(dataRowNode, restoredObjects); 145 AddDataRow(dataRow); 189 146 } 190 147 191 XmlNode xAxisElement = node.SelectSingleNode("XAxis"); 192 if (xAxisElement != null) { 193 xAxisDescriptor.Color = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("Color", Color.Blue.ToArgb().ToString(), xAxisElement))); 194 xAxisDescriptor.GridColor = Color.FromArgb(int.Parse(XmlSupport.GetAttribute("GridColor", Color.LightBlue.ToArgb().ToString(), xAxisElement))); 195 xAxisDescriptor.Label = XmlSupport.GetAttribute("Label", "", xAxisElement); 196 xAxisDescriptor.ShowGrid = XmlSupport.GetAttribute("ShowGrid", "true", xAxisElement) == "true"; 197 xAxisDescriptor.ShowLabel = XmlSupport.GetAttribute("ShowLabel", "true", xAxisElement) == "true"; 198 } 148 XmlNode defaultYAxisNode = node.SelectSingleNode("DefaultYAxis"); 149 if (defaultYAxisNode != null) 150 this.defaultYAxisDescriptor = (YAxisDescriptor)PersistenceManager.Restore(defaultYAxisNode, restoredObjects); 199 151 200 XmlNode xAxisLabelProviderNode = node.SelectSingleNode("LabelProvider"); 201 xAxisDescriptor.LabelProvider = xAxisDescriptor.LabelProvider.PopulateLabelProviderXmlNode(xAxisLabelProviderNode); 202 203 foreach (XmlNode dataRow in node.SelectNodes("Row")) { 204 string rowLabel = XmlSupport.GetAttribute("Label", "", dataRow); 205 206 DataRow row = new DataRow(); 207 row.RowSettings.Label = rowLabel; 208 row.RowSettings.Color = Color.FromArgb(Int32.Parse(XmlSupport.GetAttribute("Color", Color.Black.ToArgb().ToString(), dataRow))); 209 row.RowSettings.LineType = (DataRowType)Enum.Parse(typeof(DataRowType), XmlSupport.GetAttribute("LineType", "Normal", dataRow)); 210 row.RowSettings.Thickness = Int32.Parse(XmlSupport.GetAttribute("Thickness", "2", dataRow)); 211 row.RowSettings.ShowMarkers = XmlSupport.GetAttribute("ShowMarkers", "true", dataRow) == "true"; 212 row.RowSettings.Style = (DrawingStyle)Enum.Parse(typeof (DrawingStyle), XmlSupport.GetAttribute("Style", DrawingStyle.Solid.ToString(), dataRow)); 213 214 foreach (YAxisDescriptor yAxis in yAxes) { 215 if (yAxis.Label.Equals(XmlSupport.GetAttribute("YAxis", dataRow))) 216 row.YAxis = yAxis; 217 } 218 219 string[] tokens = dataRow.InnerText.Split(';'); 220 foreach (string token in tokens) { 221 double value = double.Parse(token, CultureInfo.InvariantCulture); 222 row.AddValue(value); 223 } 224 225 AddDataRow(row); 226 } 152 XmlNode xAxisNode = node.SelectSingleNode("XAxis"); 153 if (xAxisNode != null) 154 this.XAxis = (XAxisDescriptor)PersistenceManager.Restore(xAxisNode, restoredObjects); 227 155 } 228 156 }
Note: See TracChangeset
for help on using the changeset viewer.