Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/11/14 15:06:24 (10 years ago)
Author:
rstoll
Message:
  • removed ChartLogic and

moved logic accordingly to PreprocessingChartContent, ScatterPlotContent
modified views etc. to use IFilteredPreprocessingData instead of ChartLogic

  • reordered code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingChartContent.cs

    r10967 r10992  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
    2224using System.Drawing;
     25using HeuristicLab.Analysis;
    2326using HeuristicLab.Common;
    2427using HeuristicLab.Core;
    2528using HeuristicLab.Data;
    26 using System;
    27 using System.Collections.Generic;
     29using HeuristicLab.DataPreprocessing.Interfaces;
    2830
    2931namespace HeuristicLab.DataPreprocessing {
    3032  [Item("PreprocessingChart", "Represents a preprocessing chart.")]
    3133  public class PreprocessingChartContent : Item, IViewChartShortcut {
     34    public static new Image StaticItemImage {
     35      get { return HeuristicLab.Common.Resources.VSImageLibrary.PieChart; }
     36    }
    3237
    3338    private bool allInOneMode = true;
     39    public bool AllInOneMode {
     40      get { return this.allInOneMode; }
     41      set { this.allInOneMode = value; }
     42    }
    3443
    3544    private ICheckedItemList<StringValue> variableItemList = null;
     45    public ICheckedItemList<StringValue> VariableItemList {
     46      get { return this.variableItemList; }
     47      set { this.variableItemList = value; }
     48    }
    3649
     50    public IFilteredPreprocessingData PreprocessingData { get; private set; }
    3751
    38     private readonly IChartLogic chartLogic;
    39 
    40 
    41     public PreprocessingChartContent(IChartLogic chartLogic) {
    42       this.chartLogic = chartLogic;
     52    public PreprocessingChartContent(IFilteredPreprocessingData preprocessingData) {
     53      PreprocessingData = preprocessingData;
    4354    }
    4455
    4556    public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
    4657      : base(content, cloner) {
    47         this.allInOneMode = content.allInOneMode;
    48         this.chartLogic = content.chartLogic;
    49         this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
     58      this.allInOneMode = content.allInOneMode;
     59      this.PreprocessingData = cloner.Clone<IFilteredPreprocessingData>(PreprocessingData);
     60      this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
    5061    }
    51 
    52     public IChartLogic ChartLogic {
    53       get {
    54         return chartLogic;
    55       }
    56     }
    57 
    58     public static new Image StaticItemImage {
    59       get { return HeuristicLab.Common.Resources.VSImageLibrary.PieChart; }
    60     }
    61 
    6262    public override IDeepCloneable Clone(Cloner cloner) {
    6363      return new PreprocessingChartContent(this, cloner);
    6464    }
    6565
    66     public event DataPreprocessingChangedEventHandler Changed {
    67       add { chartLogic.Changed += value; }
    68       remove { chartLogic.Changed -= value; }
     66
     67    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     68      IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
     69      DataRow row = new DataRow(variableName, "", values);
     70      row.VisualProperties.ChartType = chartType;
     71      return row;
    6972    }
    7073
    71     public bool AllInOneMode
    72     {
    73       get { return this.allInOneMode; }
    74       set { this.allInOneMode = value; }
     74    public List<DataRow> CreateAllDataRows(DataRowVisualProperties.DataRowChartType chartType) {
     75      List<DataRow> dataRows = new List<DataRow>();
     76      foreach (var name in PreprocessingData.GetDoubleVariableNames())
     77        dataRows.Add(CreateDataRow(name, chartType));
     78      return dataRows;
    7579    }
    7680
    77     public ICheckedItemList<StringValue> VariableItemList
    78     {
    79       get { return this.variableItemList; }
    80       set { this.variableItemList = value; }
     81    public DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     82
     83      IDictionary<int, IList<int>> selection = PreprocessingData.Selection;
     84      int variableIndex = PreprocessingData.GetColumnIndex(variableName);
     85
     86      if (selection.Keys.Contains(variableIndex)) {
     87        List<int> selectedIndices = new List<int>(selection[variableIndex]);
     88        //need selection with more than 1 value
     89        if (selectedIndices.Count < 2)
     90          return null;
     91
     92        selectedIndices.Sort();
     93        int start = selectedIndices[0];
     94        int end = selectedIndices[selectedIndices.Count - 1];
     95
     96        DataRow rowSelect = CreateDataRowRange(variableName, start, end, chartType);
     97        return rowSelect;
     98      } else
     99        return null;
    81100    }
     101
     102    public DataRow CreateDataRowRange(string variableName, int start, int end, DataRowVisualProperties.DataRowChartType chartType) {
     103      IList<double> values = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableName));
     104      IList<double> valuesRange = new List<double>();
     105      for (int i = 0; i < values.Count; i++) {
     106        if (i >= start && i <= end)
     107          valuesRange.Add(values[i]);
     108        else
     109          valuesRange.Add(Double.NaN);
     110      }
     111
     112      DataRow row = new DataRow(variableName, "", valuesRange);
     113      row.VisualProperties.ChartType = chartType;
     114      return row;
     115    }
     116
     117    public List<DataRow> CreateAllSelectedDataRows(DataRowVisualProperties.DataRowChartType chartType) {
     118      List<DataRow> dataRows = new List<DataRow>();
     119      foreach (var name in PreprocessingData.GetDoubleVariableNames()) {
     120        DataRow row = CreateSelectedDataRow(name, chartType);
     121        if (row != null)
     122          dataRows.Add(row);
     123      }
     124      return dataRows;
     125    }
     126
     127
     128    public ICheckedItemList<StringValue> CreateVariableItemList() {
     129      ICheckedItemList<StringValue> itemList = new CheckedItemList<StringValue>();
     130      foreach (string name in PreprocessingData.GetDoubleVariableNames()) {
     131        itemList.Add(new StringValue(name), true);
     132      }
     133      return new ReadOnlyCheckedItemList<StringValue>(itemList);
     134    }
     135
     136    public event DataPreprocessingChangedEventHandler Changed {
     137      add { PreprocessingData.Changed += value; }
     138      remove { PreprocessingData.Changed -= value; }
     139    }
     140
    82141  }
    83142}
Note: See TracChangeset for help on using the changeset viewer.