[10539] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 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] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[10539] | 24 | using System.Drawing;
|
---|
[10992] | 25 | using HeuristicLab.Analysis;
|
---|
[10539] | 26 | using HeuristicLab.Common;
|
---|
[10245] | 27 | using HeuristicLab.Core;
|
---|
[10818] | 28 | using HeuristicLab.Data;
|
---|
[10242] | 29 |
|
---|
[10539] | 30 | namespace HeuristicLab.DataPreprocessing {
|
---|
[10658] | 31 | [Item("PreprocessingChart", "Represents a preprocessing chart.")]
|
---|
[10962] | 32 | public class PreprocessingChartContent : Item, IViewChartShortcut {
|
---|
[10992] | 33 | public static new Image StaticItemImage {
|
---|
| 34 | get { return HeuristicLab.Common.Resources.VSImageLibrary.PieChart; }
|
---|
| 35 | }
|
---|
[10252] | 36 |
|
---|
[10818] | 37 | private bool allInOneMode = true;
|
---|
[10992] | 38 | public bool AllInOneMode {
|
---|
| 39 | get { return this.allInOneMode; }
|
---|
| 40 | set { this.allInOneMode = value; }
|
---|
| 41 | }
|
---|
[10818] | 42 |
|
---|
| 43 | private ICheckedItemList<StringValue> variableItemList = null;
|
---|
[10992] | 44 | public ICheckedItemList<StringValue> VariableItemList {
|
---|
| 45 | get { return this.variableItemList; }
|
---|
| 46 | set { this.variableItemList = value; }
|
---|
| 47 | }
|
---|
[10818] | 48 |
|
---|
[10992] | 49 | public IFilteredPreprocessingData PreprocessingData { get; private set; }
|
---|
[10818] | 50 |
|
---|
[10992] | 51 | public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
|
---|
| 52 | PreprocessingData = preprocessingData;
|
---|
[10252] | 53 | }
|
---|
| 54 |
|
---|
[10658] | 55 | public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
|
---|
[10539] | 56 | : base(content, cloner) {
|
---|
[10992] | 57 | this.allInOneMode = content.allInOneMode;
|
---|
[10995] | 58 | this.PreprocessingData = content.PreprocessingData;
|
---|
[10992] | 59 | this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
|
---|
[10245] | 60 | }
|
---|
[10992] | 61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 62 | return new PreprocessingChartContent(this, cloner);
|
---|
| 63 | }
|
---|
[10245] | 64 |
|
---|
[10992] | 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;
|
---|
[10252] | 71 | }
|
---|
| 72 |
|
---|
[10992] | 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;
|
---|
[10245] | 78 | }
|
---|
| 79 |
|
---|
[10992] | 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;
|
---|
[10245] | 99 | }
|
---|
[10573] | 100 |
|
---|
[10992] | 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;
|
---|
[10573] | 114 | }
|
---|
[10818] | 115 |
|
---|
[10992] | 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;
|
---|
[10818] | 124 | }
|
---|
| 125 |
|
---|
[10992] | 126 |
|
---|
[14418] | 127 | public ICheckedItemList<StringValue> CreateVariableItemList(IList<string> checkedItems = null) {
|
---|
| 128 | if (checkedItems == null) checkedItems = new string[0];
|
---|
[10992] | 129 | ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
|
---|
| 130 | foreach (string name in PreprocessingData.GetDoubleVariableNames()) {
|
---|
[12676] | 131 | var n = new StringValue(name);
|
---|
[14418] | 132 | itemList.Add(n, 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 | }
|
---|