Changeset 1385
- Timestamp:
- 03/21/09 10:07:16 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Visualization
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/ChartDataRowsModel.cs
r1350 r1385 204 204 node.AppendChild(columnElement); 205 205 } 206 207 XmlNode labelProviderNode = document.ImportNode(labelProvider.GetLabelProviderXmlNode(), true); 208 node.AppendChild(labelProviderNode); 209 206 210 return node; 207 211 } … … 211 215 212 216 foreach (XmlNode dataRow in node.ChildNodes) { 213 XmlAttributeCollection attrs = dataRow.Attributes; 214 XmlAttribute rowIdAttr = (XmlAttribute)attrs.GetNamedItem("label"); 215 string rowLabel = rowIdAttr.Value; 216 DataRow row = new DataRow(); 217 row.Label = rowLabel; 218 219 string[] tokens = dataRow.InnerText.Split(';'); 220 double[] data = new double[tokens.Length]; 221 for (int i = 0; i < data.Length; i++) { 222 if (tokens[i].Length != 0) { 223 if ( 224 double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == 225 false) { 226 throw new FormatException("Can't parse " + tokens[i] + " as double value."); 217 if (dataRow.Name.Equals("LabelProvider")) { 218 labelProvider = labelProvider.PopulateLabelProviderXmlNode(dataRow); 219 } else { 220 XmlAttributeCollection attrs = dataRow.Attributes; 221 XmlAttribute rowIdAttr = (XmlAttribute)attrs.GetNamedItem("label"); 222 string rowLabel = rowIdAttr.Value; 223 DataRow row = new DataRow(); 224 row.Label = rowLabel; 225 226 string[] tokens = dataRow.InnerText.Split(';'); 227 double[] data = new double[tokens.Length]; 228 for (int i = 0; i < data.Length; i++) { 229 if (tokens[i].Length != 0) { 230 if ( 231 double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == 232 false) { 233 throw new FormatException("Can't parse " + tokens[i] + " as double value."); 234 } 227 235 } 228 236 } 229 } 230 row.AddValues(data); 231 232 AddDataRow(row); 237 row.AddValues(data); 238 AddDataRow(row); 239 } 233 240 } 234 241 } -
trunk/sources/HeuristicLab.Visualization/LabelProvider/ContinuousLabelProvider.cs
r1194 r1385 1 1 using System.Globalization; 2 using System.Xml; 2 3 3 4 namespace HeuristicLab.Visualization.LabelProvider { … … 14 15 return value.ToString(format, CultureInfo.InvariantCulture); 15 16 } 17 18 public XmlNode GetLabelProviderXmlNode() 19 { 20 XmlDocument Xdoc = new XmlDocument(); 21 22 XmlNode lblProvInfo = Xdoc.CreateNode(XmlNodeType.Element, "LabelProvider", null); 23 lblProvInfo.InnerText = "ContinuousLabelProvider"; 24 25 XmlAttribute idFormat = Xdoc.CreateAttribute("format"); 26 idFormat.Value = this.format; 27 28 lblProvInfo.Attributes.Append(idFormat); 29 30 return lblProvInfo; 31 } 32 33 public ILabelProvider PopulateLabelProviderXmlNode(XmlNode node) { 34 var labelProvider = new ContinuousLabelProvider(node.SelectSingleNode("//LabelProvider").Attributes[0].Value); 35 return labelProvider; 36 } 16 37 } 17 38 } -
trunk/sources/HeuristicLab.Visualization/LabelProvider/DiscreteLabelProvider.cs
r1194 r1385 1 1 using System; 2 using System.Xml; 2 3 3 4 namespace HeuristicLab.Visualization.LabelProvider { … … 12 13 return string.Empty; 13 14 } 15 16 public XmlNode GetLabelProviderXmlNode() 17 { 18 XmlDocument Xdoc = new XmlDocument(); 19 20 XmlNode lblProvInfo = Xdoc.CreateNode(XmlNodeType.Element, "LabelProvider", null); 21 lblProvInfo.InnerText = "DiscreteLabelProvider"; 22 23 return lblProvInfo; 24 } 25 26 public ILabelProvider PopulateLabelProviderXmlNode(XmlNode node) { 27 var labelProvider = new DiscreteLabelProvider(); 28 return labelProvider; 29 } 14 30 } 15 31 } -
trunk/sources/HeuristicLab.Visualization/LabelProvider/ILabelProvider.cs
r1194 r1385 1 using System.Xml; 2 1 3 namespace HeuristicLab.Visualization.LabelProvider { 2 4 public interface ILabelProvider { 3 5 string GetLabel(double value); 6 XmlNode GetLabelProviderXmlNode(); 7 ILabelProvider PopulateLabelProviderXmlNode(XmlNode node); 4 8 } 5 9 } -
trunk/sources/HeuristicLab.Visualization/LabelProvider/StringLabelProvider.cs
r1194 r1385 2 2 using System.Collections.Generic; 3 3 using HeuristicLab.Visualization.LabelProvider; 4 using System.Xml; 4 5 5 6 namespace HeuristicLab.Visualization.LabelProvider { … … 26 27 return string.Empty; 27 28 } 29 30 public XmlNode GetLabelProviderXmlNode() { 31 XmlDocument Xdoc = new XmlDocument(); 32 33 XmlNode lblProvInfo = Xdoc.CreateNode(XmlNodeType.Element, "LabelProvider", null); 34 lblProvInfo.InnerText = "StringLabelProvider"; 35 36 foreach (KeyValuePair<int, string> pair in labels) 37 { 38 XmlNode strLbl = Xdoc.CreateNode(XmlNodeType.Element, "String", null); 39 40 XmlAttribute idStrLbl = Xdoc.CreateAttribute("id"); 41 idStrLbl.Value = pair.Key.ToString(); 42 strLbl.Attributes.Append(idStrLbl); 43 44 strLbl.InnerText = pair.Value; 45 lblProvInfo.AppendChild(strLbl); 46 } 47 return lblProvInfo; 48 } 49 50 public ILabelProvider PopulateLabelProviderXmlNode(XmlNode node) { 51 var labelProvider = new StringLabelProvider(); 52 53 foreach (XmlNode strLbl in node.SelectNodes("//String")) 54 { 55 labelProvider.SetLabel(int.Parse(strLbl.Attributes[0].Value), strLbl.InnerText); 56 } 57 return labelProvider; 58 } 28 59 } 29 60 }
Note: See TracChangeset
for help on using the changeset viewer.