- Timestamp:
- 03/06/15 15:01:05 (9 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 12134-12135,12139-12140,12143,12145
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Analysis.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Analysis.Views merged: 12134,12139-12140,12143,12145
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Analysis.Views/3.3/HistogramControl.cs
r12009 r12154 31 31 public partial class HistogramControl : UserControl { 32 32 protected static readonly string SeriesName = "Histogram"; 33 33 protected static readonly decimal bandwidthMin = 0.0000000000001m; 34 34 protected Dictionary<string, List<double>> points; 35 protected bool suppressUpdate; 36 35 37 public int NumberOfBins { 36 38 get { return (int)binsNumericUpDown.Value; } … … 123 125 } 124 126 125 protected void UpdateHistogram( ) {127 protected void UpdateHistogram(double bandwith = double.NaN) { 126 128 if (InvokeRequired) { 127 Invoke((Action )UpdateHistogram, null);129 Invoke((Action<double>)UpdateHistogram, bandwith); 128 130 return; 129 131 } … … 134 136 135 137 chart.Series.Clear(); 136 137 138 foreach (var point in points) { 138 139 if (!point.Value.Any()) continue; … … 140 141 Series histogramSeries = new Series(point.Key); 141 142 chart.Series.Add(histogramSeries); 142 143 143 double minValue = point.Value.Min(); 144 144 double maxValue = point.Value.Max(); … … 165 165 histogramSeries["PointWidth"] = "1"; 166 166 167 CalculateDensity(histogramSeries, point.Value);168 169 167 overallMax = Math.Max(overallMax, maxValue); 170 168 overallMin = Math.Min(overallMin, minValue); 171 169 } 172 170 171 chart.ApplyPaletteColors(); 172 173 int i = 0; 174 foreach (var point in points) { 175 if (!point.Value.Any()) continue; 176 177 var histogramSeries = chart.Series[i]; 178 CalculateDensity(histogramSeries, point.Value, bandwith); 179 180 i++; 181 } 182 183 173 184 ChartArea chartArea = chart.ChartAreas[0]; 185 // don't show grid lines for second y-axis 186 chartArea.AxisY2.MajorGrid.Enabled = false; 187 chartArea.AxisY2.MinorGrid.Enabled = false; 174 188 chartArea.AxisY.Title = "Frequency"; 175 189 … … 182 196 } 183 197 184 protected void CalculateDensity(Series series, List<double> row ) {198 protected void CalculateDensity(Series series, List<double> row, double bandwidth = double.NaN) { 185 199 string densitySeriesName = "Density " + series.Name; 186 200 double stepWidth = series.Points[1].XValue - series.Points[0].XValue; 201 var rowArray = row.ToArray(); 187 202 188 203 if (chart.Series.Any(x => x.Name == densitySeriesName)) { … … 191 206 } 192 207 193 var density = NormalDistribution.Density(row.ToArray(), row.Count, stepWidth); 208 if (double.IsNaN(bandwidth)) { 209 bandwidth = KernelDensityEstimator.EstimateBandwidth(rowArray); 210 decimal bwDecimal = (decimal)bandwidth; 211 if (bwDecimal < bandwidthMin) { 212 bwDecimal = bandwidthMin; 213 bandwidth = decimal.ToDouble(bwDecimal); 214 } 215 suppressUpdate = true; 216 bandwidthNumericUpDown.Value = bwDecimal; 217 } 218 var density = KernelDensityEstimator.Density(rowArray, rowArray.Length, stepWidth, bandwidth); 194 219 195 220 Series newSeries = new Series(densitySeriesName); 221 newSeries.Color = series.Color; 196 222 newSeries.ChartType = SeriesChartType.FastLine; 197 223 newSeries.BorderWidth = 2; … … 200 226 } 201 227 228 // densities should be plotted on the second axis (different scale) 229 newSeries.YAxisType = AxisType.Secondary; 202 230 chart.Series.Add(newSeries); 203 231 } … … 221 249 UpdateHistogram(); 222 250 } 251 252 private void bandwidthNumericUpDown_ValueChanged(object sender, EventArgs e) { 253 if (!suppressUpdate) { 254 UpdateHistogram(decimal.ToDouble(bandwidthNumericUpDown.Value)); 255 } 256 suppressUpdate = false; 257 } 223 258 } 224 259 }
Note: See TracChangeset
for help on using the changeset viewer.