Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10952


Ignore:
Timestamp:
06/04/14 15:32:33 (11 years ago)
Author:
aesterer
Message:

Completed scatter plot view

Location:
branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/MultiScatterPlotView.cs

    r10915 r10952  
    1818
    1919  [View("Multi Scatter Plot View")]
    20   [Content(typeof(ScatterPlotContent), true)]
     20  [Content(typeof(ScatterPlotContent), false)]
    2121  public partial class MultiScatterPlotView : ItemView {
     22
     23    private const int HEADER_WIDTH = 50;
     24    private const int HEADER_HEIGHT = 50;
     25    private const int MAX_AUTO_SIZE_ELEMENTS = 6;
     26    private const int FIXED_CHART_WIDTH = 250;
     27    private const int FIXED_CHART_HEIGHT = 150;
    2228
    2329    private IChartLogic logic;
     
    3440
    3541    public void InitData() {
    36 
    3742      variables = new List<string>(logic.GetVariableNames());
    38 
    3943    }
    4044
     
    4549        InitData();
    4650        GenerateMultiLayout();
     51      }
     52    }
     53
     54    //Add header elements to the table layout panel
     55    private void addHeaderToTableLayoutPanels() {
     56
     57      for (int i = 1; i < variables.Count + 1; i++) {
     58        // Use buttons for header elements
     59        Button xButton = new Button();
     60        xButton.Enabled = false;
     61        xButton.BackColor = Color.Gainsboro;
     62        xButton.Text = variables[i - 1];
     63        xButton.Dock = DockStyle.Fill;
     64        tableLayoutPanel.Controls.Add(xButton, 0, i);
     65        Button yButton = new Button();
     66        yButton.Enabled = false;
     67        yButton.BackColor = Color.Gainsboro;
     68        yButton.Text = variables[i - 1];
     69        yButton.Dock = DockStyle.Fill;
     70        tableLayoutPanel.Controls.Add(yButton, i, 0);
    4771      }
    4872    }
     
    5983      tableLayoutPanel.RowCount = variables.Count+1;
    6084
    61       int headerSize = 50;
    62       int maxAutoSizeElements = 6;
    63       int fixedElementSize = 200;
    64 
    65       tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, headerSize));
    66       tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, headerSize));
     85      tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, HEADER_WIDTH));
     86      tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, HEADER_HEIGHT));
    6787      // set column and row layout
    6888      for (int x = 0; x < variables.Count; x++)
    6989      {
    7090        // auto size
    71         if (variables.Count <= maxAutoSizeElements) {
    72           tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, (tableLayoutPanel.Width - headerSize) / variables.Count));
    73           tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, (tableLayoutPanel.Height - headerSize) / variables.Count));
     91        if (variables.Count <= MAX_AUTO_SIZE_ELEMENTS) {
     92          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, (tableLayoutPanel.Width - HEADER_WIDTH) / variables.Count));
     93          tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, (tableLayoutPanel.Height - HEADER_HEIGHT) / variables.Count));
    7494        }
    7595        // fixed size
    7696        else {
    77           tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, fixedElementSize));
    78           tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, fixedElementSize));
     97          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, FIXED_CHART_WIDTH));
     98          tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, FIXED_CHART_HEIGHT));
    7999        }
    80100      }
    81101
    82       // set variable header elements
    83       for (int i = 1; i < variables.Count +1; i++)
    84       {
    85          Button b1 = new Button();
    86          b1.Text = variables[i-1];
    87          b1.Dock = DockStyle.Fill;
    88          tableLayoutPanel.Controls.Add(b1,0,i);
    89          Button b2 = new Button();
    90          b2.Text = variables[i - 1];
    91          b2.Dock = DockStyle.Fill;
    92          tableLayoutPanel.Controls.Add(b2, i, 0);
    93       }
     102      addHeaderToTableLayoutPanels();
     103      addChartsToTableLayoutPanel();
     104 
     105    }
    94106
     107    private void addChartsToTableLayoutPanel() {
    95108      //set scatter plots and histograms
    96       for (int x = 1; x < variables.Count + 1; x++)
    97       {
     109      for (int x = 1; x < variables.Count + 1; x++) {
    98110
    99         for (int y = 1; y < variables.Count + 1; y++)
    100         {
    101           // use historgram if x variable equals y variable
     111        for (int y = 1; y < variables.Count + 1; y++) {
     112          // use historgram if x and y variable are equal
    102113          if (x == y) {
    103114            PreprocessingDataTable dataTable = new PreprocessingDataTable();
     
    105116            dataTable.Rows.Add(dataRow);
    106117            PreprocessingDataTableView pcv = new PreprocessingDataTableView();
    107             pcv.DoubleClick += tableLayoutElementDoubleClick;
     118            pcv.ChartDoubleClick += HistogramDoubleClick;
    108119            pcv.Content = dataTable;
    109120            tableLayoutPanel.Controls.Add(pcv, y, x);
    110121          }
    111122          //scatter plot
    112           else {   
    113             ScatterPlot scatterPlot = logic.CreateScatterPlot(variables[x - 1], variables[y-1]);   
     123          else {
     124            ScatterPlot scatterPlot = logic.CreateScatterPlot(variables[x - 1], variables[y - 1]);
    114125            PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView();
    115             pspv.DoubleClick += tableLayoutElementDoubleClick;
     126            pspv.ChartDoubleClick += ScatterPlotDoubleClick;
    116127            pspv.Content = scatterPlot;
    117128            pspv.Dock = DockStyle.Fill;
    118             tableLayoutPanel.Controls.Add(pspv, y, x);
     129            tableLayoutPanel.Controls.Add(pspv, x, y);
    119130          }
    120131        }
     
    122133    }
    123134
    124     private void tableLayoutElementDoubleClick(object sender, EventArgs e) {
     135    //Open scatter plot in new tab with new content when double clicked
     136    private void ScatterPlotDoubleClick(object sender, EventArgs e) {
     137      PreprocessingScatterPlotView pspv = (PreprocessingScatterPlotView)sender;
     138      ScatterPlotContent scatterContent = new ScatterPlotContent(logic);  // create new content
     139      ScatterPlot scatterPlot = pspv.Content;
     140      setVariablesInContentFromScatterPlot(scatterContent, scatterPlot);
    125141
    126        //histogram clicked
    127        if(sender.GetType() == typeof(PreprocessingDataTableView))
    128        {
    129          PreprocessingDataTableView pcv = (PreprocessingDataTableView)sender;
    130          //ScatterPlotContent spc = new ScatterPlotContent(
    131          
    132        }
    133        // scatter plot clicked
    134        else if (sender.GetType() == typeof(PreprocessingScatterPlotView)) {
    135          PreprocessingScatterPlotView pspv = (PreprocessingScatterPlotView)sender;
    136          MainFormManager.MainForm.ShowContent(this.Content, typeof(SingleScatterPlotView));
    137        }
     142      MainFormManager.MainForm.ShowContent(scatterContent, typeof(SingleScatterPlotView));  // open in new tab
     143    }
    138144
    139        
     145    //Extract variable names from scatter plot and set them in content
     146    private void setVariablesInContentFromScatterPlot(ScatterPlotContent scatterContent, ScatterPlot scatterPlot) {
     147
     148      // only one data row should be in scatter plot
     149      if (scatterPlot.Rows.Count == 1) {
     150        // TODO -> find better way to get variable names
     151        string[] variables = scatterPlot.Rows.ElementAt(0).Name.Split(new string[]{" - "},StringSplitOptions.None); // extract variable names from string
     152        scatterContent.SelectedXVariable = variables[0];
     153        scatterContent.SelectedYVariable = variables[1];
     154      }
     155    }
     156
     157    //Set variable item list from with variable from data table
     158    private void setVariableItemListFromDataTable(HistogramContent histoContent, PreprocessingDataTable dataTable) {
     159
     160      // only one data row should be in data table
     161      if (dataTable.Rows.Count == 1) {
     162        string variableName = dataTable.Rows.ElementAt(0).Name;
     163
     164        // set only variable name checked
     165        foreach(var checkedItem in histoContent.VariableItemList)
     166        {
     167          if(checkedItem.Value == variableName)
     168            histoContent.VariableItemList.SetItemCheckedState(checkedItem,true);
     169          else
     170            histoContent.VariableItemList.SetItemCheckedState(checkedItem,false);
     171           
     172        }
     173      }
     174    }
     175
     176    //open histogram in new tab with new content when double clicked
     177    private void HistogramDoubleClick(object sender, EventArgs e) {
     178      PreprocessingDataTableView pcv = (PreprocessingDataTableView)sender;
     179      HistogramContent histoContent = new HistogramContent(logic);  // create new content
     180      histoContent.VariableItemList = logic.CreateVariableItemList();
     181      PreprocessingDataTable dataTable = pcv.Content;
     182      setVariableItemListFromDataTable(histoContent, dataTable);
     183
     184      MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView));  // open in new tab
    140185    }
    141186   
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.cs

    r10908 r10952  
    373373
    374374
    375 
    376375  }
    377376}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingDataTableView.Designer.cs

    r10877 r10952  
    7373      legend1.Name = "Default";
    7474      this.chart.Legends.Add(legend1);
    75       this.chart.Location = new System.Drawing.Point(0, 3);
     75      this.chart.Location = new System.Drawing.Point(0, 0);
    7676      this.chart.Name = "chart";
    7777      series1.ChartArea = "Default";
     
    7979      series1.Name = "Default";
    8080      this.chart.Series.Add(series1);
    81       this.chart.Size = new System.Drawing.Size(359, 271);
     81      this.chart.Size = new System.Drawing.Size(359, 274);
    8282      this.chart.TabIndex = 3;
    8383      this.chart.Text = "chart";
     
    8888      this.chart.Titles.Add(title1);
    8989      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
     90      this.chart.DoubleClick += new System.EventHandler(this.chart_DoubleClick);
    9091      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    9192      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingDataTableView.cs

    r10914 r10952  
    3939    protected List<Series> invisibleSeries;
    4040    protected Dictionary<IObservableList<double>, DataRow> valuesRowsTable;
     41    private event EventHandler chartDoubleClick;
    4142
    4243    public new PreprocessingDataTable Content {
     
    759760    }
    760761
     762    public event EventHandler ChartDoubleClick {
     763      add { chartDoubleClick += value; }
     764      remove { chartDoubleClick -= value; }
     765    }
     766
    761767    #region Helpers
    762768    public static IEnumerable<double> DoubleRange(double min, double max, double step) {
     
    816822    }
    817823    #endregion
     824
     825    //bubble double click event with data table view as sender
     826    private void chart_DoubleClick(object sender, EventArgs e) {
     827      if (chartDoubleClick != null)
     828        chartDoubleClick(this, e);
     829    }
    818830  }
    819831}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingScatterPlotView.Designer.cs

    r10915 r10952  
    7272      legend1.Name = "Default";
    7373      this.chart.Legends.Add(legend1);
    74       this.chart.Location = new System.Drawing.Point(0, 3);
     74      this.chart.Location = new System.Drawing.Point(0, 0);
    7575      this.chart.Name = "chart";
    7676      series1.ChartArea = "Default";
     
    7878      series1.Name = "Default";
    7979      this.chart.Series.Add(series1);
    80       this.chart.Size = new System.Drawing.Size(359, 271);
     80      this.chart.Size = new System.Drawing.Size(359, 274);
    8181      this.chart.TabIndex = 3;
    8282      this.chart.Text = "chart";
     
    8787      this.chart.Titles.Add(title1);
    8888      this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
     89      this.chart.DoubleClick += new System.EventHandler(this.chart_DoubleClick);
    8990      this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    9091      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingScatterPlotView.cs

    r10915 r10952  
    3939    protected List<Series> invisibleSeries;
    4040    protected Dictionary<IObservableList<Point2D<double>>, ScatterPlotDataRow> pointsRowsTable;
     41    private event EventHandler chartDoubleClick;
    4142
    4243    public new ScatterPlot Content {
     
    220221      double yZoomInterval = Math.Pow(10, digits);
    221222      this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
     223    }
     224
     225
     226    public event EventHandler ChartDoubleClick {
     227      add { chartDoubleClick += value; }
     228      remove { chartDoubleClick -= value; }
    222229    }
    223230
     
    450457    }
    451458    #endregion
     459
     460    //bubble double click event with scatter plot view as sender
     461    private void chart_DoubleClick(object sender, EventArgs e) {
     462      if (chartDoubleClick != null)
     463        chartDoubleClick(this, e);
     464    }
    452465  }
    453466}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/SingleScatterPlotView.cs

    r10915 r10952  
    1919
    2020  [View("Single Scatter Plot View")]
    21   [Content(typeof(ScatterPlotContent), false)]
     21  [Content(typeof(ScatterPlotContent), true)]
    2222  public partial class SingleScatterPlotView : ItemView {
    2323
     
    4242      comboBoxYVariable.Items.AddRange(variables.ToArray());
    4343
    44       if (variables.Count() >= 2) {
    45         comboBoxXVariable.SelectedIndex = 0;
    46         comboBoxYVariable.SelectedIndex = 1;
    47         UpdateScatterPlot();
    48        
     44      // use x and y variable from content
     45      if (Content.SelectedXVariable != null && Content.SelectedYVariable != null) {
     46        comboBoxXVariable.SelectedItem = Content.SelectedXVariable;
     47        comboBoxYVariable.SelectedItem = Content.SelectedYVariable;
     48      } else {
     49        if (variables.Count() >= 2) {
     50          comboBoxXVariable.SelectedIndex = 0;
     51          comboBoxYVariable.SelectedIndex = 1;
     52          UpdateScatterPlot();
     53
     54        }
    4955      }
    5056
     
    6773        ScatterPlot scatterPlot = logic.CreateScatterPlot((string)comboBoxXVariable.SelectedItem, (string)comboBoxYVariable.SelectedItem);
    6874        scatterPlotView.Content = scatterPlot;
     75
     76        //save selected x and y variable in content
     77        this.Content.SelectedXVariable = (string)comboBoxXVariable.SelectedItem;
     78        this.Content.SelectedYVariable = (string)comboBoxYVariable.SelectedItem;
    6979      }
    7080    }
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ViewShortcutListView.cs

    r10904 r10952  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Core;
    2324using HeuristicLab.Core.Views;
     
    3334      itemsGroupBox.Text = "View Shortcuts";
    3435    }
     36
     37    protected override void itemsListView_DoubleClick(object sender, EventArgs e) {
     38      if (itemsListView.SelectedItems.Count == 1) {
     39        IViewShortcut item = itemsListView.SelectedItems[0].Tag as IViewShortcut;
     40        if (item != null) {
     41
     42          if (item is IViewChartShortcut)
     43            item = (IViewChartShortcut)item.Clone();
     44
     45          IContentView view = MainFormManager.MainForm.ShowContent(item);
     46          if (view != null) {
     47            view.ReadOnly = ReadOnly;
     48            view.Locked = Locked;
     49          }
     50        }
     51      }
     52    }
    3553  }
    3654}
Note: See TracChangeset for help on using the changeset viewer.