Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13850


Ignore:
Timestamp:
05/18/16 16:28:59 (9 years ago)
Author:
pfleck
Message:

#2597

  • Extracted DensityChart from DensityTrackbar.
  • Added DensityChart to RegressionSolutionTargetResponseView with different options (none/training/test/all).
  • Moved RegressionSolutionGradientView and RegressionSolutionTargetResponseView to subfolder.
Location:
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4
Files:
2 added
5 edited
4 moved

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/DensityTrackbar.Designer.cs

    r13846 r13850  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.components = new System.ComponentModel.Container();
    48       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    49       System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
    5047      this.radioButton = new System.Windows.Forms.RadioButton();
    5148      this.trackBar = new System.Windows.Forms.TrackBar();
    52       this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
     49      this.chart = new HeuristicLab.Problems.DataAnalysis.Views.DensityChart();
    5350      this.textBox = new System.Windows.Forms.TextBox();
    5451      this.groupBox = new System.Windows.Forms.GroupBox();
    5552      this.doubleLimitView = new HeuristicLab.Problems.DataAnalysis.Views.DoubleLimitView();
    5653      ((System.ComponentModel.ISupportInitialize)(this.trackBar)).BeginInit();
    57       ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    5854      this.groupBox.SuspendLayout();
    5955      this.SuspendLayout();
     
    9187            | System.Windows.Forms.AnchorStyles.Left)
    9288            | System.Windows.Forms.AnchorStyles.Right)));
    93       chartArea1.AxisX.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.False;
    94       chartArea1.AxisX.IsMarginVisible = false;
    95       chartArea1.AxisY.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.False;
    96       chartArea1.AxisY.IsMarginVisible = false;
    97       chartArea1.AxisY.MajorTickMark.Enabled = false;
    98       chartArea1.AxisY.Minimum = 0D;
    99       chartArea1.BackColor = System.Drawing.Color.White;
    100       chartArea1.BorderColor = System.Drawing.Color.White;
    101       chartArea1.Name = "ChartArea1";
    102       chartArea1.Position.Auto = false;
    103       chartArea1.Position.Height = 100F;
    104       chartArea1.Position.Width = 100F;
    105       this.chart.ChartAreas.Add(chartArea1);
    10689      this.chart.Location = new System.Drawing.Point(156, 35);
    10790      this.chart.Name = "chart";
    108       series1.ChartArea = "ChartArea1";
    109       series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StepLine;
    110       series1.Name = "Default";
    111       this.chart.Series.Add(series1);
    11291      this.chart.Size = new System.Drawing.Size(345, 20);
    11392      this.chart.TabIndex = 3;
    114       this.chart.Text = "Density";
    11593      //
    11694      // textBox
     
    154132      this.Size = new System.Drawing.Size(678, 62);
    155133      ((System.ComponentModel.ISupportInitialize)(this.trackBar)).EndInit();
    156       ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    157134      this.groupBox.ResumeLayout(false);
    158135      this.groupBox.PerformLayout();
     
    166143    private System.Windows.Forms.TrackBar trackBar;
    167144    private Problems.DataAnalysis.Views.DoubleLimitView doubleLimitView;
    168     private Visualization.ChartControlsExtensions.EnhancedChart chart;
     145    private HeuristicLab.Problems.DataAnalysis.Views.DensityChart chart;
    169146    private System.Windows.Forms.TextBox textBox;
    170147    private System.Windows.Forms.GroupBox groupBox;
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/DensityTrackbar.cs

    r13846 r13850  
    2323using System.Collections.Generic;
    2424using System.Globalization;
    25 using System.Linq;
    2625using System.Windows.Forms;
    27 using System.Windows.Forms.DataVisualization.Charting;
    28 using HeuristicLab.Common;
    2926using HeuristicLab.Problems.DataAnalysis;
    3027
     
    7673
    7774    private void UpdateDensityChart() {
    78       var series = chart.Series[0];
    79       ClearPointsQuick(series.Points);
    80 
    81       int numBuckets = trackBar.Maximum - trackBar.Minimum;
    82       var buckets = new double[numBuckets];
    83       var bucketSize = (Limits.Upper - Limits.Lower) / buckets.Length;
    84       foreach (var value in trainingValues) {
    85         if (bucketSize > 0.0) {
    86           int bucketIndex = (int)((value - Limits.Lower) / bucketSize);
    87           if (bucketIndex == numBuckets) {
    88             bucketIndex--;
    89           }
    90           buckets[bucketIndex] += 1.0;
    91         }
    92       }
    93 
    94       // set minimum height of all non-zero buckets on 20% of maximum
    95       double min = buckets.Max() / 20.0;
    96       for (int i = 0; i < buckets.Length; i++) {
    97         if (buckets[i] >= 1 && buckets[i] < min)
    98           buckets[i] = min;
    99       }
    100 
    101       series.Points.DataBindY(buckets);
    102 
    103       // Set trackbar on highest density
    104       double highestDensity = buckets.Max();
    105       var highestIndices = buckets.Select((v, i) => new { v, i }).Where(x => x.v.IsAlmost(highestDensity)).Select(x => x.i).ToList();
    106       trackBar.Value = highestIndices[highestIndices.Count / 2];
     75      chart.UpdateChart(trainingValues, Limits.Lower, Limits.Upper,
     76        numBuckets: trackBar.Maximum - trackBar.Minimum, minimumHeight: 0.1);
    10777    }
    10878
     
    155125      return (int)((value - lower) / ((upper - lower) / numberOfTicks));
    156126    }
    157 
    158     // workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance
    159     private static void ClearPointsQuick(DataPointCollection points) {
    160       points.SuspendUpdates();
    161       while (points.Count > 0)
    162         points.RemoveAt(points.Count - 1);
    163       points.ResumeUpdates();
    164     }
    165 
    166127    #endregion
    167128  }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.Designer.cs

    r13842 r13850  
    5252      chartArea1.AxisX.StripLines.Add(stripLine2);
    5353      chartArea1.Name = "ChartArea";
     54      chartArea1.Position.Auto = false;
     55      chartArea1.Position.Height = 100F;
     56      chartArea1.Position.Width = 100F;
    5457      this.chart.ChartAreas.Add(chartArea1);
    5558      this.chart.Dock = System.Windows.Forms.DockStyle.Fill;
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs

    r13846 r13850  
    168168      get { return (VerticalLineAnnotation)chart.Annotations.SingleOrDefault(x => x is VerticalLineAnnotation); }
    169169    }
     170
     171    internal ElementPosition InnerPlotPosition {
     172      get { return chart.ChartAreas[0].InnerPlotPosition; }
     173    }
    170174    #endregion
    171175
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r13831 r13850  
    246246      <DependentUpon>ClusteringSolutionVisualizationView.cs</DependentUpon>
    247247    </Compile>
     248    <Compile Include="DensityChart.cs">
     249      <SubType>UserControl</SubType>
     250    </Compile>
     251    <Compile Include="DensityChart.Designer.cs">
     252      <DependentUpon>DensityChart.cs</DependentUpon>
     253    </Compile>
    248254    <Compile Include="DensityTrackbar.cs">
    249255      <SubType>UserControl</SubType>
     
    277283      <DependentUpon>GradientChart.cs</DependentUpon>
    278284    </Compile>
    279     <Compile Include="RegressionSolutionGradientView.cs">
    280       <SubType>UserControl</SubType>
    281     </Compile>
    282     <Compile Include="RegressionSolutionGradientView.Designer.cs">
     285    <Compile Include="Regression\RegressionSolutionGradientView.cs">
     286      <SubType>UserControl</SubType>
     287    </Compile>
     288    <Compile Include="Regression\RegressionSolutionGradientView.Designer.cs">
    283289      <DependentUpon>RegressionSolutionGradientView.cs</DependentUpon>
    284290    </Compile>
     
    298304      <DependentUpon>ProblemDataView.cs</DependentUpon>
    299305    </Compile>
    300     <Compile Include="RegressionSolutionTargetResponseGradientView.cs">
    301       <SubType>UserControl</SubType>
    302     </Compile>
    303     <Compile Include="RegressionSolutionTargetResponseGradientView.Designer.cs">
     306    <Compile Include="Regression\RegressionSolutionTargetResponseGradientView.cs">
     307      <SubType>UserControl</SubType>
     308    </Compile>
     309    <Compile Include="Regression\RegressionSolutionTargetResponseGradientView.Designer.cs">
    304310      <DependentUpon>RegressionSolutionTargetResponseGradientView.cs</DependentUpon>
    305311    </Compile>
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.Designer.cs

    r13846 r13850  
    2525    private void InitializeComponent() {
    2626      this.variableListView = new System.Windows.Forms.ListView();
    27       this.panel1 = new System.Windows.Forms.Panel();
    2827      this.gradientChartTableLayout = new System.Windows.Forms.TableLayoutPanel();
    2928      this.yAxisConfigGroupBox = new System.Windows.Forms.GroupBox();
    3029      this.limitView = new HeuristicLab.Problems.DataAnalysis.Views.DoubleLimitView();
    3130      this.automaticYAxisCheckBox = new System.Windows.Forms.CheckBox();
    32       this.panel1.SuspendLayout();
     31      this.densityGroupBox = new System.Windows.Forms.GroupBox();
     32      this.densityComboBox = new System.Windows.Forms.ComboBox();
     33      this.configSplitContainer = new System.Windows.Forms.SplitContainer();
     34      this.variableGroupBox = new System.Windows.Forms.GroupBox();
     35      this.scrollPanel = new System.Windows.Forms.Panel();
    3336      this.yAxisConfigGroupBox.SuspendLayout();
     37      this.densityGroupBox.SuspendLayout();
     38      ((System.ComponentModel.ISupportInitialize)(this.configSplitContainer)).BeginInit();
     39      this.configSplitContainer.Panel1.SuspendLayout();
     40      this.configSplitContainer.Panel2.SuspendLayout();
     41      this.configSplitContainer.SuspendLayout();
     42      this.variableGroupBox.SuspendLayout();
     43      this.scrollPanel.SuspendLayout();
    3444      this.SuspendLayout();
    3545      //
    3646      // variableListView
    3747      //
    38       this.variableListView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    39             | System.Windows.Forms.AnchorStyles.Left)));
    4048      this.variableListView.CheckBoxes = true;
    41       this.variableListView.Location = new System.Drawing.Point(4, 4);
     49      this.variableListView.Dock = System.Windows.Forms.DockStyle.Fill;
     50      this.variableListView.Location = new System.Drawing.Point(3, 16);
    4251      this.variableListView.Name = "variableListView";
    43       this.variableListView.Size = new System.Drawing.Size(152, 332);
     52      this.variableListView.Size = new System.Drawing.Size(163, 482);
    4453      this.variableListView.TabIndex = 0;
    4554      this.variableListView.UseCompatibleStateImageBehavior = false;
    4655      this.variableListView.View = System.Windows.Forms.View.List;
    47       //
    48       // panel1
    49       //
    50       this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    51             | System.Windows.Forms.AnchorStyles.Left)
    52             | System.Windows.Forms.AnchorStyles.Right)));
    53       this.panel1.AutoScroll = true;
    54       this.panel1.Controls.Add(this.gradientChartTableLayout);
    55       this.panel1.Location = new System.Drawing.Point(162, 4);
    56       this.panel1.Name = "panel1";
    57       this.panel1.Size = new System.Drawing.Size(868, 693);
    58       this.panel1.TabIndex = 1;
    5956      //
    6057      // gradientChartTableLayout
     
    6461      this.gradientChartTableLayout.AutoSize = true;
    6562      this.gradientChartTableLayout.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
    66       this.gradientChartTableLayout.ColumnCount = 4;
    67       this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
    68       this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
    69       this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
    70       this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 25F));
    71       this.gradientChartTableLayout.Location = new System.Drawing.Point(3, 3);
     63      this.gradientChartTableLayout.ColumnCount = 1;
     64      this.gradientChartTableLayout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
     65      this.gradientChartTableLayout.Location = new System.Drawing.Point(0, 0);
    7266      this.gradientChartTableLayout.Name = "gradientChartTableLayout";
    7367      this.gradientChartTableLayout.RowCount = 1;
    74       this.gradientChartTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 693F));
    75       this.gradientChartTableLayout.Size = new System.Drawing.Size(828, 693);
     68      this.gradientChartTableLayout.RowStyles.Add(new System.Windows.Forms.RowStyle());
     69      this.gradientChartTableLayout.Size = new System.Drawing.Size(542, 0);
    7670      this.gradientChartTableLayout.TabIndex = 2;
    7771      //
    7872      // yAxisConfigGroupBox
    7973      //
    80       this.yAxisConfigGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    8174      this.yAxisConfigGroupBox.Controls.Add(this.limitView);
    8275      this.yAxisConfigGroupBox.Controls.Add(this.automaticYAxisCheckBox);
    83       this.yAxisConfigGroupBox.Location = new System.Drawing.Point(4, 342);
     76      this.yAxisConfigGroupBox.Dock = System.Windows.Forms.DockStyle.Top;
     77      this.yAxisConfigGroupBox.Location = new System.Drawing.Point(0, 0);
    8478      this.yAxisConfigGroupBox.Name = "yAxisConfigGroupBox";
    85       this.yAxisConfigGroupBox.Size = new System.Drawing.Size(152, 98);
     79      this.yAxisConfigGroupBox.Size = new System.Drawing.Size(169, 98);
    8680      this.yAxisConfigGroupBox.TabIndex = 2;
    8781      this.yAxisConfigGroupBox.TabStop = false;
     
    9084      // limitView
    9185      //
     86      this.limitView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     87            | System.Windows.Forms.AnchorStyles.Right)));
    9288      this.limitView.Caption = "DoubleLimit View";
    9389      this.limitView.Content = null;
     
    9591      this.limitView.Name = "limitView";
    9692      this.limitView.ReadOnly = false;
    97       this.limitView.Size = new System.Drawing.Size(140, 47);
     93      this.limitView.Size = new System.Drawing.Size(157, 47);
    9894      this.limitView.TabIndex = 1;
    9995      //
     
    108104      this.automaticYAxisCheckBox.UseVisualStyleBackColor = true;
    109105      //
     106      // densityGroupBox
     107      //
     108      this.densityGroupBox.Controls.Add(this.densityComboBox);
     109      this.densityGroupBox.Dock = System.Windows.Forms.DockStyle.Top;
     110      this.densityGroupBox.Location = new System.Drawing.Point(0, 98);
     111      this.densityGroupBox.Name = "densityGroupBox";
     112      this.densityGroupBox.Size = new System.Drawing.Size(169, 49);
     113      this.densityGroupBox.TabIndex = 3;
     114      this.densityGroupBox.TabStop = false;
     115      this.densityGroupBox.Text = "Density";
     116      //
     117      // densityComboBox
     118      //
     119      this.densityComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     120            | System.Windows.Forms.AnchorStyles.Right)));
     121      this.densityComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     122      this.densityComboBox.FormattingEnabled = true;
     123      this.densityComboBox.Items.AddRange(new object[] {
     124            "None",
     125            "Training",
     126            "Test",
     127            "All"});
     128      this.densityComboBox.Location = new System.Drawing.Point(6, 19);
     129      this.densityComboBox.Name = "densityComboBox";
     130      this.densityComboBox.Size = new System.Drawing.Size(157, 21);
     131      this.densityComboBox.TabIndex = 0;
     132      this.densityComboBox.SelectedIndexChanged += new System.EventHandler(this.densityComboBox_SelectedIndexChanged);
     133      //
     134      // configSplitContainer
     135      //
     136      this.configSplitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
     137      this.configSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
     138      this.configSplitContainer.Location = new System.Drawing.Point(0, 0);
     139      this.configSplitContainer.Name = "configSplitContainer";
     140      //
     141      // configSplitContainer.Panel1
     142      //
     143      this.configSplitContainer.Panel1.Controls.Add(this.variableGroupBox);
     144      this.configSplitContainer.Panel1.Controls.Add(this.densityGroupBox);
     145      this.configSplitContainer.Panel1.Controls.Add(this.yAxisConfigGroupBox);
     146      //
     147      // configSplitContainer.Panel2
     148      //
     149      this.configSplitContainer.Panel2.Controls.Add(this.scrollPanel);
     150      this.configSplitContainer.Size = new System.Drawing.Size(715, 648);
     151      this.configSplitContainer.SplitterDistance = 169;
     152      this.configSplitContainer.TabIndex = 0;
     153      //
     154      // variableGroupBox
     155      //
     156      this.variableGroupBox.Controls.Add(this.variableListView);
     157      this.variableGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     158      this.variableGroupBox.Location = new System.Drawing.Point(0, 147);
     159      this.variableGroupBox.Name = "variableGroupBox";
     160      this.variableGroupBox.Size = new System.Drawing.Size(169, 501);
     161      this.variableGroupBox.TabIndex = 1;
     162      this.variableGroupBox.TabStop = false;
     163      this.variableGroupBox.Text = "Variables";
     164      //
     165      // scrollPanel
     166      //
     167      this.scrollPanel.Controls.Add(this.gradientChartTableLayout);
     168      this.scrollPanel.Dock = System.Windows.Forms.DockStyle.Fill;
     169      this.scrollPanel.Location = new System.Drawing.Point(0, 0);
     170      this.scrollPanel.Name = "scrollPanel";
     171      this.scrollPanel.Size = new System.Drawing.Size(542, 648);
     172      this.scrollPanel.TabIndex = 0;
     173      //
    110174      // RegressionSolutionTargetResponseGradientView
    111175      //
    112176      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    113177      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    114       this.Controls.Add(this.yAxisConfigGroupBox);
    115       this.Controls.Add(this.panel1);
    116       this.Controls.Add(this.variableListView);
     178      this.Controls.Add(this.configSplitContainer);
    117179      this.Name = "RegressionSolutionTargetResponseGradientView";
    118       this.Size = new System.Drawing.Size(1033, 700);
    119       this.panel1.ResumeLayout(false);
    120       this.panel1.PerformLayout();
     180      this.Size = new System.Drawing.Size(715, 648);
    121181      this.yAxisConfigGroupBox.ResumeLayout(false);
    122182      this.yAxisConfigGroupBox.PerformLayout();
     183      this.densityGroupBox.ResumeLayout(false);
     184      this.configSplitContainer.Panel1.ResumeLayout(false);
     185      this.configSplitContainer.Panel2.ResumeLayout(false);
     186      ((System.ComponentModel.ISupportInitialize)(this.configSplitContainer)).EndInit();
     187      this.configSplitContainer.ResumeLayout(false);
     188      this.variableGroupBox.ResumeLayout(false);
     189      this.scrollPanel.ResumeLayout(false);
     190      this.scrollPanel.PerformLayout();
    123191      this.ResumeLayout(false);
    124192
     
    128196
    129197    private System.Windows.Forms.ListView variableListView;
    130     private System.Windows.Forms.Panel panel1;
    131198    private System.Windows.Forms.TableLayoutPanel gradientChartTableLayout;
    132199    private System.Windows.Forms.GroupBox yAxisConfigGroupBox;
    133200    private System.Windows.Forms.CheckBox automaticYAxisCheckBox;
    134201    private DoubleLimitView limitView;
     202    private System.Windows.Forms.GroupBox densityGroupBox;
     203    private System.Windows.Forms.ComboBox densityComboBox;
     204    private System.Windows.Forms.SplitContainer configSplitContainer;
     205    private System.Windows.Forms.GroupBox variableGroupBox;
     206    private System.Windows.Forms.Panel scrollPanel;
    135207  }
    136208}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.cs

    r13846 r13850  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using System.Threading.Tasks;
     
    3334  [Content(typeof(IRegressionSolution))]
    3435  public partial class RegressionSolutionTargetResponseGradientView : DataAnalysisSolutionEvaluationView {
    35     private readonly Dictionary<string, GradientChart> charts;
     36    private readonly Dictionary<string, GradientChart> gradientCharts;
     37    private readonly Dictionary<string, DensityChart> densityCharts;
     38    private readonly Dictionary<string, Panel> groupingPanels;
     39
    3640    private const int Points = 200;
    37 
    38     private IEnumerable<GradientChart> VisibleCharts {
    39       get { return gradientChartTableLayout.Controls.OfType<GradientChart>(); }
     41    private const int MaxColumns = 4;
     42
     43    private IEnumerable<string> VisibleVariables {
     44      get {
     45        foreach (ListViewItem item in variableListView.CheckedItems)
     46          yield return item.Text;
     47      }
     48    }
     49    private IEnumerable<GradientChart> VisibleGradientCharts {
     50      get { return VisibleVariables.Select(v => gradientCharts[v]); }
     51    }
     52    private IEnumerable<DensityChart> VisibleDensityCharts {
     53      get { return VisibleVariables.Select(v => densityCharts[v]); }
     54    }
     55    private IEnumerable<Panel> VisibleChartsPanels {
     56      get { return VisibleVariables.Select(v => groupingPanels[v]); }
    4057    }
    4158
    4259    public RegressionSolutionTargetResponseGradientView() {
    4360      InitializeComponent();
    44       charts = new Dictionary<string, GradientChart>();
     61      gradientCharts = new Dictionary<string, GradientChart>();
     62      densityCharts = new Dictionary<string, DensityChart>();
     63      groupingPanels = new Dictionary<string, Panel>();
    4564
    4665      limitView.Content = new DoubleLimit(0, 1);
     66      densityComboBox.SelectedIndex = 0; // select None
     67
     68      // Avoid additional horizontal scrollbar
     69      var vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
     70      scrollPanel.Padding = new Padding(0, 0, vertScrollWidth, 0);
     71      scrollPanel.AutoScroll = true;
    4772    }
    4873
     
    91116      var variableValues = allowedInputVariables.Select(x => new List<double> { problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median() });
    92117      var sharedFixedVariables = new ModifiableDataset(allowedInputVariables, variableValues);
    93       // create charts
    94       charts.Clear();
     118
     119      // create controls
     120      gradientCharts.Clear();
     121      densityCharts.Clear();
     122      groupingPanels.Clear();
    95123      foreach (var variableName in allowedInputVariables) {
    96         var gradientChart = new GradientChart {
     124        var gradientChart = CreateGradientChart(variableName, sharedFixedVariables);
     125        gradientCharts.Add(variableName, gradientChart);
     126
     127        var densityChart = new DensityChart() {
     128          //Dock = DockStyle.Top,
     129          //Location = new Point(0, 0),
     130          Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right,
     131          Margin = Padding.Empty,
     132          Height = 12,
     133          Visible = false
     134        };
     135        densityCharts.Add(variableName, densityChart);
     136
     137        var panel = new Panel() {
    97138          Dock = DockStyle.Fill,
    98139          Margin = Padding.Empty,
    99           ShowLegend = false,
    100           ShowCursor = true,
    101           ShowXAxisLabel = true,
    102           ShowYAxisLabel = true,
    103           YAxisTicks = 5,
     140          BackColor = Color.White
    104141        };
    105         gradientChart.VariableValueChanged += async (o, e) => {
    106           var recalculations = VisibleCharts.Except(new[] { (GradientChart)o }).Select(async chart => {
    107             await chart.RecalculateAsync(updateOnFinish: false, resetYAxis: false);
    108           }).ToList();
    109           await Task.WhenAll(recalculations);
    110 
    111           if (recalculations.All(t => t.IsCompleted))
    112             SetupYAxis();
    113         };
    114         gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableName, Points);
    115         charts[variableName] = gradientChart;
    116       }
     142
     143        panel.Controls.Add(densityChart);
     144        panel.Controls.Add(gradientChart);
     145        groupingPanels.Add(variableName, panel);
     146      }
     147
    117148      // update variable list
    118149      variableListView.Items.Clear();
     
    123154        variableListView.Items[variable].Checked = true;
    124155    }
     156    private GradientChart CreateGradientChart(string variableName, ModifiableDataset sharedFixedVariables) {
     157      var gradientChart = new GradientChart {
     158        Dock = DockStyle.Fill,
     159        Margin = Padding.Empty,
     160        ShowLegend = false,
     161        ShowCursor = true,
     162        ShowXAxisLabel = true,
     163        ShowYAxisLabel = true,
     164        YAxisTicks = 5,
     165      };
     166      gradientChart.VariableValueChanged += async (o, e) => {
     167        var recalculations = VisibleGradientCharts.Except(new[] { (GradientChart)o }).Select(async chart => {
     168          await chart.RecalculateAsync(updateOnFinish: false, resetYAxis: false);
     169        }).ToList();
     170        await Task.WhenAll(recalculations);
     171
     172        if (recalculations.All(t => t.IsCompleted))
     173          SetupYAxis();
     174      };
     175      gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableName, Points);
     176
     177      return gradientChart;
     178    }
    125179
    126180    private void SetupYAxis() {
     
    128182      if (automaticYAxisCheckBox.Checked) {
    129183        double min = double.MaxValue, max = double.MinValue;
    130         foreach (var chart in VisibleCharts) {
     184        foreach (var chart in VisibleGradientCharts) {
    131185          if (chart.YMin < min) min = chart.YMin;
    132186          if (chart.YMax > max) max = chart.YMax;
     
    140194      }
    141195
    142       foreach (var chart in VisibleCharts) {
     196      foreach (var chart in VisibleGradientCharts) {
    143197        chart.FixedYAxisMin = axisMin;
    144198        chart.FixedYAxisMax = axisMax;
    145         chart.Update();
    146       }
    147     }
    148 
    149     // sort chart controls so that they always appear in the same order as in the list view
    150     // the gradient chart layout should be suspended before calling this method
    151     private void SortControls() {
     199        //chart.Update();
     200      }
     201    }
     202
     203    // reorder chart controls so that they always appear in the same order as in the list view
     204    // the table layout containing the controls should be suspended before calling this method
     205    private void ReOrderControls() {
    152206      var tl = gradientChartTableLayout;
    153       var indices = variableListView.CheckedItems.Cast<ListViewItem>().ToDictionary(checkedItem => checkedItem.Text, checkedItem => checkedItem.Index);
    154       var count = tl.Controls.Count;
    155       var charts = new GradientChart[count];
    156       for (int i = 0; i < count; ++i) charts[i] = (GradientChart)tl.Controls[i];
    157       Array.Sort(charts, (a, b) => indices[a.FreeVariable].CompareTo(indices[b.FreeVariable]));
    158207      tl.Controls.Clear();
    159       tl.Controls.AddRange(charts);
     208      int row = 0, column = 0;
     209      foreach (var chartsPanel in VisibleChartsPanels) {
     210        tl.Controls.Add(chartsPanel, column, row);
     211        column++;
     212        if (column == MaxColumns) {
     213          row++;
     214          column = 0;
     215        }
     216      }
    160217    }
    161218
    162219    private async void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
    163       if (charts == null) return;
    164220      var item = e.Item;
    165221      var variable = item.Text;
    166       var chart = charts[variable];
     222      var gradientChart = gradientCharts[variable];
     223      var densityChart = densityCharts[variable];
     224      var chartsPanel = groupingPanels[variable];
    167225      var tl = gradientChartTableLayout;
     226
    168227      tl.SuspendLayout();
    169       var columnWidth = tl.GetColumnWidths()[0]; // all columns have the same width
    170       var rowHeight = 0.8f * columnWidth;
    171       tl.RowStyles.Clear();
     228
    172229      if (item.Checked) {
    173         tl.Controls.Add(chart);
    174         await chart.RecalculateAsync();
     230        tl.Controls.Add(chartsPanel);
     231        await gradientChart.RecalculateAsync();
     232        UpdateDensityChart(densityChart, variable);
    175233      } else {
    176         tl.Controls.Remove(chart);
    177       }
    178       SetupYAxis();
    179 
    180       var count = tl.Controls.Count;
    181       SortControls();
    182       tl.RowCount = count / tl.ColumnCount + (count % tl.ColumnCount == 0 ? 0 : 1);
    183       for (int i = 0; i < count; ++i) {
    184         var control = tl.Controls[i];
    185         int rowIndex = i / tl.ColumnCount;
    186         int columnIndex = i % tl.ColumnCount;
    187         tl.SetRow(control, rowIndex);
    188         tl.SetColumn(control, columnIndex);
    189       }
    190       for (int i = 0; i < tl.RowCount; ++i) {
    191         tl.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
    192       }
     234        tl.Controls.Remove(chartsPanel);
     235      }
     236
     237      if (tl.Controls.Count > 0) {
     238        SetupYAxis();
     239
     240        ReOrderControls();
     241
     242        // set column styles
     243        int numVariables = VisibleVariables.Count();
     244        tl.ColumnCount = Math.Min(numVariables, MaxColumns);
     245        tl.ColumnStyles.Clear();
     246        for (int c = 0; c < tl.ColumnCount; c++)
     247          tl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100.0f / tl.ColumnCount));
     248
     249        // set column styles
     250        tl.RowCount = (int)Math.Ceiling((double)numVariables / tl.ColumnCount);
     251        var columnWidth = tl.Width / tl.ColumnCount; // assume all columns have the same width
     252        var rowHeight = (int)(0.8 * columnWidth);
     253        tl.RowStyles.Clear();
     254        for (int r = 0; r < tl.RowCount; r++)
     255          tl.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
     256      }
     257
    193258      tl.ResumeLayout();
    194259    }
     
    204269      SetupYAxis();
    205270    }
     271
     272    private void densityComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     273      int si = densityComboBox.SelectedIndex;
     274      if (si == 0) {
     275        foreach (var densityChart in densityCharts.Values)
     276          densityChart.Visible = false;
     277      } else {
     278        var indices = GetDensityIndices(si).ToList();
     279
     280        foreach (var entry in densityCharts) {
     281          var variableName = entry.Key;
     282          var densityChart = entry.Value;
     283          if (!VisibleVariables.Contains(variableName))
     284            continue;
     285          UpdateDensityChart(densityChart, variableName, indices);
     286
     287        }
     288      }
     289    }
     290    private IEnumerable<int> GetDensityIndices(int selectedIndex) {
     291      var problemData = Content.ProblemData;
     292      return
     293        selectedIndex == 1 ? problemData.TrainingIndices :
     294        selectedIndex == 2 ? problemData.TestIndices :
     295        problemData.AllIndices;
     296    }
     297    private void UpdateDensityChart(DensityChart densityChart, string variable, IList<int> indices = null) {
     298      if (densityComboBox.SelectedIndex == 0)
     299        return;
     300      if (indices == null) {
     301        indices = GetDensityIndices(densityComboBox.SelectedIndex).ToList();
     302      }
     303      var data = Content.ProblemData.Dataset.GetDoubleValues(variable, indices).ToList();
     304      var gradientChart = gradientCharts[variable];
     305      var min = gradientChart.FixedXAxisMin;
     306      var max = gradientChart.FixedXAxisMax;
     307      var buckets = gradientChart.DrawingSteps;
     308      if (min.HasValue && max.HasValue) {
     309        densityChart.UpdateChart(data, min.Value, max.Value, buckets);
     310        densityChart.Width = gradientChart.Width;
     311
     312        var gcPlotPosition = gradientChart.InnerPlotPosition;
     313        densityChart.Left = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width);
     314        densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width);
     315
     316        densityChart.Visible = true;
     317      }
     318    }
    206319  }
    207320}
     321
Note: See TracChangeset for help on using the changeset viewer.