Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingChartContent.cs @ 14046

Last change on this file since 14046 was 12718, checked in by mkommend, 9 years ago

#2335: Merged all changes into stable.

File size: 5.6 KB
RevLine 
[10539]1#region License Information
2/* HeuristicLab
[12009]3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10539]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
[10992]22using System;
23using System.Collections.Generic;
[10539]24using System.Drawing;
[12718]25using System.Linq;
[10992]26using HeuristicLab.Analysis;
[10539]27using HeuristicLab.Common;
[10245]28using HeuristicLab.Core;
[10818]29using HeuristicLab.Data;
[10992]30using HeuristicLab.DataPreprocessing.Interfaces;
[10242]31
[10539]32namespace HeuristicLab.DataPreprocessing {
[10658]33  [Item("PreprocessingChart", "Represents a preprocessing chart.")]
[10962]34  public class PreprocessingChartContent : Item, IViewChartShortcut {
[10992]35    public static new Image StaticItemImage {
36      get { return HeuristicLab.Common.Resources.VSImageLibrary.PieChart; }
37    }
[10252]38
[10818]39    private bool allInOneMode = true;
[10992]40    public bool AllInOneMode {
41      get { return this.allInOneMode; }
42      set { this.allInOneMode = value; }
43    }
[10818]44
45    private ICheckedItemList<StringValue> variableItemList = null;
[10992]46    public ICheckedItemList<StringValue> VariableItemList {
47      get { return this.variableItemList; }
48      set { this.variableItemList = value; }
49    }
[10818]50
[10992]51    public IFilteredPreprocessingData PreprocessingData { get; private set; }
[10818]52
[10992]53    public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
54      PreprocessingData = preprocessingData;
[10252]55    }
56
[10658]57    public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
[10539]58      : base(content, cloner) {
[10992]59      this.allInOneMode = content.allInOneMode;
[10995]60      this.PreprocessingData = content.PreprocessingData;
[10992]61      this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
[10245]62    }
[10992]63    public override IDeepCloneable Clone(Cloner cloner) {
64      return new PreprocessingChartContent(this, cloner);
65    }
[10245]66
[10992]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;
[10252]73    }
74
[10992]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;
[10245]80    }
81
[10992]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;
[10245]101    }
[10573]102
[10992]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;
[10573]116    }
[10818]117
[10992]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;
[10818]126    }
127
[10992]128
[12718]129    public ICheckedItemList<StringValue> CreateVariableItemList(IEnumerable<string> checkedItems = null) {
[10992]130      ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
131      foreach (string name in PreprocessingData.GetDoubleVariableNames()) {
[12718]132        var n = new StringValue(name);
133        itemList.Add(n, (checkedItems == null) ? true : checkedItems.Contains(name));
[10992]134      }
135      return new ReadOnlyCheckedItemList<StringValue>(itemList);
[10818]136    }
[10992]137
138    public event DataPreprocessingChangedEventHandler Changed {
139      add { PreprocessingData.Changed += value; }
140      remove { PreprocessingData.Changed -= value; }
141    }
142
[10242]143  }
144}
Note: See TracBrowser for help on using the repository browser.