Changeset 3428


Ignore:
Timestamp:
04/20/10 00:39:59 (11 years ago)
Author:
mkommend
Message:

added new version of RunCollectionBubbleChartView (ticket #970)

Location:
trunk/sources
Files:
4 edited

Legend:

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

    r3411 r3428  
    179179      this.chart.TabIndex = 16;
    180180      this.chart.Text = "chart1";
     181      this.chart.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chart_MouseUp);
    181182      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    182183      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r3411 r3428  
    5555      this.yJitter = new Dictionary<IRun, double>();
    5656      this.random = new Random();
     57      this.colorDialog.Color = Color.Black;
     58      this.colorButton.Image = this.GenerateImage(16, 16, this.colorDialog.Color);
     59      this.isSelecting = false;
    5760
    5861      this.chart.Series[0]["BubbleMaxSize"] = "0";
     
    8790      Content.Reset += new EventHandler(Content_Reset);
    8891      Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
    89     }
     92      Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
     93      Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
     94      Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     95      foreach (IRun run in Content)
     96        run.Changed += new EventHandler(run_Changed);
     97    }
     98
    9099    protected override void DeregisterContentEvents() {
    91100      base.DeregisterContentEvents();
    92101      Content.Reset -= new EventHandler(Content_Reset);
    93102      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
    94     }
     103      Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
     104      Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
     105      Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
     106      foreach (IRun run in Content)
     107        run.Changed -= new EventHandler(run_Changed);
     108    }
     109
     110    private void Content_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     111      foreach (IRun run in e.OldItems)
     112        run.Changed -= new EventHandler(run_Changed);
     113      foreach (IRun run in e.Items)
     114        run.Changed += new EventHandler(run_Changed);
     115    }
     116
     117    private void Content_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     118      foreach (IRun run in e.OldItems)
     119        run.Changed -= new EventHandler(run_Changed);
     120    }
     121    private void Content_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IRun> e) {
     122      foreach (IRun run in e.Items)
     123        run.Changed += new EventHandler(run_Changed);
     124    }
     125    private void run_Changed(object sender, EventArgs e) {
     126      IRun run = (IRun)sender;
     127      DataPoint point = this.chart.Series[0].Points.Where(p => p.Tag == run).SingleOrDefault();
     128      if (point != null) {
     129        point.Color = run.Color;
     130        if (!run.Visible)
     131          this.chart.Series[0].Points.Remove(point);
     132      } else
     133        AddDataPoint(run);
     134    }
     135
    95136    protected override void OnContentChanged() {
    96137      base.OnContentChanged();
     
    98139      this.UpdateComboBoxes();
    99140    }
    100 
    101141    private void Content_ColumnNamesChanged(object sender, EventArgs e) {
    102142      if (InvokeRequired)
     
    128168      Series series = this.chart.Series[0];
    129169      series.Points.Clear();
    130 
     170      foreach (IRun run in this.Content)
     171        this.AddDataPoint(run);
     172    }
     173    private void AddDataPoint(IRun run) {
    131174      double? xValue;
    132175      double? yValue;
    133176      double? sizeValue;
    134       for (int row = 0; row < Content.Count; row++) {
    135         xValue = GetValue(row, xAxisComboBox.SelectedIndex);
    136         yValue = GetValue(row, yAxisComboBox.SelectedIndex);
    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;
     177      Series series = this.chart.Series[0];
     178      int row = this.Content.ToList().IndexOf(run);
     179      xValue = GetValue(row, xAxisComboBox.SelectedIndex);
     180      yValue = GetValue(row, yAxisComboBox.SelectedIndex);
     181      sizeValue = 1.0;
     182      if (xValue.HasValue && yValue.HasValue) {
     183        if (sizeComboBox.SelectedIndex > 0)
     184          sizeValue = GetValue(row, sizeComboBox.SelectedIndex - 1);
     185        xValue = xValue.Value + xValue.Value * GetXJitter(Content.ElementAt(row)) * xJitterFactor;
     186        yValue = yValue.Value + yValue.Value * GetYJitter(Content.ElementAt(row)) * yJitterFactor;
     187        if (run.Visible) {
    143188          DataPoint point = new DataPoint(xValue.Value, new double[] { yValue.Value, sizeValue.Value });
    144189          point.ToolTip = this.CreateTooltip(row);
    145           point.Tag = this.Content.ElementAt(row);
     190          point.Tag = run;
     191          point.Color = run.Color;
    146192          series.Points.Add(point);
    147193        }
     
    180226      HitTestResult h = this.chart.HitTest(e.X, e.Y);
    181227      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;
     228        IRun run =(IRun)((DataPoint)h.Object).Tag;
     229        if (e.Clicks >= 2) {
     230          IContentView view = MainFormManager.CreateDefaultView(run);
     231          view.ReadOnly = this.ReadOnly;
     232          view.Locked = this.Locked;
     233          view.Show();
     234        } else {
     235          this.draggedRun = run;
     236          this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = false;
     237          this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = false;
     238          this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = false;
     239          this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = false;
     240        }
     241      }
     242    }
     243
     244    private void chart_MouseUp(object sender, MouseEventArgs e) {
     245      if (isDragOperationInProgress) {
     246        this.isDragOperationInProgress = false;
     247        this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !isSelecting;
     248        this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !isSelecting;
     249        this.chart.ChartAreas[0].CursorX.SetSelectionPosition(0, 0);
     250        this.chart.ChartAreas[0].CursorY.SetSelectionPosition(0, 0);
     251        this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
     252        this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
     253        return;
     254      }
     255      if (!isSelecting) return;
     256      System.Windows.Forms.DataVisualization.Charting.Cursor xCursor = chart.ChartAreas[0].CursorX;
     257      System.Windows.Forms.DataVisualization.Charting.Cursor yCursor = chart.ChartAreas[0].CursorY;
     258
     259      double minX = Math.Min(xCursor.SelectionStart, xCursor.SelectionEnd);
     260      double maxX = Math.Max(xCursor.SelectionStart, xCursor.SelectionEnd);
     261      double minY = Math.Min(yCursor.SelectionStart, yCursor.SelectionEnd);
     262      double maxY = Math.Max(yCursor.SelectionStart, yCursor.SelectionEnd);
     263
     264      //check for click to select model
     265      if (minX == maxX && minY == maxY) {
     266        HitTestResult hitTest = chart.HitTest(e.X, e.Y);
     267        if (hitTest.ChartElementType == ChartElementType.DataPoint) {
     268          int pointIndex = hitTest.PointIndex;
     269          IRun run = (IRun)this.chart.Series[0].Points[pointIndex].Tag;
     270          run.Color = colorDialog.Color;
     271        }
     272      } else {
     273      List<DataPoint> selectedPoints = new List<DataPoint>();
     274      foreach (DataPoint p in this.chart.Series[0].Points) {
     275        if (p.XValue >= minX && p.XValue < maxX &&
     276          p.YValues[0] >= minY && p.YValues[0] < maxY) {
     277          selectedPoints.Add(p);
     278        }
     279      }
     280      foreach (DataPoint p in selectedPoints) {
     281        IRun run = (IRun)p.Tag;
     282        run.Color = colorDialog.Color;
     283      }
     284      xCursor.SetSelectionPosition(0, 0);
     285      yCursor.SetSelectionPosition(0, 0);
    187286      }
    188287    }
  • trunk/sources/HeuristicLab.Optimization/3.3/Interfaces/IRun.cs

    r3376 r3428  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using System.Drawing;
     26using System;
    2527
    2628namespace HeuristicLab.Optimization {
     
    3234    IDictionary<string, IItem> Parameters { get; }
    3335    IDictionary<string, IItem> Results { get; }
     36
     37    Color Color {get;set;}
     38    bool Visible { get; set; }
     39    event EventHandler Changed;
    3440  }
    3541}
  • trunk/sources/HeuristicLab.Optimization/3.3/Run.cs

    r3376 r3428  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using System.Drawing;
    2728
    2829namespace HeuristicLab.Optimization {
     
    4748    public IDictionary<string, IItem> Results {
    4849      get { return results; }
     50    }
     51
     52    private Color color = Color.Black;
     53    public Color Color {
     54      get { return this.color; }
     55      set {
     56        if (color != value) {
     57          this.color = value;
     58          this.OnChanged();
     59        }
     60      }
     61    }
     62    private bool visible = true;
     63    public bool Visible {
     64      get { return this.visible; }
     65      set {
     66        if (visible != value) {
     67          this.visible = value;
     68          this.OnChanged();
     69        }
     70      }
     71    }
     72    public event EventHandler Changed;
     73    private void OnChanged() {
     74      EventHandler handler = Changed;
     75      if (handler != null)
     76        handler(this, EventArgs.Empty);
    4977    }
    5078
Note: See TracChangeset for help on using the changeset viewer.