Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 10549 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
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 {
[10377]28    private IPreprocessingData preprocessingData;
[10382]29    private DataTable dataTable;
[10377]30
31    public LineChartLogic(IPreprocessingData preprocessingData) {
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() {
[10382]50      return preprocessingData.VariableNames;
51    }
52
[10539]53    public DataTable GetDataTable() {
[10382]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) {
[10539]75        if (item.Name == name)
76          return true;
[10382]77      }
78      return false;
79    }
80
[10544]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    }
[10244]102  }
103}
Note: See TracBrowser for help on using the repository browser.