Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10557 was 10552, checked in by aesterer, 11 years ago

Revised line chart and added histogram

File size: 3.7 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      List<string> doubleVariableNames = new List<string>();
51
52      //only return variable names from type double
53      foreach (string variableName in preprocessingData.VariableNames) {
54        if (preprocessingData.IsType<double>(preprocessingData.GetColumnIndex(variableName)))
55          doubleVariableNames.Add(variableName);
56      }
57
58      return doubleVariableNames;
59    }
60
61    public DataTable GetDataTable() {
62      return dataTable;
63    }
64
65    public void RemoveVariable(string name) {
66      dataTable.Rows.Remove(name);
67    }
68
69    public void AddVariable(string name) {
70      IList<double> values = preprocessingData.GetValues<double>(name);
71      DataRow row = new DataRow(name, "", values);
72      dataTable.Rows.Add(row);
73    }
74
75    public bool VariableIsDisplayed(string name) {
76
77      foreach (var item in dataTable.Rows) {
78        if (item.Name == name)
79          return true;
80      }
81      return false;
82    }
83
84    void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
85      var variableName = preprocessingData.GetVariableName(e.Column);
86      switch (e.Type) {
87        case DataPreprocessingChangedEventType.DeleteColumn:
88          dataTable.Rows.Remove(variableName);
89          break;
90        case DataPreprocessingChangedEventType.AddColumn:
91          dataTable.Rows.Add(new DataRow(variableName, String.Empty, preprocessingData.GetValues<double>(e.Column)));
92          break;
93        case DataPreprocessingChangedEventType.ChangeColumn:
94        case DataPreprocessingChangedEventType.ChangeItem:
95          dataTable.Rows.Remove(variableName);
96          dataTable.Rows.Add(new DataRow(variableName, String.Empty, preprocessingData.GetValues<double>(e.Column)));
97          break;
98        case DataPreprocessingChangedEventType.DeleteRow:
99        case DataPreprocessingChangedEventType.AddRow:
100          dataTable.Rows.Clear();
101          FillDataTable();
102          break;
103      }
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.