Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/07/17 16:55:03 (7 years ago)
Author:
mkommend
Message:

#2709: Added grouping for multi scatter plot view.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/HistogramContent.cs

    r14581 r14725  
    2020#endregion
    2121
     22using System;
    2223using System.Drawing;
     24using System.Linq;
     25using HeuristicLab.Analysis;
    2326using HeuristicLab.Common;
    2427using HeuristicLab.Core;
     
    4952    }
    5053
     54    public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataRowVisualProperties.DataRowHistogramAggregation aggregation) {
     55      {
     56        var dataTable = new DataTable();
     57
     58        if (string.IsNullOrEmpty(groupingVariableName)) {
     59          var row = PreprocessingChartContent.CreateDataRow(preprocessingData, variableName, DataRowVisualProperties.DataRowChartType.Histogram);
     60          dataTable.Rows.Add(row);
     61          return dataTable;
     62        }
     63
     64        dataTable.VisualProperties.Title = variableName;
     65
     66        int variableIndex = preprocessingData.GetColumnIndex(variableName);
     67        var variableValues = preprocessingData.GetValues<double>(variableIndex);
     68        int groupVariableIndex = preprocessingData.GetColumnIndex(groupingVariableName);
     69        var groupingValues = Enumerable.Empty<string>();
     70
     71        if (preprocessingData.VariableHasType<double>(groupVariableIndex)) {
     72          groupingValues = preprocessingData.GetValues<double>(groupVariableIndex).Select(x => x.ToString());
     73        } else if (preprocessingData.VariableHasType<string>(groupVariableIndex)) {
     74          groupingValues = preprocessingData.GetValues<string>(groupVariableIndex);
     75        } else if (preprocessingData.VariableHasType<DateTime>(groupVariableIndex)) {
     76          groupingValues = preprocessingData.GetValues<DateTime>(groupVariableIndex).Select(x => x.ToString());
     77        }
     78
     79        var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);
     80
     81        foreach (var group in groups) {
     82          var classRow = new DataRow();
     83          classRow.Name = group.Key;
     84          classRow.VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Histogram;
     85          classRow.VisualProperties.Aggregation = aggregation;
     86          classRow.Values.AddRange(group);
     87          dataTable.Rows.Add(classRow);
     88        }
     89        return dataTable;
     90      }
     91    }
     92
    5193
    5294  }
Note: See TracChangeset for help on using the changeset viewer.