Free cookie consent management tool by TermsFeed Policy Generator

Changeset 14521


Ignore:
Timestamp:
12/22/16 12:42:09 (8 years ago)
Author:
pfleck
Message:

#2709 Added an option for the preprocessing scatterplot to use a color gradient instead of the chart color palette.

Location:
branches/DataPreprocessing Enhancements
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/HeuristicLab.DataPreprocessing.Views-3.4.csproj

    r14514 r14521  
    317317      <Name>HeuristicLab.DataPreprocessing-3.4</Name>
    318318    </ProjectReference>
     319  </ItemGroup>
     320  <ItemGroup>
     321    <EmbeddedResource Include="ScatterPlotSingleView.resx">
     322      <DependentUpon>ScatterPlotSingleView.cs</DependentUpon>
     323    </EmbeddedResource>
    319324  </ItemGroup>
    320325  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.Designer.cs

    r14514 r14521  
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ScatterPlotSingleView));
    4748      this.scatterPlotControl = new HeuristicLab.Analysis.Views.ScatterPlotControl();
    4849      this.groupBox1 = new System.Windows.Forms.GroupBox();
     50      this.useGradientCheckBox = new System.Windows.Forms.CheckBox();
    4951      this.label3 = new System.Windows.Forms.Label();
    5052      this.label2 = new System.Windows.Forms.Label();
     
    5961      this.label4 = new System.Windows.Forms.Label();
    6062      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
     63      this.gradientPanel = new System.Windows.Forms.Panel();
     64      this.gradientMinimumLabel = new System.Windows.Forms.Label();
     65      this.gradientMaximumLabel = new System.Windows.Forms.Label();
     66      this.gradientPictureBox = new System.Windows.Forms.PictureBox();
    6167      this.groupBox1.SuspendLayout();
    6268      this.regressionGroupBox.SuspendLayout();
     
    6672      this.splitContainer1.Panel2.SuspendLayout();
    6773      this.splitContainer1.SuspendLayout();
     74      this.gradientPanel.SuspendLayout();
     75      ((System.ComponentModel.ISupportInitialize)(this.gradientPictureBox)).BeginInit();
    6876      this.SuspendLayout();
    6977      //
    7078      // scatterPlotControl
    7179      //
     80      this.scatterPlotControl.Caption = "View";
    7281      this.scatterPlotControl.Content = null;
    7382      this.scatterPlotControl.Dock = System.Windows.Forms.DockStyle.Fill;
    7483      this.scatterPlotControl.Location = new System.Drawing.Point(0, 0);
    7584      this.scatterPlotControl.Name = "scatterPlotControl";
    76       this.scatterPlotControl.Size = new System.Drawing.Size(687, 517);
     85      this.scatterPlotControl.ReadOnly = false;
     86      this.scatterPlotControl.Size = new System.Drawing.Size(618, 517);
    7787      this.scatterPlotControl.TabIndex = 0;
    7888      //
    7989      // groupBox1
    8090      //
     91      this.groupBox1.Controls.Add(this.useGradientCheckBox);
    8192      this.groupBox1.Controls.Add(this.label3);
    8293      this.groupBox1.Controls.Add(this.label2);
     
    8899      this.groupBox1.Location = new System.Drawing.Point(0, 0);
    89100      this.groupBox1.Name = "groupBox1";
    90       this.groupBox1.Size = new System.Drawing.Size(172, 137);
     101      this.groupBox1.Size = new System.Drawing.Size(172, 150);
    91102      this.groupBox1.TabIndex = 1;
    92103      this.groupBox1.TabStop = false;
    93104      this.groupBox1.Text = "Variables";
     105      //
     106      // useGradientCheckBox
     107      //
     108      this.useGradientCheckBox.AutoSize = true;
     109      this.useGradientCheckBox.Location = new System.Drawing.Point(51, 121);
     110      this.useGradientCheckBox.Name = "useGradientCheckBox";
     111      this.useGradientCheckBox.Size = new System.Drawing.Size(115, 17);
     112      this.useGradientCheckBox.TabIndex = 4;
     113      this.useGradientCheckBox.Text = "Use Color Gradient";
     114      this.useGradientCheckBox.UseVisualStyleBackColor = true;
     115      this.useGradientCheckBox.CheckedChanged += new System.EventHandler(this.useGradientCheckBox_CheckedChanged);
    94116      //
    95117      // label3
     
    122144      // comboBoxGroup
    123145      //
    124       this.comboBoxGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     146      this.comboBoxGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    125147            | System.Windows.Forms.AnchorStyles.Right)));
    126148      this.comboBoxGroup.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     
    135157      // comboBoxYVariable
    136158      //
    137       this.comboBoxYVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     159      this.comboBoxYVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    138160            | System.Windows.Forms.AnchorStyles.Right)));
    139161      this.comboBoxYVariable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     
    148170      // comboBoxXVariable
    149171      //
    150       this.comboBoxXVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     172      this.comboBoxXVariable.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    151173            | System.Windows.Forms.AnchorStyles.Right)));
    152174      this.comboBoxXVariable.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     
    166188      this.regressionGroupBox.Controls.Add(this.label4);
    167189      this.regressionGroupBox.Dock = System.Windows.Forms.DockStyle.Top;
    168       this.regressionGroupBox.Location = new System.Drawing.Point(0, 137);
     190      this.regressionGroupBox.Location = new System.Drawing.Point(0, 150);
    169191      this.regressionGroupBox.Name = "regressionGroupBox";
    170192      this.regressionGroupBox.Size = new System.Drawing.Size(172, 78);
     
    175197      // regressionTypeComboBox
    176198      //
    177       this.regressionTypeComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     199      this.regressionTypeComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    178200            | System.Windows.Forms.AnchorStyles.Right)));
    179201      this.regressionTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     
    187209      // polynomialRegressionOrderNumericUpDown
    188210      //
    189       this.polynomialRegressionOrderNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     211      this.polynomialRegressionOrderNumericUpDown.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    190212            | System.Windows.Forms.AnchorStyles.Right)));
    191213      this.polynomialRegressionOrderNumericUpDown.Location = new System.Drawing.Point(51, 47);
     
    244266      //
    245267      this.splitContainer1.Panel2.Controls.Add(this.scatterPlotControl);
     268      this.splitContainer1.Panel2.Controls.Add(this.gradientPanel);
    246269      this.splitContainer1.Size = new System.Drawing.Size(863, 517);
    247270      this.splitContainer1.SplitterDistance = 172;
    248271      this.splitContainer1.TabIndex = 5;
     272      //
     273      // gradientPanel
     274      //
     275      this.gradientPanel.Controls.Add(this.gradientPictureBox);
     276      this.gradientPanel.Controls.Add(this.gradientMinimumLabel);
     277      this.gradientPanel.Controls.Add(this.gradientMaximumLabel);
     278      this.gradientPanel.Dock = System.Windows.Forms.DockStyle.Right;
     279      this.gradientPanel.Location = new System.Drawing.Point(618, 0);
     280      this.gradientPanel.Name = "gradientPanel";
     281      this.gradientPanel.Size = new System.Drawing.Size(69, 517);
     282      this.gradientPanel.TabIndex = 1;
     283      //
     284      // gradientMinimumLabel
     285      //
     286      this.gradientMinimumLabel.BackColor = System.Drawing.Color.Transparent;
     287      this.gradientMinimumLabel.Dock = System.Windows.Forms.DockStyle.Bottom;
     288      this.gradientMinimumLabel.Location = new System.Drawing.Point(0, 492);
     289      this.gradientMinimumLabel.Name = "gradientMinimumLabel";
     290      this.gradientMinimumLabel.Size = new System.Drawing.Size(69, 25);
     291      this.gradientMinimumLabel.TabIndex = 18;
     292      this.gradientMinimumLabel.Text = "0.0";
     293      this.gradientMinimumLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
     294      //
     295      // gradientMaximumLabel
     296      //
     297      this.gradientMaximumLabel.BackColor = System.Drawing.Color.Transparent;
     298      this.gradientMaximumLabel.Dock = System.Windows.Forms.DockStyle.Top;
     299      this.gradientMaximumLabel.Location = new System.Drawing.Point(0, 0);
     300      this.gradientMaximumLabel.Name = "gradientMaximumLabel";
     301      this.gradientMaximumLabel.Size = new System.Drawing.Size(69, 25);
     302      this.gradientMaximumLabel.TabIndex = 17;
     303      this.gradientMaximumLabel.Text = "1.0";
     304      this.gradientMaximumLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
     305      //
     306      // gradientPictureBox
     307      //
     308      this.gradientPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     309            | System.Windows.Forms.AnchorStyles.Left)));
     310      this.gradientPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     311      this.gradientPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("GradientPictureBox.Image")));
     312      this.gradientPictureBox.Location = new System.Drawing.Point(17, 29);
     313      this.gradientPictureBox.Name = "gradientPictureBox";
     314      this.gradientPictureBox.Size = new System.Drawing.Size(35, 460);
     315      this.gradientPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
     316      this.gradientPictureBox.TabIndex = 19;
     317      this.gradientPictureBox.TabStop = false;
    249318      //
    250319      // ScatterPlotSingleView
     
    264333      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
    265334      this.splitContainer1.ResumeLayout(false);
     335      this.gradientPanel.ResumeLayout(false);
     336      ((System.ComponentModel.ISupportInitialize)(this.gradientPictureBox)).EndInit();
    266337      this.ResumeLayout(false);
    267338
     
    284355    private System.Windows.Forms.Label label4;
    285356    private System.Windows.Forms.SplitContainer splitContainer1;
     357    private System.Windows.Forms.CheckBox useGradientCheckBox;
     358    private System.Windows.Forms.Panel gradientPanel;
     359    private System.Windows.Forms.Label gradientMinimumLabel;
     360    private System.Windows.Forms.Label gradientMaximumLabel;
     361    protected System.Windows.Forms.PictureBox gradientPictureBox;
    286362  }
    287363}
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs

    r14514 r14521  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using System.Linq;
    2526using HeuristicLab.Analysis;
     27using HeuristicLab.Common;
    2628using HeuristicLab.Core.Views;
    2729using HeuristicLab.MainForm;
     30using HeuristicLab.MainForm.WindowsForms;
    2831using RegressionType = HeuristicLab.Analysis.ScatterPlotDataRowVisualProperties.ScatterPlotDataRowRegressionType;
    2932
     
    3336  [Content(typeof(SingleScatterPlotContent), true)]
    3437  public partial class ScatterPlotSingleView : ItemView {
     38
     39    private readonly string NoGroupItem = "-";
    3540
    3641    public new SingleScatterPlotContent Content {
     
    5560      comboBoxXVariable.Items.AddRange(variables.ToArray());
    5661      comboBoxYVariable.Items.AddRange(variables.ToArray());
    57       comboBoxGroup.Items.Add("-");
     62      comboBoxGroup.Items.Add(NoGroupItem);
    5863      for (int i = 0; i < Content.PreprocessingData.Columns; ++i) {
    5964        if (Content.PreprocessingData.VariableHasType<double>(i)) {
    60           double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
    61           if (distinctValueCount <= 20)
    62             comboBoxGroup.Items.Add(Content.PreprocessingData.GetVariableName(i));
     65          //double distinctValueCount = Content.PreprocessingData.GetValues<double>(i).GroupBy(x => x).Count();
     66          //if (distinctValueCount <= 20)
     67          comboBoxGroup.Items.Add(Content.PreprocessingData.GetVariableName(i));
    6368        }
    6469      }
     
    8691    }
    8792
     93    protected override void SetEnabledStateOfControls() {
     94      base.SetEnabledStateOfControls();
     95      useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem;
     96      gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked; ;
     97    }
     98
    8899    private void UpdateScatterPlot() {
    89100      if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null && comboBoxGroup.SelectedItem != null) {
     
    91102        var yVariable = (string)comboBoxYVariable.SelectedItem;
    92103        var groupVariable = (string)comboBoxGroup.SelectedItem;
     104
     105        bool groupingActive = useGradientCheckBox.Checked && groupVariable != NoGroupItem;
     106        double min = 0, max = 1;
     107        if (groupingActive) {
     108          var groupValues = Content.PreprocessingData.GetValues<double>(Content.PreprocessingData.GetColumnIndex(groupVariable))
     109            .Distinct().OrderBy(x => x).ToList();
     110          min = groupValues.First();
     111          max = groupValues.Last();
     112        }
    93113        ScatterPlot scatterPlot = Content.CreateScatterPlot(xVariable, yVariable, groupVariable);
     114        var rows = scatterPlot.Rows.ToList();
     115        scatterPlot.Rows.Clear();
    94116        var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
    95117        int order = (int)polynomialRegressionOrderNumericUpDown.Value;
    96         foreach (var row in scatterPlot.Rows) {
     118        foreach (var row in rows) {
    97119          row.VisualProperties.PointSize = 6;
    98120          row.VisualProperties.IsRegressionVisibleInLegend = false;
    99121          row.VisualProperties.RegressionType = regressionType;
    100122          row.VisualProperties.PolynomialRegressionOrder = order;
    101         }
     123          row.VisualProperties.IsVisibleInLegend = !useGradientCheckBox.Checked;
     124          if (groupingActive)
     125            row.VisualProperties.Color = GetColor(double.Parse(row.Name), min, max);
     126        }
     127        scatterPlot.Rows.AddRange(rows);
    102128        var vp = scatterPlot.VisualProperties;
    103129        vp.Title = string.Empty;
     
    106132
    107133        scatterPlotControl.Content = scatterPlot;
     134
     135        if (groupingActive) {
     136          gradientMinimumLabel.Text = min.ToString("G5");
     137          gradientMaximumLabel.Text = max.ToString("G5");
     138        }
    108139
    109140        //save selected x and y variable in content
     
    152183
    153184    private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) {
     185      useGradientCheckBox.Enabled = (string)comboBoxGroup.SelectedItem != NoGroupItem;
     186      gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked;
    154187      UpdateScatterPlot();
    155188    }
     
    159192      var regressionType = (RegressionType)regressionTypeComboBox.SelectedValue;
    160193      polynomialRegressionOrderNumericUpDown.Enabled = regressionType == RegressionType.Polynomial;
     194
    161195      UpdateRegressionLine();
    162196    }
     
    170204      int order = (int)polynomialRegressionOrderNumericUpDown.Value;
    171205
    172       foreach (var row in scatterPlotControl.Content.Rows) {
     206      var rows = scatterPlotControl.Content.Rows.ToList();
     207      scatterPlotControl.Content.Rows.Clear();
     208      foreach (var row in rows) {
    173209        row.VisualProperties.IsRegressionVisibleInLegend = false;
    174210        row.VisualProperties.RegressionType = regressionType;
    175211        row.VisualProperties.PolynomialRegressionOrder = order;
    176212      }
     213      scatterPlotControl.Content.Rows.AddRange(rows);
    177214    }
    178215    #endregion
     216
     217    private void useGradientCheckBox_CheckedChanged(object sender, EventArgs e) {
     218      gradientPanel.Visible = useGradientCheckBox.Enabled && useGradientCheckBox.Checked;
     219
     220      // remove rows and re-add them later to avoid firing visual property changd events
     221      var rows = scatterPlotControl.Content.Rows.ToDictionary(r => r.Name, r => r);
     222      scatterPlotControl.Content.Rows.Clear();
     223
     224      if (useGradientCheckBox.Checked) {
     225        var groupVariable = (string)comboBoxGroup.SelectedItem;
     226        if (groupVariable == NoGroupItem) return;
     227
     228        var groupValues = Content.PreprocessingData.GetValues<double>(Content.PreprocessingData.GetColumnIndex(groupVariable))
     229          .Distinct().OrderBy(x => x).ToList();
     230        double min = groupValues.First(), max = groupValues.Last();
     231        foreach (var group in groupValues) {
     232          ScatterPlotDataRow row;
     233          if (rows.TryGetValue(group.ToString("R"), out row)) {
     234            row.VisualProperties.Color = GetColor(group, min, max);
     235            row.VisualProperties.IsVisibleInLegend = false;
     236          }
     237        }
     238        gradientMinimumLabel.Text = min.ToString("G5");
     239        gradientMaximumLabel.Text = max.ToString("G5");
     240      } else {
     241        foreach (var row in rows.Values) {
     242          row.VisualProperties.Color = Color.Empty;
     243          row.VisualProperties.IsVisibleInLegend = true;
     244        }
     245      }
     246      scatterPlotControl.Content.Rows.AddRange(rows.Values);
     247    }
     248
     249    private static Color GetColor(double value, double min, double max) {
     250      if (double.IsNaN(value)) {
     251        return Color.DarkGray;
     252      }
     253      var colors = ColorGradient.Colors;
     254      int index = (int)((colors.Count - 1) * (value - min) / (max - min));
     255      if (index >= colors.Count) index = colors.Count - 1;
     256      if (index < 0) index = 0;
     257      return colors[index];
     258    }
     259
     260    private void BatchRowUpdate(Action<ScatterPlotDataRow> rowAction) {
     261      var scatterPlot = scatterPlotControl.Content;
     262      var rows = scatterPlot.Rows.ToList();
     263      // remove rows and re-add them later to avoid firing visual property changd events
     264      scatterPlot.Rows.Clear();
     265      foreach (var row in rows) {
     266        rowAction(row);
     267      }
     268      scatterPlot.Rows.AddRange(rows);
     269    }
    179270  }
    180271}
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs

    r14511 r14521  
    7272      } else {
    7373        var groupValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameGroup));
    74         var data = points.Zip(groupValues, (p, g) => new { p, g });
    75         foreach (var groupValue in groupValues.Distinct()) {
     74        var data = points.Zip(groupValues, (p, g) => new { p, g })
     75          .Where(x => !double.IsNaN(x.p.X) && !double.IsNaN(x.p.Y) && !double.IsNaN(x.g) && !double.IsInfinity(x.p.X) && !double.IsInfinity(x.p.Y) && !double.IsInfinity(x.g))
     76          .ToList();
     77
     78        foreach (var groupValue in groupValues.Distinct().OrderBy(g => g)) {
    7679          var values = data.Where(x => x.g == groupValue).Select(v => v.p);
    7780          var row = new ScatterPlotDataRow(string.Format("{0} ({1})", variableNameGroup, groupValue), "", values) {
     81            Name = groupValue.ToString("R"),
    7882            VisualProperties = { PointSize = 6 }
    7983          };
Note: See TracChangeset for help on using the changeset viewer.