Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/LineChartLogic.cs @ 10544

Last change on this file since 10544 was 10544, checked in by sbreuer, 11 years ago
  • created changed event in preprocessing data
  • register to event in line chart
File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Analysis;
25
26namespace HeuristicLab.DataPreprocessing {
27  public class LineChartLogic : ILineChartLogic {
28    private IPreprocessingData preprocessingData;
29    private DataTable dataTable;
30
31    public LineChartLogic(IPreprocessingData preprocessingData) {
32      this.preprocessingData = preprocessingData;
33      dataTable = new DataTable("LineChart");
34      FillDataTable();
35      preprocessingData.Changed += PreprocessingData_Changed;
36    }
37
38    private void FillDataTable() {
39      IEnumerable<string> variableNames = preprocessingData.VariableNames;
40
41      foreach (string variableName in variableNames) {
42        IList<double> values = preprocessingData.GetValues<double>(variableName);
43        DataRow row = new DataRow(variableName, "", values);
44        dataTable.Rows.Add(row);
45      }
46
47    }
48
49    public IEnumerable<object> GetVariableNames() {
50      return preprocessingData.VariableNames;
51    }
52
53    public DataTable GetDataTable() {
54      return dataTable;
55    }
56
57
58    #region ILineChartLogic Members
59
60    public void RemoveVariable(string name) {
61      dataTable.Rows.Remove(name);
62    }
63
64    public void AddVariable(string name) {
65      IList<double> values = preprocessingData.GetValues<double>(name);
66      DataRow row = new DataRow(name, "", values);
67      dataTable.Rows.Add(row);
68    }
69
70    #endregion
71
72    public bool VariableIsDisplayed(string name) {
73
74      foreach (var item in dataTable.Rows) {
75        if (item.Name == name)
76          return true;
77      }
78      return false;
79    }
80
81    void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
82      var variableName = preprocessingData.GetVariableName(e.Column);
83      switch (e.Type) {
84        case DataPreprocessingChangedEventType.DeleteColumn:
85          dataTable.Rows.Remove(variableName);
86          break;
87        case DataPreprocessingChangedEventType.AddColumn:
88          dataTable.Rows.Add(new DataRow(variableName, String.Empty, preprocessingData.GetValues<double>(e.Column)));
89          break;
90        case DataPreprocessingChangedEventType.ChangeColumn:
91        case DataPreprocessingChangedEventType.ChangeItem:
92          dataTable.Rows.Remove(variableName);
93          dataTable.Rows.Add(new DataRow(variableName, String.Empty, preprocessingData.GetValues<double>(e.Column)));
94          break;
95        case DataPreprocessingChangedEventType.DeleteRow:
96        case DataPreprocessingChangedEventType.AddRow:
97          dataTable.Rows.Clear();
98          FillDataTable();
99          break;
100      }
101    }
102  }
103}
Note: See TracBrowser for help on using the repository browser.