Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2709

  • Added Check Inputs/All/None buttons instead of showing disabled buttons of the ItemCollectionView.
  • Removed the PreprocessingCheckedItemListView. A standard ListView is used instead.
  • Fixed slow updating when simultaneously (un-)checking multiple variables in the chart views. (currently only works by using the new buttons)
File size: 5.6 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;
30using HeuristicLab.Visualization.ChartControlsExtensions;
31
32namespace HeuristicLab.DataPreprocessing.Views {
33
34  [View("Line Chart View")]
35  [Content(typeof(LineChartContent), true)]
36  public partial class LineChartView : PreprocessingChartView {
37
38    protected Dictionary<string, DataRow> allInOneDataRows;
39    protected DataTable allInOneDataTable;
40    protected DataTableControl allInOneDataTableControl;
41
42    public LineChartView() {
43      InitializeComponent();
44      allInOneDataRows = new Dictionary<string, DataRow>();
45      allInOneDataTable= new DataTable();
46    }
47
48    public new LineChartContent Content {
49      get { return (LineChartContent)base.Content; }
50      set { base.Content = value; }
51    }
52
53    protected override void InitData() {
54      base.InitData();
55
56      allInOneDataRows.Clear();
57      foreach (var x in Content.VariableItemList.Select((v, i) => new { variable = v.Value, i })) {
58        var row = Content.CreateDataRow(x.variable, DataRowVisualProperties.DataRowChartType.Line);
59        row.VisualProperties.Color = Colors[x.i % Colors.Length];
60        allInOneDataRows.Add(x.variable, row);
61      }
62
63      allInOneDataTable.Rows.Clear();
64      var rows = Content.VariableItemList.CheckedItems.Select(v => allInOneDataRows[v.Value.Value]);
65      allInOneDataTable.Rows.AddRange(rows);
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      var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Line);
82      dt.Rows.Add(row);
83
84      var validValues = row.Values.Where(x => !double.IsNaN(x) && !double.IsInfinity(x)).ToList();
85      if (validValues.Any()) {
86        try {
87          double axisMin, axisMax, axisInterval;
88          ChartUtil.CalculateOptimalAxisInterval(validValues.Min(), validValues.Max(), out axisMin, out axisMax, out axisInterval);
89          dt.VisualProperties.YAxisMinimumAuto = false;
90          dt.VisualProperties.YAxisMaximumAuto = false;
91          dt.VisualProperties.YAxisMinimumFixedValue = axisMin;
92          dt.VisualProperties.YAxisMaximumFixedValue = axisMax;
93        } catch (ArgumentOutOfRangeException) { }
94      }
95      return dt;
96    }
97
98    private void allInOneCheckBox_CheckedChanged(object sender, EventArgs e) {
99      Content.AllInOneMode = allInOneCheckBox.Checked;
100
101      GenerateLayout();
102    }
103
104    protected override void OnContentChanged() {
105      base.OnContentChanged();
106      if (Content != null) {
107        allInOneCheckBox.Checked = Content.AllInOneMode;
108      }
109    }
110
111    protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
112      base.CheckedItemsChanged(sender, checkedItems);
113
114      foreach (IndexedItem<StringValue> item in checkedItems.Items) {
115        string variableName = item.Value.Value;
116
117        if (IsVariableChecked(variableName)) {
118          // ToDo: avoid clearing all rows, but how?
119          allInOneDataTable.Rows.Clear();
120          var rows = Content.VariableItemList.CheckedItems.Select(r => allInOneDataRows[r.Value.Value]);
121          allInOneDataTable.Rows.AddRange(rows);
122        } else {
123          allInOneDataTable.Rows.Remove(variableName);
124        }
125      }
126    }
127
128    #region Add/Remove/Update Variable, Reset
129    protected override void AddVariable(string name) {
130      base.AddVariable(name);
131      var row = Content.CreateDataRow(name, DataRowVisualProperties.DataRowChartType.Line);
132      allInOneDataTable.Rows.Add(row);
133    }
134
135    // remove variable from data table and item list
136    protected override void RemoveVariable(string name) {
137      base.RemoveVariable(name);
138      allInOneDataTable.Rows.Remove(name);
139    }
140
141    protected override void UpdateVariable(string name) {
142      base.UpdateVariable(name);
143      allInOneDataTable.Rows.Remove(name);
144      var newRow = Content.CreateDataRow(name, DataRowVisualProperties.DataRowChartType.Line);
145      allInOneDataTable.Rows.Add(newRow);
146    }
147    #endregion
148  }
149}
Note: See TracBrowser for help on using the repository browser.