Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs @ 14279

Last change on this file since 14279 was 14186, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

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