Free cookie consent management tool by TermsFeed Policy Generator

Changeset 12881


Ignore:
Timestamp:
08/19/15 13:13:51 (9 years ago)
Author:
pfleck
Message:

#2379 Added jitter for x and y axis.

Location:
branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/BubbleChartView.Designer.cs

    r12600 r12881  
    6262      this.includeChildrenCheckBox = new System.Windows.Forms.CheckBox();
    6363      this.sizeTrackBar = new System.Windows.Forms.TrackBar();
     64      this.yJitterLabel = new System.Windows.Forms.Label();
     65      this.xJitterLabel = new System.Windows.Forms.Label();
     66      this.yJitterTrackBar = new System.Windows.Forms.TrackBar();
     67      this.xJitterTrackBar = new System.Windows.Forms.TrackBar();
    6468      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    6569      this.childrenGroupBox.SuspendLayout();
     
    7074      ((System.ComponentModel.ISupportInitialize)(this.levelNumericUpDown)).BeginInit();
    7175      ((System.ComponentModel.ISupportInitialize)(this.sizeTrackBar)).BeginInit();
     76      ((System.ComponentModel.ISupportInitialize)(this.yJitterTrackBar)).BeginInit();
     77      ((System.ComponentModel.ISupportInitialize)(this.xJitterTrackBar)).BeginInit();
    7278      this.SuspendLayout();
    7379      //
     
    8591      this.xLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    8692      this.xLabel.AutoSize = true;
    87       this.xLabel.Location = new System.Drawing.Point(725, 713);
     93      this.xLabel.Location = new System.Drawing.Point(700, 712);
    8894      this.xLabel.Name = "xLabel";
    8995      this.xLabel.Size = new System.Drawing.Size(15, 13);
     
    107113      series1.YValuesPerPoint = 2;
    108114      this.chart.Series.Add(series1);
    109       this.chart.Size = new System.Drawing.Size(965, 668);
     115      this.chart.Size = new System.Drawing.Size(966, 668);
    110116      this.chart.TabIndex = 7;
    111117      this.chart.AxisViewChanged += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ViewEventArgs>(this.chart_AxisViewChanged);
     
    117123      this.yAxisComboBox.Location = new System.Drawing.Point(239, 2);
    118124      this.yAxisComboBox.Name = "yAxisComboBox";
    119       this.yAxisComboBox.Size = new System.Drawing.Size(340, 21);
     125      this.yAxisComboBox.Size = new System.Drawing.Size(263, 21);
    120126      this.yAxisComboBox.TabIndex = 8;
    121127      this.yAxisComboBox.SelectedValueChanged += new System.EventHandler(this.axisComboBox_SelectedValueChanged);
     
    126132      this.xAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    127133      this.xAxisComboBox.FormattingEnabled = true;
    128       this.xAxisComboBox.Location = new System.Drawing.Point(746, 710);
     134      this.xAxisComboBox.Location = new System.Drawing.Point(721, 709);
    129135      this.xAxisComboBox.Name = "xAxisComboBox";
    130       this.xAxisComboBox.Size = new System.Drawing.Size(340, 21);
     136      this.xAxisComboBox.Size = new System.Drawing.Size(249, 21);
    131137      this.xAxisComboBox.TabIndex = 9;
    132138      this.xAxisComboBox.SelectedValueChanged += new System.EventHandler(this.axisComboBox_SelectedValueChanged);
     
    140146      this.treeView.Location = new System.Drawing.Point(6, 19);
    141147      this.treeView.Name = "treeView";
    142       this.treeView.Size = new System.Drawing.Size(90, 643);
     148      this.treeView.Size = new System.Drawing.Size(89, 643);
    143149      this.treeView.TabIndex = 10;
    144150      this.treeView.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeView_AfterCheck);
     
    153159      this.childrenGroupBox.Location = new System.Drawing.Point(3, 3);
    154160      this.childrenGroupBox.Name = "childrenGroupBox";
    155       this.childrenGroupBox.Size = new System.Drawing.Size(102, 668);
     161      this.childrenGroupBox.Size = new System.Drawing.Size(101, 668);
    156162      this.childrenGroupBox.TabIndex = 11;
    157163      this.childrenGroupBox.TabStop = false;
     
    174180      this.splitContainer.Panel2.Controls.Add(this.chart);
    175181      this.splitContainer.Size = new System.Drawing.Size(1083, 674);
    176       this.splitContainer.SplitterDistance = 108;
     182      this.splitContainer.SplitterDistance = 107;
    177183      this.splitContainer.TabIndex = 12;
    178184      //
     
    242248      this.sizeTrackBar.ValueChanged += new System.EventHandler(this.sizeTrackBar_ValueChanged);
    243249      //
     250      // yJitterLabel
     251      //
     252      this.yJitterLabel.AutoSize = true;
     253      this.yJitterLabel.Location = new System.Drawing.Point(509, 6);
     254      this.yJitterLabel.Name = "yJitterLabel";
     255      this.yJitterLabel.Size = new System.Drawing.Size(32, 13);
     256      this.yJitterLabel.TabIndex = 19;
     257      this.yJitterLabel.Text = "Jitter:";
     258      //
     259      // xJitterLabel
     260      //
     261      this.xJitterLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     262      this.xJitterLabel.AutoSize = true;
     263      this.xJitterLabel.Location = new System.Drawing.Point(977, 712);
     264      this.xJitterLabel.Name = "xJitterLabel";
     265      this.xJitterLabel.Size = new System.Drawing.Size(32, 13);
     266      this.xJitterLabel.TabIndex = 20;
     267      this.xJitterLabel.Text = "Jitter:";
     268      //
     269      // yJitterTrackBar
     270      //
     271      this.yJitterTrackBar.Enabled = false;
     272      this.yJitterTrackBar.Location = new System.Drawing.Point(547, 2);
     273      this.yJitterTrackBar.Maximum = 100;
     274      this.yJitterTrackBar.Name = "yJitterTrackBar";
     275      this.yJitterTrackBar.Size = new System.Drawing.Size(65, 45);
     276      this.yJitterTrackBar.TabIndex = 21;
     277      this.yJitterTrackBar.TickStyle = System.Windows.Forms.TickStyle.None;
     278      this.yJitterTrackBar.ValueChanged += new System.EventHandler(this.jitterTrackBar_ValueChanged);
     279      //
     280      // xJitterTrackBar
     281      //
     282      this.xJitterTrackBar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     283      this.xJitterTrackBar.Enabled = false;
     284      this.xJitterTrackBar.Location = new System.Drawing.Point(1019, 707);
     285      this.xJitterTrackBar.Maximum = 100;
     286      this.xJitterTrackBar.Name = "xJitterTrackBar";
     287      this.xJitterTrackBar.Size = new System.Drawing.Size(65, 45);
     288      this.xJitterTrackBar.TabIndex = 22;
     289      this.xJitterTrackBar.TickStyle = System.Windows.Forms.TickStyle.None;
     290      this.xJitterTrackBar.ValueChanged += new System.EventHandler(this.jitterTrackBar_ValueChanged);
     291      //
    244292      // BubbleChartView
    245293      //
     
    248296      this.BackColor = System.Drawing.SystemColors.Window;
    249297      this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     298      this.Controls.Add(this.xJitterTrackBar);
     299      this.Controls.Add(this.yJitterTrackBar);
     300      this.Controls.Add(this.xJitterLabel);
     301      this.Controls.Add(this.yJitterLabel);
    250302      this.Controls.Add(this.sizeTrackBar);
    251303      this.Controls.Add(this.includeChildrenCheckBox);
     
    269321      ((System.ComponentModel.ISupportInitialize)(this.levelNumericUpDown)).EndInit();
    270322      ((System.ComponentModel.ISupportInitialize)(this.sizeTrackBar)).EndInit();
     323      ((System.ComponentModel.ISupportInitialize)(this.yJitterTrackBar)).EndInit();
     324      ((System.ComponentModel.ISupportInitialize)(this.xJitterTrackBar)).EndInit();
    271325      this.ResumeLayout(false);
    272326      this.PerformLayout();
     
    290344    private System.Windows.Forms.CheckBox includeChildrenCheckBox;
    291345    private System.Windows.Forms.TrackBar sizeTrackBar;
     346    private System.Windows.Forms.Label yJitterLabel;
     347    private System.Windows.Forms.Label xJitterLabel;
     348    private System.Windows.Forms.TrackBar yJitterTrackBar;
     349    private System.Windows.Forms.TrackBar xJitterTrackBar;
    292350  }
    293351}
  • branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/BubbleChartView.cs

    r12880 r12881  
    2121
    2222using System;
    23 using System.Collections;
    2423using System.Collections.Generic;
    2524using System.Linq;
     
    4443    private readonly Dictionary<string, Dictionary<object, double>> categoricalMapping = new Dictionary<string, Dictionary<object, double>>();
    4544
     45    private readonly Dictionary<RecursiveDataItem, double> xJitter = new Dictionary<RecursiveDataItem, double>();
     46    private readonly Dictionary<RecursiveDataItem, double> yJitter = new Dictionary<RecursiveDataItem, double>();
     47    private readonly Random random = new Random();
     48
     49
    4650    private string XAxisValue { get { return (string)xAxisComboBox.SelectedItem; } }
    4751    private string YAxisValue { get { return (string)yAxisComboBox.SelectedItem; } }
     
    4953
    5054    private bool updating = false;
     55
     56    private double xJitterFactor = 0.0;
     57    private double yJitterFactor = 0.0;
    5158
    5259    public new RecursiveDataItem Content {
     
    7885      base.SetEnabledStateOfControls();
    7986      levelNumericUpDown.Enabled = Content != null;
    80       // ToDo
     87      xJitterTrackBar.Enabled = Content != null;
     88      yJitterTrackBar.Enabled = Content != null;
     89      xAxisComboBox.Enabled = Content != null;
     90      yAxisComboBox.Enabled = Content != null;
    8191    }
    8292
     
    200210            AddPoints(xss[i], yss[j], series);
    201211      }
    202     }
    203     void AddPoints(double[] xs, double[] ys, Series series) {
    204       if (xs.Length != ys.Length) return;
    205       for (int k = 0; k < xs.Length; k++) {
    206         series.Points.Add(new DataPoint(xs[k], new[] { ys[k], 1.0 }));
    207       }
    208     }
    209 
    210     private List<double[]> GetValues(string key) {
    211       var collector = new List<double[]>();
     212
     213      xJitterTrackBar.Value = 0;
     214      yJitterTrackBar.Value = 0;
     215
     216      //needed to set axis back to automatic and refresh them, otherwise their values may remain NaN
     217      var xAxis = chart.ChartAreas[0].AxisX;
     218      var yAxis = chart.ChartAreas[0].AxisY;
     219      SetAutomaticUpdateOfAxis(xAxis, true);
     220      SetAutomaticUpdateOfAxis(yAxis, true);
     221      chart.Refresh();
     222    }
     223    void AddPoints(Tuple<double[], RecursiveDataItem> xs, Tuple<double[], RecursiveDataItem> ys, Series series) {
     224      if (xs.Item1.Length != ys.Item1.Length) return;
     225      for (int k = 0; k < xs.Item1.Length; k++) {
     226        series.Points.Add(new DataPoint(xs.Item1[k], new[] { ys.Item1[k], 1.0 }) {
     227          Tag = Tuple.Create(xs.Item1[k], ys.Item1[k], xs.Item2, ys.Item2)
     228        });
     229      }
     230    }
     231
     232    private List<Tuple<double[], RecursiveDataItem>> GetValues(string key) {
     233      var collector = new List<Tuple<double[], RecursiveDataItem>>();
    212234      GetValues(Content, key, collector);
    213235      return collector;
    214236    }
    215     private void GetValues(RecursiveDataItem node, string key, List<double[]> collector) {
     237    private void GetValues(RecursiveDataItem node, string key, List<Tuple<double[], RecursiveDataItem>> collector) {
    216238      IItem item;
    217239      if (node.Data.TryGetValue(key, out item)) {
    218240        var value = ConvertToDoubles(node, key);
    219         collector.Add(value);
     241        collector.Add(Tuple.Create(value, node));
    220242      }
    221243
     
    437459      }
    438460    }
     461
     462    private void UpdateDataPointJitter() {
     463      var xAxis = this.chart.ChartAreas[0].AxisX;
     464      var yAxis = this.chart.ChartAreas[0].AxisY;
     465
     466      double xAxisRange = xAxis.Maximum - xAxis.Minimum;
     467      double yAxisRange = yAxis.Maximum - yAxis.Minimum;
     468
     469      foreach (DataPoint point in chart.Series[0].Points) {
     470        var tag = (Tuple<double, double, RecursiveDataItem, RecursiveDataItem>)point.Tag;
     471        var xItem = tag.Item3;
     472        var yItem = tag.Item4;
     473        double xValue = tag.Item1;
     474        double yValue = tag.Item2;
     475
     476        if (!xJitterFactor.IsAlmost(0.0))
     477          xValue += 0.1 * GetXJitter(xItem) * xJitterFactor * (xAxisRange);
     478        if (!yJitterFactor.IsAlmost(0.0))
     479          yValue += 0.1 * GetYJitter(yItem) * yJitterFactor * (yAxisRange);
     480
     481        point.XValue = xValue;
     482        point.YValues[0] = yValue;
     483      }
     484
     485      if (xJitterFactor.IsAlmost(0.0) && yJitterFactor.IsAlmost(0.0)) {
     486        SetAutomaticUpdateOfAxis(xAxis, true);
     487        SetAutomaticUpdateOfAxis(yAxis, true);
     488        chart.ChartAreas[0].RecalculateAxesScale();
     489      } else {
     490        SetAutomaticUpdateOfAxis(xAxis, false);
     491        SetAutomaticUpdateOfAxis(yAxis, false);
     492      }
     493    }
     494    private double GetXJitter(RecursiveDataItem item) {
     495      if (!this.xJitter.ContainsKey(item))
     496        this.xJitter[item] = random.NextDouble() * 2.0 - 1.0;
     497      return this.xJitter[item];
     498    }
     499    private double GetYJitter(RecursiveDataItem item) {
     500      if (!this.yJitter.ContainsKey(item))
     501        this.yJitter[item] = random.NextDouble() * 2.0 - 1.0;
     502      return this.yJitter[item];
     503    }
     504
     505    // sets an axis to automatic or restrains it to its current values
     506    // this is used that none of the set values is changed when jitter is applied, so that the chart stays the same
     507    private void SetAutomaticUpdateOfAxis(Axis axis, bool enabled) {
     508      if (enabled) {
     509        axis.Maximum = double.NaN;
     510        axis.Minimum = double.NaN;
     511        axis.MajorGrid.Interval = double.NaN;
     512        axis.MajorTickMark.Interval = double.NaN;
     513        axis.LabelStyle.Interval = double.NaN;
     514      } else {
     515        axis.Minimum = axis.Minimum;
     516        axis.Maximum = axis.Maximum;
     517        axis.MajorGrid.Interval = axis.MajorGrid.Interval;
     518        axis.MajorTickMark.Interval = axis.MajorTickMark.Interval;
     519        axis.LabelStyle.Interval = axis.LabelStyle.Interval;
     520      }
     521    }
    439522    #endregion
    440523
     
    480563      UpdateMarkerSizes();
    481564    }
     565
     566    private void jitterTrackBar_ValueChanged(object sender, EventArgs e) {
     567      this.xJitterFactor = xJitterTrackBar.Value / 100.0;
     568      this.yJitterFactor = yJitterTrackBar.Value / 100.0;
     569      UpdateDataPointJitter();
     570    }
    482571    #endregion
    483572
Note: See TracChangeset for help on using the changeset viewer.