Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10987


Ignore:
Timestamp:
06/11/14 14:23:19 (10 years ago)
Author:
aesterer
Message:

Refactored scatter plot

Location:
branches/DataPreprocessing
Files:
4 edited
4 moved

Legend:

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

    r10977 r10987  
    6161          new LineChartContent(chartLogic),
    6262          new HistogramContent(chartLogic),
    63           new ScatterPlotContent(chartLogic),
     63          new ScatterPlotContent(Content),
    6464          new CorrelationMatrixContent(Content),
    6565          new DataCompletenessChartContent(dataGridLogic, searchLogic),
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/HeuristicLab.DataPreprocessing.Views-3.4.csproj

    r10950 r10987  
    9292      <DependentUpon>ComparisonFilterView.cs</DependentUpon>
    9393    </Compile>
    94     <Compile Include="SingleScatterPlotView.cs">
    95       <SubType>UserControl</SubType>
    96     </Compile>
    97     <Compile Include="SingleScatterPlotView.Designer.cs">
    98       <DependentUpon>SingleScatterPlotView.cs</DependentUpon>
     94    <Compile Include="ScatterPlotSingleView.cs">
     95      <SubType>UserControl</SubType>
     96    </Compile>
     97    <Compile Include="ScatterPlotSingleView.Designer.cs">
     98      <DependentUpon>ScatterPlotSingleView.cs</DependentUpon>
    9999    </Compile>
    100100    <Compile Include="DataCompletenessView.cs">
     
    129129      <DependentUpon>FilterView.cs</DependentUpon>
    130130    </Compile>
    131     <Compile Include="MultiScatterPlotView.cs">
    132       <SubType>UserControl</SubType>
    133     </Compile>
    134     <Compile Include="MultiScatterPlotView.Designer.cs">
    135       <DependentUpon>MultiScatterPlotView.cs</DependentUpon>
     131    <Compile Include="ScatterPlotMultiView.cs">
     132      <SubType>UserControl</SubType>
     133    </Compile>
     134    <Compile Include="ScatterPlotMultiView.Designer.cs">
     135      <DependentUpon>ScatterPlotMultiView.cs</DependentUpon>
    136136    </Compile>
    137137    <Compile Include="PreprocessingScatterPlotView.cs">
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/PreprocessingChartView.cs

    r10972 r10987  
    4949    private const string DEFAULT_CHART_TITLE = "Chart";
    5050    private const int FIXED_CHART_SIZE = 300;
    51     private const int MAX_TABLE_ROWS = 3;
     51    private const int MAX_TABLE_AUTO_SIZE_ROWS = 3;
    5252
    5353    public IEnumerable<double> Classification { get; set; }
     
    328328      int columns = GetNrOfMultiChartColumns(checkedItemsCnt);
    329329      int rows = GetNrOfMultiChartRows(checkedItemsCnt, columns);
     330      tableLayoutPanel.VerticalScroll.Enabled = true;
    330331     
    331332      tableLayoutPanel.ColumnCount = columns;
     
    335336      for (int x = 0; x < columns; x++) {
    336337
    337         if (rows <= MAX_TABLE_ROWS)
     338        if (rows <= MAX_TABLE_AUTO_SIZE_ROWS)
    338339          tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100 / columns));
    339340        else
     
    344345          if (x == 0) {
    345346            // fixed chart size when there are more than 3 tables
    346             if (rows > MAX_TABLE_ROWS)
     347            if (rows > MAX_TABLE_AUTO_SIZE_ROWS)
    347348              tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, FIXED_CHART_SIZE));
    348349            else
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.Designer.cs

    r10986 r10987  
    11namespace HeuristicLab.DataPreprocessing.Views {
    2   partial class MultiScatterPlotView {
     2  partial class ScatterPlotMultiView {
    33    /// <summary>
    44    /// Required designer variable.
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotMultiView.cs

    r10982 r10987  
    99using HeuristicLab.Analysis.Views;
    1010using HeuristicLab.Collections;
     11using HeuristicLab.Common;
    1112using HeuristicLab.Core;
    1213using HeuristicLab.Core.Views;
     
    1718namespace HeuristicLab.DataPreprocessing.Views {
    1819
    19   [View("Multi Scatter Plot View")]
     20  [View("Scatter Plot Multi View")]
    2021  [Content(typeof(ScatterPlotContent), false)]
    21   public partial class MultiScatterPlotView : ItemView {
     22  public partial class ScatterPlotMultiView : ItemView {
    2223
    2324    private const int HEADER_WIDTH = 50;
     
    2728    private const int FIXED_CHART_HEIGHT = 150;
    2829
    29     private IChartLogic logic;
    30     private List<string> variables;
    31 
    32     public MultiScatterPlotView() {
     30    public ScatterPlotMultiView() {
    3331      InitializeComponent();
    3432    }
     
    3937    }
    4038
    41     public void InitData() {
    42       variables = new List<string>(logic.GetVariableNames());
    43     }
    44 
    4539    protected override void OnContentChanged() {
    4640      base.OnContentChanged();
    4741      if (Content != null) {
    48         logic = Content.ChartLogic;
    49         InitData();
    5042        GenerateMultiLayout();
    5143      }
     
    5446    //Add header elements to the table layout panel
    5547    private void addHeaderToTableLayoutPanels() {
     48
     49      List<string> variables = Content.GetVariableNames().ToList();
    5650
    5751      for (int i = 1; i < variables.Count + 1; i++) {
     
    7468    private void GenerateMultiLayout()
    7569    {
     70      List<string> variables = Content.GetVariableNames().ToList();
     71
    7672      tableLayoutPanel.Controls.Clear();
    7773      //Clear out the existing row and column styles
     
    106102
    107103    private void addChartsToTableLayoutPanel() {
     104
     105      List<string> variables = Content.GetVariableNames().ToList();
     106
    108107      //set scatter plots and histograms
    109108      for (int x = 1; x < variables.Count + 1; x++) {
     
    113112          if (x == y) {
    114113            PreprocessingDataTable dataTable = new PreprocessingDataTable();
    115             DataRow dataRow = logic.CreateDataRow(variables[x - 1], DataRowVisualProperties.DataRowChartType.Histogram);
     114            DataRow dataRow = Content.CreateDataRow(variables[x - 1], DataRowVisualProperties.DataRowChartType.Histogram);
    116115            dataTable.Rows.Add(dataRow);
    117116            PreprocessingDataTableView pcv = new PreprocessingDataTableView();
     
    122121          //scatter plot
    123122          else {
    124             ScatterPlot scatterPlot = logic.CreateScatterPlot(variables[x - 1], variables[y - 1]);
     123            ScatterPlot scatterPlot = Content.CreateScatterPlot(variables[x - 1], variables[y - 1]);
    125124            PreprocessingScatterPlotView pspv = new PreprocessingScatterPlotView();
    126125            pspv.ChartDoubleClick += ScatterPlotDoubleClick;
     
    136135    private void ScatterPlotDoubleClick(object sender, EventArgs e) {
    137136      PreprocessingScatterPlotView pspv = (PreprocessingScatterPlotView)sender;
    138       ScatterPlotContent scatterContent = new ScatterPlotContent(logic);  // create new content
     137      ScatterPlotContent scatterContent = new ScatterPlotContent(Content, new Cloner());  // create new content
    139138      ScatterPlot scatterPlot = pspv.Content;
    140139      setVariablesInContentFromScatterPlot(scatterContent, scatterPlot);
    141140
    142       MainFormManager.MainForm.ShowContent(scatterContent, typeof(SingleScatterPlotView));  // open in new tab
     141      MainFormManager.MainForm.ShowContent(scatterContent, typeof(ScatterPlotSingleView));  // open in new tab
    143142    }
    144143
     
    148147      // only one data row should be in scatter plot
    149148      if (scatterPlot.Rows.Count == 1) {
    150         // TODO -> find better way to get variable names
    151149        string[] variables = scatterPlot.Rows.ElementAt(0).Name.Split(new string[]{" - "},StringSplitOptions.None); // extract variable names from string
    152150        scatterContent.SelectedXVariable = variables[0];
     
    176174    //open histogram in new tab with new content when double clicked
    177175    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);
     176      //PreprocessingDataTableView pcv = (PreprocessingDataTableView)sender;
     177      //HistogramContent histoContent = new HistogramContent(Content,);  // create new content     
     178      //histoContent.VariableItemList = logic.CreateVariableItemList();
     179      //PreprocessingDataTable dataTable = pcv.Content;
     180      //setVariableItemListFromDataTable(histoContent, dataTable);
    183181
    184       MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView));  // open in new tab
     182      //MainFormManager.MainForm.ShowContent(histoContent, typeof(HistogramView));  // open in new tab
    185183    }
    186184   
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.Designer.cs

    r10982 r10987  
    11namespace HeuristicLab.DataPreprocessing.Views {
    2   partial class SingleScatterPlotView {
     2  partial class ScatterPlotSingleView {
    33    /// <summary>
    44    /// Required designer variable.
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.4/ScatterPlotSingleView.cs

    r10982 r10987  
    1818namespace HeuristicLab.DataPreprocessing.Views {
    1919
    20   [View("Single Scatter Plot View")]
     20  [View("Scatter Plot Single View")]
    2121  [Content(typeof(ScatterPlotContent), true)]
    22   public partial class SingleScatterPlotView : ItemView {
     22  public partial class ScatterPlotSingleView : ItemView {
    2323
    24     private IChartLogic logic;
    25 
    26     public SingleScatterPlotView() {
     24    public ScatterPlotSingleView() {
    2725      InitializeComponent();
    2826    }
     
    3533    public void InitData() {
    3634
    37       IEnumerable<string> variables = logic.GetVariableNames();
     35      IEnumerable<string> variables = Content.GetVariableNames();
    3836
    3937      // add variables to combo boxes
     
    6058      base.OnContentChanged();
    6159      if (Content != null) {
    62         logic = Content.ChartLogic;
    6360        InitData();
    6461      }
     
    7269      if (comboBoxXVariable.SelectedItem != null && comboBoxYVariable.SelectedItem != null) {
    7370        //get scatter plot with selected x and y variable
    74         ScatterPlot scatterPlot = logic.CreateScatterPlot((string)comboBoxXVariable.SelectedItem, (string)comboBoxYVariable.SelectedItem);
     71        ScatterPlot scatterPlot = Content.CreateScatterPlot((string)comboBoxXVariable.SelectedItem, (string)comboBoxYVariable.SelectedItem);
    7572        scatterPlotView.Content = scatterPlot;
    7673
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ScatterPlotContent.cs

    r10967 r10987  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Drawing;
     24using HeuristicLab.Analysis;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    2729
    2830  [Item("ScatterPlot", "Represents a scatter plot.")]
    29   public class ScatterPlotContent : PreprocessingChartContent {
     31  public class ScatterPlotContent : Item, IViewChartShortcut {
     32    public static new Image StaticItemImage {
     33      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
     34    }
    3035
    3136    public string SelectedXVariable { get; set; }
    32 
    3337    public string SelectedYVariable { get; set; }
    3438
    35     public ScatterPlotContent(IChartLogic chartlogic)
    36       : base(chartlogic) {
     39    public IPreprocessingContext Context {
     40      get;
     41      private set;
     42    }
     43    public ITransactionalPreprocessingData PreprocessingData {
     44      get { return Context.Data; }
     45    }
     46
     47    public ScatterPlotContent(IPreprocessingContext context)
     48      : base() {
     49      this.Context = context;
    3750    }
    3851
    3952    public ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
    4053      : base(content, cloner) {
    41         this.SelectedXVariable = content.SelectedXVariable;
    42         this.SelectedYVariable = content.SelectedYVariable;
     54      this.Context = content.Context;
     55      this.SelectedXVariable = content.SelectedXVariable;
     56      this.SelectedYVariable = content.SelectedYVariable;
    4357    }
    44 
    45     public static new Image StaticItemImage {
    46       get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
    47     }
    48 
    4958    public override IDeepCloneable Clone(Cloner cloner) {
    5059      return new ScatterPlotContent(this, cloner);
    5160    }
    5261
     62    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     63      int columnIndex = PreprocessingData.GetColumnIndex(variableName);
     64      IList<double> values = PreprocessingData.GetValues<double>(columnIndex);
     65      DataRow row = new DataRow(variableName, "", values);
     66      row.VisualProperties.ChartType = chartType;
     67      return row;
     68    }
     69
     70    public IEnumerable<string> GetVariableNames() {
     71      List<string> doubleVariableNames = new List<string>();
     72
     73      //only return variable names from type double
     74      foreach (string variableName in PreprocessingData.VariableNames) {
     75        if (PreprocessingData.IsType<double>(PreprocessingData.GetColumnIndex(variableName)))
     76          doubleVariableNames.Add(variableName);
     77      }
     78
     79      return doubleVariableNames;
     80    }
     81
     82    public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY) {
     83      ScatterPlot scatterPlot = new ScatterPlot();
     84
     85      int xColumnIndex = PreprocessingData.GetColumnIndex(variableNameX);
     86      int yColumnIndex = PreprocessingData.GetColumnIndex(variableNameY);
     87
     88      IList<double> xValues = PreprocessingData.GetValues<double>(xColumnIndex);
     89      IList<double> yValues = PreprocessingData.GetValues<double>(yColumnIndex);
     90
     91      List<Point2D<double>> points = new List<Point2D<double>>();
     92
     93      for (int i = 0; i < xValues.Count; i++) {
     94        Point2D<double> point = new Point2D<double>(xValues[i], yValues[i]);
     95        points.Add(point);
     96      }
     97
     98      ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
     99      scatterPlot.Rows.Add(scdr);
     100      return scatterPlot;
     101    }
     102
    53103  }
    54104}
Note: See TracChangeset for help on using the changeset viewer.