Free cookie consent management tool by TermsFeed Policy Generator

Changeset 232 for trunk


Ignore:
Timestamp:
05/11/08 12:33:07 (16 years ago)
Author:
gkronber
Message:

implemented #144

Location:
trunk/sources/HeuristicLab.DataAnalysis
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.DataAnalysis/Dataset.cs

    r207 r232  
    6060      if(v != samples[columns * i + j]) {
    6161        samples[columns * i + j] = v;
     62        CreateDictionaries();
    6263        FireChanged();
    6364      }
     
    8586      Rows = 1;
    8687      Samples = new double[1];
    87     }
    88 
    89     void samples_Changed(object sender, EventArgs e) {
    90       CreateDictionaries();
    9188    }
    9289
     
    233230      }
    234231    }
     232
     233    public double GetMaximum(int column) {
     234      double max = Double.NegativeInfinity;
     235      for(int i = 0; i < Rows; i++) {
     236        double val = GetValue(i, column);
     237        if(val > max) max = val;
     238      }
     239      return max;
     240    }
     241
     242    public double GetMinimum(int column) {
     243      double min = Double.PositiveInfinity;
     244      for(int i = 0; i < Rows; i++) {
     245        double val = GetValue(i, column);
     246        if(val < min) min = val;
     247      }
     248      return min;
     249    }
    235250  }
    236251}
  • trunk/sources/HeuristicLab.DataAnalysis/DatasetView.cs

    r168 r232  
    2525
    2626namespace HeuristicLab.DataAnalysis {
    27   public partial class DatasetView : ViewBase {
    28 
    29     private OpenFileDialog openFileDialog;
    30 
     27  public partial class DatasetView : EditorBase {
    3128    public Dataset Dataset {
    3229      get { return (Dataset)Item; }
     
    3734    }
    3835
     36    private double[] scalingFactor;
     37    private double[] scalingOffset;
    3938    public DatasetView()
    4039      : base() {
    4140      InitializeComponent();
    42       openFileDialog = new OpenFileDialog();
    4341    }
    4442
     
    5048    protected override void UpdateControls() {
    5149      base.UpdateControls();
     50      if(this.scalingFactor == null) {
     51        this.scalingFactor = new double[Dataset.Columns];
     52        this.scalingOffset = new double[Dataset.Columns];
     53        for(int i = 0; i < scalingFactor.Length; i++) {
     54          scalingFactor[i] = 1.0;
     55          scalingOffset[i] = 0.0;
     56        }
     57      }
    5258      if (Dataset != null) {
    5359        int rows = Dataset.Rows;
     
    6369          }
    6470        }
    65         if (Dataset.VariableNames.Length == dataGridView.Columns.Count) {
    66           for (int i = 0; i < columns; i++) {
    67             dataGridView.Columns[i].Name = Dataset.VariableNames[i];
    68           }
    69         } else {
    70           for (int i = 0; i < columns; i++) {
    71             dataGridView.Columns[i].Name = "Var" + i;
    72           }
     71        for (int i = 0; i < columns; i++) {
     72          dataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
     73          dataGridView.Columns[i].Name = GetColumnName(i);
     74          dataGridView.Columns[i].ContextMenuStrip = contextMenuStrip;
    7375        }
    74 
     76        dataGridView.SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
    7577      } else {
    7678        rowsTextBox.Text = "1";
     
    104106      return element != null && double.TryParse(element, out result);
    105107    }
     108
     109    private void exportButton_Click(object sender, EventArgs e) {
     110      throw new NotImplementedException();
     111    }
     112
     113    private void scaleValuesToolStripMenuItem_Click(object sender, EventArgs e) {
     114      foreach(DataGridViewColumn column in dataGridView.SelectedColumns) {
     115        if(scalingFactor[column.Index] == 1.0) {
     116          double min = Dataset.GetMinimum(column.Index);
     117          double max = Dataset.GetMaximum(column.Index);
     118          double range = max - min;
     119          scalingFactor[column.Index] = range;
     120          scalingOffset[column.Index] = min;
     121          column.Name = GetColumnName(column.Index) + " [scaled]";
     122          for(int i = 0; i < Dataset.Rows; i++) {
     123            Dataset.SetValue(i, column.Index, (Dataset.GetValue(i, column.Index)-min) / range);
     124          }
     125        }
     126      }
     127      Refresh();
     128    }
     129
     130    private void originalValuesToolStripMenuItem_Click(object sender, EventArgs e) {
     131      foreach(DataGridViewColumn column in dataGridView.SelectedColumns) {
     132        if(scalingFactor[column.Index] != 1.0) {
     133          column.Name = GetColumnName(column.Index);
     134          for(int i = 0; i < Dataset.Rows; i++) {
     135            Dataset.SetValue(i, column.Index, Dataset.GetValue(i, column.Index) * scalingFactor[column.Index] + scalingOffset[column.Index]);
     136          }
     137          scalingFactor[column.Index] = 1.0;
     138          scalingOffset[column.Index] = 0.0;
     139        }
     140      }
     141      Refresh();     
     142    }
     143
     144    private string GetColumnName(int index) {
     145      if(Dataset.VariableNames.Length == dataGridView.Columns.Count) {
     146        return Dataset.VariableNames[index];
     147      } else {
     148        return "Var " + index;
     149      }
     150    }
    106151  }
    107152}
  • trunk/sources/HeuristicLab.DataAnalysis/DatasetView.designer.cs

    r2 r232  
    4545    /// </summary>
    4646    private void InitializeComponent() {
     47      this.components = new System.ComponentModel.Container();
    4748      this.rowsTextBox = new System.Windows.Forms.TextBox();
    4849      this.columnsTextBox = new System.Windows.Forms.TextBox();
     
    5253      this.nameLabel = new System.Windows.Forms.Label();
    5354      this.nameTextBox = new System.Windows.Forms.TextBox();
     55      this.exportButton = new System.Windows.Forms.Button();
     56      this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
     57      this.scaleValuesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
     58      this.originalValuesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    5459      ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
     60      this.contextMenuStrip.SuspendLayout();
    5561      this.SuspendLayout();
    5662      //
    5763      // rowsTextBox
    5864      //
    59       this.rowsTextBox.Location = new System.Drawing.Point(46, 32);
     65      this.rowsTextBox.Location = new System.Drawing.Point(50, 29);
    6066      this.rowsTextBox.Name = "rowsTextBox";
    6167      this.rowsTextBox.ReadOnly = true;
     
    6571      // columnsTextBox
    6672      //
    67       this.columnsTextBox.Location = new System.Drawing.Point(208, 32);
     73      this.columnsTextBox.Location = new System.Drawing.Point(217, 29);
    6874      this.columnsTextBox.Name = "columnsTextBox";
    6975      this.columnsTextBox.ReadOnly = true;
     
    7985                  | System.Windows.Forms.AnchorStyles.Right)));
    8086      this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    81       this.dataGridView.Location = new System.Drawing.Point(3, 58);
     87      this.dataGridView.Location = new System.Drawing.Point(3, 84);
    8288      this.dataGridView.Name = "dataGridView";
    83       this.dataGridView.Size = new System.Drawing.Size(554, 482);
     89      this.dataGridView.Size = new System.Drawing.Size(554, 456);
    8490      this.dataGridView.TabIndex = 3;
    8591      this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating);
     
    8894      //
    8995      this.rowsLabel.AutoSize = true;
    90       this.rowsLabel.Location = new System.Drawing.Point(3, 35);
     96      this.rowsLabel.Location = new System.Drawing.Point(3, 32);
    9197      this.rowsLabel.Name = "rowsLabel";
    9298      this.rowsLabel.Size = new System.Drawing.Size(37, 13);
     
    97103      //
    98104      this.columnsLabel.AutoSize = true;
    99       this.columnsLabel.Location = new System.Drawing.Point(152, 35);
     105      this.columnsLabel.Location = new System.Drawing.Point(161, 32);
    100106      this.columnsLabel.Name = "columnsLabel";
    101107      this.columnsLabel.Size = new System.Drawing.Size(50, 13);
     
    114120      // nameTextBox
    115121      //
    116       this.nameTextBox.Location = new System.Drawing.Point(46, 3);
     122      this.nameTextBox.Location = new System.Drawing.Point(50, 3);
    117123      this.nameTextBox.Name = "nameTextBox";
    118124      this.nameTextBox.ReadOnly = true;
    119       this.nameTextBox.Size = new System.Drawing.Size(262, 20);
     125      this.nameTextBox.Size = new System.Drawing.Size(219, 20);
    120126      this.nameTextBox.TabIndex = 7;
     127      //
     128      // exportButton
     129      //
     130      this.exportButton.Location = new System.Drawing.Point(6, 55);
     131      this.exportButton.Name = "exportButton";
     132      this.exportButton.Size = new System.Drawing.Size(75, 23);
     133      this.exportButton.TabIndex = 11;
     134      this.exportButton.Text = "Export ...";
     135      this.exportButton.UseVisualStyleBackColor = true;
     136      this.exportButton.Click += new System.EventHandler(this.exportButton_Click);
     137      //
     138      // contextMenuStrip
     139      //
     140      this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     141            this.scaleValuesToolStripMenuItem,
     142            this.originalValuesToolStripMenuItem});
     143      this.contextMenuStrip.Name = "contextMenuStrip";
     144      this.contextMenuStrip.Size = new System.Drawing.Size(146, 48);
     145      //
     146      // scaleValuesToolStripMenuItem
     147      //
     148      this.scaleValuesToolStripMenuItem.Name = "scaleValuesToolStripMenuItem";
     149      this.scaleValuesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
     150      this.scaleValuesToolStripMenuItem.Text = "Scale values";
     151      this.scaleValuesToolStripMenuItem.Click += new System.EventHandler(this.scaleValuesToolStripMenuItem_Click);
     152      //
     153      // originalValuesToolStripMenuItem
     154      //
     155      this.originalValuesToolStripMenuItem.Name = "originalValuesToolStripMenuItem";
     156      this.originalValuesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
     157      this.originalValuesToolStripMenuItem.Text = "Unscale values";
     158      this.originalValuesToolStripMenuItem.Click += new System.EventHandler(this.originalValuesToolStripMenuItem_Click);
    121159      //
    122160      // DatasetView
     
    125163      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    126164      this.Controls.Add(this.nameTextBox);
     165      this.Controls.Add(this.exportButton);
    127166      this.Controls.Add(this.nameLabel);
    128167      this.Controls.Add(this.columnsLabel);
     
    134173      this.Size = new System.Drawing.Size(560, 543);
    135174      ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
     175      this.contextMenuStrip.ResumeLayout(false);
    136176      this.ResumeLayout(false);
    137177      this.PerformLayout();
     
    148188    private System.Windows.Forms.Label nameLabel;
    149189    private System.Windows.Forms.TextBox nameTextBox;
     190    private System.Windows.Forms.Button exportButton;
     191    private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
     192    private System.Windows.Forms.ToolStripMenuItem scaleValuesToolStripMenuItem;
     193    private System.Windows.Forms.ToolStripMenuItem originalValuesToolStripMenuItem;
    150194  }
    151195}
  • trunk/sources/HeuristicLab.DataAnalysis/DatasetView.resx

    r2 r232  
    118118    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
    119119  </resheader>
     120  <metadata name="contextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     121    <value>17, 17</value>
     122  </metadata>
    120123</root>
Note: See TracChangeset for help on using the changeset viewer.