Beispiel #1
0
 public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
     : base(content, cloner)
 {
     this.allInOneMode      = content.allInOneMode;
     this.PreprocessingData = content.PreprocessingData;
     this.variableItemList  = cloner.Clone <ICheckedItemList <StringValue> >(variableItemList);
 }
        public static DataTable CreateHistogram(IFilteredPreprocessingData preprocessingData, string variableName, string groupingVariableName, DataTableVisualProperties.DataTableHistogramAggregation aggregation, LegendOrder legendOrder = LegendOrder.Alphabetically)
        {
            var dataTable = new DataTable {
                VisualProperties = { Title = variableName, HistogramAggregation = aggregation },
            };

            if (string.IsNullOrEmpty(groupingVariableName))
            {
                var row = PreprocessingChartContent.CreateDataRow(preprocessingData, variableName, DataRowVisualProperties.DataRowChartType.Histogram);
                row.VisualProperties.IsVisibleInLegend = false;
                dataTable.Rows.Add(row);
                return(dataTable);
            }

            int variableIndex      = preprocessingData.GetColumnIndex(variableName);
            var variableValues     = preprocessingData.GetValues <double>(variableIndex);
            int groupVariableIndex = preprocessingData.GetColumnIndex(groupingVariableName);
            var groupingValues     = Enumerable.Empty <string>();

            if (preprocessingData.VariableHasType <double>(groupVariableIndex))
            {
                groupingValues = preprocessingData.GetValues <double>(groupVariableIndex).Select(x => x.ToString());
            }
            else if (preprocessingData.VariableHasType <string>(groupVariableIndex))
            {
                groupingValues = preprocessingData.GetValues <string>(groupVariableIndex);
            }
            else if (preprocessingData.VariableHasType <DateTime>(groupVariableIndex))
            {
                groupingValues = preprocessingData.GetValues <DateTime>(groupVariableIndex).Select(x => x.ToString());
            }

            var groups = groupingValues.Zip(variableValues, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);

            if (legendOrder == LegendOrder.Alphabetically)
            {
                groups = groups.OrderBy(x => x.Key, new NaturalStringComparer());
            }

            foreach (var group in groups)
            {
                var classRow = new DataRow {
                    Name             = group.Key,
                    VisualProperties =
                    {
                        ChartType         = DataRowVisualProperties.DataRowChartType.Histogram,
                        IsVisibleInLegend = !string.IsNullOrEmpty(groupingVariableName)
                    }
                };
                classRow.Values.AddRange(group);
                dataTable.Rows.Add(classRow);
            }
            return(dataTable);
        }
 public PreprocessingChartContent(PreprocessingChartContent original, Cloner cloner)
     : base(original, cloner)
 {
     variableItemList = cloner.Clone(original.variableItemList);
 }
 public PreprocessingChartContent(PreprocessingChartContent content, Cloner cloner)
   : base(content, cloner) {
   this.allInOneMode = content.allInOneMode;
   this.PreprocessingData = content.PreprocessingData;
   this.variableItemList = cloner.Clone<ICheckedItemList<StringValue>>(variableItemList);
 }