Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/ChartDataRowsModel.cs @ 793

Last change on this file since 793 was 761, checked in by mstoeger, 16 years ago

changed interface between model and view (#316)

File size: 5.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using HeuristicLab.Core;
5
6namespace HeuristicLab.Visualization{
7  public delegate void DataRowAddedHandler(IDataRow row);
8  public delegate void DataRowRemovedHandler(IDataRow row);
9
10  public delegate void ModelChangedHandler();
11
12  public class ChartDataRowsModel : ChartDataModelBase, IChartDataRowsModel {
13    private string title;
14    private string xAxisLabel;
15    private string yAxisLabel;
16
17    public void AddLabel(string label) {
18      throw new NotImplementedException();
19      // TODO ModelChangedEvent auslösen
20    }
21
22    public void AddLabel(string label, int index) {
23      throw new NotImplementedException();
24      // TODO ModelChangedEvent auslösen
25    }
26
27    public void AddLabels(string[] labels) {
28      throw new NotImplementedException();
29      // TODO ModelChangedEvent auslösen
30    }
31
32    public void AddLabels(string[] labels, int index) {
33      throw new NotImplementedException();
34      // TODO ModelChangedEvent auslösen
35    }
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();
62      }
63    }
64
65    public string XAxisLabel {
66      get { return xAxisLabel; }
67      set {
68        xAxisLabel = value;
69        OnModelChanged();
70      }
71    }
72
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      }
119    }
120
121    public override IView CreateView() {
122      return new LineChart(this); //when LineChart is implemented
123    }
124
125    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
126      throw new NotImplementedException();
127
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;
148    }
149
150
151   
152    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
153      throw new NotImplementedException();
154
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//      }
175    }
176  }
177}
Note: See TracBrowser for help on using the repository browser.