Changeset 3411


Ignore:
Timestamp:
04/19/10 17:13:02 (12 years ago)
Author:
mkommend
Message:

enhanced RunCollectionBubbleChartView (ticket #970)

Location:
trunk/sources/HeuristicLab.Optimization.Views/3.3
Files:
2 edited

Legend:

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

    r3349 r3411  
    7979      this.xTrackBar.TabIndex = 11;
    8080      this.xTrackBar.TickStyle = System.Windows.Forms.TickStyle.None;
     81      this.xTrackBar.ValueChanged += new System.EventHandler(this.jitterTrackBar_ValueChanged);
    8182      //
    8283      // xAxisLabel
     
    133134      this.yTrackBar.TabIndex = 10;
    134135      this.yTrackBar.TickStyle = System.Windows.Forms.TickStyle.None;
     136      this.yTrackBar.ValueChanged += new System.EventHandler(this.jitterTrackBar_ValueChanged);
    135137      //
    136138      // sizeComboBox
     
    144146      this.sizeComboBox.Size = new System.Drawing.Size(121, 21);
    145147      this.sizeComboBox.TabIndex = 14;
     148      this.sizeComboBox.SelectedIndexChanged += new System.EventHandler(this.AxisComboBox_SelectedIndexChanged);
    146149      //
    147150      // sizeLabel
     
    176179      this.chart.TabIndex = 16;
    177180      this.chart.Text = "chart1";
     181      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
     182      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
     183      this.chart.LostFocus += new System.EventHandler(this.chart_LostFocus);
    178184      //
    179185      // zoomButton
     
    189195      this.zoomButton.Text = "Zoom";
    190196      this.zoomButton.UseVisualStyleBackColor = true;
     197      this.zoomButton.CheckedChanged += new System.EventHandler(this.zoomButton_CheckedChanged);
    191198      //
    192199      // selectButton
     
    224231      this.colorButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
    225232      this.colorButton.UseVisualStyleBackColor = true;
     233      this.colorButton.Click += new System.EventHandler(this.colorButton_Click);
    226234      //
    227235      // colorDialog
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r3376 r3411  
    3838  [Content(typeof(RunCollection), false)]
    3939  public partial class RunCollectionBubbleChartView : AsynchronousContentView {
     40    private const string constantLabel = "constant";
    4041    private Dictionary<int, Dictionary<object, double>> categoricalMapping;
     42    private Dictionary<IRun, double> xJitter;
     43    private Dictionary<IRun, double> yJitter;
     44    private double xJitterFactor = 0.0;
     45    private double yJitterFactor = 0.0;
     46    private Random random;
     47    private bool isSelecting = false;
    4148
    4249    public RunCollectionBubbleChartView() {
    4350      InitializeComponent();
    4451      Caption = "Run Collection Bubble Chart";
     52
    4553      this.categoricalMapping = new Dictionary<int, Dictionary<object, double>>();
     54      this.xJitter = new Dictionary<IRun, double>();
     55      this.yJitter = new Dictionary<IRun, double>();
     56      this.random = new Random();
     57
     58      this.chart.Series[0]["BubbleMaxSize"] = "0";
     59      this.chart.Series[0]["BubbleMaxScale"] = "Auto";
     60      this.chart.Series[0]["BubbleMinScale"] = "Auto";
     61      this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
     62      this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
     63      this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !this.isSelecting;
     64      this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !this.isSelecting;
     65      this.chart.ChartAreas[0].CursorX.Interval = 0;
     66      this.chart.ChartAreas[0].CursorY.Interval = 0;
     67
    4668      base.ReadOnly = true;
    4769    }
     
    6688      Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
    6789    }
    68 
    6990    protected override void DeregisterContentEvents() {
    7091      base.DeregisterContentEvents();
     
    7293      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
    7394    }
    74 
    7595    protected override void OnContentChanged() {
    7696      base.OnContentChanged();
     97      this.categoricalMapping.Clear();
    7798      this.UpdateComboBoxes();
    7899    }
     
    88109      this.xAxisComboBox.Items.Clear();
    89110      this.yAxisComboBox.Items.Clear();
     111      this.sizeComboBox.Items.Clear();
    90112      this.xAxisComboBox.Items.AddRange(Content.ColumnNames.ToArray());
    91113      this.yAxisComboBox.Items.AddRange(Content.ColumnNames.ToArray());
     114      this.sizeComboBox.Items.Add(constantLabel);
     115      this.sizeComboBox.Items.AddRange(Content.ColumnNames.ToArray());
    92116    }
    93117
     
    107131      double? xValue;
    108132      double? yValue;
     133      double? sizeValue;
    109134      for (int row = 0; row < Content.Count; row++) {
    110135        xValue = GetValue(row, xAxisComboBox.SelectedIndex);
    111136        yValue = GetValue(row, yAxisComboBox.SelectedIndex);
    112         if (xValue.HasValue && yValue.HasValue)
    113           series.Points.Add(new DataPoint(xValue.Value, yValue.Value));
    114       }
    115     }
    116 
    117     private void AxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    118       UpdateDataPoints();
    119       UpdateAxisLabels();
    120     }
    121 
     137        sizeValue = 1.0;
     138        if (xValue.HasValue && yValue.HasValue) {
     139          if (sizeComboBox.SelectedIndex > 0)
     140            sizeValue = GetValue(row, sizeComboBox.SelectedIndex-1);
     141          xValue = xValue.Value + xValue.Value * GetXJitter(Content.ElementAt(row)) * xJitterFactor;
     142          yValue = yValue.Value + yValue.Value * GetYJitter(Content.ElementAt(row)) * yJitterFactor;
     143          DataPoint point = new DataPoint(xValue.Value, new double[] { yValue.Value, sizeValue.Value });
     144          point.ToolTip = this.CreateTooltip(row);
     145          point.Tag = this.Content.ElementAt(row);
     146          series.Points.Add(point);
     147        }
     148      }
     149    }
    122150    private double? GetValue(int row, int column) {
    123151      if (column < 0 || row < 0)
     
    145173    }
    146174
     175    #region drag and drop
     176    private IRun draggedRun;
     177    private bool isDragOperationInProgress = false;
     178
     179    private void chart_MouseDown(object sender, MouseEventArgs e) {
     180      HitTestResult h = this.chart.HitTest(e.X, e.Y);
     181      if (h.ChartElementType == ChartElementType.DataPoint) {
     182        this.draggedRun = (IRun)((DataPoint)h.Object).Tag;
     183        this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = false;
     184        this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = false;
     185        this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = false;
     186        this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = false;
     187      }
     188    }
     189
     190    private void chart_MouseMove(object sender, MouseEventArgs e) {
     191      HitTestResult h = this.chart.HitTest(e.X, e.Y);
     192      if (this.draggedRun != null && h.ChartElementType != ChartElementType.DataPoint) {
     193        //this.isDragOperationInProgress = true;
     194        DataObject data = new DataObject();
     195        data.SetData("Type", draggedRun.GetType());
     196        data.SetData("Value", draggedRun);
     197        if (ReadOnly) {
     198          DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
     199        } else {
     200          DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
     201          if ((result & DragDropEffects.Move) == DragDropEffects.Move)
     202            Content.Remove(draggedRun);
     203        }
     204        this.draggedRun = null;
     205      }
     206    }
     207    private void chart_LostFocus(object sender, EventArgs e) {
     208      if (this.isDragOperationInProgress) {
     209        this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !isSelecting;
     210        this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !isSelecting;
     211        this.chart.ChartAreas[0].CursorX.SetSelectionPosition(0, 0);
     212        this.chart.ChartAreas[0].CursorY.SetSelectionPosition(0, 0);
     213        this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
     214        this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
     215        this.isDragOperationInProgress = false;
     216      }
     217    }
     218    #endregion
     219
     220    #region GUI events and updating
     221    private double GetXJitter(IRun run) {
     222      if (!this.xJitter.ContainsKey(run))
     223        this.xJitter[run] = random.NextDouble() * 2.0 - 1.0;
     224      return this.xJitter[run];
     225    }
     226    private double GetYJitter(IRun run) {
     227      if (!this.yJitter.ContainsKey(run))
     228        this.yJitter[run] = random.NextDouble() * 2.0 - 1.0;
     229      return this.yJitter[run];
     230    }
     231    private void jitterTrackBar_ValueChanged(object sender, EventArgs e) {
     232      this.xJitterFactor = xTrackBar.Value / 100.0;
     233      this.yJitterFactor = yTrackBar.Value / 100.0;
     234      this.UpdateDataPoints();
     235    }
     236
     237    private void AxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     238      UpdateDataPoints();
     239      UpdateAxisLabels();
     240    }
    147241    private void UpdateAxisLabels() {
    148242      Axis xAxis = this.chart.ChartAreas[0].AxisX;
    149243      Axis yAxis = this.chart.ChartAreas[0].AxisY;
    150       SetAxisLabels(xAxis, xAxisComboBox.SelectedIndex);
    151       SetAxisLabels(yAxis, yAxisComboBox.SelectedIndex);
    152     }
    153     private void SetAxisLabels(Axis axis, int dimension) {
     244      SetCustomAxisLabels(xAxis, xAxisComboBox.SelectedIndex);
     245      SetCustomAxisLabels(yAxis, yAxisComboBox.SelectedIndex);
     246    }
     247    private void SetCustomAxisLabels(Axis axis, int dimension) {
     248      axis.CustomLabels.Clear();
    154249      if (categoricalMapping.ContainsKey(dimension)) {
    155         axis.CustomLabels.Clear();
    156250        CustomLabel label = null;
    157251        foreach (var pair in categoricalMapping[dimension]) {
     
    165259      }
    166260    }
     261
     262    private string CreateTooltip(int runIndex) {
     263      StringBuilder builder = new StringBuilder();
     264      builder.AppendLine(this.Content.ElementAt(runIndex).Name);
     265      int columnIndex = 0;
     266      foreach (string columnName in this.Content.ColumnNames) {
     267        builder.Append(columnName);
     268        builder.Append(": ");
     269        builder.AppendLine(this.Content.GetValue(runIndex, columnIndex));
     270        columnIndex++;
     271      }
     272      return builder.ToString();
     273    }
     274
     275    private void zoomButton_CheckedChanged(object sender, EventArgs e) {
     276      this.isSelecting = selectButton.Checked;
     277      this.colorButton.Enabled = this.isSelecting;
     278      this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !isSelecting;
     279      this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !isSelecting;
     280    }
     281
     282    private void colorButton_Click(object sender, EventArgs e) {
     283      if (colorDialog.ShowDialog(this) == DialogResult.OK) {
     284        this.colorButton.Image = this.GenerateImage(16, 16, this.colorDialog.Color);
     285      }
     286    }
     287    private Image GenerateImage(int width, int height, Color fillColor) {
     288      Image colorImage = new Bitmap(width, height);
     289      using (Graphics gfx = Graphics.FromImage(colorImage)) {
     290        using (SolidBrush brush = new SolidBrush(fillColor)) {
     291          gfx.FillRectangle(brush, 0, 0, width, height);
     292        }
     293      }
     294      return colorImage;
     295    }
     296    #endregion
    167297  }
    168298}
Note: See TracChangeset for help on using the changeset viewer.