Changeset 761 for trunk/sources/HeuristicLab.Visualization
- Timestamp:
- 11/15/08 10:47:40 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Visualization
- Files:
-
- 3 added
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/ChartDataRowsModel.cs
r754 r761 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Globalization;4 using System.IO;5 using System.Linq;6 using System.Runtime.Serialization;7 using System.Text;8 //using System.Collections.Specialized;9 3 using System.Xml; 10 using System.Xml.Serialization;11 4 using HeuristicLab.Core; 12 using HeuristicLab.Data;13 14 5 15 6 namespace HeuristicLab.Visualization{ 7 public delegate void DataRowAddedHandler(IDataRow row); 8 public delegate void DataRowRemovedHandler(IDataRow row); 9 10 public delegate void ModelChangedHandler(); 11 16 12 public class ChartDataRowsModel : ChartDataModelBase, IChartDataRowsModel { 13 private string title; 14 private string xAxisLabel; 15 private string yAxisLabel; 17 16 18 private IntData test = new IntData(1); 19 20 public ChartDataRowsModel(){ 21 22 columns = new List<ChartDataRowsModelColumn>(); 23 24 17 public void AddLabel(string label) { 18 throw new NotImplementedException(); 19 // TODO ModelChangedEvent auslösen 25 20 } 26 21 27 public void AddDataRow(int id){ 28 29 double[] vals = new double[0]; 30 31 ChartDataRowsModelColumn col = new ChartDataRowsModelColumn(id, vals); 32 33 columns.Add(col); 22 public void AddLabel(string label, int index) { 23 throw new NotImplementedException(); 24 // TODO ModelChangedEvent auslösen 34 25 } 35 26 36 public void PushData(int dataRowId, double value){ 27 public void AddLabels(string[] labels) { 28 throw new NotImplementedException(); 29 // TODO ModelChangedEvent auslösen 30 } 37 31 38 double[] vals = new double[columns[dataRowId].Values.Length + 1]; 39 for (int i = 0; i < columns[dataRowId].Values.Length; i++) { 40 vals[i] = columns[dataRowId].Values[i]; 32 public void AddLabels(string[] labels, int index) { 33 throw new NotImplementedException(); 34 // TODO ModelChangedEvent auslösen 35 } 41 36 37 public void ModifyLabel(string label, int index) { 38 throw new NotImplementedException(); 39 // TODO ModelChangedEvent auslösen 40 } 41 42 public void ModifyLabels(string[] labels, int index) { 43 throw new NotImplementedException(); 44 // TODO ModelChangedEvent auslösen 45 } 46 47 public void RemoveLabel(int index) { 48 throw new NotImplementedException(); 49 // TODO ModelChangedEvent auslösen 50 } 51 52 public void RemoveLabels(int index, int count) { 53 throw new NotImplementedException(); 54 // TODO ModelChangedEvent auslösen 55 } 56 57 public string Title { 58 get { return title; } 59 set { 60 title = value; 61 OnModelChanged(); 42 62 } 63 } 43 64 44 vals[vals.Length-1] = value; 45 columns[dataRowId].Values = vals; 65 public string XAxisLabel { 66 get { return xAxisLabel; } 67 set { 68 xAxisLabel = value; 69 OnModelChanged(); 70 } 71 } 46 72 47 RaiseColumnChanged(ChangeType.Add, vals.Length-1, new double[1]{value}); 73 public string YAxisLabel { 74 get { return yAxisLabel; } 75 set { 76 yAxisLabel = value; 77 OnModelChanged(); 78 } 79 } 80 81 public event ModelChangedHandler ModelChanged; 82 83 protected void OnModelChanged() { 84 if (ModelChanged != null) { 85 ModelChanged(); 86 } 87 } 88 89 private readonly List<IDataRow> rows = new List<IDataRow>(); 90 91 public static IDataRow CreateDataRow() { 92 throw new NotImplementedException(); 93 } 94 95 public void AddDataRow(IDataRow row) { 96 rows.Add(row); 97 OnDataRowAdded(row); 98 } 99 100 public void RemoveDataRow(IDataRow row) { 101 rows.Remove(row); 102 OnDataRowRemoved(row); 103 } 104 105 public event DataRowAddedHandler DataRowAdded; 106 107 protected void OnDataRowAdded(IDataRow row) { 108 if (DataRowAdded != null) { 109 DataRowAdded(row); 110 } 111 } 112 113 public event DataRowRemovedHandler DataRowRemoved; 114 115 protected void OnDataRowRemoved(IDataRow row) { 116 if (DataRowRemoved != null) { 117 DataRowRemoved(row); 118 } 48 119 } 49 120 50 121 public override IView CreateView() { 51 122 return new LineChart(this); //when LineChart is implemented 52 return new IntDataView(test);53 123 } 54 124 55 public event ChartDataRowsModelColumnChangedHandler ColumnChanged; 125 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 126 throw new NotImplementedException(); 56 127 57 private void RaiseColumnChanged(ChangeType type, long columnId, double[] values) { 58 if (ColumnChanged != null) { 59 ColumnChanged(type, columnId, values); 60 } 61 } 62 63 private List<ChartDataRowsModelColumn> columns; 64 65 public List<ChartDataRowsModelColumn> Columns { 66 get { return columns; } 67 } 68 69 70 71 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 72 73 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 74 75 foreach (ChartDataRowsModelColumn column in Columns){ 76 XmlNode columnElement = document.CreateNode(XmlNodeType.Element, "column", null); 77 78 XmlAttribute idAttr = document.CreateAttribute("id"); 79 idAttr.Value = (column.ColumnId).ToString(); 80 columnElement.Attributes.Append(idAttr); 81 82 for (int i = 0; i < column.Values.Length; i++){ 83 if (i == 0){ 84 columnElement.InnerText += column.Values[i].ToString(CultureInfo.InvariantCulture.NumberFormat); 85 } else{ 86 columnElement.InnerText += ";" + column.Values[i].ToString(CultureInfo.InvariantCulture.NumberFormat); 87 } 88 } 89 node.AppendChild(columnElement); 90 } 91 92 return node; 93 128 // XmlNode node = base.GetXmlNode(name, document, persistedObjects); 129 // 130 // foreach (ChartDataRowsModelColumn column in Columns){ 131 // XmlNode columnElement = document.CreateNode(XmlNodeType.Element, "column", null); 132 // 133 // XmlAttribute idAttr = document.CreateAttribute("id"); 134 // idAttr.Value = (column.ColumnId).ToString(); 135 // columnElement.Attributes.Append(idAttr); 136 // 137 // for (int i = 0; i < column.Values.Length; i++){ 138 // if (i == 0){ 139 // columnElement.InnerText += column.Values[i].ToString(CultureInfo.InvariantCulture.NumberFormat); 140 // } else{ 141 // columnElement.InnerText += ";" + column.Values[i].ToString(CultureInfo.InvariantCulture.NumberFormat); 142 // } 143 // } 144 // node.AppendChild(columnElement); 145 // } 146 // 147 // return node; 94 148 } 95 149 … … 97 151 98 152 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 99 base.Populate(node, restoredObjects);153 throw new NotImplementedException(); 100 154 101 102 foreach (XmlNode column in node.ChildNodes){ 103 XmlAttributeCollection attrs = column.Attributes; 104 XmlAttribute rowIdAttr = (XmlAttribute)attrs.GetNamedItem("id"); 105 int rowId = int.Parse(rowIdAttr.Value); 106 AddDataRow(rowId); 107 string[] tokens = column.InnerText.Split(';'); 108 double[] data = new double[tokens.Length]; 109 for (int i = 0; i < data.Length; i++){ 110 if (tokens[i].Length != 0){ 111 if ( 112 double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == 113 false){ 114 throw new FormatException("Can't parse " + tokens[i] + " as double value."); 115 } 116 } 117 } 118 Columns[rowId-1].Values = data; 119 } 155 // base.Populate(node, restoredObjects); 156 // 157 // foreach (XmlNode column in node.ChildNodes){ 158 // XmlAttributeCollection attrs = column.Attributes; 159 // XmlAttribute rowIdAttr = (XmlAttribute)attrs.GetNamedItem("id"); 160 // int rowId = int.Parse(rowIdAttr.Value); 161 // AddDataRow(rowId); 162 // string[] tokens = column.InnerText.Split(';'); 163 // double[] data = new double[tokens.Length]; 164 // for (int i = 0; i < data.Length; i++){ 165 // if (tokens[i].Length != 0){ 166 // if ( 167 // double.TryParse(tokens[i], NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, out data[i]) == 168 // false){ 169 // throw new FormatException("Can't parse " + tokens[i] + " as double value."); 170 // } 171 // } 172 // } 173 // Columns[rowId-1].Values = data; 174 // } 120 175 } 121 176 } -
trunk/sources/HeuristicLab.Visualization/ChartDataRowsModelDummy.cs
r754 r761 9 9 Random rand = new Random(); 10 10 11 11 // TODO an neues model interface anpassen 12 throw new NotImplementedException(); 13 12 14 // test rows 13 for (int i = 0; i < 10; i++){14 AddDataRow(i);15 PushData(i, rand.NextDouble() * 1000);16 PushData(i, rand.NextDouble() * 1000);17 PushData(i, rand.NextDouble() * 1000);18 }15 // for (int i = 0; i < 10; i++){ 16 // AddDataRow(i); 17 // PushData(i, rand.NextDouble() * 1000); 18 // PushData(i, rand.NextDouble() * 1000); 19 // PushData(i, rand.NextDouble() * 1000); 20 // } 19 21 } 20 22 } -
trunk/sources/HeuristicLab.Visualization/HeuristicLab.Visualization.csproj
r754 r761 61 61 <Compile Include="ChartDataModelBase.cs" /> 62 62 <Compile Include="ChartDataRowsModel.cs" /> 63 <Compile Include="ChartDataRowsModelColumn.cs" />64 <Compile Include="ChartDataRowsModelColumnChangedHandler.cs" />65 63 <Compile Include="ChartDataRowsModelDummy.cs" /> 66 64 <Compile Include="CompositeShape.cs" /> 65 <Compile Include="DataRow.cs" /> 66 <Compile Include="DrawingStyle.cs" /> 67 67 <Compile Include="HeuristicLabVisualizationPlugin.cs" /> 68 68 <Compile Include="ICanvas.cs" /> 69 69 <Compile Include="IChartDataModel.cs" /> 70 70 <Compile Include="IChartDataRowsModel.cs" /> 71 <Compile Include="IDataRow.cs" /> 71 72 <Compile Include="IShape.cs" /> 72 73 <Compile Include="LineChart.cs"> -
trunk/sources/HeuristicLab.Visualization/IChartDataRowsModel.cs
r697 r761 1 using System.Collections.Generic; 1 namespace HeuristicLab.Visualization { 2 public interface IChartDataRowsModel { 3 string Title { get; set; } 4 string XAxisLabel { get; set; } 5 string YAxisLabel { get; set; } 2 6 3 namespace HeuristicLab.Visualization { 4 public interface IChartDataRowsModel { 5 event ChartDataRowsModelColumnChangedHandler ColumnChanged; 6 List<ChartDataRowsModelColumn> Columns { get; } 7 void AddDataRow(IDataRow row); 8 void RemoveDataRow(IDataRow row); 9 10 void AddLabel(string label); 11 void AddLabel(string label, int index); 12 void AddLabels(string[] labels); 13 void AddLabels(string[] labels, int index); 14 void ModifyLabel(string label, int index); 15 void ModifyLabels(string[] labels, int index); 16 void RemoveLabel(int index); 17 void RemoveLabels(int index, int count); 18 19 event ModelChangedHandler ModelChanged; 20 event DataRowAddedHandler DataRowAdded; 21 event DataRowRemovedHandler DataRowRemoved; 7 22 } 8 23 } -
trunk/sources/HeuristicLab.Visualization/LineChart.cs
r754 r761 49 49 private void Reset() 50 50 { 51 BeginUpdate(); 52 53 // TODO clear existing shapes 54 55 WorldShape mainWorld = canvasUI1.MainCanvas.WorldShape; 56 57 double spacing = mainWorld.BoundingBox.Width/model.Columns.Count; 58 double oldX = 0; 59 double currentX = spacing; 60 ChartDataRowsModelColumn oldColumn = null; 61 // reload data from the model and create shapes 62 foreach (ChartDataRowsModelColumn column in model.Columns) 63 { 64 if (oldColumn != null) 65 { 66 if (column.Values != null) 67 { 68 for (int i = 0; i < column.Values.Length; i++) 69 { 70 LineShape line = new LineShape(oldX, oldColumn.Values[i], currentX, column.Values[i], 0, lineColors[i]); 71 mainWorld.AddShape(line); 72 } 73 oldX = currentX; 74 currentX += spacing; 75 } 76 oldColumn = column; 77 } 78 else 79 { 80 oldColumn = column; 81 } 82 83 canvasUI1.Invalidate(); 84 85 // AddColumn(column.ColumnId, column.Values); 86 } 87 88 EndUpdate(); 51 // TODO an neues model interface anpassen 52 throw new NotImplementedException(); 53 54 // BeginUpdate(); 55 // 56 // // TODO clear existing shapes 57 // 58 // WorldShape mainWorld = canvasUI1.MainCanvas.WorldShape; 59 // 60 // double spacing = mainWorld.BoundingBox.Width/model.Columns.Count; 61 // double oldX = 0; 62 // double currentX = spacing; 63 // ChartDataRowsModelColumn oldColumn = null; 64 // // reload data from the model and create shapes 65 // foreach (ChartDataRowsModelColumn column in model.Columns) 66 // { 67 // if (oldColumn != null) 68 // { 69 // if (column.Values != null) 70 // { 71 // for (int i = 0; i < column.Values.Length; i++) 72 // { 73 // LineShape line = new LineShape(oldX, oldColumn.Values[i], currentX, column.Values[i], 0, lineColors[i]); 74 // mainWorld.AddShape(line); 75 // } 76 // oldX = currentX; 77 // currentX += spacing; 78 // } 79 // oldColumn = column; 80 // } 81 // else 82 // { 83 // oldColumn = column; 84 // } 85 // 86 // canvasUI1.Invalidate(); 87 // 88 // // AddColumn(column.ColumnId, column.Values); 89 // } 90 // 91 // EndUpdate(); 89 92 } 90 93 … … 146 149 protected override void AddItemEvents() 147 150 { 148 base.AddItemEvents(); 149 model.ColumnChanged += OnDataChanged; 151 // TODO an neues model interface anpassen 152 throw new NotImplementedException(); 153 // base.AddItemEvents(); 154 // model.ColumnChanged += OnDataChanged; 150 155 } 151 156 152 157 protected override void RemoveItemEvents() 153 158 { 154 base.RemoveItemEvents(); 155 model.ColumnChanged -= OnDataChanged; 159 // TODO an neues model interface anpassen 160 throw new NotImplementedException(); 161 162 // base.RemoveItemEvents(); 163 // model.ColumnChanged -= OnDataChanged; 156 164 } 157 165
Note: See TracChangeset
for help on using the changeset viewer.