Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10847


Ignore:
Timestamp:
05/14/14 13:37:28 (11 years ago)
Author:
aesterer
Message:

Added coloring feature for line chart

Location:
branches/DataPreprocessing
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/PreprocessingChartView.cs

    r10818 r10847  
    4242    private List<PreprocessingDataTable> dataTablePerVariable;
    4343    private List<DataRow> dataRows;
     44    private List<DataRow> selectedDataRows;
    4445
    4546    protected DataRowVisualProperties.DataRowChartType chartType;
     
    5859      foreach (IndexedItem<StringValue> item in checkedItems.Items) {
    5960        string variableName = item.Value.Value;
     61
     62        //variable is displayed -> remove
    6063        if (VariableIsDisplayed(variableName)) {
    6164          dataTable.Rows.Remove(variableName);
     65          dataTable.SelectedRows.Remove(variableName);
    6266          dataTablePerVariable.Remove(dataTablePerVariable.Find(x => (x.Name == variableName)));
     67        //variable isnt't displayed -> add
    6368        } else {
    6469          DataRow row = GetDataRow(variableName);
     70          DataRow selectedRow = GetSelectedDataRow(variableName);
    6571          dataTable.Rows.Add(row);
    6672          PreprocessingDataTable d = new PreprocessingDataTable(variableName);
    6773          d.Rows.Add(row);
    6874          dataTablePerVariable.Add(d);
     75          if (selectedRow != null)
     76          {
     77            dataTable.SelectedRows.Add(selectedRow);
     78            d.SelectedRows.Add(selectedRow);
    6979        }
     80      }
    7081      }
    7182
     
    8899      base.RegisterContentEvents();
    89100      Content.ChartLogic.Changed += PreprocessingData_Changed;
     101      Content.ChartLogic.SelectionChanged += PreprocessingData_SelctionChanged;
    90102
    91103    }
     
    94106      base.DeregisterContentEvents();
    95107      Content.ChartLogic.Changed -= PreprocessingData_Changed;
     108      Content.ChartLogic.SelectionChanged -= PreprocessingData_SelctionChanged;
    96109    }
    97110
     
    109122      dataRows = logic.CreateAllDataRows(chartType);
    110123
    111       // init data table
    112124      dataTable = new PreprocessingDataTable(chartTitle);
    113       dataTable.Rows.AddRange(dataRows);
    114 
    115 
    116       // init data table per variable
    117125      dataTablePerVariable = new List<PreprocessingDataTable>();
     126
     127      //add data rows to data tables according to checked item list
    118128      foreach (var checkedItem in Content.VariableItemList.CheckedItems)
    119129      {
     
    121131        PreprocessingDataTable d = new PreprocessingDataTable(variableName);
    122132        DataRow row = GetDataRow(variableName);
    123         //DataRow rowSelect = logic.CreateDataRowRange(variableName, 200, 400, chartType);
    124         //rowSelect.Name = variableName + "(Selected)";
    125         //rowSelect.VisualProperties.Color = Color.Green;
    126 
     133
     134        //add row to data table
     135        dataTable.Rows.Add(row);
     136
     137        //add row to data table per variable
    127138        d.Rows.Add(row);
    128         //d.SelectedRows.Add(rowSelect);
    129 
    130139        dataTablePerVariable.Add(d);
    131 
    132       }
     140      }
     141
     142      UpdateSelection();
     143    }
     144
     145    private void UpdateSelection() {
     146
     147      //update data table selection
     148      selectedDataRows = logic.CreateAllSelectedDataRows(chartType);
     149      dataTable.SelectedRows.Clear();
     150      dataTable.SelectedRows.AddRange(selectedDataRows);
     151
     152      //update data table per variable selection
     153      foreach (PreprocessingDataTable d in dataTablePerVariable) {
     154        d.SelectedRows.Clear();
     155        DataRow row = selectedDataRows.Find(x => x.Name == d.Name);
     156        if (row != null)
     157          d.SelectedRows.Add(row);
     158      }
     159
     160    }
     161
     162    private DataRow GetSelectedDataRow(string variableName) {
     163      foreach (DataRow row in selectedDataRows) {
     164        if (row.Name == variableName)
     165          return row;
     166      }
     167      return null;
    133168    }
    134169
     
    168203        case DataPreprocessingChangedEventType.Any:
    169204        default:
     205           //TODO: test with transform
    170206          InitData();
    171207          GenerateChart();
    172208          break;
    173209      }
     210    }
     211
     212    private void PreprocessingData_SelctionChanged(object sender, EventArgs e) {
     213      UpdateSelection();
    174214    }
    175215
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing.Views/3.3/PreprocessingDataTableView.cs

    r10804 r10847  
    6060      Content.Rows.ItemsReplaced -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced);
    6161      Content.Rows.CollectionReset -= new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset);
     62
     63      Content.SelectedRows.ItemsAdded -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded);
     64      Content.SelectedRows.ItemsRemoved -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved);
     65      Content.SelectedRows.ItemsReplaced -= new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced);
     66      Content.SelectedRows.CollectionReset -= new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset);
    6267      base.DeregisterContentEvents();
    6368    }
     
    6974      Content.Rows.ItemsReplaced += new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced);
    7075      Content.Rows.CollectionReset += new CollectionItemsChangedEventHandler<DataRow>(Rows_CollectionReset);
    71     }
     76
     77      Content.SelectedRows.ItemsAdded += new CollectionItemsChangedEventHandler<DataRow>(SelectedRows_ItemsAdded);
     78      Content.SelectedRows.ItemsRemoved += new CollectionItemsChangedEventHandler<DataRow>(SelectedRows_ItemsRemoved);
     79      Content.SelectedRows.ItemsReplaced += new CollectionItemsChangedEventHandler<DataRow>(SelectedRows_ItemsReplaced);
     80      Content.SelectedRows.CollectionReset += new CollectionItemsChangedEventHandler<DataRow>(SelectedRows_CollectionReset);
     81    }
     82
    7283
    7384    protected virtual void RegisterDataRowEvents(DataRow row) {
     
    141152      foreach (var row in rows) {
    142153        if (row.VisualProperties.ChartType == DataRowVisualProperties.DataRowChartType.Line) {
    143           //RegisterDataRowEvents(row);
    144154          row.VisualProperties.IsVisibleInLegend = false;
    145           var series = new Series(row.Name);
     155
     156          //add selected to name in order to avoid naming conflict
     157          var series = new Series(row.Name+"(Selected)");
    146158          ConfigureSeries(series, row);
    147159          FillSeriesWithRowValues(series, row);
    148160          chart.Series.Add(series);
    149161        }
     162      }
     163    }
     164
     165    protected virtual void RemoveSelectedDataRows(IEnumerable<DataRow> rows) {
     166      foreach (var row in rows) {
     167        Series series = chart.Series[row.Name + "(Selected)"];
     168        chart.Series.Remove(series);
    150169      }
    151170    }
     
    307326    #endregion
    308327    #region Rows Event Handlers
     328
     329    private void SelectedRows_CollectionReset(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     330      if (InvokeRequired)
     331        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced), sender, e);
     332      else {
     333        RemoveSelectedDataRows(e.OldItems);
     334        AddSelectedDataRows(e.Items);
     335      }
     336    }
     337
     338    private void SelectedRows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     339      if (InvokeRequired)
     340        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsReplaced), sender, e);
     341      else {
     342        RemoveSelectedDataRows(e.OldItems);
     343        AddSelectedDataRows(e.Items);
     344      }
     345    }
     346
     347    private void SelectedRows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     348      if (InvokeRequired)
     349        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsRemoved), sender, e);
     350      else {
     351        RemoveSelectedDataRows(e.Items);
     352      }
     353    }
     354
     355    private void SelectedRows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
     356      if (InvokeRequired)
     357        Invoke(new CollectionItemsChangedEventHandler<DataRow>(Rows_ItemsAdded), sender, e);
     358      else {
     359        AddSelectedDataRows(e.Items);
     360      }
     361    }
     362
     363
    309364    private void Rows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<DataRow> e) {
    310365      if (InvokeRequired)
     
    570625      }
    571626
     627
    572628      if (!row.VisualProperties.ExactBins) {
    573629        intervalWidth = HumanRoundRange(intervalWidth);
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/ChartLogic.cs

    r10811 r10847  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Drawing;
    2425using HeuristicLab.Analysis;
    2526using HeuristicLab.Core;
     
    3536      this.preprocessingData = preprocessingData;
    3637    }
     38
     39    #region IChartLogic Members
    3740
    3841    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     
    9295    }
    9396
     97    public event EventHandler SelectionChanged {
     98      add { preprocessingData.SelectionChanged += value; }
     99      remove { preprocessingData.SelectionChanged -= value; }
     100    }
     101
    94102    public string GetVariableNameByIndex(int index) {
    95103      return preprocessingData.GetVariableName(index);
     
    104112    }
    105113
     114    public List<DataRow> CreateAllSelectedDataRows(DataRowVisualProperties.DataRowChartType chartType) {
     115      List<DataRow> dataRows = new List<DataRow>();
     116      foreach (var name in GetVariableNames()) {
     117        DataRow row = CreateSelectedDataRow(name, chartType);
     118        if(row != null)
     119          dataRows.Add(row);
     120      }
     121      return dataRows;
     122    }
     123
     124    public DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     125     
     126      IDictionary<int,IList<int>> selection = preprocessingData.GetSelection();
     127      int variableIndex = preprocessingData.GetColumnIndex(variableName);
     128
     129      if (selection.Keys.Contains(variableIndex))
     130      {
     131        List<int> selectedIndices = new List<int>(selection[variableIndex]);
     132        //need selection with more than 1 value
     133        if(selectedIndices.Count < 2)
     134          return null;
     135
     136        int end = selectedIndices[0];      // indices are provided in reverse order
     137        int start = selectedIndices[selectedIndices.Count-1];
     138
     139        DataRow rowSelect = CreateDataRowRange(variableName, start, end, chartType);
     140        rowSelect.VisualProperties.Color = Color.Green;
     141        return rowSelect;
     142      }
     143      else
     144       return null;
     145    }
     146
     147    #endregion
    106148  }
    107149}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/FilteredPreprocessingData.cs

    r10810 r10847  
    186186    }
    187187
    188     public event EventHandler SelectionChanged;
     188    public event EventHandler SelectionChanged {
     189      add { originalData.SelectionChanged += value; }
     190      remove { originalData.SelectionChanged -= value; }
     191    }
    189192
    190193    #endregion
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingDataTable.cs

    r10803 r10847  
    44using System.Text;
    55using HeuristicLab.Analysis;
     6using HeuristicLab.Collections;
    67using HeuristicLab.Core;
    78
     
    2627        if (selectedRows != null) throw new InvalidOperationException("Rows already set");
    2728        selectedRows = value;
    28         //if (selectedRows != null) RegisterRowsEvents();
     29        //if (selectedRows != null) RegisterSelectedRowEvents();
    2930      }
    3031    }
    3132
    32 
    33 
    3433  }
    3534}
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IChartLogic.cs

    r10803 r10847  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using HeuristicLab.Analysis;
     
    3233    event DataPreprocessingChangedEventHandler Changed;
    3334
     35    event EventHandler SelectionChanged;
     36
    3437    ICheckedItemList<StringValue> CreateVariableItemList();
     38
     39    List<DataRow> CreateAllSelectedDataRows(DataRowVisualProperties.DataRowChartType chartType);
     40
     41    DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType);
    3542
    3643    DataRow CreateDataRow(string variableName,DataRowVisualProperties.DataRowChartType chartType);
Note: See TracChangeset for help on using the changeset viewer.