Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/10 10:44:04 (14 years ago)
Author:
mkommend
Message:

Corrected and redesigned automatic coloring in RunCollectionBubbleChartView (ticket #1261).

File:
1 edited

Legend:

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

    r4812 r4845  
    232232      double? sizeValue;
    233233      Series series = this.chart.Series[0];
    234       int row = this.Content.ToList().IndexOf(run);
    235 
    236       if (!xAxisComboBox.DroppedDown)
    237         this.xAxisValue = (string)xAxisComboBox.SelectedItem;
    238       if (!yAxisComboBox.DroppedDown)
    239         this.yAxisValue = (string)yAxisComboBox.SelectedItem;
    240       if (!sizeComboBox.DroppedDown)
    241         this.sizeAxisValue = (string)sizeComboBox.SelectedItem;
    242 
    243       xValue = GetValue(run, this.xAxisValue);
    244       yValue = GetValue(run, this.yAxisValue);
    245       sizeValue = GetValue(run, this.sizeAxisValue);
     234
     235      xValue = GetValue(run, xAxisValue);
     236      yValue = GetValue(run, yAxisValue);
     237      sizeValue = GetValue(run, sizeAxisValue);
    246238
    247239      if (xValue.HasValue && yValue.HasValue && sizeValue.HasValue) {
     
    508500      xTrackBar.Enabled = yTrackBar.Enabled = axisSelected;
    509501      colorXAxisButton.Enabled = colorYAxisButton.Enabled = axisSelected;
     502
     503      if (!xAxisComboBox.DroppedDown)
     504        xAxisValue = (string)xAxisComboBox.SelectedItem;
     505      if (!yAxisComboBox.DroppedDown)
     506        yAxisValue = (string)yAxisComboBox.SelectedItem;
     507      if (!sizeComboBox.DroppedDown)
     508        sizeAxisValue = (string)sizeComboBox.SelectedItem;
     509
    510510      UpdateDataPoints();
    511511      UpdateAxisLabels();
     
    584584    #region automatic coloring
    585585    private void colorXAxisButton_Click(object sender, EventArgs e) {
    586       double minValue = chart.Series[0].Points.Min(p => p.XValue);
    587       double maxValue = chart.Series[0].Points.Max(p => p.XValue);
    588       foreach (DataPoint point in chart.Series[0].Points) {
    589         int colorIndex = (int)((ColorGradient.Colors.Count - 1) * (point.XValue - minValue) / (maxValue - minValue));
    590         IRun run = point.Tag as IRun;
    591         if (run != null) run.Color = ColorGradient.Colors[colorIndex];
    592       }
     586      ColorRuns(xAxisValue);
    593587    }
    594588
    595589    private void colorYAxisButton_Click(object sender, EventArgs e) {
    596       double minValue = chart.Series[0].Points.Min(p => p.YValues[0]);
    597       double maxValue = chart.Series[0].Points.Max(p => p.YValues[0]);
    598       foreach (DataPoint point in chart.Series[0].Points) {
    599         int colorIndex = (int)((ColorGradient.Colors.Count - 1) * (point.YValues[0] - minValue) / (maxValue - minValue));
    600         IRun run = point.Tag as IRun;
    601         if (run != null) run.Color = ColorGradient.Colors[colorIndex];
     590      ColorRuns(yAxisValue);
     591    }
     592
     593    private void ColorRuns(string axisValue) {
     594      var runs = Content.Select(r => new { Run = r, Value = GetValue(r, axisValue) }).Where(r => r.Value.HasValue);
     595      double minValue = runs.Min(r => r.Value.Value);
     596      double maxValue = runs.Max(r => r.Value.Value);
     597      double range = maxValue - minValue;
     598
     599      foreach (var r in runs) {
     600        int colorIndex = 0;
     601        if (!range.IsAlmost(0)) colorIndex = (int)((ColorGradient.Colors.Count - 1) * (r.Value.Value - minValue) / (maxValue - minValue));
     602        r.Run.Color = ColorGradient.Colors[colorIndex];
    602603      }
    603604    }
Note: See TracChangeset for help on using the changeset viewer.