Changeset 572 for trunk/sources/HeuristicLab.CEDMA.Charting
- Timestamp:
- 09/14/08 22:18:29 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Charting/Histogram.cs
r571 r572 37 37 private double maxFrequency; 38 38 private const int N_BUCKETS = 50; 39 private const int MAX_BUCKETS = 100; 39 40 private List<Record> records; 40 41 private ResultList results; … … 58 59 foreach(Record r in results.Records) { 59 60 records.Add(r); 60 r.OnSelectionChanged += new EventHandler(Record_OnSelectionChanged);61 61 } 62 62 results.OnRecordAdded += new EventHandler<RecordAddedEventArgs>(results_OnRecordAdded); … … 73 73 void results_OnRecordAdded(object sender, RecordAddedEventArgs e) { 74 74 lock(records) { 75 e.Record.OnSelectionChanged += new EventHandler(Record_OnSelectionChanged);76 75 records.Add(e.Record); 77 }78 }79 80 void Record_OnSelectionChanged(object sender, EventArgs e) {81 Record r = (Record)sender;82 IPrimitive primitive;83 recordToPrimitiveDictionary.TryGetValue(r, out primitive);84 if(primitive != null) {85 ((FixedSizeCircle)primitive).UpdateEnabled = false;86 bars.UpdateEnabled = false;87 if(r.Selected) {88 int alpha = primitive.Pen.Color.A;89 primitive.Pen.Color = Color.FromArgb(alpha, selectionColor);90 primitive.Brush = primitive.Pen.Brush;91 primitive.IntoForeground();92 } else {93 int alpha = primitive.Pen.Color.A;94 primitive.Pen.Color = Color.FromArgb(alpha, defaultColor);95 primitive.Brush = primitive.Pen.Brush;96 primitive.IntoBackground();97 }98 ((FixedSizeCircle)primitive).UpdateEnabled = true;99 bars.UpdateEnabled = true;100 76 } 101 77 } … … 119 95 Group.Add(new Axis(this, 0, 0, AxisType.Both)); 120 96 UpdateViewSize(0, 0); 121 var values = records.Select(r => r.Get(dimension)).Where(122 x => !double.IsNaN(x) && !double.IsInfinity(x) && x != double.MinValue && x != double.MaxValue).OrderBy(x => x);123 IEnumerable<IGrouping<double,double>> frequencies;124 double bucketSize;125 if(dimension == Record.TARGET_VARIABLE || dimension == Record.TREE_HEIGHT || dimension == Record.TREE_SIZE) {126 frequencies = values.GroupBy(x => x);127 bucketSize = 1.0;128 } else {129 double min = values.ElementAt((int)(values.Count() * 0.05));130 double max = values.ElementAt((int)(values.Count() * 0.95));131 bucketSize = (max - min) / N_BUCKETS;132 frequencies = values.GroupBy(x => Math.Min(Math.Max(min, Math.Floor((x - min) / bucketSize) * bucketSize + min), max));133 }134 97 Pen defaultPen = new Pen(defaultColor); 135 98 Brush defaultBrush = defaultPen.Brush; 136 foreach(IGrouping<double, double> g in frequencies) { 99 PaintHistogram(records, defaultPen, defaultBrush); 100 Pen selectionPen = new Pen(selectionColor); 101 Brush selectionBrush = selectionPen.Brush; 102 PaintHistogram(records.Where(r => r.Selected), selectionPen, selectionBrush); 103 Group.Add(bars); 104 UpdateEnabled = true; 105 } 106 107 private void PaintHistogram(IEnumerable<Record> records, Pen pen, Brush brush) { 108 var values = records.Select(r => new { Record = r, Value = r.Get(dimension) }).Where( 109 x => !double.IsNaN(x.Value) && !double.IsInfinity(x.Value) && x.Value != double.MinValue && x.Value != double.MaxValue).OrderBy(x => x.Value); 110 if(values.Count() == 0) return; 111 double bucketSize = 1.0; 112 var frequencies = values.GroupBy(x => x.Value); 113 if(frequencies.Count() > MAX_BUCKETS) { 114 double min = values.ElementAt((int)(values.Count() * 0.05)).Value; 115 double max = values.ElementAt((int)(values.Count() * 0.95)).Value; 116 bucketSize = (max - min) / N_BUCKETS; 117 frequencies = values.GroupBy(x => Math.Min(Math.Max(min, Math.Floor((x.Value - min) / bucketSize) * bucketSize + min), max)); 118 } 119 foreach(var g in frequencies) { 137 120 double freq = g.Count(); 138 121 double lower = g.Key; 139 double upper = g.Key+bucketSize; 140 HeuristicLab.Charting.Rectangle bar = new HeuristicLab.Charting.Rectangle(this, lower, 0, upper, freq, defaultPen, defaultBrush); 141 primitiveToRecordsDictionary[bar] = records; 142 if(lower == frequencies.First().Key) bar.ToolTipText = " x < "+upper+" : "+freq; 143 else if(lower ==frequencies.Last().Key) bar.ToolTipText = "x >= "+lower+" : "+freq; 144 else bar.ToolTipText = "x in ["+lower+" .. "+upper+"[ : "+freq; 122 double upper = g.Key + bucketSize; 123 HeuristicLab.Charting.Rectangle bar = new HeuristicLab.Charting.Rectangle(this, lower, 0, upper, freq, pen, brush); 124 primitiveToRecordsDictionary[bar] = g.Select(r => r.Record).ToList(); 125 primitiveToRecordsDictionary[bar].ForEach(x => recordToPrimitiveDictionary[x] = bar); 126 if(lower == frequencies.First().Key) bar.ToolTipText = " x < " + upper + " : " + freq; 127 else if(lower == frequencies.Last().Key) bar.ToolTipText = "x >= " + lower + " : " + freq; 128 else bar.ToolTipText = "x in [" + lower + " .. " + upper + "[ : " + freq; 145 129 bars.Add(bar); 146 130 UpdateViewSize(lower, freq); 147 131 UpdateViewSize(upper, freq); 148 132 } 149 Group.Add(bars);150 UpdateEnabled = true;151 133 } 152 134 … … 166 148 if(x < minX) minX = x; 167 149 if(x > maxX) maxX = x; 168 if(freq 150 if(freq > maxFrequency) maxFrequency = freq; 169 151 } 170 152 … … 187 169 if(button == MouseButtons.Left) { 188 170 List<Record> rs = GetRecords(point); 171 UpdateEnabled = false; 189 172 if(rs != null) rs.ForEach(r => r.ToggleSelected()); 173 UpdateEnabled = true; 190 174 results.FireChanged(); 191 175 } else {
Note: See TracChangeset
for help on using the changeset viewer.