Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/13 10:49:30 (12 years ago)
Author:
mkommend
Message:

#2016: Implemented changes in BubbleChart and BoxPlots to improve the coloring and the display of categorical values.

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  
    124124        this.categoricalMapping.Clear();
    125125        UpdateDataPoints();
     126        UpdateAxisLabels();
    126127      }
    127128    }
     
    326327    }
    327328    private double GetCategoricalValue(int dimension, string value) {
    328       if (!this.categoricalMapping.ContainsKey(dimension))
     329      if (!this.categoricalMapping.ContainsKey(dimension)) {
    329330        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        }
    335339      }
    336340      return this.categoricalMapping[dimension][value];
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionBubbleChartView.cs

    r9229 r9235  
    4444
    4545    private Dictionary<IRun, List<DataPoint>> runToDataPointMapping;
     46    private Dictionary<IRun, int> runToIndexMapping;
    4647    private Dictionary<int, Dictionary<object, double>> categoricalMapping;
    4748    private Dictionary<IRun, double> xJitter;
     
    5253    private bool isSelecting = false;
    5354    private bool suppressUpdates = false;
     55
     56
    5457
    5558    public RunCollectionBubbleChartView() {
     
    167170      UpdateDataPoints();
    168171      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
    170186    private void Content_ColumnNamesChanged(object sender, EventArgs e) {
    171187      if (InvokeRequired)
     
    210226          changed = true;
    211227        }
    212         if (changed)
     228        if (changed) {
    213229          UpdateDataPoints();
     230          UpdateAxisLabels();
     231        }
    214232      }
    215233    }
     
    236254      else {
    237255        this.categoricalMapping.Clear();
     256        RebuildInverseIndex();
    238257        UpdateDataPoints();
     258        UpdateAxisLabels();
    239259      }
    240260    }
     
    399419    }
    400420    private double GetCategoricalValue(int dimension, string value) {
    401       if (!this.categoricalMapping.ContainsKey(dimension))
     421      if (!this.categoricalMapping.ContainsKey(dimension)) {
    402422        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        }
    408431      }
    409432      return this.categoricalMapping[dimension][value];
    410433    }
     434
    411435    private double GetValue(IRun run, AxisDimension axisDimension) {
    412436      double value = double.NaN;
    413437      switch (axisDimension) {
    414438        case AxisDimension.Index: {
    415             value = Content.ToList().IndexOf(run);
     439            value = runToIndexMapping[run];
    416440            break;
    417441          }
     
    740764
    741765    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();
    743767      double minValue = runs.Min(r => r.Value.Value);
    744768      double maxValue = runs.Max(r => r.Value.Value);
    745769      double range = maxValue - minValue;
    746770
    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        }
    751780      }
    752781    }
Note: See TracChangeset for help on using the changeset viewer.