Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs @ 14381

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

#2698

  • Refactored CheckedVariablesView out of the ChartView to allow reuse of the checked variables list.
    • The new list visualizes the non-input/target variables in gray.
    • Added context menu to quickly (un)check all variables or only the inputs+target variables.
  • In the Multi-Scatterplot
    • New structure and layout of the single charts to support fixed header rows and columns (for the variable names). Instead, removed the legend of each plot for better usage of plot area.
    • Adapted the new CheckedVariablesView (but hidden until (un)checking is implemented).
File size: 6.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.Drawing;
24using System.Linq;
25using System.Windows.Forms;
26using HeuristicLab.Collections;
27using HeuristicLab.Core.Views;
28using HeuristicLab.Data;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.DataPreprocessing.Views {
32  [View("Preprocessing Checked Variables View")]
33  [Content(typeof(PreprocessingChartContent), false)]
34  public /*abstract*/ partial class PreprocessingCheckedVariablesView : ItemView {
35
36    public new PreprocessingChartContent Content {
37      get { return (PreprocessingChartContent)base.Content; }
38      set { base.Content = value; }
39    }
40
41    protected PreprocessingCheckedVariablesView() {
42      InitializeComponent();
43    }
44
45    protected bool VariableIsChecked(string name) {
46      return Content.VariableItemList.CheckedItems.Any(x => x.Value.Value == name);
47    }
48
49
50    protected override void OnContentChanged() {
51      base.OnContentChanged();
52      if (Content == null) return;
53
54      if (Content.VariableItemList == null) {
55        Content.VariableItemList = Content.CreateVariableItemList();
56      } else {
57        var checkedNames = Content.VariableItemList.CheckedItems.Select(x => x.Value.Value);
58        Content.VariableItemList = Content.CreateVariableItemList(checkedNames);
59      }
60      Content.VariableItemList.CheckedItemsChanged += CheckedItemsChanged;
61
62      checkedItemList.Content = Content.VariableItemList;
63      var target = Content.PreprocessingData.TargetVariable;
64      var inputAndTarget = Content.PreprocessingData.InputVariables.Union(target != null ? new[] { target } : new string[] { });
65      foreach (var col in Content.PreprocessingData.GetDoubleVariableNames().Except(inputAndTarget)) {
66        var listViewItem = checkedItemList.ItemsListView.FindItemWithText(col);
67        listViewItem.ForeColor = Color.LightGray;
68      }
69    }
70    protected override void RegisterContentEvents() {
71      base.RegisterContentEvents();
72      Content.PreprocessingData.Changed += PreprocessingData_Changed;
73      Content.PreprocessingData.SelectionChanged += PreprocessingData_SelctionChanged;
74    }
75    protected override void DeregisterContentEvents() {
76      Content.PreprocessingData.Changed -= PreprocessingData_Changed;
77      Content.PreprocessingData.SelectionChanged -= PreprocessingData_SelctionChanged;
78      base.DeregisterContentEvents();
79    }
80
81    protected virtual void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
82    }
83
84    private void PreprocessingData_Changed(object sender, DataPreprocessingChangedEventArgs e) {
85      switch (e.Type) {
86        case DataPreprocessingChangedEventType.DeleteColumn:
87          RemoveVariable(Content.PreprocessingData.GetVariableName(e.Column));
88          break;
89        case DataPreprocessingChangedEventType.AddColumn:
90          AddVariable(Content.PreprocessingData.GetVariableName(e.Column));
91          break;
92        case DataPreprocessingChangedEventType.ChangeColumn:
93        case DataPreprocessingChangedEventType.ChangeItem:
94          UpdateVariable(Content.PreprocessingData.GetVariableName(e.Column));
95          break;
96        default:
97          ResetAllVariables();
98          break;
99      }
100    }
101
102    protected virtual void AddVariable(string name) {
103      Content.VariableItemList.Add(new StringValue(name));
104      if (!Content.PreprocessingData.InputVariables.Contains(name) && Content.PreprocessingData.TargetVariable != name) {
105        var listViewItem = checkedItemList.ItemsListView.FindItemWithText(name);
106        listViewItem.ForeColor = Color.LightGray;
107      }
108    }
109    protected virtual void RemoveVariable(string name) {
110      var stringValue = Content.VariableItemList.SingleOrDefault(n => n.Value == name);
111      if (stringValue != null)
112        Content.VariableItemList.Remove(stringValue);
113    }
114    protected virtual void UpdateVariable(string name) {
115    }
116    protected virtual void ResetAllVariables() {
117    }
118
119    protected virtual void PreprocessingData_SelctionChanged(object sender, EventArgs e) {
120    }
121
122    #region ContextMenu Events
123    private void variablesListcontextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
124      var data = Content.PreprocessingData;
125      checkInputsTargetToolStripMenuItem.Text = "Check Inputs" + (data.TargetVariable != null ? "+Target" : "");
126      checkOnlyInputsTargetToolStripMenuItem.Text = "Check only Inputs" + (data.TargetVariable != null ? "+Target" : "");
127    }
128    private void checkInputsTargetToolStripMenuItem_Click(object sender, EventArgs e) {
129      foreach (var name in checkedItemList.Content) {
130        var isInputTarget = Content.PreprocessingData.InputVariables.Contains(name.Value) || Content.PreprocessingData.TargetVariable == name.Value;
131        if (isInputTarget) {
132          checkedItemList.Content.SetItemCheckedState(name, true);
133        }
134      }
135    }
136    private void checkOnlyInputsTargetToolStripMenuItem_Click(object sender, EventArgs e) {
137      foreach (var name in checkedItemList.Content) {
138        var isInputTarget = Content.PreprocessingData.InputVariables.Contains(name.Value) || Content.PreprocessingData.TargetVariable == name.Value;
139        checkedItemList.Content.SetItemCheckedState(name, isInputTarget);
140      }
141    }
142    private void checkAllToolStripMenuItem_Click(object sender, EventArgs e) {
143      foreach (var name in checkedItemList.Content) {
144        checkedItemList.Content.SetItemCheckedState(name, true);
145      }
146    }
147    private void uncheckAllToolStripMenuItem_Click(object sender, EventArgs e) {
148      foreach (var name in checkedItemList.Content) {
149        checkedItemList.Content.SetItemCheckedState(name, false);
150      }
151    }
152    #endregion
153  }
154}
155
156
Note: See TracBrowser for help on using the repository browser.