Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/15/10 17:13:21 (13 years ago)
Author:
mkommend
Message:

Added automatic coloring to the RunCollectionBubbleChartView (ticket #1261).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r4653 r4799  
    4343    private string sizeAxisValue;
    4444
     45    private Dictionary<IRun, DataPoint> runToDataPointMapping;
    4546    private Dictionary<int, Dictionary<object, double>> categoricalMapping;
    4647    private Dictionary<IRun, double> xJitter;
     
    5455      InitializeComponent();
    5556
     57      runToDataPointMapping = new Dictionary<IRun, DataPoint>();
    5658      categoricalMapping = new Dictionary<int, Dictionary<object, double>>();
    5759      xJitter = new Dictionary<IRun, double>();
     
    123125
    124126    private void UpdateRun(IRun run) {
    125       DataPoint point = this.chart.Series[0].Points.Where(p => p.Tag == run).SingleOrDefault();
     127      DataPoint point = runToDataPointMapping[run];
    126128      if (point != null) {
    127129        point.Color = run.Color;
    128         if (!run.Visible)
     130        if (!run.Visible) {
    129131          this.chart.Series[0].Points.Remove(point);
    130       } else
     132          runToDataPointMapping.Remove(run);
     133          UpdateCursorInterval();
     134          chart.ChartAreas[0].RecalculateAxesScale();
     135        }
     136      } else {
    131137        AddDataPoint(run);
    132       UpdateCursorInterval();
    133       chart.ChartAreas[0].RecalculateAxesScale();
     138        UpdateCursorInterval();
     139        chart.ChartAreas[0].RecalculateAxesScale();
     140      }
    134141
    135142
     
    201208      Series series = this.chart.Series[0];
    202209      series.Points.Clear();
     210      runToDataPointMapping.Clear();
    203211      if (Content != null) {
    204212        foreach (IRun run in this.Content)
     
    249257          point.Color = run.Color;
    250258          series.Points.Add(point);
     259          runToDataPointMapping[run] = point;
    251260        }
    252261      }
     
    569578    }
    570579    #endregion
     580
     581    #region automatic coloring
     582    private static Color[] colors;
     583    protected static Color[] Colors {
     584      get {
     585        if (colors == null) InitializeColors();
     586        return colors;
     587      }
     588    }
     589    private static void InitializeColors() {
     590      colors = new Color[256];
     591      int stepWidth = (256 * 4) / colors.Length;
     592      int currentValue;
     593      int currentClass;
     594      for (int i = 0; i < colors.Length; i++) {
     595        currentValue = (i * stepWidth) % 256;
     596        currentClass = (i * stepWidth) / 256;
     597        switch (currentClass) {
     598          case 0: { colors[i] = Color.FromArgb(0, currentValue, 255); break; }        // blue -> cyan
     599          case 1: { colors[i] = Color.FromArgb(0, 255, 255 - currentValue); break; }  // cyan -> green
     600          case 2: { colors[i] = Color.FromArgb(currentValue, 255, 0); break; }        // green -> yellow
     601          case 3: { colors[i] = Color.FromArgb(255, 255 - currentValue, 0); break; }  // yellow -> red
     602        }
     603      }
     604    }
     605
     606    private void colorXAxisButton_Click(object sender, EventArgs e) {
     607      double minValue = chart.Series[0].Points.Min(p => p.XValue);
     608      double maxValue = chart.Series[0].Points.Max(p => p.XValue);
     609      foreach (DataPoint point in chart.Series[0].Points) {
     610        int colorIndex = (int)((Colors.Length - 1) * (point.XValue - minValue) / (maxValue - minValue));
     611        IRun run = point.Tag as IRun;
     612        if (run != null)
     613          run.Color = Colors[colorIndex];
     614      }
     615    }
     616
     617    private void colorYAxisButton_Click(object sender, EventArgs e) {
     618      double minValue = chart.Series[0].Points.Min(p => p.YValues[0]);
     619      double maxValue = chart.Series[0].Points.Max(p => p.YValues[0]);
     620      foreach (DataPoint point in chart.Series[0].Points) {
     621        int colorIndex = (int)((Colors.Length - 1) * (point.YValues[0] - minValue) / (maxValue - minValue));
     622        IRun run = point.Tag as IRun;
     623        if (run != null)
     624          run.Color = Colors[colorIndex];
     625      }
     626    }
     627    #endregion
    571628  }
    572629}
Note: See TracChangeset for help on using the changeset viewer.