- Timestamp:
- 12/01/14 16:16:29 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/HistogramControl.Designer.cs
r11171 r11608 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.components = new System.ComponentModel.Container(); 47 48 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); 49 System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 48 50 System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); 49 51 this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart(); … … 58 60 // 59 61 this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 60 61 62 | System.Windows.Forms.AnchorStyles.Left) 63 | System.Windows.Forms.AnchorStyles.Right))); 62 64 chartArea1.Name = "ChartArea1"; 63 65 this.chart.ChartAreas.Add(chartArea1); 66 legend1.Alignment = System.Drawing.StringAlignment.Center; 67 legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top; 68 legend1.Name = "Default"; 69 this.chart.Legends.Add(legend1); 64 70 this.chart.Location = new System.Drawing.Point(0, 27); 65 71 this.chart.Name = "chart"; 66 72 series1.ChartArea = "ChartArea1"; 73 series1.Legend = "Default"; 67 74 series1.Name = "Series1"; 68 75 this.chart.Series.Add(series1); … … 116 123 // HistogramControl 117 124 // 118 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);119 125 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 120 126 this.Controls.Add(this.exactCheckBox); -
trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/HistogramControl.cs
r11171 r11608 29 29 namespace HeuristicLab.Visualization.ChartControlsExtensions { 30 30 public partial class HistogramControl : UserControl { 31 pr ivatestatic readonly string SeriesName = "Histogram";32 33 pr ivate List<double> points;31 protected static readonly string SeriesName = "Histogram"; 32 33 protected Dictionary<string, List<double>> points; 34 34 public int NumberOfBins { 35 35 get { return (int)binsNumericUpDown.Value; } … … 64 64 public HistogramControl() { 65 65 InitializeComponent(); 66 points = new List<double>();66 points = new Dictionary<string, List<double>>(); 67 67 InitializeChart(); 68 68 } 69 69 70 protected void InitNewRow(string name) { 71 if (!points.ContainsKey(name)) { 72 points.Add(name, new List<double>()); 73 } 74 } 75 76 protected void InitSeries(string name) { 77 if (!chart.Series.Any(x => x.Name == name)) { 78 Series s = chart.Series.Add(name); 79 s.ChartType = SeriesChartType.Column; 80 s.BorderColor = Color.Black; 81 s.BorderWidth = 1; 82 s.BorderDashStyle = ChartDashStyle.Solid; 83 } 84 } 85 70 86 public void AddPoint(double point) { 71 points.Add(point); 87 InitNewRow(SeriesName); 88 InitSeries(SeriesName); 89 points[SeriesName].Add(point); 72 90 UpdateHistogram(); 73 91 } 74 92 75 93 public void AddPoints(IEnumerable<double> points) { 76 this.points.AddRange(points); 94 InitNewRow(SeriesName); 95 InitSeries(SeriesName); 96 this.points[SeriesName].AddRange(points); 97 UpdateHistogram(); 98 } 99 100 public void AddPoint(string name, double point, bool replace = false) { 101 InitNewRow(name); 102 InitSeries(name); 103 if (replace) { 104 points[name].Clear(); 105 } 106 points[name].Add(point); 107 UpdateHistogram(); 108 } 109 110 public void AddPoints(string name, IEnumerable<double> points, bool replace = false) { 111 InitNewRow(name); 112 InitSeries(name); 113 if (replace) { 114 this.points[name].Clear(); 115 } 116 this.points[name].AddRange(points); 77 117 UpdateHistogram(); 78 118 } … … 83 123 } 84 124 85 pr ivatevoid InitializeChart() {125 protected void InitializeChart() { 86 126 chart.Series.Clear(); 87 Series s = chart.Series.Add(SeriesName); 88 s.ChartType = SeriesChartType.Column; 89 s.BorderColor = Color.Black; 90 s.BorderWidth = 1; 91 s.BorderDashStyle = ChartDashStyle.Solid; 92 } 93 94 private void UpdateHistogram() { 127 } 128 129 protected void UpdateHistogram() { 95 130 if (InvokeRequired) { 96 131 Invoke((Action)UpdateHistogram, null); 97 132 return; 98 133 } 99 Series histogramSeries = chart.Series[SeriesName]; 100 histogramSeries.Points.Clear(); 101 102 if (!points.Any()) return; 134 135 double overallMin = double.MaxValue; 136 double overallMax = double.MinValue; 103 137 int bins = (int)binsNumericUpDown.Value; 104 138 105 double minValue = points.Min(); 106 double maxValue = points.Max(); 107 double intervalWidth = (maxValue - minValue) / bins; 108 if (intervalWidth <= 0) return; 109 110 if (!exactCheckBox.Checked) { 111 intervalWidth = HumanRoundRange(intervalWidth); 112 minValue = Math.Floor(minValue / intervalWidth) * intervalWidth; 113 maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth; 114 } 115 116 double current = minValue, intervalCenter = intervalWidth / 2.0; 117 int count = 0; 118 foreach (double v in points.OrderBy(x => x)) { 119 while (v > current + intervalWidth) { 120 histogramSeries.Points.AddXY(current + intervalCenter, count); 121 current += intervalWidth; 122 count = 0; 139 chart.Series.Clear(); 140 141 foreach (var point in points) { 142 if (!point.Value.Any()) continue; 143 144 Series histogramSeries = new Series(point.Key); 145 chart.Series.Add(histogramSeries); 146 147 double minValue = point.Value.Min(); 148 double maxValue = point.Value.Max(); 149 double intervalWidth = (maxValue - minValue) / bins; 150 if (intervalWidth <= 0) continue; 151 152 if (!exactCheckBox.Checked) { 153 intervalWidth = HumanRoundRange(intervalWidth); 154 minValue = Math.Floor(minValue / intervalWidth) * intervalWidth; 155 maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth; 123 156 } 124 count++; 125 } 126 histogramSeries.Points.AddXY(current + intervalCenter, count); 127 128 histogramSeries["PointWidth"] = "1"; 129 130 ChartArea chartArea = chart.ChartAreas[histogramSeries.ChartArea]; 157 158 double current = minValue, intervalCenter = intervalWidth / 2.0; 159 int count = 0; 160 foreach (double v in point.Value.OrderBy(x => x)) { 161 while (v > current + intervalWidth) { 162 histogramSeries.Points.AddXY(current + intervalCenter, count); 163 current += intervalWidth; 164 count = 0; 165 } 166 count++; 167 } 168 histogramSeries.Points.AddXY(current + intervalCenter, count); 169 histogramSeries["PointWidth"] = "1"; 170 171 overallMax = Math.Max(overallMax, maxValue); 172 overallMin = Math.Min(overallMin, minValue); 173 } 174 175 ChartArea chartArea = chart.ChartAreas[0]; 131 176 chartArea.AxisY.Title = "Frequency"; 132 chartArea.AxisX.Minimum = minValue; 133 chartArea.AxisX.Maximum = maxValue; 134 135 double axisInterval = intervalWidth; 136 while ((maxValue - minValue) / axisInterval > 10.0) { 177 chartArea.AxisX.Minimum = overallMin; 178 chartArea.AxisX.Maximum = overallMax; 179 180 double overallIntervalWidth = (overallMax - overallMin) / bins; 181 182 double axisInterval = overallIntervalWidth; 183 while ((overallMax - overallMin) / axisInterval > 10.0) { 137 184 axisInterval *= 2.0; 138 185 } … … 140 187 } 141 188 142 pr ivatedouble HumanRoundRange(double range) {189 protected double HumanRoundRange(double range) { 143 190 double base10 = Math.Pow(10.0, Math.Floor(Math.Log10(range))); 144 191 double rounding = range / base10;
Note: See TracChangeset
for help on using the changeset viewer.