Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10615 was 10586, checked in by tsteinre, 11 years ago
  • divided/refactored PreprocessingData into TransactionalPreprocessingData and preprocessingData
File size: 4.0 KB
RevLine 
[10539]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
[10544]22using System;
[10244]23using System.Collections.Generic;
[10377]24using HeuristicLab.Analysis;
[10244]25
[10539]26namespace HeuristicLab.DataPreprocessing {
27  public class LineChartLogic : ILineChartLogic {
[10586]28    private ITransactionalPreprocessingData preprocessingData;
[10382]29    private DataTable dataTable;
[10377]30
[10586]31    public LineChartLogic(ITransactionalPreprocessingData preprocessingData) {
[10377]32      this.preprocessingData = preprocessingData;
[10382]33      dataTable = new DataTable("LineChart");
34      FillDataTable();
[10544]35      preprocessingData.Changed += PreprocessingData_Changed;
[10377]36    }
37
[10382]38    private void FillDataTable() {
[10377]39      IEnumerable<string> variableNames = preprocessingData.VariableNames;
40
[10539]41      foreach (string variableName in variableNames) {
[10377]42        IList<double> values = preprocessingData.GetValues<double>(variableName);
43        DataRow row = new DataRow(variableName, "", values);
44        dataTable.Rows.Add(row);
45      }
[10539]46
[10377]47    }
[10382]48
[10539]49    public IEnumerable<object> GetVariableNames() {
[10552]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;
[10382]59    }
60
[10539]61    public DataTable GetDataTable() {
[10382]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) {
[10539]78        if (item.Name == name)
79          return true;
[10382]80      }
81      return false;
82    }
83
[10581]84    //TODO: refactor: possible code duplication with HistogramLogic
[10544]85    void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
86      switch (e.Type) {
87        case DataPreprocessingChangedEventType.DeleteColumn:
[10581]88          dataTable.Rows.Remove(preprocessingData.GetVariableName(e.Column));
[10544]89          break;
90        case DataPreprocessingChangedEventType.AddColumn:
[10581]91          dataTable.Rows.Add(new DataRow(preprocessingData.GetVariableName(e.Column), String.Empty, preprocessingData.GetValues<double>(e.Column)));
[10544]92          break;
93        case DataPreprocessingChangedEventType.ChangeColumn:
94        case DataPreprocessingChangedEventType.ChangeItem:
[10581]95          dataTable.Rows.Remove(preprocessingData.GetVariableName(e.Column));
96          dataTable.Rows.Add(new DataRow(preprocessingData.GetVariableName(e.Column), String.Empty, preprocessingData.GetValues<double>(e.Column)));
[10544]97          break;
98        case DataPreprocessingChangedEventType.DeleteRow:
99        case DataPreprocessingChangedEventType.AddRow:
100          dataTable.Rows.Clear();
101          FillDataTable();
102          break;
103      }
104    }
[10573]105
106    public event DataPreprocessingChangedEventHandler Changed {
107      add { preprocessingData.Changed += value; }
108      remove { preprocessingData.Changed -= value; }
109    }
[10244]110  }
111}
Note: See TracBrowser for help on using the repository browser.