Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2708_ScopedAlgorithms/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingChartContent.cs @ 17915

Last change on this file since 17915 was 12676, checked in by mkommend, 9 years ago

#2335: Merged changes into trunk.

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