source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/LineChartView.cs @ 14467

Last change on this file since 14467 was 14459, checked in by pfleck, 4 years ago

#2709

  • Removed the PreprocessingDataTable and PreprocessingDataTableView and use dhe HL DatatTableControl instead.
  • Moved and refactored some code of PreprocessingChart and moved unnecessary code from base classes to actual derivative classes.
File size: 4.9 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.Linq;
25using HeuristicLab.Analysis;
26using HeuristicLab.Analysis.Views;
27using HeuristicLab.Collections;
28using HeuristicLab.Data;
29using HeuristicLab.MainForm;
30
31namespace HeuristicLab.DataPreprocessing.Views {
32
33  [View("Line Chart View")]
34  [Content(typeof(LineChartContent), true)]
35  public partial class LineChartView : PreprocessingChartView {
36
37    protected Dictionary<string, DataRow> allInOneDataRows;
38    protected DataTable allInOneDataTable;
39    protected DataTableControl allInOneDataTableControl;
40
41    public LineChartView() {
42      InitializeComponent();
43      allInOneDataRows = new Dictionary<string, DataRow>();
44      allInOneDataTable= new DataTable();
45    }
46
47    public new LineChartContent Content {
48      get { return (LineChartContent)base.Content; }
49      set { base.Content = value; }
50    }
51
52    protected override void InitData() {
53      base.InitData();
54
55      allInOneDataRows.Clear();
56      foreach (var x in Content.VariableItemList.Select((v, i) => new { variable = v.Value, i })) {
57        var row = Content.CreateDataRow(x.variable, DataRowVisualProperties.DataRowChartType.Line);
58        row.VisualProperties.Color = Colors[x.i % Colors.Length];
59        allInOneDataRows.Add(x.variable, row);
60      }
61
62      allInOneDataTable.Rows.Clear();
63      foreach (var variable in Content.VariableItemList.CheckedItems) {
64        allInOneDataTable.Rows.Add(allInOneDataRows[variable.Value.Value]);
65      }
66    }
67
68    protected override int GetNumberOfVisibleDataTables() {
69      return Content.AllInOneMode ? 1 : base.GetNumberOfVisibleDataTables();
70    }
71    protected override IEnumerable<DataTableControl> GetVisibleDataTables() {
72      if (Content.AllInOneMode) {
73        if (allInOneDataTableControl == null)
74          allInOneDataTableControl = new DataTableControl() { Content = allInOneDataTable };
75        return new[] { allInOneDataTableControl };
76      }
77      return base.GetVisibleDataTables();
78    }
79    protected override DataTable CreateDataTable(string variableName) {
80      var dt = new DataTable();
81      dt.Rows.Add(Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Line));
82      return dt;
83    }
84
85    private void allInOneCheckBox_CheckedChanged(object sender, EventArgs e) {
86      Content.AllInOneMode = allInOneCheckBox.Checked;
87
88      GenerateLayout();
89    }
90
91    protected override void OnContentChanged() {
92      base.OnContentChanged();
93      if (Content != null) {
94        allInOneCheckBox.Checked = Content.AllInOneMode;
95      }
96    }
97
98    protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
99      base.CheckedItemsChanged(sender, checkedItems);
100
101      foreach (IndexedItem<StringValue> item in checkedItems.Items) {
102        string variableName = item.Value.Value;
103
104        if (IsVariableChecked(variableName)) {
105          // ToDo: avoid clearing all rows, but how?
106          allInOneDataTable.Rows.Clear();
107          foreach (var variable in Content.VariableItemList.CheckedItems) {
108            allInOneDataTable.Rows.Add(allInOneDataRows[variable.Value.Value]);
109          }
110        } else {
111          allInOneDataTable.Rows.Remove(variableName);
112        }
113      }
114    }
115
116    #region Add/Remove/Update Variable, Reset
117    protected override void AddVariable(string name) {
118      base.AddVariable(name);
119      var row = Content.CreateDataRow(name, DataRowVisualProperties.DataRowChartType.Line);
120      allInOneDataTable.Rows.Add(row);
121    }
122
123    // remove variable from data table and item list
124    protected override void RemoveVariable(string name) {
125      base.RemoveVariable(name);
126      allInOneDataTable.Rows.Remove(name);
127    }
128
129    protected override void UpdateVariable(string name) {
130      base.UpdateVariable(name);
131      allInOneDataTable.Rows.Remove(name);
132      var newRow = Content.CreateDataRow(name, DataRowVisualProperties.DataRowChartType.Line);
133      allInOneDataTable.Rows.Add(newRow);
134    }
135    #endregion
136  }
137}
Note: See TracBrowser for help on using the repository browser.