Free cookie consent management tool by TermsFeed Policy Generator

source: branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs @ 14232

Last change on this file since 14232 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 5.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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 System.Drawing;
25using System.Linq;
26using HeuristicLab.Analysis;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29using HeuristicLab.Data;
30
31namespace HeuristicLab.DataPreprocessing {
32  [Item("PreprocessingChart", "Represents a preprocessing chart.")]
33  public class PreprocessingChartContent : Item, IViewChartShortcut {
34    public static new Image StaticItemImage {
35      get { return HeuristicLab.Common.Resources.VSImageLibrary.PieChart; }
36    }
37
38    private bool allInOneMode = true;
39    public bool AllInOneMode {
40      get { return this.allInOneMode; }
41      set { this.allInOneMode = value; }
42    }
43
44    private ICheckedItemList<StringValue> variableItemList = null;
45    public ICheckedItemList<StringValue> VariableItemList {
46      get { return this.variableItemList; }
47      set { this.variableItemList = value; }
48    }
49
50    public IFilteredPreprocessingData PreprocessingData { get; private set; }
51
52    public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
53      PreprocessingData = preprocessingData;
54    }
55
56    public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
57      : base(content, cloner) {
58      this.allInOneMode = content.allInOneMode;
59      this.PreprocessingData = content.PreprocessingData;
60      this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
61    }
62    public override IDeepCloneable Clone(Cloner cloner) {
63      return new PreprocessingChartContent(this, cloner);
64    }
65
66
67    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
68      IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
69      DataRow row = new DataRow(variableName, "", values);
70      row.VisualProperties.ChartType = chartType;
71      return row;
72    }
73
74    public List<DataRow> CreateAllDataRows(DataRowVisualProperties.DataRowChartType chartType) {
75      List<DataRow> dataRows = new List<DataRow>();
76      foreach (var name in PreprocessingData.GetDoubleVariableNames())
77        dataRows.Add(CreateDataRow(name, chartType));
78      return dataRows;
79    }
80
81    public DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
82
83      IDictionary<int, IList<int>> selection = PreprocessingData.Selection;
84      int variableIndex = PreprocessingData.GetColumnIndex(variableName);
85
86      if (selection.Keys.Contains(variableIndex)) {
87        List<int> selectedIndices = new List<int>(selection[variableIndex]);
88        //need selection with more than 1 value
89        if (selectedIndices.Count < 2)
90          return null;
91
92        selectedIndices.Sort();
93        int start = selectedIndices[0];
94        int end = selectedIndices[selectedIndices.Count - 1];
95
96        DataRow rowSelect = CreateDataRowRange(variableName, start, end, chartType);
97        return rowSelect;
98      } else
99        return null;
100    }
101
102    public DataRow CreateDataRowRange(string variableName, int start, int end, DataRowVisualProperties.DataRowChartType chartType) {
103      IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
104      IList<double> valuesRange = new List<double>();
105      for (int i = 0; i < values.Count; i++) {
106        if (i >= start && i <= end)
107          valuesRange.Add(values[i]);
108        else
109          valuesRange.Add(Double.NaN);
110      }
111
112      DataRow row = new DataRow(variableName, "", valuesRange);
113      row.VisualProperties.ChartType = chartType;
114      return row;
115    }
116
117    public List<DataRow> CreateAllSelectedDataRows(DataRowVisualProperties.DataRowChartType chartType) {
118      List<DataRow> dataRows = new List<DataRow>();
119      foreach (var name in PreprocessingData.GetDoubleVariableNames()) {
120        DataRow row = CreateSelectedDataRow(name, chartType);
121        if (row != null)
122          dataRows.Add(row);
123      }
124      return dataRows;
125    }
126
127
128    public ICheckedItemList<StringValue> CreateVariableItemList(IEnumerable<string> checkedItems = null) {
129      ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
130      foreach (string name in PreprocessingData.GetDoubleVariableNames()) {
131        var n = new StringValue(name);
132        itemList.Add(n, (checkedItems == null) ? true : checkedItems.Contains(name));
133      }
134      return new ReadOnlyCheckedItemList<StringValue>(itemList);
135    }
136
137    public event DataPreprocessingChangedEventHandler Changed {
138      add { PreprocessingData.Changed += value; }
139      remove { PreprocessingData.Changed -= value; }
140    }
141
142  }
143}
Note: See TracBrowser for help on using the repository browser.