Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs @ 14418

Last change on this file since 14418 was 14418, checked in by pfleck, 7 years ago

#2698 Only input and target variables are pre-checked for linechart, histrogram and scatterplot.

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