- Timestamp:
- 02/20/13 10:49:30 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBoxPlotView.cs
r8962 r9235 124 124 this.categoricalMapping.Clear(); 125 125 UpdateDataPoints(); 126 UpdateAxisLabels(); 126 127 } 127 128 } … … 326 327 } 327 328 private double GetCategoricalValue(int dimension, string value) { 328 if (!this.categoricalMapping.ContainsKey(dimension)) 329 if (!this.categoricalMapping.ContainsKey(dimension)) { 329 330 this.categoricalMapping[dimension] = new Dictionary<object, double>(); 330 if (!this.categoricalMapping[dimension].ContainsKey(value)) { 331 if (this.categoricalMapping[dimension].Values.Count == 0) 332 this.categoricalMapping[dimension][value] = 1.0; 333 else 334 this.categoricalMapping[dimension][value] = this.categoricalMapping[dimension].Values.Max() + 1.0; 331 var orderedCategories = Content.Select(r => Content.GetValue(r, dimension).ToString()) 332 .Distinct() 333 .OrderBy(x => x, new NaturalStringComparer()); 334 int count = 1; 335 foreach (var category in orderedCategories) { 336 this.categoricalMapping[dimension].Add(category, count); 337 count++; 338 } 335 339 } 336 340 return this.categoricalMapping[dimension][value]; -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBubbleChartView.cs
r9229 r9235 44 44 45 45 private Dictionary<IRun, List<DataPoint>> runToDataPointMapping; 46 private Dictionary<IRun, int> runToIndexMapping; 46 47 private Dictionary<int, Dictionary<object, double>> categoricalMapping; 47 48 private Dictionary<IRun, double> xJitter; … … 52 53 private bool isSelecting = false; 53 54 private bool suppressUpdates = false; 55 56 54 57 55 58 public RunCollectionBubbleChartView() { … … 167 170 UpdateDataPoints(); 168 171 UpdateCaption(); 169 } 172 RebuildInverseIndex(); 173 } 174 175 private void RebuildInverseIndex() { 176 if (Content != null) { 177 runToIndexMapping = new Dictionary<IRun, int>(Content.Count); 178 int i = 0; 179 foreach (var run in Content) { 180 runToIndexMapping.Add(run, i); 181 i++; 182 } 183 } 184 } 185 170 186 private void Content_ColumnNamesChanged(object sender, EventArgs e) { 171 187 if (InvokeRequired) … … 210 226 changed = true; 211 227 } 212 if (changed) 228 if (changed) { 213 229 UpdateDataPoints(); 230 UpdateAxisLabels(); 231 } 214 232 } 215 233 } … … 236 254 else { 237 255 this.categoricalMapping.Clear(); 256 RebuildInverseIndex(); 238 257 UpdateDataPoints(); 258 UpdateAxisLabels(); 239 259 } 240 260 } … … 399 419 } 400 420 private double GetCategoricalValue(int dimension, string value) { 401 if (!this.categoricalMapping.ContainsKey(dimension)) 421 if (!this.categoricalMapping.ContainsKey(dimension)) { 402 422 this.categoricalMapping[dimension] = new Dictionary<object, double>(); 403 if (!this.categoricalMapping[dimension].ContainsKey(value)) { 404 if (this.categoricalMapping[dimension].Values.Count == 0) 405 this.categoricalMapping[dimension][value] = 1.0; 406 else 407 this.categoricalMapping[dimension][value] = this.categoricalMapping[dimension].Values.Max() + 1.0; 423 var orderedCategories = Content.Select(r => Content.GetValue(r, dimension).ToString()) 424 .Distinct() 425 .OrderBy(x => x, new NaturalStringComparer()); 426 int count = 1; 427 foreach (var category in orderedCategories) { 428 this.categoricalMapping[dimension].Add(category, count); 429 count++; 430 } 408 431 } 409 432 return this.categoricalMapping[dimension][value]; 410 433 } 434 411 435 private double GetValue(IRun run, AxisDimension axisDimension) { 412 436 double value = double.NaN; 413 437 switch (axisDimension) { 414 438 case AxisDimension.Index: { 415 value = Content.ToList().IndexOf(run);439 value = runToIndexMapping[run]; 416 440 break; 417 441 } … … 740 764 741 765 private void ColorRuns(string axisValue) { 742 var runs = Content.Where(r => r.Visible).Select(r => new { Run = r, Value = GetValue(r, axisValue) }).Where(r => r.Value.HasValue) ;766 var runs = Content.Where(r => r.Visible).Select(r => new { Run = r, Value = GetValue(r, axisValue) }).Where(r => r.Value.HasValue).ToList(); 743 767 double minValue = runs.Min(r => r.Value.Value); 744 768 double maxValue = runs.Max(r => r.Value.Value); 745 769 double range = maxValue - minValue; 746 770 747 foreach (var r in runs) { 748 int colorIndex = 0; 749 if (!range.IsAlmost(0)) colorIndex = (int)((ColorGradient.Colors.Count - 1) * (r.Value.Value - minValue) / (range)); 750 r.Run.Color = ColorGradient.Colors[colorIndex]; 771 if (range.IsAlmost(0)) { 772 Color c = ColorGradient.Colors[0]; 773 runs.ForEach(r => r.Run.Color = c); 774 } else { 775 int maxColorIndex = ColorGradient.Colors.Count - 1; 776 foreach (var r in runs) { 777 int colorIndex = (int)(maxColorIndex * (r.Value - minValue) / (range)); 778 r.Run.Color = ColorGradient.Colors[colorIndex]; 779 } 751 780 } 752 781 }
Note: See TracChangeset
for help on using the changeset viewer.