Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13995 for branches


Ignore:
Timestamp:
07/04/16 23:43:46 (8 years ago)
Author:
bburlacu
Message:

#2597: Improved drag & drop support for all charts. Added configuration option to adjust the number of columns in the view. Fixed bug where attempting to set row & column style would result in an exception. Fixed boundaries of the vertical annotation line in the GradientChart.

Location:
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.Designer.cs

    r13855 r13995  
    4242      //
    4343      this.calculationPendingLabel.BackColor = System.Drawing.Color.White;
    44       this.calculationPendingLabel.Image = HeuristicLab.Common.Resources.VSImageLibrary.Timer;
     44      this.calculationPendingLabel.Image = ((System.Drawing.Image)(resources.GetObject("calculationPendingLabel.Image")));
    4545      this.calculationPendingLabel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
    4646      this.calculationPendingLabel.Location = new System.Drawing.Point(3, 3);
     
    6666      verticalLineAnnotation1.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;
    6767      verticalLineAnnotation1.Name = "VerticalLineAnnotation";
    68       verticalLineAnnotation1.YAxisName = "ChartArea1\\rY";
     68      verticalLineAnnotation1.YAxisName = "ChartArea\\rY";
    6969      this.chart.Annotations.Add(verticalLineAnnotation1);
    7070      stripLine1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(40)))), ((int)(((byte)(223)))), ((int)(((byte)(58)))), ((int)(((byte)(2)))));
     
    9797      this.configurationButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    9898      this.configurationButton.AutoSize = true;
    99       this.configurationButton.Image = HeuristicLab.Common.Resources.VSImageLibrary.Properties;
     99      this.configurationButton.Image = ((System.Drawing.Image)(resources.GetObject("configurationButton.Image")));
    100100      this.configurationButton.Location = new System.Drawing.Point(426, 3);
    101101      this.configurationButton.Name = "configurationButton";
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs

    r13855 r13995  
    116116        if ((value.HasValue && fixedYAxisMin.HasValue && !value.Value.IsAlmost(fixedYAxisMin.Value)) || (value.HasValue != fixedYAxisMin.HasValue)) {
    117117          fixedYAxisMin = value;
    118           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     118          // the check below prevents an exception when yMin >= yMax
     119          if (yMin < yMax)
     120            SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    119121        }
    120122      }
     
    126128        if ((value.HasValue && fixedYAxisMax.HasValue && !value.Value.IsAlmost(fixedYAxisMax.Value)) || (value.HasValue != fixedYAxisMax.HasValue)) {
    127129          fixedYAxisMax = value;
    128           SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
     130          // the check below prevents an exception when yMin >= yMax
     131          if (yMin < yMax)
     132            SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
    129133        }
    130134      }
     
    258262
    259263      // Set cursor and x-axis
     264      // Make sure to allow a small offset to be able to distinguish the vertical line annotation from the axis
    260265      var defaultValue = sharedFixedVariables.GetDoubleValue(freeVariable, 0);
    261       VerticalLineAnnotation.X = defaultValue;
     266      var step = (trainingMax - trainingMin) / drawingSteps;
     267      var minimum = chart.ChartAreas[0].AxisX.Minimum;
     268      var maximum = chart.ChartAreas[0].AxisX.Maximum;
     269      if (defaultValue.IsAlmost(minimum))
     270        VerticalLineAnnotation.X = minimum + step;
     271      else if (defaultValue.IsAlmost(maximum))
     272        VerticalLineAnnotation.X = maximum - step;
     273      else
     274        VerticalLineAnnotation.X = defaultValue;
     275
    262276      if (ShowCursor)
    263277        chart.ChartAreas[0].AxisX.Title = FreeVariable + " : " + defaultValue.ToString("N3", CultureInfo.CurrentCulture);
     
    379393        if (ciSeriesCache.TryGetValue(solution, out ciSeries)) {
    380394          var series = seriesCache[solution];
    381           ciSeries.Color =  Color.FromArgb(40, series.Color);
     395          ciSeries.Color = Color.FromArgb(40, series.Color);
    382396          int idx = chart.Series.IndexOf(seriesCache[solution]);
    383397          chart.Series.Insert(idx, ciSeries);
     
    484498
    485499      await RecalculateAsync();
    486     }
     500      var args = new EventArgs<IRegressionSolution>(solution);
     501      OnSolutionAdded(this, args);
     502    }
     503
    487504    public async Task RemoveSolutionAsync(IRegressionSolution solution) {
    488505      if (!solutions.Remove(solution))
     
    495512
    496513      await RecalculateAsync();
     514      var args = new EventArgs<IRegressionSolution>(solution);
     515      OnSolutionRemoved(this, args);
    497516    }
    498517
     
    524543
    525544    #region Events
     545    public event EventHandler<EventArgs<IRegressionSolution>> SolutionAdded;
     546    public void OnSolutionAdded(object sender, EventArgs<IRegressionSolution> args) {
     547      var added = SolutionAdded;
     548      if (added == null) return;
     549      added(sender, args);
     550    }
     551
     552    public event EventHandler<EventArgs<IRegressionSolution>> SolutionRemoved;
     553    public void OnSolutionRemoved(object sender, EventArgs<IRegressionSolution> args) {
     554      var removed = SolutionRemoved;
     555      if (removed == null) return;
     556      removed(sender, args);
     557    }
     558
    526559    public event EventHandler VariableValueChanged;
    527560    public void OnVariableValueChanged(object sender, EventArgs args) {
     
    544577    }
    545578
    546     private double oldCurserPosition = double.NaN;
    547579    private void chart_AnnotationPositionChanging(object sender, AnnotationPositionChangingEventArgs e) {
    548580      var step = (trainingMax - trainingMin) / drawingSteps;
    549581      double newLocation = step * (long)Math.Round(e.NewLocationX / step);
    550582      var axisX = chart.ChartAreas[0].AxisX;
    551       if (newLocation > axisX.Maximum)
    552         newLocation = axisX.Maximum;
    553       if (newLocation < axisX.Minimum)
    554         newLocation = axisX.Minimum;
    555 
    556       if (oldCurserPosition.IsAlmost(newLocation))
    557         return;
     583      if (newLocation >= axisX.Maximum)
     584        newLocation = axisX.Maximum - step;
     585      if (newLocation <= axisX.Minimum)
     586        newLocation = axisX.Minimum + step;
    558587
    559588      e.NewLocationX = newLocation;
    560       oldCurserPosition = e.NewLocationX;
    561 
    562589      var annotation = VerticalLineAnnotation;
    563590      var x = annotation.X;
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.Designer.cs

    r13853 r13995  
    2424    /// </summary>
    2525    private void InitializeComponent() {
     26      this.components = new System.ComponentModel.Container();
    2627      this.variableListView = new System.Windows.Forms.ListView();
    2728      this.gradientChartTableLayout = new System.Windows.Forms.TableLayoutPanel();
     
    3334      this.configSplitContainer = new System.Windows.Forms.SplitContainer();
    3435      this.variableGroupBox = new System.Windows.Forms.GroupBox();
     36      this.layoutGroupBox = new System.Windows.Forms.GroupBox();
     37      this.columnsTextBox = new System.Windows.Forms.TextBox();
     38      this.columnsLabel = new System.Windows.Forms.Label();
    3539      this.scrollPanel = new System.Windows.Forms.Panel();
     40      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
    3641      this.yAxisConfigGroupBox.SuspendLayout();
    3742      this.densityGroupBox.SuspendLayout();
     
    4146      this.configSplitContainer.SuspendLayout();
    4247      this.variableGroupBox.SuspendLayout();
     48      this.layoutGroupBox.SuspendLayout();
    4349      this.scrollPanel.SuspendLayout();
     50      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    4451      this.SuspendLayout();
    4552      //
     
    5057      this.variableListView.Location = new System.Drawing.Point(3, 16);
    5158      this.variableListView.Name = "variableListView";
    52       this.variableListView.Size = new System.Drawing.Size(163, 503);
     59      this.variableListView.Size = new System.Drawing.Size(163, 458);
    5360      this.variableListView.TabIndex = 0;
    5461      this.variableListView.UseCompatibleStateImageBehavior = false;
     
    142149      //
    143150      this.configSplitContainer.Panel1.Controls.Add(this.variableGroupBox);
     151      this.configSplitContainer.Panel1.Controls.Add(this.layoutGroupBox);
    144152      this.configSplitContainer.Panel1.Controls.Add(this.densityGroupBox);
    145153      this.configSplitContainer.Panel1.Controls.Add(this.yAxisConfigGroupBox);
     
    156164      this.variableGroupBox.Controls.Add(this.variableListView);
    157165      this.variableGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
    158       this.variableGroupBox.Location = new System.Drawing.Point(0, 126);
     166      this.variableGroupBox.Location = new System.Drawing.Point(0, 171);
    159167      this.variableGroupBox.Name = "variableGroupBox";
    160       this.variableGroupBox.Size = new System.Drawing.Size(169, 522);
     168      this.variableGroupBox.Size = new System.Drawing.Size(169, 477);
    161169      this.variableGroupBox.TabIndex = 1;
    162170      this.variableGroupBox.TabStop = false;
    163171      this.variableGroupBox.Text = "Variables";
     172      //
     173      // layoutGroupBox
     174      //
     175      this.layoutGroupBox.Controls.Add(this.columnsTextBox);
     176      this.layoutGroupBox.Controls.Add(this.columnsLabel);
     177      this.layoutGroupBox.Dock = System.Windows.Forms.DockStyle.Top;
     178      this.layoutGroupBox.Location = new System.Drawing.Point(0, 126);
     179      this.layoutGroupBox.Name = "layoutGroupBox";
     180      this.layoutGroupBox.Size = new System.Drawing.Size(169, 45);
     181      this.layoutGroupBox.TabIndex = 5;
     182      this.layoutGroupBox.TabStop = false;
     183      this.layoutGroupBox.Text = "Layout";
     184      //
     185      // columnsTextBox
     186      //
     187      this.columnsTextBox.Location = new System.Drawing.Point(66, 17);
     188      this.columnsTextBox.Name = "columnsTextBox";
     189      this.columnsTextBox.Size = new System.Drawing.Size(94, 20);
     190      this.columnsTextBox.TabIndex = 1;
     191      this.columnsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.columnsTextBox_Validating);
     192      this.columnsTextBox.Validated += new System.EventHandler(this.columnsTextBox_Validated);
     193      //
     194      // columnsLabel
     195      //
     196      this.columnsLabel.AutoSize = true;
     197      this.columnsLabel.Location = new System.Drawing.Point(7, 20);
     198      this.columnsLabel.Name = "columnsLabel";
     199      this.columnsLabel.Size = new System.Drawing.Size(50, 13);
     200      this.columnsLabel.TabIndex = 0;
     201      this.columnsLabel.Text = "Columns:";
    164202      //
    165203      // scrollPanel
     
    171209      this.scrollPanel.Size = new System.Drawing.Size(542, 648);
    172210      this.scrollPanel.TabIndex = 0;
     211      //
     212      // errorProvider
     213      //
     214      this.errorProvider.ContainerControl = this;
    173215      //
    174216      // RegressionSolutionTargetResponseGradientView
     
    187229      this.configSplitContainer.ResumeLayout(false);
    188230      this.variableGroupBox.ResumeLayout(false);
     231      this.layoutGroupBox.ResumeLayout(false);
     232      this.layoutGroupBox.PerformLayout();
    189233      this.scrollPanel.ResumeLayout(false);
    190234      this.scrollPanel.PerformLayout();
     235      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    191236      this.ResumeLayout(false);
    192237
     
    205250    private System.Windows.Forms.GroupBox variableGroupBox;
    206251    private System.Windows.Forms.Panel scrollPanel;
     252    private System.Windows.Forms.GroupBox layoutGroupBox;
     253    private System.Windows.Forms.TextBox columnsTextBox;
     254    private System.Windows.Forms.Label columnsLabel;
     255    private System.Windows.Forms.ErrorProvider errorProvider;
    207256  }
    208257}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionTargetResponseGradientView.cs

    r13948 r13995  
    3939
    4040    private const int Points = 200;
    41     private const int MaxColumns = 4;
     41    private int MaxColumns = 4;
    4242
    4343    private IEnumerable<string> VisibleVariables {
     
    6666      densityComboBox.SelectedIndex = 0; // select None
    6767
     68      columnsTextBox.Text = "4";
     69
    6870      // Avoid additional horizontal scrollbar
    6971      var vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
     
    8284      limitView.Content.ValueChanged += limit_ValueChanged;
    8385      automaticYAxisCheckBox.CheckedChanged += automaticYAxisCheckBox_CheckedChanged;
     86      Content.ModelChanged += solution_ModelChanged;
    8487    }
    8588
     
    8891      limitView.Content.ValueChanged -= limit_ValueChanged;
    8992      automaticYAxisCheckBox.CheckedChanged -= automaticYAxisCheckBox_CheckedChanged;
     93      Content.ModelChanged -= solution_ModelChanged;
    9094      base.DeregisterContentEvents();
    9195    }
     
    171175      };
    172176      gradientChart.Configure(new[] { Content }, sharedFixedVariables, variableName, Points);
    173 
     177      gradientChart.SolutionAdded += gradientChart_SolutionAdded;
     178      gradientChart.SolutionRemoved += gradientChart_SolutionRemoved;
    174179      return gradientChart;
    175180    }
     
    214219    }
    215220
     221    private void SetStyles() {
     222      var tl = gradientChartTableLayout;
     223      tl.RowStyles.Clear();
     224      tl.ColumnStyles.Clear();
     225      int numVariables = VisibleVariables.Count();
     226      if (numVariables == 0)
     227        return;
     228
     229      // set column styles
     230      tl.ColumnCount = Math.Min(numVariables, MaxColumns);
     231      for (int c = 0; c < tl.ColumnCount; c++)
     232        tl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100.0f / tl.ColumnCount));
     233
     234      // set row styles
     235      tl.RowCount = (int)Math.Ceiling((double)numVariables / tl.ColumnCount);
     236      var columnWidth = tl.Width / tl.ColumnCount; // assume all columns have the same width
     237      var rowHeight = (int)(0.8 * columnWidth);
     238      for (int r = 0; r < tl.RowCount; r++)
     239        tl.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
     240    }
     241
     242    private async void gradientChart_SolutionAdded(object sender, EventArgs<IRegressionSolution> e) {
     243      var solution = e.Value;
     244      foreach (var chart in gradientCharts.Values) {
     245        if (sender == chart) continue;
     246        await chart.AddSolutionAsync(solution);
     247      }
     248    }
     249
     250    private async void gradientChart_SolutionRemoved(object sender, EventArgs<IRegressionSolution> e) {
     251      var solution = e.Value;
     252      foreach (var chart in gradientCharts.Values) {
     253        if (sender == chart) continue;
     254        await chart.RemoveSolutionAsync(solution);
     255      }
     256    }
     257
    216258    private async void variableListView_ItemChecked(object sender, ItemCheckedEventArgs e) {
    217259      var item = e.Item;
     
    223265
    224266      tl.SuspendLayout();
    225 
    226267      if (item.Checked) {
    227268        tl.Controls.Add(chartsPanel);
     
    234275      if (tl.Controls.Count > 0) {
    235276        SetupYAxis();
    236 
    237277        ReOrderControls();
    238 
    239         // set column styles
    240         int numVariables = VisibleVariables.Count();
    241         tl.ColumnCount = Math.Min(numVariables, MaxColumns);
    242         tl.ColumnStyles.Clear();
    243         for (int c = 0; c < tl.ColumnCount; c++)
    244           tl.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100.0f / tl.ColumnCount));
    245 
    246         // set column styles
    247         tl.RowCount = (int)Math.Ceiling((double)numVariables / tl.ColumnCount);
    248         var columnWidth = tl.Width / tl.ColumnCount; // assume all columns have the same width
    249         var rowHeight = (int)(0.8 * columnWidth);
    250         tl.RowStyles.Clear();
    251         for (int r = 0; r < tl.RowCount; r++)
    252           tl.RowStyles.Add(new RowStyle(SizeType.Absolute, rowHeight));
    253       }
    254 
     278        SetStyles();
     279      }
    255280      tl.ResumeLayout();
    256281    }
     
    314339      }
    315340    }
     341
     342    private void columnsTextBox_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
     343      int columns;
     344      if (!int.TryParse(columnsTextBox.Text, out columns)) {
     345        e.Cancel = true;
     346        columnsTextBox.Select();
     347        errorProvider.SetError(columnsTextBox, "Columns number must be a positive integer.");
     348      }
     349    }
     350
     351    private void columnsTextBox_Validated(object sender, EventArgs e) {
     352      errorProvider.SetError(columnsTextBox, "");
     353      MaxColumns = int.Parse(columnsTextBox.Text);
     354      int columns = Math.Min(VisibleVariables.Count(), MaxColumns);
     355      if (columns > 0) {
     356        var tl = gradientChartTableLayout;
     357        MaxColumns = columns;
     358        tl.SuspendLayout();
     359        ReOrderControls();
     360        SetStyles();
     361        tl.ResumeLayout();
     362      }
     363    }
     364
     365    private void solution_ModelChanged(object sender, EventArgs e) {
     366      OnContentChanged();
     367    }
    316368  }
    317369}
    318370
     371
Note: See TracChangeset for help on using the changeset viewer.