Changeset 13850
- Timestamp:
- 05/18/16 16:28:59 (9 years ago)
- 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 45 45 /// </summary> 46 46 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();50 47 this.radioButton = new System.Windows.Forms.RadioButton(); 51 48 this.trackBar = new System.Windows.Forms.TrackBar(); 52 this.chart = new HeuristicLab. Visualization.ChartControlsExtensions.EnhancedChart();49 this.chart = new HeuristicLab.Problems.DataAnalysis.Views.DensityChart(); 53 50 this.textBox = new System.Windows.Forms.TextBox(); 54 51 this.groupBox = new System.Windows.Forms.GroupBox(); 55 52 this.doubleLimitView = new HeuristicLab.Problems.DataAnalysis.Views.DoubleLimitView(); 56 53 ((System.ComponentModel.ISupportInitialize)(this.trackBar)).BeginInit(); 57 ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();58 54 this.groupBox.SuspendLayout(); 59 55 this.SuspendLayout(); … … 91 87 | System.Windows.Forms.AnchorStyles.Left) 92 88 | 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);106 89 this.chart.Location = new System.Drawing.Point(156, 35); 107 90 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);112 91 this.chart.Size = new System.Drawing.Size(345, 20); 113 92 this.chart.TabIndex = 3; 114 this.chart.Text = "Density";115 93 // 116 94 // textBox … … 154 132 this.Size = new System.Drawing.Size(678, 62); 155 133 ((System.ComponentModel.ISupportInitialize)(this.trackBar)).EndInit(); 156 ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();157 134 this.groupBox.ResumeLayout(false); 158 135 this.groupBox.PerformLayout(); … … 166 143 private System.Windows.Forms.TrackBar trackBar; 167 144 private Problems.DataAnalysis.Views.DoubleLimitView doubleLimitView; 168 private Visualization.ChartControlsExtensions.EnhancedChart chart;145 private HeuristicLab.Problems.DataAnalysis.Views.DensityChart chart; 169 146 private System.Windows.Forms.TextBox textBox; 170 147 private System.Windows.Forms.GroupBox groupBox; -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/DensityTrackbar.cs
r13846 r13850 23 23 using System.Collections.Generic; 24 24 using System.Globalization; 25 using System.Linq;26 25 using System.Windows.Forms; 27 using System.Windows.Forms.DataVisualization.Charting;28 using HeuristicLab.Common;29 26 using HeuristicLab.Problems.DataAnalysis; 30 27 … … 76 73 77 74 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); 107 77 } 108 78 … … 155 125 return (int)((value - lower) / ((upper - lower) / numberOfTicks)); 156 126 } 157 158 // workaround as per http://stackoverflow.com/questions/5744930/datapointcollection-clear-performance159 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 166 127 #endregion 167 128 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.Designer.cs
r13842 r13850 52 52 chartArea1.AxisX.StripLines.Add(stripLine2); 53 53 chartArea1.Name = "ChartArea"; 54 chartArea1.Position.Auto = false; 55 chartArea1.Position.Height = 100F; 56 chartArea1.Position.Width = 100F; 54 57 this.chart.ChartAreas.Add(chartArea1); 55 58 this.chart.Dock = System.Windows.Forms.DockStyle.Fill; -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs
r13846 r13850 168 168 get { return (VerticalLineAnnotation)chart.Annotations.SingleOrDefault(x => x is VerticalLineAnnotation); } 169 169 } 170 171 internal ElementPosition InnerPlotPosition { 172 get { return chart.ChartAreas[0].InnerPlotPosition; } 173 } 170 174 #endregion 171 175 -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj
r13831 r13850 246 246 <DependentUpon>ClusteringSolutionVisualizationView.cs</DependentUpon> 247 247 </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> 248 254 <Compile Include="DensityTrackbar.cs"> 249 255 <SubType>UserControl</SubType> … … 277 283 <DependentUpon>GradientChart.cs</DependentUpon> 278 284 </Compile> 279 <Compile Include="Regression SolutionGradientView.cs">280 <SubType>UserControl</SubType> 281 </Compile> 282 <Compile Include="Regression SolutionGradientView.Designer.cs">285 <Compile Include="Regression\RegressionSolutionGradientView.cs"> 286 <SubType>UserControl</SubType> 287 </Compile> 288 <Compile Include="Regression\RegressionSolutionGradientView.Designer.cs"> 283 289 <DependentUpon>RegressionSolutionGradientView.cs</DependentUpon> 284 290 </Compile> … … 298 304 <DependentUpon>ProblemDataView.cs</DependentUpon> 299 305 </Compile> 300 <Compile Include="Regression SolutionTargetResponseGradientView.cs">301 <SubType>UserControl</SubType> 302 </Compile> 303 <Compile Include="Regression SolutionTargetResponseGradientView.Designer.cs">306 <Compile Include="Regression\RegressionSolutionTargetResponseGradientView.cs"> 307 <SubType>UserControl</SubType> 308 </Compile> 309 <Compile Include="Regression\RegressionSolutionTargetResponseGradientView.Designer.cs"> 304 310 <DependentUpon>RegressionSolutionTargetResponseGradientView.cs</DependentUpon> 305 311 </Compile> -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.Designer.cs
r13846 r13850 25 25 private void InitializeComponent() { 26 26 this.variableListView = new System.Windows.Forms.ListView(); 27 this.panel1 = new System.Windows.Forms.Panel();28 27 this.gradientChartTableLayout = new System.Windows.Forms.TableLayoutPanel(); 29 28 this.yAxisConfigGroupBox = new System.Windows.Forms.GroupBox(); 30 29 this.limitView = new HeuristicLab.Problems.DataAnalysis.Views.DoubleLimitView(); 31 30 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(); 33 36 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(); 34 44 this.SuspendLayout(); 35 45 // 36 46 // variableListView 37 47 // 38 this.variableListView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)39 | System.Windows.Forms.AnchorStyles.Left)));40 48 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); 42 51 this.variableListView.Name = "variableListView"; 43 this.variableListView.Size = new System.Drawing.Size(1 52, 332);52 this.variableListView.Size = new System.Drawing.Size(163, 482); 44 53 this.variableListView.TabIndex = 0; 45 54 this.variableListView.UseCompatibleStateImageBehavior = false; 46 55 this.variableListView.View = System.Windows.Forms.View.List; 47 //48 // panel149 //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;59 56 // 60 57 // gradientChartTableLayout … … 64 61 this.gradientChartTableLayout.AutoSize = true; 65 62 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); 72 66 this.gradientChartTableLayout.Name = "gradientChartTableLayout"; 73 67 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); 76 70 this.gradientChartTableLayout.TabIndex = 2; 77 71 // 78 72 // yAxisConfigGroupBox 79 73 // 80 this.yAxisConfigGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));81 74 this.yAxisConfigGroupBox.Controls.Add(this.limitView); 82 75 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); 84 78 this.yAxisConfigGroupBox.Name = "yAxisConfigGroupBox"; 85 this.yAxisConfigGroupBox.Size = new System.Drawing.Size(1 52, 98);79 this.yAxisConfigGroupBox.Size = new System.Drawing.Size(169, 98); 86 80 this.yAxisConfigGroupBox.TabIndex = 2; 87 81 this.yAxisConfigGroupBox.TabStop = false; … … 90 84 // limitView 91 85 // 86 this.limitView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 87 | System.Windows.Forms.AnchorStyles.Right))); 92 88 this.limitView.Caption = "DoubleLimit View"; 93 89 this.limitView.Content = null; … … 95 91 this.limitView.Name = "limitView"; 96 92 this.limitView.ReadOnly = false; 97 this.limitView.Size = new System.Drawing.Size(1 40, 47);93 this.limitView.Size = new System.Drawing.Size(157, 47); 98 94 this.limitView.TabIndex = 1; 99 95 // … … 108 104 this.automaticYAxisCheckBox.UseVisualStyleBackColor = true; 109 105 // 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 // 110 174 // RegressionSolutionTargetResponseGradientView 111 175 // 112 176 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 113 177 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); 117 179 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); 121 181 this.yAxisConfigGroupBox.ResumeLayout(false); 122 182 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(); 123 191 this.ResumeLayout(false); 124 192 … … 128 196 129 197 private System.Windows.Forms.ListView variableListView; 130 private System.Windows.Forms.Panel panel1;131 198 private System.Windows.Forms.TableLayoutPanel gradientChartTableLayout; 132 199 private System.Windows.Forms.GroupBox yAxisConfigGroupBox; 133 200 private System.Windows.Forms.CheckBox automaticYAxisCheckBox; 134 201 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; 135 207 } 136 208 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.cs
r13846 r13850 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using System.Threading.Tasks; … … 33 34 [Content(typeof(IRegressionSolution))] 34 35 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 36 40 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]); } 40 57 } 41 58 42 59 public RegressionSolutionTargetResponseGradientView() { 43 60 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>(); 45 64 46 65 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; 47 72 } 48 73 … … 91 116 var variableValues = allowedInputVariables.Select(x => new List<double> { problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median() }); 92 117 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(); 95 123 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() { 97 138 Dock = DockStyle.Fill, 98 139 Margin = Padding.Empty, 99 ShowLegend = false, 100 ShowCursor = true, 101 ShowXAxisLabel = true, 102 ShowYAxisLabel = true, 103 YAxisTicks = 5, 140 BackColor = Color.White 104 141 }; 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 117 148 // update variable list 118 149 variableListView.Items.Clear(); … … 123 154 variableListView.Items[variable].Checked = true; 124 155 } 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 } 125 179 126 180 private void SetupYAxis() { … … 128 182 if (automaticYAxisCheckBox.Checked) { 129 183 double min = double.MaxValue, max = double.MinValue; 130 foreach (var chart in Visible Charts) {184 foreach (var chart in VisibleGradientCharts) { 131 185 if (chart.YMin < min) min = chart.YMin; 132 186 if (chart.YMax > max) max = chart.YMax; … … 140 194 } 141 195 142 foreach (var chart in Visible Charts) {196 foreach (var chart in VisibleGradientCharts) { 143 197 chart.FixedYAxisMin = axisMin; 144 198 chart.FixedYAxisMax = axisMax; 145 chart.Update();146 } 147 } 148 149 // sortchart controls so that they always appear in the same order as in the list view150 // the gradient chart layoutshould be suspended before calling this method151 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() { 152 206 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]));158 207 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 } 160 217 } 161 218 162 219 private async void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) { 163 if (charts == null) return;164 220 var item = e.Item; 165 221 var variable = item.Text; 166 var chart = charts[variable]; 222 var gradientChart = gradientCharts[variable]; 223 var densityChart = densityCharts[variable]; 224 var chartsPanel = groupingPanels[variable]; 167 225 var tl = gradientChartTableLayout; 226 168 227 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 172 229 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); 175 233 } 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 193 258 tl.ResumeLayout(); 194 259 } … … 204 269 SetupYAxis(); 205 270 } 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 } 206 319 } 207 320 } 321
Note: See TracChangeset
for help on using the changeset viewer.