[10709] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[16140] | 3 | * Copyright (C) 2002-2018 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] | 22 | using System;
|
---|
[15110] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
[10658] | 25 | using HeuristicLab.Analysis;
|
---|
[15110] | 26 | using HeuristicLab.Analysis.Views;
|
---|
| 27 | using HeuristicLab.Collections;
|
---|
| 28 | using HeuristicLab.Data;
|
---|
[10658] | 29 | using HeuristicLab.MainForm;
|
---|
[15110] | 30 | using HeuristicLab.Visualization.ChartControlsExtensions;
|
---|
[10658] | 31 |
|
---|
| 32 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
| 33 | [View("Line Chart View")]
|
---|
[10712] | 34 | [Content(typeof(LineChartContent), true)]
|
---|
[10658] | 35 | public partial class LineChartView : PreprocessingChartView {
|
---|
[15110] | 36 | protected Dictionary<string, DataRow> allInOneDataRows;
|
---|
| 37 | protected DataTable allInOneDataTable;
|
---|
| 38 | protected DataTableView allInOneDataTableView;
|
---|
[10658] | 39 |
|
---|
[15110] | 40 | public new LineChartContent Content {
|
---|
| 41 | get { return (LineChartContent)base.Content; }
|
---|
| 42 | set { base.Content = value; }
|
---|
| 43 | }
|
---|
[10658] | 44 |
|
---|
| 45 | public LineChartView() {
|
---|
| 46 | InitializeComponent();
|
---|
[15110] | 47 | sizeGroupBox.Visible = false;
|
---|
| 48 |
|
---|
| 49 | allInOneDataRows = new Dictionary<string, DataRow>();
|
---|
| 50 | allInOneDataTable = new DataTable();
|
---|
[10658] | 51 | }
|
---|
| 52 |
|
---|
[15110] | 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);
|
---|
[10658] | 66 | }
|
---|
[10717] | 67 |
|
---|
[15110] | 68 | protected override int GetNumberOfVisibleDataTables() {
|
---|
| 69 | return Content.AllInOneMode ? 1 : base.GetNumberOfVisibleDataTables();
|
---|
| 70 | }
|
---|
| 71 | protected override IEnumerable<DataTableView> GetVisibleDataTables() {
|
---|
| 72 | if (Content.AllInOneMode) {
|
---|
| 73 | if (allInOneDataTableView == null)
|
---|
| 74 | allInOneDataTableView = new DataTableView() { Content = allInOneDataTable, ShowChartOnly = true };
|
---|
| 75 | return new[] { allInOneDataTableView };
|
---|
| 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 |
|
---|
[10736] | 98 | private void allInOneCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[10867] | 99 | Content.AllInOneMode = allInOneCheckBox.Checked;
|
---|
[13502] | 100 |
|
---|
[15110] | 101 | sizeGroupBox.Visible = !allInOneCheckBox.Checked;
|
---|
| 102 |
|
---|
| 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 | }
|
---|
[15110] | 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();
|
---|
| 122 | var rows = Content.VariableItemList.CheckedItems.Select(r => allInOneDataRows[r.Value.Value]);
|
---|
| 123 | allInOneDataTable.Rows.AddRange(rows);
|
---|
| 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 | }
|
---|
[15110] | 151 | } |
---|