Changeset 14449


Ignore:
Timestamp:
12/02/16 17:35:05 (4 years ago)
Author:
gkronber
Message:

#2650: merged r14422:14443 from trunk to branches resolving conflicts

Location:
branches/symbreg-factors-2650
Files:
6 added
23 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessBase.cs

    r14185 r14449  
    2121#endregion
    2222
     23using System.Linq;
    2324using HeuristicLab.Algorithms.GradientDescent;
    2425using HeuristicLab.Common;
     
    119120
    120121      // necessary for BFGS
    121       Parameters.Add(new ValueParameter<BoolValue>("Maximization", new BoolValue(false)));
    122       Parameters["Maximization"].Hidden = true;
     122      Parameters.Add(new FixedValueParameter<BoolValue>("Maximization (BFGS)", new BoolValue(false)));
     123      Parameters["Maximization (BFGS)"].Hidden = true;
    123124
    124125      var randomCreator = new HeuristicLab.Random.RandomCreator();
     
    164165      modelCreator.Successor = updateResults;
    165166
     167      updateResults.MaximizationParameter.ActualName = "Maximization (BFGS)";
    166168      updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
    167169      updateResults.QualityParameter.ActualName = NegativeLogLikelihoodParameterName;
     
    197199      // BackwardsCompatibility3.4
    198200      #region Backwards compatible code, remove with 3.5
    199       if (!Parameters.ContainsKey("Maximization")) {
    200         Parameters.Add(new ValueParameter<BoolValue>("Maximization", new BoolValue(false)));
    201         Parameters["Maximization"].Hidden = true;
     201      if (Parameters.ContainsKey("Maximization")) {
     202        Parameters.Remove("Maximization");
     203      }
     204
     205      if (!Parameters.ContainsKey("Maximization (BFGS)")) {
     206        Parameters.Add(new FixedValueParameter<BoolValue>("Maximization (BFGS)", new BoolValue(false)));
     207        Parameters["Maximization (BFGS)"].Hidden = true;
     208        OperatorGraph.Operators.OfType<LbfgsUpdateResults>().First().MaximizationParameter.ActualName = "Maximization BFGS";
    202209      }
    203210
  • branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.Designer.cs

    r14185 r14449  
    5454      this.label3 = new System.Windows.Forms.Label();
    5555      this.commonGroupBox = new System.Windows.Forms.GroupBox();
     56      this.isVisibleInLegendCheckBox = new System.Windows.Forms.CheckBox();
     57      this.label10 = new System.Windows.Forms.Label();
    5658      this.displayNameTextBox = new System.Windows.Forms.TextBox();
    5759      this.axisGroupBox = new System.Windows.Forms.GroupBox();
     60      this.panel2 = new System.Windows.Forms.Panel();
    5861      this.yAxisSecondaryRadioButton = new System.Windows.Forms.RadioButton();
     62      this.yAxisPrimaryRadioButton = new System.Windows.Forms.RadioButton();
     63      this.panel1 = new System.Windows.Forms.Panel();
    5964      this.xAxisPrimaryRadioButton = new System.Windows.Forms.RadioButton();
    60       this.yAxisPrimaryRadioButton = new System.Windows.Forms.RadioButton();
     65      this.xAxisSecondaryRadioButton = new System.Windows.Forms.RadioButton();
    6166      this.label5 = new System.Windows.Forms.Label();
    62       this.xAxisSecondaryRadioButton = new System.Windows.Forms.RadioButton();
    6367      this.label6 = new System.Windows.Forms.Label();
    6468      this.label9 = new System.Windows.Forms.Label();
     
    7276      this.lineStyleComboBox = new System.Windows.Forms.ComboBox();
    7377      this.label8 = new System.Windows.Forms.Label();
    74       this.panel1 = new System.Windows.Forms.Panel();
    75       this.panel2 = new System.Windows.Forms.Panel();
    7678      ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).BeginInit();
    7779      this.commonGroupBox.SuspendLayout();
    7880      this.axisGroupBox.SuspendLayout();
     81      this.panel2.SuspendLayout();
     82      this.panel1.SuspendLayout();
    7983      this.histoGramGroupBox.SuspendLayout();
    8084      this.lineChartGroupBox.SuspendLayout();
    8185      ((System.ComponentModel.ISupportInitialize)(this.lineWidthNumericUpDown)).BeginInit();
    82       this.panel1.SuspendLayout();
    83       this.panel2.SuspendLayout();
    8486      this.SuspendLayout();
    8587      //
     
    9092      this.chartTypeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    9193      this.chartTypeComboBox.FormattingEnabled = true;
    92       this.chartTypeComboBox.Location = new System.Drawing.Point(57, 45);
     94      this.chartTypeComboBox.Location = new System.Drawing.Point(102, 45);
    9395      this.chartTypeComboBox.Name = "chartTypeComboBox";
    94       this.chartTypeComboBox.Size = new System.Drawing.Size(264, 21);
     96      this.chartTypeComboBox.Size = new System.Drawing.Size(219, 21);
    9597      this.chartTypeComboBox.TabIndex = 3;
    9698      this.chartTypeComboBox.SelectedValueChanged += new System.EventHandler(this.chartTypeComboBox_SelectedValueChanged);
     
    103105      //
    104106      this.colorButton.BackColor = System.Drawing.SystemColors.Control;
    105       this.colorButton.Location = new System.Drawing.Point(56, 72);
     107      this.colorButton.Location = new System.Drawing.Point(102, 72);
    106108      this.colorButton.Name = "colorButton";
    107109      this.colorButton.Size = new System.Drawing.Size(23, 23);
     
    172174      this.commonGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    173175            | System.Windows.Forms.AnchorStyles.Right)));
     176      this.commonGroupBox.Controls.Add(this.isVisibleInLegendCheckBox);
     177      this.commonGroupBox.Controls.Add(this.label10);
    174178      this.commonGroupBox.Controls.Add(this.displayNameTextBox);
    175179      this.commonGroupBox.Controls.Add(this.axisGroupBox);
     
    181185      this.commonGroupBox.Location = new System.Drawing.Point(0, 0);
    182186      this.commonGroupBox.Name = "commonGroupBox";
    183       this.commonGroupBox.Size = new System.Drawing.Size(327, 174);
     187      this.commonGroupBox.Size = new System.Drawing.Size(327, 199);
    184188      this.commonGroupBox.TabIndex = 0;
    185189      this.commonGroupBox.TabStop = false;
    186190      this.commonGroupBox.Text = "Common";
    187191      //
     192      // isVisibleInLegendCheckBox
     193      //
     194      this.isVisibleInLegendCheckBox.AutoSize = true;
     195      this.isVisibleInLegendCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
     196      this.isVisibleInLegendCheckBox.Location = new System.Drawing.Point(102, 104);
     197      this.isVisibleInLegendCheckBox.Name = "isVisibleInLegendCheckBox";
     198      this.isVisibleInLegendCheckBox.Size = new System.Drawing.Size(15, 14);
     199      this.isVisibleInLegendCheckBox.TabIndex = 8;
     200      this.isVisibleInLegendCheckBox.UseVisualStyleBackColor = true;
     201      this.isVisibleInLegendCheckBox.CheckedChanged += new System.EventHandler(this.isVisibleInLegendCheckBox_CheckedChanged);
     202      //
     203      // label10
     204      //
     205      this.label10.AutoSize = true;
     206      this.label10.Location = new System.Drawing.Point(6, 104);
     207      this.label10.Name = "label10";
     208      this.label10.Size = new System.Drawing.Size(90, 13);
     209      this.label10.TabIndex = 7;
     210      this.label10.Text = "&Visible in Legend:";
     211      //
    188212      // displayNameTextBox
    189213      //
    190214      this.displayNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    191215            | System.Windows.Forms.AnchorStyles.Right)));
    192       this.displayNameTextBox.Location = new System.Drawing.Point(57, 19);
     216      this.displayNameTextBox.Location = new System.Drawing.Point(102, 19);
    193217      this.displayNameTextBox.Name = "displayNameTextBox";
    194       this.displayNameTextBox.Size = new System.Drawing.Size(264, 20);
     218      this.displayNameTextBox.Size = new System.Drawing.Size(219, 20);
    195219      this.displayNameTextBox.TabIndex = 1;
    196220      this.displayNameTextBox.Validated += new System.EventHandler(this.displayNameTextBox_Validated);
     
    205229      this.axisGroupBox.Controls.Add(this.label5);
    206230      this.axisGroupBox.Controls.Add(this.label6);
    207       this.axisGroupBox.Location = new System.Drawing.Point(6, 101);
     231      this.axisGroupBox.Location = new System.Drawing.Point(6, 126);
    208232      this.axisGroupBox.Name = "axisGroupBox";
    209233      this.axisGroupBox.Size = new System.Drawing.Size(315, 67);
     
    211235      this.axisGroupBox.TabStop = false;
    212236      this.axisGroupBox.Text = "Axes";
     237      //
     238      // panel2
     239      //
     240      this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     241            | System.Windows.Forms.AnchorStyles.Right)));
     242      this.panel2.Controls.Add(this.yAxisSecondaryRadioButton);
     243      this.panel2.Controls.Add(this.yAxisPrimaryRadioButton);
     244      this.panel2.Location = new System.Drawing.Point(51, 42);
     245      this.panel2.Name = "panel2";
     246      this.panel2.Size = new System.Drawing.Size(258, 17);
     247      this.panel2.TabIndex = 7;
    213248      //
    214249      // yAxisSecondaryRadioButton
     
    224259      this.yAxisSecondaryRadioButton.CheckedChanged += new System.EventHandler(this.yAxisRadioButton_CheckedChanged);
    225260      //
     261      // yAxisPrimaryRadioButton
     262      //
     263      this.yAxisPrimaryRadioButton.AutoSize = true;
     264      this.yAxisPrimaryRadioButton.Location = new System.Drawing.Point(0, 0);
     265      this.yAxisPrimaryRadioButton.Name = "yAxisPrimaryRadioButton";
     266      this.yAxisPrimaryRadioButton.Size = new System.Drawing.Size(59, 17);
     267      this.yAxisPrimaryRadioButton.TabIndex = 4;
     268      this.yAxisPrimaryRadioButton.TabStop = true;
     269      this.yAxisPrimaryRadioButton.Text = "&Primary";
     270      this.yAxisPrimaryRadioButton.UseVisualStyleBackColor = true;
     271      this.yAxisPrimaryRadioButton.CheckedChanged += new System.EventHandler(this.yAxisRadioButton_CheckedChanged);
     272      //
     273      // panel1
     274      //
     275      this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     276            | System.Windows.Forms.AnchorStyles.Right)));
     277      this.panel1.Controls.Add(this.xAxisPrimaryRadioButton);
     278      this.panel1.Controls.Add(this.xAxisSecondaryRadioButton);
     279      this.panel1.Location = new System.Drawing.Point(51, 19);
     280      this.panel1.Name = "panel1";
     281      this.panel1.Size = new System.Drawing.Size(258, 17);
     282      this.panel1.TabIndex = 6;
     283      //
    226284      // xAxisPrimaryRadioButton
    227285      //
     
    236294      this.xAxisPrimaryRadioButton.CheckedChanged += new System.EventHandler(this.xAxisRadioButton_CheckedChanged);
    237295      //
    238       // yAxisPrimaryRadioButton
    239       //
    240       this.yAxisPrimaryRadioButton.AutoSize = true;
    241       this.yAxisPrimaryRadioButton.Location = new System.Drawing.Point(0, 0);
    242       this.yAxisPrimaryRadioButton.Name = "yAxisPrimaryRadioButton";
    243       this.yAxisPrimaryRadioButton.Size = new System.Drawing.Size(59, 17);
    244       this.yAxisPrimaryRadioButton.TabIndex = 4;
    245       this.yAxisPrimaryRadioButton.TabStop = true;
    246       this.yAxisPrimaryRadioButton.Text = "&Primary";
    247       this.yAxisPrimaryRadioButton.UseVisualStyleBackColor = true;
    248       this.yAxisPrimaryRadioButton.CheckedChanged += new System.EventHandler(this.yAxisRadioButton_CheckedChanged);
    249       //
    250       // label5
    251       //
    252       this.label5.AutoSize = true;
    253       this.label5.Location = new System.Drawing.Point(6, 44);
    254       this.label5.Name = "label5";
    255       this.label5.Size = new System.Drawing.Size(39, 13);
    256       this.label5.TabIndex = 3;
    257       this.label5.Text = "&Y-Axis:";
    258       //
    259296      // xAxisSecondaryRadioButton
    260297      //
     
    269306      this.xAxisSecondaryRadioButton.CheckedChanged += new System.EventHandler(this.xAxisRadioButton_CheckedChanged);
    270307      //
     308      // label5
     309      //
     310      this.label5.AutoSize = true;
     311      this.label5.Location = new System.Drawing.Point(6, 44);
     312      this.label5.Name = "label5";
     313      this.label5.Size = new System.Drawing.Size(39, 13);
     314      this.label5.TabIndex = 3;
     315      this.label5.Text = "&Y-Axis:";
     316      //
    271317      // label6
    272318      //
     
    295341      this.histoGramGroupBox.Controls.Add(this.binsNumericUpDown);
    296342      this.histoGramGroupBox.Controls.Add(this.label3);
    297       this.histoGramGroupBox.Location = new System.Drawing.Point(0, 280);
     343      this.histoGramGroupBox.Location = new System.Drawing.Point(0, 305);
    298344      this.histoGramGroupBox.Name = "histoGramGroupBox";
    299345      this.histoGramGroupBox.Size = new System.Drawing.Size(327, 47);
     
    338384      this.lineChartGroupBox.Controls.Add(this.lineStyleComboBox);
    339385      this.lineChartGroupBox.Controls.Add(this.label8);
    340       this.lineChartGroupBox.Location = new System.Drawing.Point(0, 180);
     386      this.lineChartGroupBox.Location = new System.Drawing.Point(0, 205);
    341387      this.lineChartGroupBox.Name = "lineChartGroupBox";
    342388      this.lineChartGroupBox.Size = new System.Drawing.Size(327, 94);
     
    404450      this.label8.Text = "&Style:";
    405451      //
    406       // panel1
    407       //
    408       this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    409             | System.Windows.Forms.AnchorStyles.Right)));
    410       this.panel1.Controls.Add(this.xAxisPrimaryRadioButton);
    411       this.panel1.Controls.Add(this.xAxisSecondaryRadioButton);
    412       this.panel1.Location = new System.Drawing.Point(51, 19);
    413       this.panel1.Name = "panel1";
    414       this.panel1.Size = new System.Drawing.Size(258, 17);
    415       this.panel1.TabIndex = 6;
    416       //
    417       // panel2
    418       //
    419       this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    420             | System.Windows.Forms.AnchorStyles.Right)));
    421       this.panel2.Controls.Add(this.yAxisSecondaryRadioButton);
    422       this.panel2.Controls.Add(this.yAxisPrimaryRadioButton);
    423       this.panel2.Location = new System.Drawing.Point(51, 42);
    424       this.panel2.Name = "panel2";
    425       this.panel2.Size = new System.Drawing.Size(258, 17);
    426       this.panel2.TabIndex = 7;
    427       //
    428452      // DataRowVisualPropertiesControl
    429453      //
    430       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    431454      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    432455      this.Controls.Add(this.lineChartGroupBox);
     
    434457      this.Controls.Add(this.commonGroupBox);
    435458      this.Name = "DataRowVisualPropertiesControl";
    436       this.Size = new System.Drawing.Size(327, 331);
     459      this.Size = new System.Drawing.Size(327, 356);
    437460      ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).EndInit();
    438461      this.commonGroupBox.ResumeLayout(false);
     
    440463      this.axisGroupBox.ResumeLayout(false);
    441464      this.axisGroupBox.PerformLayout();
     465      this.panel2.ResumeLayout(false);
     466      this.panel2.PerformLayout();
     467      this.panel1.ResumeLayout(false);
     468      this.panel1.PerformLayout();
    442469      this.histoGramGroupBox.ResumeLayout(false);
    443470      this.histoGramGroupBox.PerformLayout();
     
    445472      this.lineChartGroupBox.PerformLayout();
    446473      ((System.ComponentModel.ISupportInitialize)(this.lineWidthNumericUpDown)).EndInit();
    447       this.panel1.ResumeLayout(false);
    448       this.panel1.PerformLayout();
    449       this.panel2.ResumeLayout(false);
    450       this.panel2.PerformLayout();
    451474      this.ResumeLayout(false);
    452475
     
    484507    private System.Windows.Forms.Panel panel2;
    485508    private System.Windows.Forms.Panel panel1;
     509    private System.Windows.Forms.Label label10;
     510    private System.Windows.Forms.CheckBox isVisibleInLegendCheckBox;
    486511  }
    487512}
  • branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.cs

    r14185 r14449  
    9494          binsExactRadioButton.Checked = Content.ExactBins;
    9595          displayNameTextBox.Text = Content.DisplayName;
     96          isVisibleInLegendCheckBox.Checked = Content.IsVisibleInLegend;
    9697        }
    9798      } finally { SuppressEvents = false; }
     
    103104      lineChartGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Line;
    104105      histoGramGroupBox.Enabled = Content != null && Content.ChartType == DataRowVisualProperties.DataRowChartType.Histogram;
     106      isVisibleInLegendCheckBox.Enabled = Content != null;
    105107    }
    106108
     
    188190      }
    189191    }
     192
     193    private void isVisibleInLegendCheckBox_CheckedChanged(object sender, EventArgs e) {
     194      if (!SuppressEvents && Content != null) {
     195        Content.IsVisibleInLegend = isVisibleInLegendCheckBox.Checked;
     196      }
     197    }
    190198    #endregion
    191199  }
  • branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/DataTableView.Designer.cs

    r14185 r14449  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    48       System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    49       System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
    50       System.Windows.Forms.DataVisualization.Charting.Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title();
    51       this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
     47      this.chart = new HeuristicLab.Analysis.Views.DataTableControl();
    5248      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    53       ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    5449      this.SuspendLayout();
    5550      //
     
    7065                  | System.Windows.Forms.AnchorStyles.Left)
    7166                  | System.Windows.Forms.AnchorStyles.Right)));
    72       this.chart.BorderlineColor = System.Drawing.Color.Black;
    73       this.chart.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
    74       chartArea1.AxisX.Minimum = 0D;
    75       chartArea1.CursorX.IsUserEnabled = true;
    76       chartArea1.CursorX.IsUserSelectionEnabled = true;
    77       chartArea1.CursorY.IsUserEnabled = true;
    78       chartArea1.CursorY.IsUserSelectionEnabled = true;
    79       chartArea1.Name = "Default";
    80       this.chart.ChartAreas.Add(chartArea1);
    81       legend1.Alignment = System.Drawing.StringAlignment.Center;
    82       legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    83       legend1.Name = "Default";
    84       this.chart.Legends.Add(legend1);
    8567      this.chart.Location = new System.Drawing.Point(0, 26);
    8668      this.chart.Name = "chart";
    87       series1.ChartArea = "Default";
    88       series1.Legend = "Default";
    89       series1.Name = "Default";
    90       this.chart.Series.Add(series1);
    9169      this.chart.Size = new System.Drawing.Size(359, 248);
    9270      this.chart.TabIndex = 3;
    9371      this.chart.Text = "chart";
    94       title1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    95       title1.Name = "Default";
    96       title1.Text = "Title";
    97       this.chart.Titles.Add(title1);
    98       this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
    99       this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    100       this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    10172      //
    10273      // DataTableView
     
    11283      this.Controls.SetChildIndex(this.nameTextBox, 0);
    11384      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    114       ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    11585      this.ResumeLayout(false);
    11686      this.PerformLayout();
    117 
    11887    }
    11988
    12089    #endregion
    12190
    122     protected HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
    123 
     91    protected HeuristicLab.Analysis.Views.DataTableControl chart;
    12492  }
    12593}
  • branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/DataTableView.cs

    r14185 r14449  
    2020#endregion
    2121
    22 using HeuristicLab.Collections;
     22using System;
    2323using HeuristicLab.Core.Views;
    2424using HeuristicLab.MainForm;
    25 using System;
    26 using System.Collections.Generic;
    27 using System.Drawing;
    28 using System.Linq;
    29 using System.Windows.Forms;
    30 using System.Windows.Forms.DataVisualization.Charting;
    3125
    3226namespace HeuristicLab.Analysis.Views {
     
    3428  [Content(typeof(DataTable), true)]
    3529  public partial class DataTableView : NamedItemView, IConfigureableView {
    36     protected List<Series> invisibleSeries;
    37     protected Dictionary<IObservableList<double>, DataRow> valuesRowsTable;
    3830
    3931    public new DataTable Content {
     
    4436    public DataTableView() {
    4537      InitializeComponent();
    46       valuesRowsTable = new Dictionary<IObservableList<double>, DataRow>();
    47       invisibleSeries = new List<Series>();
    48       chart.CustomizeAllChartAreas();
    49       chart.ChartAreas[0].CursorX.Interval = 1;
    5038    }
    51 
    52     #region Event Handler Registration
    53     protected override void DeregisterContentEvents() {
    54       foreach (DataRow row in Content.Rows)
    55         DeregisterDataRowEvents(row);
    56       Content.VisualPropertiesChanged -= new EventHandler(Content_VisualPropertiesChanged);
    57       Content.Rows.ItemsAdded -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded);
    58       Content.Rows.ItemsRemoved -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved);
    59       Content.Rows.ItemsReplaced -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced);
    60       Content.Rows.CollectionReset -= new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset);
    61       base.DeregisterContentEvents();
    62     }
    63     protected override void RegisterContentEvents() {
    64       base.RegisterContentEvents();
    65       Content.VisualPropertiesChanged += new EventHandler(Content_VisualPropertiesChanged);
    66       Content.Rows.ItemsAdded += new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded);
    67       Content.Rows.ItemsRemoved += new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved);
    68       Content.Rows.ItemsReplaced += new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced);
    69       Content.Rows.CollectionReset += new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset);
    70     }
    71 
    72     protected virtual void RegisterDataRowEvents(DataRow row) {
    73       row.NameChanged += new EventHandler(Row_NameChanged);
    74       row.VisualPropertiesChanged += new EventHandler(Row_VisualPropertiesChanged);
    75       valuesRowsTable.Add(row.Values, row);
    76       row.Values.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
    77       row.Values.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
    78       row.Values.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
    79       row.Values.ItemsMoved += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
    80       row.Values.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
    81     }
    82     protected virtual void DeregisterDataRowEvents(DataRow row) {
    83       row.Values.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded);
    84       row.Values.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved);
    85       row.Values.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced);
    86       row.Values.ItemsMoved -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved);
    87       row.Values.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset);
    88       valuesRowsTable.Remove(row.Values);
    89       row.VisualPropertiesChanged -= new EventHandler(Row_VisualPropertiesChanged);
    90       row.NameChanged -= new EventHandler(Row_NameChanged);
    91     }
    92     #endregion
    9339
    9440    protected override void OnContentChanged() {
    9541      base.OnContentChanged();
    96       invisibleSeries.Clear();
    97       chart.Titles[0].Text = string.Empty;
    98       chart.ChartAreas[0].AxisX.Title = string.Empty;
    99       chart.ChartAreas[0].AxisY.Title = string.Empty;
    100       chart.ChartAreas[0].AxisY2.Title = string.Empty;
    101       chart.Series.Clear();
    102       if (Content != null) {
    103         chart.Titles[0].Text = Content.Name;
    104         AddDataRows(Content.Rows);
    105         ConfigureChartArea(chart.ChartAreas[0]);
    106         RecalculateAxesScale(chart.ChartAreas[0]);
    107       }
     42      chart.Content = Content;
    10843    }
    10944
     
    11348    }
    11449
    115     public void ShowConfiguration() {
    116       if (Content != null) {
    117         using (var dialog = new DataTableVisualPropertiesDialog(Content)) {
    118           dialog.ShowDialog(this);
    119         }
    120       } else MessageBox.Show("Nothing to configure.");
    121     }
    122     protected virtual void AddDataRows(IEnumerable<DataRow> rows) {
    123       foreach (var row in rows) {
    124         RegisterDataRowEvents(row);
    125         var series = new Series(row.Name);
    126         if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName;
    127         else series.LegendText = row.Name;
    128         ConfigureSeries(series, row);
    129         FillSeriesWithRowValues(series, row);
    130         chart.Series.Add(series);
    131       }
    132       ConfigureChartArea(chart.ChartAreas[0]);
    133       RecalculateAxesScale(chart.ChartAreas[0]);
    134       UpdateYCursorInterval();
    135     }
    136 
    137     protected virtual void RemoveDataRows(IEnumerable<DataRow> rows) {
    138       foreach (var row in rows) {
    139         DeregisterDataRowEvents(row);
    140         Series series = chart.Series[row.Name];
    141         chart.Series.Remove(series);
    142         if (invisibleSeries.Contains(series))
    143           invisibleSeries.Remove(series);
    144       }
    145       RecalculateAxesScale(chart.ChartAreas[0]);
    146     }
    147 
    148     private void ConfigureSeries(Series series, DataRow row) {
    149       RemoveCustomPropertyIfExists(series, "PointWidth");
    150       series.BorderWidth = 1;
    151       series.BorderDashStyle = ChartDashStyle.Solid;
    152       series.BorderColor = Color.Empty;
    153 
    154       if (row.VisualProperties.Color != Color.Empty)
    155         series.Color = row.VisualProperties.Color;
    156       else series.Color = Color.Empty;
    157       series.IsVisibleInLegend = row.VisualProperties.IsVisibleInLegend;
    158 
    159       switch (row.VisualProperties.ChartType) {
    160         case DataRowVisualProperties.DataRowChartType.Line:
    161           series.ChartType = SeriesChartType.FastLine;
    162           series.BorderWidth = row.VisualProperties.LineWidth;
    163           series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
    164           break;
    165         case DataRowVisualProperties.DataRowChartType.Bars:
    166           // Bar is incompatible with anything but Bar and StackedBar*
    167           if (!chart.Series.Any(x => x.ChartType != SeriesChartType.Bar && x.ChartType != SeriesChartType.StackedBar && x.ChartType != SeriesChartType.StackedBar100))
    168             series.ChartType = SeriesChartType.Bar;
    169           else {
    170             series.ChartType = SeriesChartType.FastPoint; //default
    171             row.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Points;
    172           }
    173           break;
    174         case DataRowVisualProperties.DataRowChartType.Columns:
    175           series.ChartType = SeriesChartType.Column;
    176           break;
    177         case DataRowVisualProperties.DataRowChartType.Points:
    178           series.ChartType = SeriesChartType.FastPoint;
    179           break;
    180         case DataRowVisualProperties.DataRowChartType.Histogram:
    181           series.ChartType = SeriesChartType.Column;
    182           series.SetCustomProperty("PointWidth", "1");
    183           if (!series.Color.IsEmpty && series.Color.GetBrightness() < 0.25)
    184             series.BorderColor = Color.White;
    185           else series.BorderColor = Color.Black;
    186           break;
    187         case DataRowVisualProperties.DataRowChartType.StepLine:
    188           series.ChartType = SeriesChartType.StepLine;
    189           series.BorderWidth = row.VisualProperties.LineWidth;
    190           series.BorderDashStyle = ConvertLineStyle(row.VisualProperties.LineStyle);
    191           break;
    192         default:
    193           series.ChartType = SeriesChartType.FastPoint;
    194           break;
    195       }
    196       series.YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
    197       series.XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : AxisType.Primary;
    198       if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName;
    199       else series.LegendText = row.Name;
    200 
    201       string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle)
    202                       ? "X"
    203                       : Content.VisualProperties.XAxisTitle;
    204       string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle)
    205                             ? "Y"
    206                             : Content.VisualProperties.YAxisTitle;
    207       series.ToolTip =
    208         series.LegendText + Environment.NewLine +
    209         xAxisTitle + " = " + "#INDEX," + Environment.NewLine +
    210         yAxisTitle + " = " + "#VAL";
    211     }
    212 
    213     private void ConfigureChartArea(ChartArea area) {
    214       if (Content.VisualProperties.TitleFont != null) chart.Titles[0].Font = Content.VisualProperties.TitleFont;
    215       if (!Content.VisualProperties.TitleColor.IsEmpty) chart.Titles[0].ForeColor = Content.VisualProperties.TitleColor;
    216       chart.Titles[0].Text = Content.VisualProperties.Title;
    217 
    218       if (Content.VisualProperties.AxisTitleFont != null) area.AxisX.TitleFont = Content.VisualProperties.AxisTitleFont;
    219       if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisX.TitleForeColor = Content.VisualProperties.AxisTitleColor;
    220       area.AxisX.Title = Content.VisualProperties.XAxisTitle;
    221 
    222       if (Content.VisualProperties.AxisTitleFont != null) area.AxisX2.TitleFont = Content.VisualProperties.AxisTitleFont;
    223       if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisX2.TitleForeColor = Content.VisualProperties.AxisTitleColor;
    224       area.AxisX2.Title = Content.VisualProperties.SecondXAxisTitle;
    225 
    226       if (Content.VisualProperties.AxisTitleFont != null) area.AxisY.TitleFont = Content.VisualProperties.AxisTitleFont;
    227       if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisY.TitleForeColor = Content.VisualProperties.AxisTitleColor;
    228       area.AxisY.Title = Content.VisualProperties.YAxisTitle;
    229 
    230       if (Content.VisualProperties.AxisTitleFont != null) area.AxisY2.TitleFont = Content.VisualProperties.AxisTitleFont;
    231       if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisY2.TitleForeColor = Content.VisualProperties.AxisTitleColor;
    232       area.AxisY2.Title = Content.VisualProperties.SecondYAxisTitle;
    233 
    234       area.AxisX.IsLogarithmic = Content.VisualProperties.XAxisLogScale;
    235       area.AxisX2.IsLogarithmic = Content.VisualProperties.SecondXAxisLogScale;
    236       area.AxisY.IsLogarithmic = Content.VisualProperties.YAxisLogScale;
    237       area.AxisY2.IsLogarithmic = Content.VisualProperties.SecondYAxisLogScale;
    238     }
    239 
    240     private void RecalculateAxesScale(ChartArea area) {
    241       // Reset the axes bounds so that RecalculateAxesScale() will assign new bounds
    242       foreach (Axis a in area.Axes) {
    243         a.Minimum = double.NaN;
    244         a.Maximum = double.NaN;
    245       }
    246       area.RecalculateAxesScale();
    247       area.AxisX.IsMarginVisible = false;
    248       area.AxisX2.IsMarginVisible = false;
    249 
    250       if (!Content.VisualProperties.XAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue)) area.AxisX.Minimum = Content.VisualProperties.XAxisMinimumFixedValue;
    251       if (!Content.VisualProperties.XAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.XAxisMaximumFixedValue)) area.AxisX.Maximum = Content.VisualProperties.XAxisMaximumFixedValue;
    252       if (!Content.VisualProperties.SecondXAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.SecondXAxisMinimumFixedValue)) area.AxisX2.Minimum = Content.VisualProperties.SecondXAxisMinimumFixedValue;
    253       if (!Content.VisualProperties.SecondXAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.SecondXAxisMaximumFixedValue)) area.AxisX2.Maximum = Content.VisualProperties.SecondXAxisMaximumFixedValue;
    254       if (!Content.VisualProperties.YAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.YAxisMinimumFixedValue)) area.AxisY.Minimum = Content.VisualProperties.YAxisMinimumFixedValue;
    255       if (!Content.VisualProperties.YAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.YAxisMaximumFixedValue)) area.AxisY.Maximum = Content.VisualProperties.YAxisMaximumFixedValue;
    256       if (!Content.VisualProperties.SecondYAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.SecondYAxisMinimumFixedValue)) area.AxisY2.Minimum = Content.VisualProperties.SecondYAxisMinimumFixedValue;
    257       if (!Content.VisualProperties.SecondYAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.SecondYAxisMaximumFixedValue)) area.AxisY2.Maximum = Content.VisualProperties.SecondYAxisMaximumFixedValue;
    258       if (area.AxisX.Minimum >= area.AxisX.Maximum) area.AxisX.Maximum = area.AxisX.Minimum + 1;
    259       if (area.AxisX2.Minimum >= area.AxisX2.Maximum) area.AxisX2.Maximum = area.AxisX2.Minimum + 1;
    260       if (area.AxisY.Minimum >= area.AxisY.Maximum) area.AxisY.Maximum = area.AxisY.Minimum + 1;
    261       if (area.AxisY2.Minimum >= area.AxisY2.Maximum) area.AxisY2.Maximum = area.AxisY2.Minimum + 1;
    262     }
    263 
    264     protected virtual void UpdateYCursorInterval() {
    265       double interestingValuesRange = (
    266         from series in chart.Series
    267         where series.Enabled
    268         let values = (from point in series.Points
    269                       where !point.IsEmpty
    270                       select point.YValues[0]).DefaultIfEmpty(1.0)
    271         let range = values.Max() - values.Min()
    272         where range > 0.0
    273         select range
    274         ).DefaultIfEmpty(1.0).Min();
    275 
    276       double digits = (int)Math.Log10(interestingValuesRange) - 3;
    277       double yZoomInterval = Math.Pow(10, digits);
    278       this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
    279     }
    280 
    281     #region Event Handlers
    28250    #region Content Event Handlers
    28351    protected override void Content_NameChanged(object sender, EventArgs e) {
     
    28553        Invoke(new EventHandler(Content_NameChanged), sender, e);
    28654      else {
    287         chart.Titles[0].Text = Content.Name;
     55        Content.VisualProperties.Title = Content.Name;
    28856        base.Content_NameChanged(sender, e);
    289       }
    290     }
    291     private void Content_VisualPropertiesChanged(object sender, EventArgs e) {
    292       if (InvokeRequired)
    293         Invoke(new EventHandler(Content_VisualPropertiesChanged), sender, e);
    294       else {
    295         ConfigureChartArea(chart.ChartAreas[0]);
    296         RecalculateAxesScale(chart.ChartAreas[0]); // axes min/max could have changed
    297       }
    298     }
    299     #endregion
    300     #region Rows Event Handlers
    301     private void Rows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
    302       if (InvokeRequired)
    303         Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded), sender, e);
    304       else {
    305         AddDataRows(e.Items);
    306       }
    307     }
    308     private void Rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
    309       if (InvokeRequired)
    310         Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved), sender, e);
    311       else {
    312         RemoveDataRows(e.Items);
    313       }
    314     }
    315     private void Rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
    316       if (InvokeRequired)
    317         Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced), sender, e);
    318       else {
    319         RemoveDataRows(e.OldItems);
    320         AddDataRows(e.Items);
    321       }
    322     }
    323     private void Rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
    324       if (InvokeRequired)
    325         Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset), sender, e);
    326       else {
    327         RemoveDataRows(e.OldItems);
    328         AddDataRows(e.Items);
    329       }
    330     }
    331     #endregion
    332     #region Row Event Handlers
    333     private void Row_VisualPropertiesChanged(object sender, EventArgs e) {
    334       if (InvokeRequired)
    335         Invoke(new EventHandler(Row_VisualPropertiesChanged), sender, e);
    336       else {
    337         DataRow row = (DataRow)sender;
    338         Series series = chart.Series[row.Name];
    339         series.Points.Clear();
    340         ConfigureSeries(series, row);
    341         FillSeriesWithRowValues(series, row);
    342         RecalculateAxesScale(chart.ChartAreas[0]);
    343       }
    344     }
    345     private void Row_NameChanged(object sender, EventArgs e) {
    346       if (InvokeRequired)
    347         Invoke(new EventHandler(Row_NameChanged), sender, e);
    348       else {
    349         DataRow row = (DataRow)sender;
    350         chart.Series[row.Name].Name = row.Name;
    351       }
    352     }
    353     #endregion
    354     #region Values Event Handlers
    355     private void Values_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
    356       if (InvokeRequired)
    357         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsAdded), sender, e);
    358       else {
    359         DataRow row = null;
    360         valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
    361         if (row != null) {
    362           Series rowSeries = chart.Series[row.Name];
    363           if (!invisibleSeries.Contains(rowSeries)) {
    364             rowSeries.Points.Clear();
    365             FillSeriesWithRowValues(rowSeries, row);
    366             RecalculateAxesScale(chart.ChartAreas[0]);
    367             UpdateYCursorInterval();
    368           }
    369         }
    370       }
    371     }
    372     private void Values_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
    373       if (InvokeRequired)
    374         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsRemoved), sender, e);
    375       else {
    376         DataRow row = null;
    377         valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
    378         if (row != null) {
    379           Series rowSeries = chart.Series[row.Name];
    380           if (!invisibleSeries.Contains(rowSeries)) {
    381             rowSeries.Points.Clear();
    382             FillSeriesWithRowValues(rowSeries, row);
    383             RecalculateAxesScale(chart.ChartAreas[0]);
    384             UpdateYCursorInterval();
    385           }
    386         }
    387       }
    388     }
    389     private void Values_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
    390       if (InvokeRequired)
    391         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsReplaced), sender, e);
    392       else {
    393         DataRow row = null;
    394         valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
    395         if (row != null) {
    396           Series rowSeries = chart.Series[row.Name];
    397           if (!invisibleSeries.Contains(rowSeries)) {
    398             if (row.VisualProperties.ChartType == DataRowVisualProperties.DataRowChartType.Histogram) {
    399               rowSeries.Points.Clear();
    400               FillSeriesWithRowValues(rowSeries, row);
    401             } else {
    402               foreach (IndexedItem<double> item in e.Items) {
    403                 if (IsInvalidValue(item.Value))
    404                   rowSeries.Points[item.Index].IsEmpty = true;
    405                 else {
    406                   rowSeries.Points[item.Index].YValues = new double[] { item.Value };
    407                   rowSeries.Points[item.Index].IsEmpty = false;
    408                 }
    409               }
    410             }
    411             RecalculateAxesScale(chart.ChartAreas[0]);
    412             UpdateYCursorInterval();
    413           }
    414         }
    415       }
    416     }
    417     private void Values_ItemsMoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
    418       if (InvokeRequired)
    419         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_ItemsMoved), sender, e);
    420       else {
    421         DataRow row = null;
    422         valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
    423         if (row != null) {
    424           Series rowSeries = chart.Series[row.Name];
    425           if (!invisibleSeries.Contains(rowSeries)) {
    426             rowSeries.Points.Clear();
    427             FillSeriesWithRowValues(rowSeries, row);
    428             RecalculateAxesScale(chart.ChartAreas[0]);
    429             UpdateYCursorInterval();
    430           }
    431         }
    432       }
    433     }
    434 
    435     private void Values_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<double>> e) {
    436       if (InvokeRequired)
    437         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<double>>(Values_CollectionReset), sender, e);
    438       else {
    439         DataRow row = null;
    440         valuesRowsTable.TryGetValue((IObservableList<double>)sender, out row);
    441         if (row != null) {
    442           Series rowSeries = chart.Series[row.Name];
    443           if (!invisibleSeries.Contains(rowSeries)) {
    444             rowSeries.Points.Clear();
    445             FillSeriesWithRowValues(rowSeries, row);
    446             RecalculateAxesScale(chart.ChartAreas[0]);
    447             UpdateYCursorInterval();
    448           }
    449         }
    450       }
    451     }
    452     #endregion
    453     #endregion
    454 
    455     #region Chart Event Handlers
    456     private void chart_MouseDown(object sender, MouseEventArgs e) {
    457       HitTestResult result = chart.HitTest(e.X, e.Y);
    458       if (result.ChartElementType == ChartElementType.LegendItem) {
    459         ToggleSeriesVisible(result.Series);
    460       }
    461     }
    462     private void chart_MouseMove(object sender, MouseEventArgs e) {
    463       HitTestResult result = chart.HitTest(e.X, e.Y);
    464       if (result.ChartElementType == ChartElementType.LegendItem)
    465         this.Cursor = Cursors.Hand;
    466       else
    467         this.Cursor = Cursors.Default;
    468     }
    469     private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
    470       foreach (LegendItem legendItem in e.LegendItems) {
    471         var series = chart.Series[legendItem.SeriesName];
    472         if (series != null) {
    473           bool seriesIsInvisible = invisibleSeries.Contains(series);
    474           foreach (LegendCell cell in legendItem.Cells) {
    475             cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black;
    476           }
    477         }
    47857      }
    47958    }
    48059    #endregion
    48160
    482     private void ToggleSeriesVisible(Series series) {
    483       if (!invisibleSeries.Contains(series)) {
    484         series.Points.Clear();
    485         invisibleSeries.Add(series);
    486       } else {
    487         invisibleSeries.Remove(series);
    488         if (Content != null) {
    489 
    490           var row = (from r in Content.Rows
    491                      where r.Name == series.Name
    492                      select r).Single();
    493           FillSeriesWithRowValues(series, row);
    494           this.chart.Legends[series.Legend].ForeColor = Color.Black;
    495           RecalculateAxesScale(chart.ChartAreas[0]);
    496           UpdateYCursorInterval();
    497         }
    498       }
     61    public void ShowConfiguration() {
     62      chart.ShowConfiguration();
    49963    }
    500 
    501     private void FillSeriesWithRowValues(Series series, DataRow row) {
    502       switch (row.VisualProperties.ChartType) {
    503         case DataRowVisualProperties.DataRowChartType.Histogram:
    504           CalculateHistogram(series, row);
    505           break;
    506         default: {
    507             bool yLogarithmic = series.YAxisType == AxisType.Primary
    508                                   ? Content.VisualProperties.YAxisLogScale
    509                                   : Content.VisualProperties.SecondYAxisLogScale;
    510             bool xLogarithmic = series.XAxisType == AxisType.Primary
    511                                   ? Content.VisualProperties.XAxisLogScale
    512                                   : Content.VisualProperties.SecondXAxisLogScale;
    513             for (int i = 0; i < row.Values.Count; i++) {
    514               var value = row.Values[i];
    515               var point = new DataPoint();
    516               point.XValue = row.VisualProperties.StartIndexZero && !xLogarithmic ? i : i + 1;
    517               if (IsInvalidValue(value) || (yLogarithmic && value <= 0))
    518                 point.IsEmpty = true;
    519               else
    520                 point.YValues = new double[] { value };
    521               series.Points.Add(point);
    522             }
    523           }
    524           break;
    525       }
    526     }
    527 
    528     protected virtual void CalculateHistogram(Series series, DataRow row) {
    529       series.Points.Clear();
    530       if (!row.Values.Any()) return;
    531       int bins = row.VisualProperties.Bins;
    532 
    533       double minValue = row.Values.Min();
    534       double maxValue = row.Values.Max();
    535       double intervalWidth = (maxValue - minValue) / bins;
    536       if (intervalWidth < 0) return;
    537       if (intervalWidth == 0) {
    538         series.Points.AddXY(minValue, row.Values.Count);
    539         return;
    540       }
    541 
    542       if (!row.VisualProperties.ExactBins) {
    543         intervalWidth = HumanRoundRange(intervalWidth);
    544         minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
    545         maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
    546       }
    547 
    548       double intervalCenter = intervalWidth / 2;
    549 
    550       double min = 0.0, max = 0.0;
    551       if (!Double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue) && !Content.VisualProperties.XAxisMinimumAuto)
    552         min = Content.VisualProperties.XAxisMinimumFixedValue;
    553       else min = minValue;
    554       if (!Double.IsNaN(Content.VisualProperties.XAxisMaximumFixedValue) && !Content.VisualProperties.XAxisMaximumAuto)
    555         max = Content.VisualProperties.XAxisMaximumFixedValue;
    556       else max = maxValue + intervalWidth;
    557 
    558       double axisInterval = intervalWidth / row.VisualProperties.ScaleFactor;
    559 
    560       var area = chart.ChartAreas[0];
    561       area.AxisX.Interval = axisInterval;
    562 
    563       series.SetCustomProperty("PointWidth", "1"); // 0.8 is the default value
    564 
    565       // get the range or intervals which define the grouping of the frequency values
    566       var doubleRange = DoubleRange(min, max, intervalWidth).Skip(1).ToList();
    567 
    568       // aggregate the row values by unique key and frequency value
    569       var valueFrequencies = (from v in row.Values
    570                               where !IsInvalidValue(v)
    571                               orderby v
    572                               group v by v into g
    573                               select new Tuple<double, double>(g.First(), g.Count())).ToList();
    574 
    575       // shift the chart to the left so the bars are placed on the intervals
    576       if (valueFrequencies.First().Item1 < doubleRange.First())
    577         series.Points.Add(new DataPoint(min - intervalWidth, 0));
    578 
    579       // add data points
    580       int j = 0;
    581       foreach (var d in doubleRange) {
    582         double sum = 0.0;
    583         // sum the frequency values that fall within the same interval
    584         while (j < valueFrequencies.Count && valueFrequencies[j].Item1 < d) {
    585           sum += valueFrequencies[j].Item2;
    586           ++j;
    587         }
    588         string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle)
    589                               ? "X"
    590                               : Content.VisualProperties.XAxisTitle;
    591         string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle)
    592                               ? "Y"
    593                               : Content.VisualProperties.YAxisTitle;
    594         series.Points.Add(new DataPoint(d - intervalCenter, sum) {
    595           ToolTip =
    596             xAxisTitle + ": [" + (d - intervalWidth) + "-" + d + ")" + Environment.NewLine +
    597             yAxisTitle + ": " + sum
    598         });
    599       }
    600     }
    601 
    602     #region Helpers
    603     public static IEnumerable<double> DoubleRange(double min, double max, double step) {
    604       double i;
    605       for (i = min; i <= max; i += step)
    606         yield return i;
    607 
    608       if (i != max + step)
    609         yield return i;
    610     }
    611 
    612     protected void RemoveCustomPropertyIfExists(Series series, string property) {
    613       if (series.IsCustomPropertySet(property)) series.DeleteCustomProperty(property);
    614     }
    615 
    616     private double HumanRoundRange(double range) {
    617       double base10 = Math.Pow(10.0, Math.Floor(Math.Log10(range)));
    618       double rounding = range / base10;
    619       if (rounding <= 1.5) rounding = 1;
    620       else if (rounding <= 2.25) rounding = 2;
    621       else if (rounding <= 3.75) rounding = 2.5;
    622       else if (rounding <= 7.5) rounding = 5;
    623       else rounding = 10;
    624       return rounding * base10;
    625     }
    626 
    627     private double HumanRoundMax(double max) {
    628       double base10;
    629       if (max > 0) base10 = Math.Pow(10.0, Math.Floor(Math.Log10(max)));
    630       else base10 = Math.Pow(10.0, Math.Ceiling(Math.Log10(-max)));
    631       double rounding = (max > 0) ? base10 : -base10;
    632       while (rounding < max) rounding += base10;
    633       return rounding;
    634     }
    635 
    636     private ChartDashStyle ConvertLineStyle(DataRowVisualProperties.DataRowLineStyle dataRowLineStyle) {
    637       switch (dataRowLineStyle) {
    638         case DataRowVisualProperties.DataRowLineStyle.Dash:
    639           return ChartDashStyle.Dash;
    640         case DataRowVisualProperties.DataRowLineStyle.DashDot:
    641           return ChartDashStyle.DashDot;
    642         case DataRowVisualProperties.DataRowLineStyle.DashDotDot:
    643           return ChartDashStyle.DashDotDot;
    644         case DataRowVisualProperties.DataRowLineStyle.Dot:
    645           return ChartDashStyle.Dot;
    646         case DataRowVisualProperties.DataRowLineStyle.NotSet:
    647           return ChartDashStyle.NotSet;
    648         case DataRowVisualProperties.DataRowLineStyle.Solid:
    649           return ChartDashStyle.Solid;
    650         default:
    651           return ChartDashStyle.NotSet;
    652       }
    653     }
    654 
    655     protected static bool IsInvalidValue(double x) {
    656       return double.IsNaN(x) || x < (double)decimal.MinValue || x > (double)decimal.MaxValue;
    657     }
    658     #endregion
    65964  }
    66065}
  • branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/HeuristicLab.Analysis.Views-3.3.csproj

    r14208 r14449  
    122122  </ItemGroup>
    123123  <ItemGroup>
     124    <Compile Include="DataTableControl.cs">
     125      <SubType>UserControl</SubType>
     126    </Compile>
     127    <Compile Include="DataTableControl.Designer.cs">
     128      <DependentUpon>DataTableControl.cs</DependentUpon>
     129    </Compile>
    124130    <Compile Include="IndexedDataTableView.cs">
    125131      <SubType>UserControl</SubType>
     
    127133    <Compile Include="IndexedDataTableView.Designer.cs">
    128134      <DependentUpon>IndexedDataTableView.cs</DependentUpon>
     135    </Compile>
     136    <Compile Include="ScatterPlotControl.cs">
     137      <SubType>UserControl</SubType>
     138    </Compile>
     139    <Compile Include="ScatterPlotControl.Designer.cs">
     140      <DependentUpon>ScatterPlotControl.cs</DependentUpon>
    129141    </Compile>
    130142    <Compile Include="ScatterPlotVisualPropertiesDialog.cs">
  • branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.Designer.cs

    r14185 r14449  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    48       System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    49       System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
    50       System.Windows.Forms.DataVisualization.Charting.Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title();
    51       this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
     47      this.chart = new HeuristicLab.Analysis.Views.ScatterPlotControl();
    5248      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    53       ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    5449      this.SuspendLayout();
    5550      //
     
    7065                  | System.Windows.Forms.AnchorStyles.Left)
    7166                  | System.Windows.Forms.AnchorStyles.Right)));
    72       this.chart.BorderlineColor = System.Drawing.Color.Black;
    73       this.chart.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid;
    74       chartArea1.AxisX.Minimum = 0D;
    75       chartArea1.CursorX.IsUserEnabled = true;
    76       chartArea1.CursorX.IsUserSelectionEnabled = true;
    77       chartArea1.CursorY.IsUserEnabled = true;
    78       chartArea1.CursorY.IsUserSelectionEnabled = true;
    79       chartArea1.Name = "Default";
    80       this.chart.ChartAreas.Add(chartArea1);
    81       legend1.Alignment = System.Drawing.StringAlignment.Center;
    82       legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    83       legend1.Name = "Default";
    84       this.chart.Legends.Add(legend1);
    8567      this.chart.Location = new System.Drawing.Point(0, 26);
    8668      this.chart.Name = "chart";
    87       series1.ChartArea = "Default";
    88       series1.Legend = "Default";
    89       series1.Name = "Default";
    90       this.chart.Series.Add(series1);
    9169      this.chart.Size = new System.Drawing.Size(359, 248);
    9270      this.chart.TabIndex = 3;
    9371      this.chart.Text = "chart";
    94       title1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    95       title1.Name = "Default";
    96       title1.Text = "Title";
    97       this.chart.Titles.Add(title1);
    98       this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
    99       this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    100       this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    10172      //
    10273      // ScatterPlotView
     
    11283      this.Controls.SetChildIndex(this.nameTextBox, 0);
    11384      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    114       ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    11585      this.ResumeLayout(false);
    11686      this.PerformLayout();
    11787
    11888    }
    119 
    12089    #endregion
    12190
    122     protected HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
    123 
     91    protected HeuristicLab.Analysis.Views.ScatterPlotControl chart;
    12492  }
    12593}
  • branches/symbreg-factors-2650/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.cs

    r14185 r14449  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Drawing;
    25 using System.Linq;
    2623using System.Windows.Forms;
    27 using System.Windows.Forms.DataVisualization.Charting;
    28 using HeuristicLab.Collections;
    29 using HeuristicLab.Common;
    3024using HeuristicLab.Core.Views;
    3125using HeuristicLab.MainForm;
     
    3529  [Content(typeof(ScatterPlot), true)]
    3630  public partial class ScatterPlotView : NamedItemView, IConfigureableView {
    37     protected List<Series> invisibleSeries;
    38     protected Dictionary<IObservableList<Point2D<double>>, ScatterPlotDataRow> pointsRowsTable;
    39     private double xMin, xMax, yMin, yMax;
    4031
    4132    public new ScatterPlot Content {
     
    4637    public ScatterPlotView() {
    4738      InitializeComponent();
    48       pointsRowsTable = new Dictionary<IObservableList<Point2D<double>>, ScatterPlotDataRow>();
    49       invisibleSeries = new List<Series>();
    50       chart.CustomizeAllChartAreas();
    51       chart.ChartAreas[0].CursorX.Interval = 1;
    5239    }
    53 
    54     #region Event Handler Registration
    55     protected override void DeregisterContentEvents() {
    56       foreach (ScatterPlotDataRow row in Content.Rows)
    57         DeregisterScatterPlotDataRowEvents(row);
    58       Content.VisualPropertiesChanged -= new EventHandler(Content_VisualPropertiesChanged);
    59       Content.Rows.ItemsAdded -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsAdded);
    60       Content.Rows.ItemsRemoved -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsRemoved);
    61       Content.Rows.ItemsReplaced -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsReplaced);
    62       Content.Rows.CollectionReset -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_CollectionReset);
    63       base.DeregisterContentEvents();
    64     }
    65     protected override void RegisterContentEvents() {
    66       base.RegisterContentEvents();
    67       Content.VisualPropertiesChanged += new EventHandler(Content_VisualPropertiesChanged);
    68       Content.Rows.ItemsAdded += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsAdded);
    69       Content.Rows.ItemsRemoved += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsRemoved);
    70       Content.Rows.ItemsReplaced += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsReplaced);
    71       Content.Rows.CollectionReset += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_CollectionReset);
    72     }
    73 
    74     protected virtual void RegisterScatterPlotDataRowEvents(ScatterPlotDataRow row) {
    75       row.NameChanged += new EventHandler(Row_NameChanged);
    76       row.VisualPropertiesChanged += new EventHandler(Row_VisualPropertiesChanged);
    77       pointsRowsTable.Add(row.Points, row);
    78       row.Points.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded);
    79       row.Points.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved);
    80       row.Points.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced);
    81       row.Points.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset);
    82     }
    83     protected virtual void DeregisterScatterPlotDataRowEvents(ScatterPlotDataRow row) {
    84       row.Points.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded);
    85       row.Points.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved);
    86       row.Points.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced);
    87       row.Points.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset);
    88       pointsRowsTable.Remove(row.Points);
    89       row.VisualPropertiesChanged -= new EventHandler(Row_VisualPropertiesChanged);
    90       row.NameChanged -= new EventHandler(Row_NameChanged);
    91     }
    92     #endregion
    9340
    9441    protected override void OnContentChanged() {
    9542      base.OnContentChanged();
    96       invisibleSeries.Clear();
    97       chart.Titles[0].Text = string.Empty;
    98       chart.ChartAreas[0].AxisX.Title = string.Empty;
    99       chart.ChartAreas[0].AxisY.Title = string.Empty;
    100       chart.Series.Clear();
    101       if (Content != null) {
    102         chart.Titles[0].Text = Content.Name;
    103         AddScatterPlotDataRows(Content.Rows);
    104         ConfigureChartArea(chart.ChartAreas[0]);
    105         RecalculateMinMaxPointValues();
    106         RecalculateAxesScale(chart.ChartAreas[0]);
    107       }
     43      chart.Content = Content;
    10844    }
    10945
     
    11450
    11551    public void ShowConfiguration() {
    116       if (Content != null) {
    117         using (ScatterPlotVisualPropertiesDialog dialog = new ScatterPlotVisualPropertiesDialog(Content)) {
    118           dialog.ShowDialog(this);
    119         }
    120       } else MessageBox.Show("Nothing to configure.");
     52      chart.ShowConfiguration();
    12153    }
    12254
    123     protected virtual void AddScatterPlotDataRows(IEnumerable<ScatterPlotDataRow> rows) {
    124       foreach (var row in rows) {
    125         RegisterScatterPlotDataRowEvents(row);
    126         Series series = new Series(row.Name);
    127         if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName;
    128         else series.LegendText = row.Name;
    129         ConfigureSeries(series, row);
    130         FillSeriesWithRowValues(series, row);
    131         chart.Series.Add(series);
    132       }
    133       ConfigureChartArea(chart.ChartAreas[0]);
    134       RecalculateMinMaxPointValues();
    135       RecalculateAxesScale(chart.ChartAreas[0]);
    136       UpdateYCursorInterval();
    137     }
    138 
    139     protected virtual void RemoveScatterPlotDataRows(IEnumerable<ScatterPlotDataRow> rows) {
    140       foreach (var row in rows) {
    141         DeregisterScatterPlotDataRowEvents(row);
    142         Series series = chart.Series[row.Name];
    143         chart.Series.Remove(series);
    144         if (invisibleSeries.Contains(series))
    145           invisibleSeries.Remove(series);
    146       }
    147       RecalculateMinMaxPointValues();
    148       RecalculateAxesScale(chart.ChartAreas[0]);
    149     }
    150 
    151     private void ConfigureSeries(Series series, ScatterPlotDataRow row) {
    152       series.BorderWidth = 1;
    153       series.BorderDashStyle = ChartDashStyle.Solid;
    154       series.BorderColor = Color.Empty;
    155 
    156       if (row.VisualProperties.Color != Color.Empty)
    157         series.Color = row.VisualProperties.Color;
    158       else series.Color = Color.Empty;
    159       series.IsVisibleInLegend = row.VisualProperties.IsVisibleInLegend;
    160       series.ChartType = SeriesChartType.FastPoint;
    161       series.MarkerSize = row.VisualProperties.PointSize;
    162       series.MarkerStyle = ConvertPointStyle(row.VisualProperties.PointStyle);
    163       series.XAxisType = AxisType.Primary;
    164       series.YAxisType = AxisType.Primary;
    165 
    166       if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName;
    167       else series.LegendText = row.Name;
    168 
    169       string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle)
    170                       ? "X"
    171                       : Content.VisualProperties.XAxisTitle;
    172       string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle)
    173                             ? "Y"
    174                             : Content.VisualProperties.YAxisTitle;
    175       series.ToolTip =
    176         series.LegendText + Environment.NewLine +
    177         xAxisTitle + " = " + "#VALX," + Environment.NewLine +
    178         yAxisTitle + " = " + "#VAL";
    179     }
    180 
    181     private void ConfigureChartArea(ChartArea area) {
    182       if (Content.VisualProperties.TitleFont != null) chart.Titles[0].Font = Content.VisualProperties.TitleFont;
    183       if (!Content.VisualProperties.TitleColor.IsEmpty) chart.Titles[0].ForeColor = Content.VisualProperties.TitleColor;
    184       chart.Titles[0].Text = Content.VisualProperties.Title;
    185 
    186       if (Content.VisualProperties.AxisTitleFont != null) area.AxisX.TitleFont = Content.VisualProperties.AxisTitleFont;
    187       if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisX.TitleForeColor = Content.VisualProperties.AxisTitleColor;
    188       area.AxisX.Title = Content.VisualProperties.XAxisTitle;
    189       area.AxisX.MajorGrid.Enabled = Content.VisualProperties.XAxisGrid;
    190 
    191       if (Content.VisualProperties.AxisTitleFont != null) area.AxisY.TitleFont = Content.VisualProperties.AxisTitleFont;
    192       if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisY.TitleForeColor = Content.VisualProperties.AxisTitleColor;
    193       area.AxisY.Title = Content.VisualProperties.YAxisTitle;
    194       area.AxisY.MajorGrid.Enabled = Content.VisualProperties.YAxisGrid;
    195     }
    196 
    197     private void RecalculateAxesScale(ChartArea area) {
    198       area.AxisX.Minimum = CalculateMinBound(xMin);
    199       area.AxisX.Maximum = CalculateMaxBound(xMax);
    200       if (area.AxisX.Minimum == area.AxisX.Maximum) {
    201         area.AxisX.Minimum = xMin - 0.5;
    202         area.AxisX.Maximum = xMax + 0.5;
    203       }
    204       area.AxisY.Minimum = CalculateMinBound(yMin);
    205       area.AxisY.Maximum = CalculateMaxBound(yMax);
    206       if (area.AxisY.Minimum == area.AxisY.Maximum) {
    207         area.AxisY.Minimum = yMin - 0.5;
    208         area.AxisY.Maximum = yMax + 0.5;
    209       }
    210       if (xMax - xMin > 0) area.CursorX.Interval = Math.Pow(10, Math.Floor(Math.Log10(area.AxisX.Maximum - area.AxisX.Minimum) - 3));
    211       else area.CursorX.Interval = 1;
    212       area.AxisX.IsMarginVisible = false;
    213 
    214       if (!Content.VisualProperties.XAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue)) area.AxisX.Minimum = Content.VisualProperties.XAxisMinimumFixedValue;
    215       if (!Content.VisualProperties.XAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.XAxisMaximumFixedValue)) area.AxisX.Maximum = Content.VisualProperties.XAxisMaximumFixedValue;
    216       if (!Content.VisualProperties.YAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.YAxisMinimumFixedValue)) area.AxisY.Minimum = Content.VisualProperties.YAxisMinimumFixedValue;
    217       if (!Content.VisualProperties.YAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.YAxisMaximumFixedValue)) area.AxisY.Maximum = Content.VisualProperties.YAxisMaximumFixedValue;
    218     }
    219 
    220     private static double CalculateMinBound(double min) {
    221       if (min == 0) return 0;
    222       var scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(min))));
    223       return scale * (Math.Floor(min / scale));
    224     }
    225 
    226     private static double CalculateMaxBound(double max) {
    227       if (max == 0) return 0;
    228       var scale = Math.Pow(10, Math.Floor(Math.Log10(Math.Abs(max))));
    229       return scale * (Math.Ceiling(max / scale));
    230     }
    231 
    232     protected virtual void UpdateYCursorInterval() {
    233       double interestingValuesRange = (
    234         from series in chart.Series
    235         where series.Enabled
    236         let values = (from point in series.Points
    237                       where !point.IsEmpty
    238                       select point.YValues[0]).DefaultIfEmpty(1.0)
    239         let range = values.Max() - values.Min()
    240         where range > 0.0
    241         select range
    242         ).DefaultIfEmpty(1.0).Min();
    243 
    244       double digits = (int)Math.Log10(interestingValuesRange) - 3;
    245       double yZoomInterval = Math.Pow(10, digits);
    246       this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
    247     }
    248 
    249     #region Event Handlers
    25055    #region Content Event Handlers
    25156    protected override void Content_NameChanged(object sender, EventArgs e) {
     
    25358        Invoke(new EventHandler(Content_NameChanged), sender, e);
    25459      else {
    255         chart.Titles[0].Text = Content.Name;
     60        Content.VisualProperties.Title = Content.Name;
    25661        base.Content_NameChanged(sender, e);
    25762      }
    258     }
    259     private void Content_VisualPropertiesChanged(object sender, EventArgs e) {
    260       if (InvokeRequired)
    261         Invoke(new EventHandler(Content_VisualPropertiesChanged), sender, e);
    262       else {
    263         ConfigureChartArea(chart.ChartAreas[0]);
    264         RecalculateAxesScale(chart.ChartAreas[0]); // axes min/max could have changed
    265       }
    266     }
    267     #endregion
    268     #region Rows Event Handlers
    269     private void Rows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) {
    270       if (InvokeRequired)
    271         Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsAdded), sender, e);
    272       else {
    273         AddScatterPlotDataRows(e.Items);
    274       }
    275     }
    276     private void Rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) {
    277       if (InvokeRequired)
    278         Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsRemoved), sender, e);
    279       else {
    280         RemoveScatterPlotDataRows(e.Items);
    281       }
    282     }
    283     private void Rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) {
    284       if (InvokeRequired)
    285         Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsReplaced), sender, e);
    286       else {
    287         RemoveScatterPlotDataRows(e.OldItems);
    288         AddScatterPlotDataRows(e.Items);
    289       }
    290     }
    291     private void Rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) {
    292       if (InvokeRequired)
    293         Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_CollectionReset), sender, e);
    294       else {
    295         RemoveScatterPlotDataRows(e.OldItems);
    296         AddScatterPlotDataRows(e.Items);
    297       }
    298     }
    299     #endregion
    300     #region Row Event Handlers
    301     private void Row_VisualPropertiesChanged(object sender, EventArgs e) {
    302       if (InvokeRequired)
    303         Invoke(new EventHandler(Row_VisualPropertiesChanged), sender, e);
    304       else {
    305         ScatterPlotDataRow row = (ScatterPlotDataRow)sender;
    306         Series series = chart.Series[row.Name];
    307         series.Points.Clear();
    308         ConfigureSeries(series, row);
    309         FillSeriesWithRowValues(series, row);
    310         RecalculateMinMaxPointValues();
    311         RecalculateAxesScale(chart.ChartAreas[0]);
    312       }
    313     }
    314     private void Row_NameChanged(object sender, EventArgs e) {
    315       if (InvokeRequired)
    316         Invoke(new EventHandler(Row_NameChanged), sender, e);
    317       else {
    318         ScatterPlotDataRow row = (ScatterPlotDataRow)sender;
    319         chart.Series[row.Name].Name = row.Name;
    320       }
    321     }
    322     #endregion
    323     #region Points Event Handlers
    324     private void Points_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) {
    325       if (InvokeRequired)
    326         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded), sender, e);
    327       else {
    328         ScatterPlotDataRow row = null;
    329         pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row);
    330         if (row != null) {
    331           Series rowSeries = chart.Series[row.Name];
    332           if (!invisibleSeries.Contains(rowSeries)) {
    333             rowSeries.Points.Clear();
    334             FillSeriesWithRowValues(rowSeries, row);
    335             RecalculateMinMaxPointValues();
    336             RecalculateAxesScale(chart.ChartAreas[0]);
    337             UpdateYCursorInterval();
    338           }
    339         }
    340       }
    341     }
    342     private void Points_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) {
    343       if (InvokeRequired)
    344         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved), sender, e);
    345       else {
    346         ScatterPlotDataRow row = null;
    347         pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row);
    348         if (row != null) {
    349           Series rowSeries = chart.Series[row.Name];
    350           if (!invisibleSeries.Contains(rowSeries)) {
    351             rowSeries.Points.Clear();
    352             FillSeriesWithRowValues(rowSeries, row);
    353             RecalculateMinMaxPointValues();
    354             RecalculateAxesScale(chart.ChartAreas[0]);
    355             UpdateYCursorInterval();
    356           }
    357         }
    358       }
    359     }
    360     private void Points_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) {
    361       if (InvokeRequired)
    362         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced), sender, e);
    363       else {
    364         ScatterPlotDataRow row = null;
    365         pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row);
    366         if (row != null) {
    367           Series rowSeries = chart.Series[row.Name];
    368           if (!invisibleSeries.Contains(rowSeries)) {
    369             rowSeries.Points.Clear();
    370             FillSeriesWithRowValues(rowSeries, row);
    371             RecalculateMinMaxPointValues();
    372             RecalculateAxesScale(chart.ChartAreas[0]);
    373             UpdateYCursorInterval();
    374           }
    375         }
    376       }
    377     }
    378     private void Points_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) {
    379       if (InvokeRequired)
    380         Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset), sender, e);
    381       else {
    382         ScatterPlotDataRow row = null;
    383         pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row);
    384         if (row != null) {
    385           Series rowSeries = chart.Series[row.Name];
    386           if (!invisibleSeries.Contains(rowSeries)) {
    387             rowSeries.Points.Clear();
    388             FillSeriesWithRowValues(rowSeries, row);
    389             RecalculateMinMaxPointValues();
    390             RecalculateAxesScale(chart.ChartAreas[0]);
    391             UpdateYCursorInterval();
    392           }
    393         }
    394       }
    395     }
    396     #endregion
    397     #endregion
    398 
    399     #region Chart Event Handlers
    400     private void chart_MouseDown(object sender, MouseEventArgs e) {
    401       HitTestResult result = chart.HitTest(e.X, e.Y);
    402       if (result.ChartElementType == ChartElementType.LegendItem) {
    403         ToggleSeriesVisible(result.Series);
    404       }
    405     }
    406     private void chart_MouseMove(object sender, MouseEventArgs e) {
    407       HitTestResult result = chart.HitTest(e.X, e.Y);
    408       if (result.ChartElementType == ChartElementType.LegendItem)
    409         this.Cursor = Cursors.Hand;
    410       else
    411         this.Cursor = Cursors.Default;
    412     }
    413     private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
    414       foreach (LegendItem legendItem in e.LegendItems) {
    415         var series = chart.Series[legendItem.SeriesName];
    416         if (series != null) {
    417           bool seriesIsInvisible = invisibleSeries.Contains(series);
    418           foreach (LegendCell cell in legendItem.Cells) {
    419             cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black;
    420           }
    421         }
    422       }
    423     }
    424     #endregion
    425 
    426     private void ToggleSeriesVisible(Series series) {
    427       if (!invisibleSeries.Contains(series)) {
    428         series.Points.Clear();
    429         invisibleSeries.Add(series);
    430         RecalculateMinMaxPointValues();
    431       } else {
    432         invisibleSeries.Remove(series);
    433         if (Content != null) {
    434 
    435           var row = (from r in Content.Rows
    436                      where r.Name == series.Name
    437                      select r).Single();
    438           FillSeriesWithRowValues(series, row);
    439           RecalculateMinMaxPointValues();
    440           this.chart.Legends[series.Legend].ForeColor = Color.Black;
    441           RecalculateAxesScale(chart.ChartAreas[0]);
    442           UpdateYCursorInterval();
    443         }
    444       }
    445     }
    446 
    447     private void RecalculateMinMaxPointValues() {
    448       yMin = xMin = double.MaxValue;
    449       yMax = xMax = double.MinValue;
    450       foreach (var s in chart.Series.Where(x => x.Enabled)) {
    451         foreach (var p in s.Points) {
    452           double x = p.XValue, y = p.YValues[0];
    453           if (xMin > x) xMin = x;
    454           if (xMax < x) xMax = x;
    455           if (yMin > y) yMin = y;
    456           if (yMax < y) yMax = y;
    457         }
    458       }
    459     }
    460 
    461     private void FillSeriesWithRowValues(Series series, ScatterPlotDataRow row) {
    462       for (int i = 0; i < row.Points.Count; i++) {
    463         var value = row.Points[i];
    464         DataPoint point = new DataPoint();
    465         if (IsInvalidValue(value.X) || IsInvalidValue(value.Y))
    466           point.IsEmpty = true;
    467         else {
    468           point.XValue = value.X;
    469           point.YValues = new double[] { value.Y };
    470         }
    471         series.Points.Add(point);
    472       }
    473     }
    474 
    475     #region Helpers
    476     private MarkerStyle ConvertPointStyle(ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle pointStyle) {
    477       switch (pointStyle) {
    478         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle:
    479           return MarkerStyle.Circle;
    480         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Cross:
    481           return MarkerStyle.Cross;
    482         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Diamond:
    483           return MarkerStyle.Diamond;
    484         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Square:
    485           return MarkerStyle.Square;
    486         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star4:
    487           return MarkerStyle.Star4;
    488         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star5:
    489           return MarkerStyle.Star5;
    490         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star6:
    491           return MarkerStyle.Star6;
    492         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star10:
    493           return MarkerStyle.Star10;
    494         case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Triangle:
    495           return MarkerStyle.Triangle;
    496         default:
    497           return MarkerStyle.None;
    498       }
    499     }
    500 
    501     protected static bool IsInvalidValue(double x) {
    502       return double.IsNaN(x) || x < (double)decimal.MinValue || x > (double)decimal.MaxValue;
    50363    }
    50464    #endregion
  • branches/symbreg-factors-2650/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r14185 r14449  
    137137        for (int i = 0; i < columns.Length; ++i) {
    138138          var column = new DataGridViewTextBoxColumn();
     139          column.SortMode = DataGridViewColumnSortMode.Programmatic;
    139140          column.FillWeight = 1;
    140141          columns[i] = column;
  • branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/DataGridContentView.cs

    r14185 r14449  
    5858    public DataGridContentView() {
    5959      InitializeComponent();
     60      dataGridView.MouseDown += dataGridView_MouseDown;
    6061      dataGridView.CellMouseClick += dataGridView_CellMouseClick;
    6162      dataGridView.RowHeaderMouseClick += dataGridView_RowHeaderMouseClick;
    62       dataGridView.KeyDown += dataGridView_KeyDown;
    6363      dataGridView.MouseUp += dataGridView_MouseUp;
    6464      contextMenuCell.Items.Add(ShowHideColumns);
     
    204204    }
    205205
     206    //Necessary so that dataGridView.SelectedRows and SelectedColumns are populated correctly
     207    //further information: https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectedcolumns.aspx
     208    private void dataGridView_MouseDown(object sender, MouseEventArgs e) {
     209      var hitTestInfo = dataGridView.HitTest(e.X, e.Y);
     210      // row header click
     211      if (hitTestInfo.ColumnIndex == -1 && hitTestInfo.RowIndex >= 0) {
     212        if (dataGridView.SelectionMode != DataGridViewSelectionMode.RowHeaderSelect) {
     213          dataGridView.SelectionMode = DataGridViewSelectionMode.RowHeaderSelect;
     214        }
     215      }
     216      // column header click
     217      if (hitTestInfo.RowIndex == -1 && hitTestInfo.ColumnIndex >= 0) {
     218        if (dataGridView.SelectionMode != DataGridViewSelectionMode.ColumnHeaderSelect) {
     219          dataGridView.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
     220        }
     221      }
     222    }
     223
    206224    protected override void dataGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) {
    207       if (Content != null) {
    208         if (e.Button == MouseButtons.Left) {
    209           dataGridView.Focus();
    210           dataGridView.ClearSelection();
    211           dataGridView.SelectionChanged -= dataGridView_SelectionChanged;
    212           for (int i = 0; i < dataGridView.RowCount; i++) {
    213             if (i + 1 == dataGridView.RowCount)
    214               dataGridView.SelectionChanged += dataGridView_SelectionChanged;
    215             dataGridView[e.ColumnIndex, i].Selected = true;
    216           }
    217         } else if (e.Button == MouseButtons.Middle) {
    218           int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0;
    219           Content.PreProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
    220         } else if (e.Button == MouseButtons.Right && Content.SortableView) {
    221           SortColumn(e.ColumnIndex);
    222         }
    223       }
     225      if (Content == null) return;
     226
     227      if (e.Button == MouseButtons.Middle) {
     228        int newIndex = e.ColumnIndex >= 0 ? e.ColumnIndex : 0;
     229        Content.PreProcessingData.InsertColumn<double>(newIndex.ToString(), newIndex);
     230      } else if (e.Button == MouseButtons.Right && Content.SortableView) {
     231        SortColumn(e.ColumnIndex);
     232      }
     233
    224234      searchIterator = null;
    225235    }
     
    538548
    539549    protected override void dataGridView_KeyDown(object sender, KeyEventArgs e) {
    540       var selectedRows = dataGridView.SelectedRows;
    541       var selectedCells = dataGridView.SelectedCells;
    542       if (!Content.FilterLogic.IsFiltered) { //data is in read only mode....
    543         if (e.KeyCode == Keys.Delete && selectedCells.Count == Content.Rows && selectedCells.Count > 0) {
    544           Content.DeleteColumn(selectedCells[0].ColumnIndex);
    545         } else if (e.KeyCode == Keys.Delete && selectedRows.Count > 0) {
    546           List<int> rows = new List<int>();
    547           for (int i = 0; i < selectedRows.Count; ++i) {
    548             int index = (sortedColumnIndices.Count != 0) ? (Convert.ToInt32(selectedRows[i].HeaderCell.Value) - 1) :
    549               selectedRows[i].Index;
    550             rows.Add(index);
    551           }
    552           Content.DeleteRows(rows);
    553         } else if (e.Control && e.KeyCode == Keys.F) {
    554           CreateFindAndReplaceDialog();
    555           findAndReplaceDialog.ActivateSearch();
    556         } else if (e.Control && e.KeyCode == Keys.R) {
    557           CreateFindAndReplaceDialog();
    558           findAndReplaceDialog.ActivateReplace();
    559         }
     550      base.dataGridView_KeyDown(sender, e);
     551      //data is in read only mode....
     552      if (Content.FilterLogic.IsFiltered) return;
     553
     554      if (e.KeyCode == Keys.Delete) {
     555        //Delete column
     556        if (dataGridView.SelectedColumns.Count == 1) {
     557          Content.DeleteColumn(dataGridView.SelectedColumns[0].Index);
     558        }
     559        //Delete row
     560        if (dataGridView.SelectedRows.Count > 0) {
     561          //necessary if columns are sorted to translate the selected row index
     562          var rowIndexes = dataGridView.SelectedRows.Cast<DataGridViewRow>().Select(row => GetRowIndex(row.Index)).ToList();
     563          Content.DeleteRows(rowIndexes);
     564        }
     565      } else if (e.Control && e.KeyCode == Keys.F) {
     566        CreateFindAndReplaceDialog();
     567        findAndReplaceDialog.ActivateSearch();
     568      } else if (e.Control && e.KeyCode == Keys.R) {
     569        CreateFindAndReplaceDialog();
     570        findAndReplaceDialog.ActivateReplace();
    560571      }
    561572    }
  • branches/symbreg-factors-2650/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingCheckedVariablesView.cs

    r14421 r14449  
    5858        IList<string> inputs = Content.PreprocessingData.InputVariables;
    5959        if (Content.PreprocessingData.TargetVariable != null)
    60           inputs = inputs.Union(new[] {Content.PreprocessingData.TargetVariable}).ToList();
     60          inputs = inputs.Union(new[] { Content.PreprocessingData.TargetVariable }).ToList();
    6161        Content.VariableItemList = Content.CreateVariableItemList(inputs);
    6262      } else {
     
    7070      var inputAndTarget = Content.PreprocessingData.InputVariables.Union(target != null ? new[] { target } : new string[] { });
    7171      foreach (var col in Content.PreprocessingData.GetDoubleVariableNames().Except(inputAndTarget)) {
    72         var listViewItem = checkedItemList.ItemsListView.FindItemWithText(col);
     72        var listViewItem = checkedItemList.ItemsListView.FindItemWithText(col, false, 0, false);
    7373        listViewItem.ForeColor = Color.LightGray;
    7474      }
     
    109109      Content.VariableItemList.Add(new StringValue(name));
    110110      if (!Content.PreprocessingData.InputVariables.Contains(name) && Content.PreprocessingData.TargetVariable != name) {
    111         var listViewItem = checkedItemList.ItemsListView.FindItemWithText(name);
     111        var listViewItem = checkedItemList.ItemsListView.FindItemWithText(name, false, 0, false);
    112112        listViewItem.ForeColor = Color.LightGray;
    113113      }
  • branches/symbreg-factors-2650/HeuristicLab.Optimization/3.3/Algorithms/Algorithm.cs

    r14185 r14449  
    289289    public event EventHandler Stopped;
    290290    protected virtual void OnStopped() {
    291       foreach (IStatefulItem statefulObject in this.GetObjectGraphObjects(new HashSet<object>() { Runs }).OfType<IStatefulItem>()) {
    292         statefulObject.ClearState();
    293       }
    294       runsCounter++;
    295       runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this));
    296       ExecutionState = ExecutionState.Stopped;
    297       EventHandler handler = Stopped;
    298       if (handler != null) handler(this, EventArgs.Empty);
     291      try {
     292        foreach (
     293          IStatefulItem statefulObject in
     294          this.GetObjectGraphObjects(new HashSet<object>() {Runs}).OfType<IStatefulItem>()) {
     295          statefulObject.ClearState();
     296        }
     297        runsCounter++;
     298        try {
     299          runs.Add(new Run(string.Format("{0} Run {1}", Name, runsCounter), this));
     300        }
     301        catch (ArgumentException e) {
     302          OnExceptionOccurred(new InvalidOperationException("Run creation failed.", e));
     303        }
     304      }   
     305      finally {
     306        ExecutionState = ExecutionState.Stopped;
     307        EventHandler handler = Stopped;
     308        if (handler != null) handler(this, EventArgs.Empty);
     309      }
    299310    }
    300311    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.TimeSeriesPrognosis/3.4/SymbolicTimeSeriesPrognosisExpressionTreeInterpreter.cs

    r14185 r14449  
    4545    }
    4646
    47     [ThreadStatic]
    48     private static double[] targetVariableCache;
    49     [ThreadStatic]
    50     private static List<int> invalidateCacheIndexes;
    51 
    5247    [StorableConstructor]
    5348    private SymbolicTimeSeriesPrognosisExpressionTreeInterpreter(bool deserializing) : base(deserializing) { }
     
    7772      if (CheckExpressionsWithIntervalArithmetic)
    7873        throw new NotSupportedException("Interval arithmetic is not yet supported in the symbolic data analysis interpreter.");
    79       if (targetVariableCache == null || targetVariableCache.GetLength(0) < dataset.Rows)
    80         targetVariableCache = dataset.GetDoubleValues(TargetVariable).ToArray();
    81       if (invalidateCacheIndexes == null)
    82         invalidateCacheIndexes = new List<int>(10);
    8374
    8475      string targetVariable = TargetVariable;
     76      double[] targetVariableCache = dataset.GetDoubleValues(targetVariable).ToArray();
    8577      lock (syncRoot) {
    8678        EvaluatedSolutions++; // increment the evaluated solutions counter
     
    10092          vProgs[i] = Evaluate(dataset, ref localRow, state);
    10193          targetVariableCache[localRow] = vProgs[i];
    102           invalidateCacheIndexes.Add(localRow);
    10394          state.Reset();
    10495        }
    10596        yield return vProgs;
    106 
    107         int j = 0;
    108         foreach (var targetValue in dataset.GetDoubleValues(targetVariable, invalidateCacheIndexes)) {
    109           targetVariableCache[invalidateCacheIndexes[j]] = targetValue;
    110           j++;
    111         }
    112         invalidateCacheIndexes.Clear();
    11397      }
    11498
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs

    r14238 r14449  
    102102        if (dialog.DialogResult != DialogResult.OK) return;
    103103
    104         var symbol = dialog.SelectedSymbol();
     104        var symbol = dialog.SelectedSymbol;
    105105        var node = symbol.CreateTreeNode();
    106106        if (node is ConstantTreeNode) {
     
    110110          var variable = node as VariableTreeNode;
    111111          variable.Weight = double.Parse(dialog.variableWeightTextBox.Text);
    112           variable.VariableName = dialog.variableNamesCombo.Text;
     112          variable.VariableName = dialog.SelectedVariableName;
    113113        } else if (node.Symbol.MinimumArity <= parent.SubtreeCount && node.Symbol.MaximumArity >= parent.SubtreeCount) {
    114114          for (int i = parent.SubtreeCount - 1; i >= 0; --i) {
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeInsertDialog.Designer.cs

    r14185 r14449  
    5757      this.okButton = new System.Windows.Forms.Button();
    5858      this.cancelButton = new System.Windows.Forms.Button();
     59      this.variableNameTextBox = new System.Windows.Forms.TextBox();
    5960      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    6061      this.SuspendLayout();
     
    168169      this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
    169170      //
     171      // variableNameTextBox
     172      //
     173      this.variableNameTextBox.Location = new System.Drawing.Point(101, 63);
     174      this.variableNameTextBox.Name = "variableNameTextBox";
     175      this.variableNameTextBox.Size = new System.Drawing.Size(127, 20);
     176      this.variableNameTextBox.TabIndex = 11;
     177      this.variableNameTextBox.Visible = false;
     178      //
    170179      // InsertNodeDialog
    171180      //
     
    175184      this.ClientSize = new System.Drawing.Size(241, 133);
    176185      this.ControlBox = false;
     186      this.Controls.Add(this.variableNameTextBox);
    177187      this.Controls.Add(this.cancelButton);
    178188      this.Controls.Add(this.okButton);
     
    208218    private System.Windows.Forms.Button cancelButton;
    209219    private System.Windows.Forms.Button okButton;
     220    private System.Windows.Forms.TextBox variableNameTextBox;
    210221  }
    211222}
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeInsertDialog.cs

    r14238 r14449  
    2323using System.Collections.Generic;
    2424using System.ComponentModel;
     25using System.Linq;
    2526using System.Text;
    2627using System.Windows.Forms;
     
    3031namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3132  public partial class InsertNodeDialog : Form {
     33    public string SelectedVariableName {
     34      get {
     35        var variable = SelectedSymbol as Variable;
     36        if (variable == null)
     37          return string.Empty;
     38        return variable.VariableNames.Any() ? variableNamesCombo.Text : variableNameTextBox.Text;
     39      }
     40    }
     41
    3242    public InsertNodeDialog() {
    3343      InitializeComponent();
     
    4050    }
    4151
    42     public ISymbol SelectedSymbol() {
    43       return (ISymbol)allowedSymbolsCombo.SelectedItem;
     52    public ISymbol SelectedSymbol {
     53      get { return (ISymbol)allowedSymbolsCombo.SelectedItem; }
    4454    }
    4555
     
    5666        constantValueTextBox.Visible = true;
    5767      } else if (symbol is VariableBase) {
    58         var variable = (VariableBase)symbol;
    59         foreach (var name in variable.VariableNames) variableNamesCombo.Items.Add(name);
    60         variableNamesCombo.SelectedIndex = 0;
     68        var variableSymbol = (VariableBase)symbol;
     69        if (variableSymbol.VariableNames.Any()) {
     70          foreach (var name in variableSymbol.VariableNames)
     71            variableNamesCombo.Items.Add(name);
     72          variableNamesCombo.SelectedIndex = 0;
     73          variableNamesCombo.Visible = true;
     74          variableNameTextBox.Visible = false;
     75        } else {
     76          variableNamesCombo.Visible = false;
     77          variableNameTextBox.Visible = true;
     78        }
    6179        variableNameLabel.Visible = true;
    62         variableNamesCombo.Visible = true;
    6380        variableWeightLabel.Visible = true;
    6481        variableWeightTextBox.Visible = true;
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.Designer.cs

    r14185 r14449  
    5555      this.okButton = new System.Windows.Forms.Button();
    5656      this.cancelButton = new System.Windows.Forms.Button();
     57      this.variableNameTextBox = new System.Windows.Forms.TextBox();
    5758      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5859      this.SuspendLayout();
     
    146147      this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
    147148      //
     149      // variableNameTextBox
     150      //
     151      this.variableNameTextBox.Location = new System.Drawing.Point(101, 12);
     152      this.variableNameTextBox.Name = "variableNameTextBox";
     153      this.variableNameTextBox.Size = new System.Drawing.Size(131, 20);
     154      this.variableNameTextBox.TabIndex = 12;
     155      this.variableNameTextBox.Visible = false;
     156      //
    148157      // VariableNodeEditDialog
    149158      //
     
    154163      this.ClientSize = new System.Drawing.Size(244, 134);
    155164      this.ControlBox = false;
     165      this.Controls.Add(this.variableNameTextBox);
    156166      this.Controls.Add(this.cancelButton);
    157167      this.Controls.Add(this.okButton);
     
    188198    public System.Windows.Forms.TextBox newValueTextBox;
    189199    public System.Windows.Forms.ComboBox variableNamesCombo;
     200    private System.Windows.Forms.TextBox variableNameTextBox;
    190201  }
    191202}
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.cs

    r14185 r14449  
    2222using System;
    2323using System.ComponentModel;
     24using System.Linq;
    2425using System.Text;
    2526using System.Windows.Forms;
     
    4041    }
    4142
     43    public string SelectedVariableName {
     44      get { return variableNamesCombo.Visible ? variableNamesCombo.Text : variableNameTextBox.Text; }
     45    }
     46
    4247    public VariableNodeEditDialog(ISymbolicExpressionTreeNode node) {
    4348      InitializeComponent();
    4449      oldValueTextBox.TabStop = false; // cannot receive focus using tab key
    45 
    4650      NewNode = (VariableTreeNode)node; // will throw an invalid cast exception if node is not of the correct type
    4751      InitializeFields();
     
    5761        variableNameLabel.Visible = true;
    5862        variableNamesCombo.Visible = true;
    59         foreach (var name in variableTreeNode.Symbol.VariableNames) variableNamesCombo.Items.Add(name);
    60         variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variableTreeNode.VariableName);
     63        if (variableTreeNode.Symbol.VariableNames.Any()) {
     64          foreach (var name in variableTreeNode.Symbol.VariableNames)
     65            variableNamesCombo.Items.Add(name);
     66          variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variableTreeNode.VariableName);
     67          variableNamesCombo.Visible = true;
     68          variableNameTextBox.Visible = false;
     69        } else {
     70          variableNamesCombo.Visible = false;
     71          variableNameTextBox.Visible = true;
     72        }
    6173      }
    6274    }
     
    93105    #region combo box validation and events
    94106    private void variableNamesCombo_Validating(object sender, CancelEventArgs e) {
     107      if (variableNamesCombo.Items.Count == 0) return;
    95108      if (variableNamesCombo.Items.Contains(variableNamesCombo.SelectedItem)) return;
    96109      e.Cancel = true;
     
    119132    private void OnDialogValidated(object sender, EventArgs e) {
    120133      double weight = double.Parse(newValueTextBox.Text);
    121       var variableName = (string)variableNamesCombo.SelectedItem;
    122134      // we impose an extra validation condition: that the weight/value be different than the original ones
     135      var variableName = SelectedVariableName;
    123136      if (variableTreeNode.Weight.Equals(weight) && variableTreeNode.VariableName.Equals(variableName)) return;
    124137      variableTreeNode.Weight = weight;
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/HeuristicLab.Problems.DataAnalysis.Views-3.4.csproj

    r14351 r14449  
    416416    <Compile Include="Solution Views\TimeSeriesPrognosisSolutionView.Designer.cs">
    417417      <DependentUpon>TimeSeriesPrognosisSolutionView.cs</DependentUpon>
     418    </Compile>
     419    <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisLineChartView.cs">
     420      <SubType>UserControl</SubType>
     421    </Compile>
     422    <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisLineChartView.Designer.cs">
     423      <DependentUpon>TimeSeriesPrognosisLineChartView.cs</DependentUpon>
    418424    </Compile>
    419425    <Compile Include="TimeSeriesPrognosis\TimeSeriesPrognosisResultsView.cs">
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r14277 r14449  
    5757    }
    5858
     59    protected virtual void GetTrainingSeries(out int[] x, out double[] y) {
     60      x = Content.ProblemData.TrainingIndices.ToArray();
     61      y = Content.EstimatedTrainingValues.ToArray();
     62    }
     63
     64    protected virtual void GetTestSeries(out int[] x, out double[] y) {
     65      x = Content.ProblemData.TestIndices.ToArray();
     66      y = Content.EstimatedTestValues.ToArray();
     67    }
     68
     69    protected virtual void GetAllValuesSeries(out int[] x, out double[] y) {
     70      x = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndices).Except(Content.ProblemData.TestIndices).ToArray();
     71      var tmp = Content.EstimatedValues.ToArray();
     72      y = x.Select(index => tmp[index]).ToArray();
     73    }
     74
    5975    private void RedrawChart() {
    6076      this.chart.Series.Clear();
     
    7389        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    7490        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Color;
    75         this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndices.ToArray(), Content.EstimatedTrainingValues.ToArray());
     91        int[] trainingIdx;
     92        double[] trainingY;
     93        GetTrainingSeries(out trainingIdx, out trainingY);
     94        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(trainingIdx, trainingY);
    7695        this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME]);
    7796        this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
     97
    7898        // test series
    7999        this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
    80100        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
    81101        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    82         this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndices.ToArray(), Content.EstimatedTestValues.ToArray());
     102        int[] testIdx;
     103        double[] testY;
     104        GetTestSeries(out testIdx, out testY);
     105        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(testIdx, testY);
    83106        this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME]);
    84107        this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;
     108
    85109        // series of remaining points
    86         int[] allIndices = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndices).Except(Content.ProblemData.TestIndices).ToArray();
    87         var estimatedValues = Content.EstimatedValues.ToArray();
    88         List<double> allEstimatedValues = allIndices.Select(index => estimatedValues[index]).ToList();
     110        int[] allIdx;
     111        double[] allEstimatedValues;
     112        GetAllValuesSeries(out allIdx, out allEstimatedValues);
     113
    89114        this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
    90115        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
    91116        this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType = SeriesChartType.FastLine;
    92         if (allEstimatedValues.Count > 0) {
    93           this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndices, allEstimatedValues);
     117        if (allEstimatedValues.Length > 0) {
     118          this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIdx, allEstimatedValues);
    94119          this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
    95120        }
     
    244269        }
    245270      } else if (Content != null) {
    246         string targetVariableName = Content.ProblemData.TargetVariable;
    247 
    248         IEnumerable<int> indices = null;
     271
     272        int[] indices = null;
    249273        double[] predictedValues = null;
    250274        switch (series.Name) {
    251275          case ESTIMATEDVALUES_ALL_SERIES_NAME:
    252             indices = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndices).Except(Content.ProblemData.TestIndices).ToArray();
    253             var estimatedValues = Content.EstimatedValues.ToArray();
    254             predictedValues = indices.Select(index => estimatedValues[index]).ToArray();
     276            GetAllValuesSeries(out indices, out predictedValues);
    255277            break;
    256278          case ESTIMATEDVALUES_TRAINING_SERIES_NAME:
    257             indices = Content.ProblemData.TrainingIndices.ToArray();
    258             predictedValues = Content.EstimatedTrainingValues.ToArray();
     279            GetTrainingSeries(out indices, out predictedValues);
    259280            break;
    260281          case ESTIMATEDVALUES_TEST_SERIES_NAME:
    261             indices = Content.ProblemData.TestIndices.ToArray();
    262             predictedValues = Content.EstimatedTestValues.ToArray();
     282            GetTestSeries(out indices, out predictedValues);
    263283            break;
    264284        }
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolution.cs

    r14185 r14449  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    4344      return Model.GetPrognosedValues(ProblemData.Dataset, rows, horizons);
    4445    }
     46
     47    public override IEnumerable<double> PrognosedTestValues {
     48      get {
     49        return Model.GetPrognosedValues(ProblemData.Dataset, ProblemData.TestIndices.Take(1),
     50          new int[] { ProblemData.TestIndices.Count() }).First();
     51      }
     52    }
    4553  }
    4654}
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/TimeSeriesPrognosisSolutionBase.cs

    r14185 r14449  
    6464    }
    6565
     66    public abstract IEnumerable<double> PrognosedTestValues { get; }
    6667    public abstract IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizon);
    6768
     
    150151      OnlineCalculatorError errorState;
    151152      double trainingMean = ProblemData.TrainingIndices.Any() ? ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).Average() : double.NaN;
    152       var meanModel = new ConstantModel(trainingMean,ProblemData.TargetVariable);
     153      var meanModel = new ConstantModel(trainingMean, ProblemData.TargetVariable);
    153154
    154155      double alpha, beta;
  • branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/TimeSeriesPrognosis/ITimeSeriesPrognosisSolution.cs

    r14185 r14449  
    2828    IEnumerable<IEnumerable<double>> GetPrognosedValues(IEnumerable<int> rows, IEnumerable<int> horizon);
    2929
     30    IEnumerable<double> PrognosedTestValues { get; }
     31
    3032    double TrainingTheilsUStatisticAR1 { get; }
    3133    double TestTheilsUStatisticAR1 { get; }
Note: See TracChangeset for help on using the changeset viewer.