- Timestamp:
- 06/03/09 01:42:55 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/3.2/ChartDataRowsModel.cs
r1989 r1993 5 5 using System.Xml; 6 6 using HeuristicLab.Core; 7 using System.Text;8 7 using HeuristicLab.Visualization.Options; 8 using HeuristicLab.Visualization.Test; 9 9 10 10 namespace HeuristicLab.Visualization{ … … 123 123 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 124 124 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 125 126 XmlSupport.SetAttribute("Title", title, node); 125 127 126 List<YAxisDescriptor> yAx is = new List<YAxisDescriptor>();127 yAx is.Add(defaultYAxisDescriptor);128 List<YAxisDescriptor> yAxes = new List<YAxisDescriptor>(); 129 yAxes.Add(defaultYAxisDescriptor); 128 130 foreach (IDataRow row in rows) { 129 XmlNode rowElement = row.ToXml(row, document); 130 131 if (!yAxis.Contains(row.YAxis)) { 132 yAxis.Add(row.YAxis); 133 } 134 135 node.AppendChild(rowElement); 136 } 137 138 foreach (YAxisDescriptor axis in yAxis) { 139 XmlNode yAxisElement = document.CreateNode(XmlNodeType.Element, "yAxis", null); 140 141 XmlAttribute attrLabel = document.CreateAttribute("label"); 142 attrLabel.Value = axis.Label; 143 yAxisElement.Attributes.Append(attrLabel); 144 145 if (axis == defaultYAxisDescriptor) { 146 XmlAttribute attrDefault = document.CreateAttribute("default"); 147 attrDefault.Value = "true"; 148 yAxisElement.Attributes.Append(attrDefault); 149 } 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 150 node.AppendChild(yAxisElement); 151 152 } 153 154 XmlNode labelProviderNode = document.ImportNode(XAxis.LabelProvider.GetLabelProviderXmlNode(), true); 155 node.AppendChild(labelProviderNode); 156 157 158 159 XmlNode modelProperties = document.CreateNode(XmlNodeType.Element, "modelProperties", null); 160 161 XmlAttribute attrTitle = document.CreateAttribute("title"); 162 attrTitle.Value = Title; 163 modelProperties.Attributes.Append(attrTitle); 164 165 166 167 node.AppendChild(modelProperties); 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 161 foreach (IDataRow row in rows) { 162 node.AppendChild(row.ToXml(document)); 163 } 164 165 node.AppendChild(XAxis.LabelProvider.GetLabelProviderXmlNode(document)); 168 166 169 167 return node; … … 173 171 base.Populate(node, restoredObjects); 174 172 175 List<YAxisDescriptor> yAxis = new List<YAxisDescriptor>(); 176 foreach (XmlNode dataRow in node.ChildNodes) 177 { 178 if (dataRow.Name.Equals("yAxis")) 179 { 180 XmlAttributeCollection attrs = dataRow.Attributes; 181 182 XmlAttribute attrYAxisLabel = (XmlAttribute)attrs.GetNamedItem("label"); 183 string axisLabel = attrYAxisLabel.Value; 184 YAxisDescriptor axis = new YAxisDescriptor(); 185 axis.Label = axisLabel; 186 yAxis.Add(axis); 187 188 XmlAttribute attrDefault = (XmlAttribute)attrs.GetNamedItem("default"); 189 if (attrDefault != null) { 190 defaultYAxisDescriptor = axis; 191 } 192 } 193 } 194 195 foreach (XmlNode dataRow in node.ChildNodes) { 196 if (dataRow.Name.Equals("modelProperties")) { 197 XmlAttributeCollection attrs = dataRow.Attributes; 198 XmlAttribute attrYAxisLabel = (XmlAttribute)attrs.GetNamedItem("title"); 199 Title = attrYAxisLabel.Value; 200 } 201 } 202 203 foreach (XmlNode dataRow in node.ChildNodes) { 204 if (dataRow.Name.Equals("LabelProvider")) { 205 XAxis.LabelProvider = XAxis.LabelProvider.PopulateLabelProviderXmlNode(dataRow); 206 } else if (dataRow.Name.Equals("row")) { 207 XmlAttributeCollection attrs = dataRow.Attributes; 208 XmlAttribute rowIdAttr = (XmlAttribute)attrs.GetNamedItem("label"); 209 string rowLabel = rowIdAttr.Value; 210 211 string rowColor = attrs.GetNamedItem("color").Value; 212 DataRow row = new DataRow(); 213 row.RowSettings.Label = rowLabel; 214 row.RowSettings.Color = Color.FromArgb(Int32.Parse(rowColor)); 215 216 string rowThickness = attrs.GetNamedItem("thickness").Value; 217 int thick; 218 Int32.TryParse(rowThickness, out thick); 219 row.RowSettings.Thickness = thick; 220 221 string yAxisLabel = attrs.GetNamedItem("yAxis").Value; 222 foreach (YAxisDescriptor axis in yAxis) { 223 if (axis.Label.Equals(yAxisLabel)) { 224 row.YAxis = axis; 225 } 226 } 227 228 string[] tokens = dataRow.InnerText.Split(';'); 229 double[] data = new double[tokens.Length]; 230 for (int i = 0; i < data.Length; i++) { 231 if (tokens[i].Length != 0) { 232 if ( 233 double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == 234 false) { 235 throw new FormatException("Can't parse " + tokens[i] + " as double value."); 236 } 237 } 238 } 239 row.AddValues(data); 240 AddDataRow(row); 241 } 173 title = XmlSupport.GetAttribute("Title", "", node); 174 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; 189 } 190 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 } 199 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); 242 226 } 243 227 }
Note: See TracChangeset
for help on using the changeset viewer.