Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2709

  • renamed Column -> Variable, Row -> Datarow.
  • scatterplot using regular comboboxes for variables.
  • adapted sizing and small layouting in multiscatterplot, histogram, statistics and datagrid.
File size: 5.7 KB
RevLine 
[10709]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[10709]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
[10717]22using System;
[14459]23using System.Collections.Generic;
24using System.Linq;
[10658]25using HeuristicLab.Analysis;
[14459]26using HeuristicLab.Analysis.Views;
27using HeuristicLab.Collections;
28using HeuristicLab.Data;
[10658]29using HeuristicLab.MainForm;
[14473]30using HeuristicLab.Visualization.ChartControlsExtensions;
[10658]31
32namespace HeuristicLab.DataPreprocessing.Views {
33  [View("Line Chart View")]
[10712]34  [Content(typeof(LineChartContent), true)]
[10658]35  public partial class LineChartView : PreprocessingChartView {
[14459]36    protected Dictionary<string, DataRow> allInOneDataRows;
37    protected DataTable allInOneDataTable;
[14983]38    protected DataTableView allInOneDataTableView;
[10658]39
[14996]40    public new LineChartContent Content {
41      get { return (LineChartContent)base.Content; }
42      set { base.Content = value; }
43    }
44
[10658]45    public LineChartView() {
46      InitializeComponent();
[14902]47      sizeGroupBox.Visible = false;
48
[14459]49      allInOneDataRows = new Dictionary<string, DataRow>();
[14983]50      allInOneDataTable = new DataTable();
[10658]51    }
52
[14459]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();
[14511]64      var rows = Content.VariableItemList.CheckedItems.Select(v => allInOneDataRows[v.Value.Value]);
65      allInOneDataTable.Rows.AddRange(rows);
[14459]66    }
67
68    protected override int GetNumberOfVisibleDataTables() {
69      return Content.AllInOneMode ? 1 : base.GetNumberOfVisibleDataTables();
70    }
[14983]71    protected override IEnumerable<DataTableView> GetVisibleDataTables() {
[14459]72      if (Content.AllInOneMode) {
[14983]73        if (allInOneDataTableView == null)
[15019]74          allInOneDataTableView = new DataTableView() { Content = allInOneDataTable, ShowName = false };
[14983]75        return new[] { allInOneDataTableView };
[14459]76      }
77      return base.GetVisibleDataTables();
78    }
79    protected override DataTable CreateDataTable(string variableName) {
80      var dt = new DataTable();
[14473]81      var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Line);
82      dt.Rows.Add(row);
83
[14511]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      }
[14459]95      return dt;
96    }
97
[10736]98    private void allInOneCheckBox_CheckedChanged(object sender, EventArgs e) {
[10867]99      Content.AllInOneMode = allInOneCheckBox.Checked;
[13502]100
[14902]101      sizeGroupBox.Visible = !allInOneCheckBox.Checked;
102
[14459]103      GenerateLayout();
[10717]104    }
[10818]105
[13502]106    protected override void OnContentChanged() {
[10818]107      base.OnContentChanged();
[13502]108      if (Content != null) {
[10818]109        allInOneCheckBox.Checked = Content.AllInOneMode;
110      }
111    }
[14459]112
113    protected override void CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> checkedItems) {
114      base.CheckedItemsChanged(sender, checkedItems);
115
116      foreach (IndexedItem<StringValue> item in checkedItems.Items) {
117        string variableName = item.Value.Value;
118
119        if (IsVariableChecked(variableName)) {
120          // ToDo: avoid clearing all rows, but how?
121          allInOneDataTable.Rows.Clear();
[14511]122          var rows = Content.VariableItemList.CheckedItems.Select(r => allInOneDataRows[r.Value.Value]);
123          allInOneDataTable.Rows.AddRange(rows);
[14459]124        } else {
125          allInOneDataTable.Rows.Remove(variableName);
126        }
127      }
128    }
129
130    #region Add/Remove/Update Variable, Reset
131    protected override void AddVariable(string name) {
132      base.AddVariable(name);
133      var row = Content.CreateDataRow(name, DataRowVisualProperties.DataRowChartType.Line);
134      allInOneDataTable.Rows.Add(row);
135    }
136
137    // remove variable from data table and item list
138    protected override void RemoveVariable(string name) {
139      base.RemoveVariable(name);
140      allInOneDataTable.Rows.Remove(name);
141    }
142
143    protected override void UpdateVariable(string name) {
144      base.UpdateVariable(name);
145      allInOneDataTable.Rows.Remove(name);
146      var newRow = Content.CreateDataRow(name, DataRowVisualProperties.DataRowChartType.Line);
147      allInOneDataTable.Rows.Add(newRow);
148    }
149    #endregion
[10658]150  }
[14459]151}
Note: See TracBrowser for help on using the repository browser.