#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using HeuristicLab.Common; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; namespace HeuristicLab.Problems.DataAnalysis.Views { [View("Target Response Gradient View")] [Content(typeof(IRegressionSolution))] public partial class RegressionSolutionTargetResponseGradientView : DataAnalysisSolutionEvaluationView { private ModifiableDataset internalDataset; private Dictionary charts; private const int Points = 1000; public RegressionSolutionTargetResponseGradientView() { InitializeComponent(); } public new IRegressionSolution Content { get { return (IRegressionSolution)base.Content; } set { if (value == null || value == Content) return; base.Content = value; } } protected override void RegisterContentEvents() { base.RegisterContentEvents(); variableListView.ItemChecked += variableListView_ItemChecked; } protected override void DeregisterContentEvents() { variableListView.ItemChecked -= variableListView_ItemChecked; base.DeregisterContentEvents(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content == null) return; var pd = Content.ProblemData; var ds = pd.Dataset; // update variable list variableListView.Items.Clear(); variableListView.Items.AddRange(pd.AllowedInputVariables.Select(x => new ListViewItem(x, 0)).ToArray()); // update internal dataset var variableNames = pd.AllowedInputVariables.ToList(); var variableValues = variableNames.Select(x => new List { pd.Dataset.GetDoubleValues(x, pd.TrainingIndices).Median() }); internalDataset = new ModifiableDataset(variableNames, variableValues); // update charts and variable limits charts = new Dictionary(); foreach (var x in pd.AllowedInputVariables) { double min = 0, max = 0; foreach (var v in ds.GetDoubleValues(x, pd.TrainingIndices)) { if (v > max) max = v; if (v < min) min = v; } var gradientChart = new GradientChart { Dock = DockStyle.Fill, Margin = Padding.Empty, ShowLegend = false, ShowCursor = true, ShowXAxisLabel = true, ShowYAxisLabel = true }; gradientChart.VariableValueChanged += (o, e) => { foreach (var chart in gradientChartTableLayout.Controls.Cast()) { if (chart == (GradientChart)o) continue; chart.UpdateChart(); } }; gradientChart.Configure(new[] { Content }, pd, internalDataset, x, min, max, Points); charts[x] = gradientChart; } } private void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) { if (charts == null) return; var item = e.Item; var variable = item.Text; var chart = charts[variable]; var tl = gradientChartTableLayout; tl.SuspendLayout(); var columnWidth = tl.GetColumnWidths()[0]; // all columns have the same width var rowHeight = 0.8f * columnWidth; tl.RowStyles.Clear(); if (item.Checked) { tl.Controls.Add(chart); var index = tl.Controls.Count - 1; int rowIndex = index / tl.ColumnCount; int columnIndex = index % tl.ColumnCount; tl.SetRow(chart, rowIndex); tl.SetColumn(chart, columnIndex); chart.UpdateChart(); tl.RowCount = rowIndex + 1; } else { tl.Controls.Remove(chart); // relayout var count = tl.Controls.Count; tl.RowCount = count / tl.ColumnCount + (count % tl.ColumnCount == 0 ? 0 : 1); for (int i = 0; i < count; ++i) { var control = tl.Controls[i]; int rowIndex = i / tl.ColumnCount; int columnIndex = i % tl.ColumnCount; tl.SetRow(control, rowIndex); tl.SetColumn(control, columnIndex); } } // set absolute row sizes for (int i = 0; i < tl.RowCount; ++i) { tl.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight)); } tl.ResumeLayout(); } } }