Changeset 4799


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

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

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

    r4717 r4799  
    4848      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    4949      System.Windows.Forms.DataVisualization.Charting.Series series2 = new System.Windows.Forms.DataVisualization.Charting.Series();
     50      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RunCollectionBubbleChartView));
    5051      this.yJitterLabel = new System.Windows.Forms.Label();
    5152      this.xJitterlabel = new System.Windows.Forms.Label();
     
    5960      this.sizeLabel = new System.Windows.Forms.Label();
    6061      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
     62      this.openBoxPlotViewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    6163      this.zoomButton = new System.Windows.Forms.RadioButton();
    6264      this.selectButton = new System.Windows.Forms.RadioButton();
     
    6567      this.colorDialog = new System.Windows.Forms.ColorDialog();
    6668      this.tooltip = new System.Windows.Forms.ToolTip(this.components);
     69      this.colorXAxisButton = new System.Windows.Forms.Button();
    6770      this.noRunsLabel = new System.Windows.Forms.Label();
    68       this.openBoxPlotViewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     71      this.colorYAxisButton = new System.Windows.Forms.Button();
    6972      ((System.ComponentModel.ISupportInitialize)(this.xTrackBar)).BeginInit();
    7073      ((System.ComponentModel.ISupportInitialize)(this.yTrackBar)).BeginInit();
     
    7679      //
    7780      this.yJitterLabel.AutoSize = true;
    78       this.yJitterLabel.Location = new System.Drawing.Point(257, 6);
     81      this.yJitterLabel.Location = new System.Drawing.Point(350, 6);
    7982      this.yJitterLabel.Name = "yJitterLabel";
    8083      this.yJitterLabel.Size = new System.Drawing.Size(32, 13);
     
    8689      this.xJitterlabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    8790      this.xJitterlabel.AutoSize = true;
    88       this.xJitterlabel.Location = new System.Drawing.Point(539, 295);
     91      this.xJitterlabel.Location = new System.Drawing.Point(635, 316);
    8992      this.xJitterlabel.Name = "xJitterlabel";
    9093      this.xJitterlabel.Size = new System.Drawing.Size(32, 13);
     
    9598      //
    9699      this.xTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    97       this.xTrackBar.Location = new System.Drawing.Point(577, 292);
     100      this.xTrackBar.Location = new System.Drawing.Point(673, 313);
    98101      this.xTrackBar.Maximum = 100;
    99102      this.xTrackBar.Name = "xTrackBar";
     
    107110      this.xAxisLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    108111      this.xAxisLabel.AutoSize = true;
    109       this.xAxisLabel.Location = new System.Drawing.Point(290, 294);
     112      this.xAxisLabel.Location = new System.Drawing.Point(357, 316);
    110113      this.xAxisLabel.Name = "xAxisLabel";
    111114      this.xAxisLabel.Size = new System.Drawing.Size(15, 13);
     
    119122      this.xAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    120123      this.xAxisComboBox.FormattingEnabled = true;
    121       this.xAxisComboBox.Location = new System.Drawing.Point(311, 292);
     124      this.xAxisComboBox.Location = new System.Drawing.Point(378, 313);
    122125      this.xAxisComboBox.Name = "xAxisComboBox";
    123126      this.xAxisComboBox.Size = new System.Drawing.Size(221, 21);
     
    147150      // yTrackBar
    148151      //
    149       this.yTrackBar.Location = new System.Drawing.Point(295, 3);
     152      this.yTrackBar.Location = new System.Drawing.Point(388, 3);
    150153      this.yTrackBar.Maximum = 100;
    151154      this.yTrackBar.Name = "yTrackBar";
     
    161164      this.sizeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    162165      this.sizeComboBox.FormattingEnabled = true;
    163       this.sizeComboBox.Location = new System.Drawing.Point(418, 3);
     166      this.sizeComboBox.Location = new System.Drawing.Point(514, 3);
    164167      this.sizeComboBox.Name = "sizeComboBox";
    165168      this.sizeComboBox.Size = new System.Drawing.Size(221, 21);
     
    171174      this.sizeLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    172175      this.sizeLabel.AutoSize = true;
    173       this.sizeLabel.Location = new System.Drawing.Point(348, 6);
     176      this.sizeLabel.Location = new System.Drawing.Point(444, 6);
    174177      this.sizeLabel.Name = "sizeLabel";
    175178      this.sizeLabel.Size = new System.Drawing.Size(66, 13);
     
    194197      series2.YValuesPerPoint = 2;
    195198      this.chart.Series.Add(series2);
    196       this.chart.Size = new System.Drawing.Size(633, 248);
     199      this.chart.Size = new System.Drawing.Size(729, 269);
    197200      this.chart.TabIndex = 16;
    198201      this.chart.Text = "chart";
     
    201204      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    202205      this.chart.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chart_MouseUp);
     206      //
     207      // openBoxPlotViewToolStripMenuItem
     208      //
     209      this.openBoxPlotViewToolStripMenuItem.Name = "openBoxPlotViewToolStripMenuItem";
     210      this.openBoxPlotViewToolStripMenuItem.Size = new System.Drawing.Size(256, 22);
     211      this.openBoxPlotViewToolStripMenuItem.Text = "Open BoxPlot View";
     212      this.openBoxPlotViewToolStripMenuItem.Click += new System.EventHandler(this.openBoxPlotViewToolStripMenuItem_Click);
    203213      //
    204214      // zoomButton
     
    232242      this.radioButtonGroup.Controls.Add(this.zoomButton);
    233243      this.radioButtonGroup.Controls.Add(this.selectButton);
    234       this.radioButtonGroup.Location = new System.Drawing.Point(3, 284);
     244      this.radioButtonGroup.Location = new System.Drawing.Point(3, 305);
    235245      this.radioButtonGroup.Name = "radioButtonGroup";
    236246      this.radioButtonGroup.Size = new System.Drawing.Size(135, 32);
     
    243253      this.colorButton.Enabled = false;
    244254      this.colorButton.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
    245       this.colorButton.Location = new System.Drawing.Point(144, 292);
     255      this.colorButton.Location = new System.Drawing.Point(144, 313);
    246256      this.colorButton.Name = "colorButton";
    247257      this.colorButton.Size = new System.Drawing.Size(64, 21);
     
    257267      this.colorDialog.FullOpen = true;
    258268      //
     269      // colorXAxisButton
     270      //
     271      this.colorXAxisButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     272      this.colorXAxisButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.DisplayInColor;
     273      this.colorXAxisButton.Location = new System.Drawing.Point(605, 313);
     274      this.colorXAxisButton.Name = "colorXAxisButton";
     275      this.colorXAxisButton.Size = new System.Drawing.Size(21, 21);
     276      this.colorXAxisButton.TabIndex = 22;
     277      this.tooltip.SetToolTip(this.colorXAxisButton, "Color all runs according to their x-values");
     278      this.colorXAxisButton.UseVisualStyleBackColor = true;
     279      this.colorXAxisButton.Click += new System.EventHandler(this.colorXAxisButton_Click);
     280      //
    259281      // noRunsLabel
    260282      //
    261283      this.noRunsLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
    262284      this.noRunsLabel.AutoSize = true;
    263       this.noRunsLabel.Location = new System.Drawing.Point(261, 139);
     285      this.noRunsLabel.Location = new System.Drawing.Point(309, 150);
    264286      this.noRunsLabel.Name = "noRunsLabel";
    265287      this.noRunsLabel.Size = new System.Drawing.Size(138, 13);
     
    267289      this.noRunsLabel.Text = "No runs could be displayed.";
    268290      //
    269       // openBoxPlotViewToolStripMenuItem
    270       //
    271       this.chart.ContextMenuStrip.Items.Insert(0, openBoxPlotViewToolStripMenuItem);
    272       this.openBoxPlotViewToolStripMenuItem.Name = "openBoxPlotViewToolStripMenuItem";
    273       this.openBoxPlotViewToolStripMenuItem.Size = new System.Drawing.Size(256, 22);
    274       this.openBoxPlotViewToolStripMenuItem.Text = "Open BoxPlot View";
    275       this.openBoxPlotViewToolStripMenuItem.Click += new System.EventHandler(this.openBoxPlotViewToolStripMenuItem_Click);
     291      // colorYAxisButton
     292      //
     293      this.colorYAxisButton.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.DisplayInColor;
     294      this.colorYAxisButton.Location = new System.Drawing.Point(251, 3);
     295      this.colorYAxisButton.Name = "colorYAxisButton";
     296      this.colorYAxisButton.Size = new System.Drawing.Size(21, 21);
     297      this.colorYAxisButton.TabIndex = 23;
     298      this.tooltip.SetToolTip(this.colorYAxisButton, "Color all runs according to their y-values");
     299      this.colorYAxisButton.UseVisualStyleBackColor = true;
     300      this.colorYAxisButton.Click += new System.EventHandler(this.colorYAxisButton_Click);
    276301      //
    277302      // RunCollectionBubbleChartView
     
    281306      this.BackColor = System.Drawing.SystemColors.Window;
    282307      this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     308      this.Controls.Add(this.colorYAxisButton);
     309      this.Controls.Add(this.colorXAxisButton);
    283310      this.Controls.Add(this.noRunsLabel);
    284311      this.Controls.Add(this.colorButton);
     
    296323      this.Controls.Add(this.yTrackBar);
    297324      this.Name = "RunCollectionBubbleChartView";
    298       this.Size = new System.Drawing.Size(644, 319);
     325      this.Size = new System.Drawing.Size(740, 340);
    299326      ((System.ComponentModel.ISupportInitialize)(this.xTrackBar)).EndInit();
    300327      ((System.ComponentModel.ISupportInitialize)(this.yTrackBar)).EndInit();
     
    327354    private System.Windows.Forms.Label noRunsLabel;
    328355    private System.Windows.Forms.ToolStripMenuItem openBoxPlotViewToolStripMenuItem;
     356    private System.Windows.Forms.Button colorXAxisButton;
     357    private System.Windows.Forms.Button colorYAxisButton;
    329358  }
    330359}
  • 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.