Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/PreprocessingChartContent.cs @ 14710

Last change on this file since 14710 was 14581, checked in by mkommend, 8 years ago

#2709: Refactored get variables for grouping (extracted method to another class).

File size: 3.3 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.Common.Resources;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31
32namespace HeuristicLab.DataPreprocessing {
33  [Item("PreprocessingChart", "Represents a preprocessing chart.")]
34  public class PreprocessingChartContent : Item, IViewShortcut {
35    public static new Image StaticItemImage {
36      get { return VSImageLibrary.PieChart; }
37    }
38
39    private ICheckedItemList<StringValue> variableItemList = null;
40    public ICheckedItemList<StringValue> VariableItemList {
41      get {
42        if (variableItemList == null)
43          variableItemList = CreateVariableItemList(PreprocessingData);
44        return this.variableItemList;
45      }
46    }
47
48    public IFilteredPreprocessingData PreprocessingData { get; private set; }
49    public event DataPreprocessingChangedEventHandler Changed {
50      add { PreprocessingData.Changed += value; }
51      remove { PreprocessingData.Changed -= value; }
52    }
53
54    public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
55      PreprocessingData = preprocessingData;
56    }
57
58    public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
59      : base(content, cloner) {
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    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    private static ICheckedItemList<StringValue> CreateVariableItemList(IPreprocessingData preprocessingData) {
75      ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
76      foreach (string name in preprocessingData.GetDoubleVariableNames()) {
77        var n = new StringValue(name);
78        bool isInputTarget = preprocessingData.InputVariables.Contains(name) || preprocessingData.TargetVariable == name;
79        itemList.Add(n, isInputTarget);
80      }
81      return new ReadOnlyCheckedItemList<StringValue>(itemList);
82    }
83  }
84}
Note: See TracBrowser for help on using the repository browser.