Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/25/10 16:27:17 (15 years ago)
Author:
mkommend
Message:

implemented reviewer comments (ticket #970)

File:
1 edited

Legend:

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

    r3499 r3524  
    3939  [Content(typeof(RunCollection), false)]
    4040  public partial class RunCollectionBubbleChartView : AsynchronousContentView {
    41     private const string constantLabel = "constant";
     41    private enum SizeDimension { Constant = 0 }
     42    private enum AxisDimension { Index = 0 }
     43
    4244    private Dictionary<int, Dictionary<object, double>> categoricalMapping;
    4345    private Dictionary<IRun, double> xJitter;
     
    5961      this.colorButton.Image = this.GenerateImage(16, 16, this.colorDialog.Color);
    6062      this.isSelecting = false;
    61 
    62       this.chart.Series[0]["BubbleMaxSize"] = "0";
    63       this.chart.Series[0]["BubbleMaxScale"] = "Auto";
    64       this.chart.Series[0]["BubbleMinScale"] = "Auto";
    65       this.chart.Series[0].SmartLabelStyle.Enabled = true;
    66       this.chart.Series[0].SmartLabelStyle.IsMarkerOverlappingAllowed = false;
    67       this.chart.Series[0].SmartLabelStyle.IsOverlappedHidden = true;
    6863
    6964      this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
     
    156151      this.sizeComboBox.Items.Clear();
    157152      if (Content != null) {
     153        string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension));
     154        this.xAxisComboBox.Items.AddRange(additionalAxisDimension);
    158155        this.xAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
     156        this.yAxisComboBox.Items.AddRange(additionalAxisDimension);
    159157        this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
    160         this.sizeComboBox.Items.Add(constantLabel);
     158        string[] additionalSizeDimension = Enum.GetNames(typeof(SizeDimension));
     159        this.sizeComboBox.Items.AddRange(additionalSizeDimension);
    161160        this.sizeComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
     161        this.sizeComboBox.SelectedItem = SizeDimension.Constant.ToString();
    162162      }
    163163    }
     
    186186      Series series = this.chart.Series[0];
    187187      int row = this.Content.ToList().IndexOf(run);
    188       xValue = GetValue(row, xAxisComboBox.SelectedIndex);
    189       yValue = GetValue(row, yAxisComboBox.SelectedIndex);
    190       sizeValue = 1.0;
     188      xValue = GetValue(run, (string)xAxisComboBox.SelectedItem);
     189      yValue = GetValue(run, (string)yAxisComboBox.SelectedItem);
    191190      if (xValue.HasValue && yValue.HasValue) {
    192         if (sizeComboBox.SelectedIndex > 0)
    193           sizeValue = GetValue(row, sizeComboBox.SelectedIndex - 1);
     191       sizeValue = GetValue(run, (string)sizeComboBox.SelectedItem);
    194192        xValue = xValue.Value + xValue.Value * GetXJitter(Content.ElementAt(row)) * xJitterFactor;
    195193        yValue = yValue.Value + yValue.Value * GetYJitter(Content.ElementAt(row)) * yJitterFactor;
     
    202200      }
    203201    }
    204     private double? GetValue(int row, int column) {
    205       if (column < 0 || row < 0)
     202    private double? GetValue(IRun run, string columnName) {
     203      if (run == null || string.IsNullOrEmpty(columnName))
    206204        return null;
    207205
    208       IItem value = Content.GetValue(row, column);
    209       DoubleValue doubleValue = value as DoubleValue;
    210       IntValue intValue = value as IntValue;
    211       double ret;
    212 
    213       if (doubleValue != null)
    214         ret = doubleValue.Value;
    215       else if (intValue != null)
    216         ret = intValue.Value;
    217       else
    218         ret = GetCategoricalValue(column, Matrix.GetValue(row, column));
    219 
    220       return ret;
    221     }
    222     private double GetCategoricalValue(int dimension, object c) {
     206      if (Enum.IsDefined(typeof(AxisDimension), columnName)) {
     207        AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), columnName);
     208        return GetValue(run, axisDimension);
     209      } else if (Enum.IsDefined(typeof(SizeDimension), columnName)) {
     210        SizeDimension sizeDimension = (SizeDimension)Enum.Parse(typeof(SizeDimension), columnName);
     211        return GetValue(run, sizeDimension);
     212      } else {
     213        int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
     214        IItem value = Content.GetValue(run, columnIndex);
     215        if (value == null)
     216          return null;
     217
     218        DoubleValue doubleValue = value as DoubleValue;
     219        IntValue intValue = value as IntValue;
     220        double ret;
     221        if (doubleValue != null)
     222          ret = doubleValue.Value;
     223        else if (intValue != null)
     224          ret = intValue.Value;
     225        else
     226          ret = GetCategoricalValue(columnIndex, value.ToString());
     227
     228        return ret;
     229      }
     230    }
     231    private double GetCategoricalValue(int dimension, string value) {
    223232      if (!this.categoricalMapping.ContainsKey(dimension))
    224233        this.categoricalMapping[dimension] = new Dictionary<object, double>();
    225       if (!this.categoricalMapping[dimension].ContainsKey(c)) {
     234      if (!this.categoricalMapping[dimension].ContainsKey(value)) {
    226235        if (this.categoricalMapping[dimension].Values.Count == 0)
    227           this.categoricalMapping[dimension][c] = 1.0;
     236          this.categoricalMapping[dimension][value] = 1.0;
    228237        else
    229           this.categoricalMapping[dimension][c] = this.categoricalMapping[dimension].Values.Max() + 1.0;
    230       }
    231       return this.categoricalMapping[dimension][c];
    232     }
    233 
    234     #region drag and drop
     238          this.categoricalMapping[dimension][value] = this.categoricalMapping[dimension].Values.Max() + 1.0;
     239      }
     240      return this.categoricalMapping[dimension][value];
     241    }
     242    private double GetValue(IRun run, AxisDimension axisDimension) {
     243      double value = double.NaN;
     244      switch (axisDimension) {
     245        case AxisDimension.Index: {
     246            value = Content.ToList().IndexOf(run);
     247            break;
     248          }
     249        default: {
     250            throw new ArgumentException("No handling strategy for " + axisDimension.ToString() + " is defined.");
     251          }
     252      }
     253      return value;
     254    }
     255    private double GetValue(IRun run, SizeDimension sizeDimension) {
     256      double value = double.NaN;
     257      switch (sizeDimension) {
     258        case SizeDimension.Constant: {
     259            value = 2;
     260            break;
     261          }
     262        default: {
     263            throw new ArgumentException("No handling strategy for " + sizeDimension.ToString() + " is defined.");
     264          }
     265      }
     266      return value;
     267    }
     268
     269    #region drag and drop and tooltip
    235270    private IRun draggedRun;
    236271    private void chart_MouseDown(object sender, MouseEventArgs e) {
     
    306341        }
    307342      }
    308       string newTooltipText;
     343      string newTooltipText = string.Empty;
    309344      string oldTooltipText;
    310345      if (h.ChartElementType == ChartElementType.DataPoint) {
    311346        IRun run = (IRun)((DataPoint)h.Object).Tag;
    312         newTooltipText = run.Name + System.Environment.NewLine;
    313         newTooltipText += xAxisComboBox.SelectedItem + " : " + Content.GetValue(run, xAxisComboBox.SelectedIndex).ToString() + Environment.NewLine;
    314         newTooltipText += yAxisComboBox.SelectedItem + " : " + Content.GetValue(run, yAxisComboBox.SelectedIndex).ToString() + Environment.NewLine; ;
    315       } else
    316         newTooltipText = string.Empty;
     347        newTooltipText = BuildTooltip(run);
     348      }
     349
    317350      oldTooltipText = this.tooltip.GetToolTip(chart);
    318351      if (newTooltipText != oldTooltipText)
    319352        this.tooltip.SetToolTip(chart, newTooltipText);
     353    }
     354
     355    private string BuildTooltip(IRun run) {
     356      string tooltip;
     357      tooltip = run.Name + System.Environment.NewLine;
     358
     359      double? xValue = this.GetValue(run, (string)xAxisComboBox.SelectedItem);
     360      double? yValue = this.GetValue(run, (string)yAxisComboBox.SelectedItem);
     361      double? sizeValue = this.GetValue(run, (string)sizeComboBox.SelectedItem);
     362
     363      string xString = xValue == null ? string.Empty : xValue.Value.ToString();
     364      string yString = yValue == null ? string.Empty : yValue.Value.ToString();
     365      string sizeString = sizeValue == null ? string.Empty : sizeValue.Value.ToString();
     366
     367      tooltip += xAxisComboBox.SelectedItem + " : " + xString + Environment.NewLine;
     368      tooltip += yAxisComboBox.SelectedItem + " : " + yString + Environment.NewLine;
     369      tooltip += sizeComboBox.SelectedItem + " : " + sizeString + Environment.NewLine;
     370
     371      return tooltip;
    320372    }
    321373    #endregion
     
    384436    }
    385437    #endregion
     438
     439    private void sizeLabel_Click(object sender, EventArgs e) {
     440
     441    }
    386442  }
    387443}
Note: See TracChangeset for help on using the changeset viewer.