public List <GroupedRows> Bin(ColumnViewModel selected, List <Row> rows) { Linear linear = new Linear() { DomainStart = rows.Select(r => (Double)r.Cells[selected.Index].Content).Min(), DomainEnd = rows.Select(r => (Double)r.Cells[selected.Index].Content).Max(), }; linear.Nice(); IEnumerable <Bin> bins = HistogramCalculator.Bin( linear.DomainStart, linear.DomainEnd, linear.Step, rows, selected ); List <GroupedRows> groupedRows = new List <GroupedRows>(); foreach (Bin bin in bins) { GroupedRows grs = new GroupedRows(); grs.Keys[selected] = bin; grs.Rows = bin.Rows.ToList(); groupedRows.Add(grs); } return(groupedRows); }
public void Feed(IEnumerable <Row> rows, ColumnViewModel numerical) { DescriptiveStatisticsViewModel result = DescriptiveStatistics.Analyze( DataContext as MainPageViewModel, rows.Select(r => (Double)r.Cells[numerical.Index].Content) ); HistogramElement.VerticalAxisTitle = Const.Loader.GetString("Frequency"); HistogramElement.Width = this.Width - 20; // (Double)App.Current.Resources["ParagraphWidth"] - 20; HistogramElement.Height = this.Height - 70; BoxPlotElement.Width = this.Width - 90; // (Double)App.Current.Resources["ParagraphWidth"] - 90; BoxPlotElement.Min = result.Min; BoxPlotElement.Max = result.Max; BoxPlotElement.FirstQuartile = result.FirstQuartile; BoxPlotElement.Median = result.Median; BoxPlotElement.ThirdQuartile = result.ThirdQuartile; BoxPlotElement.Mean = result.Mean; BoxPlotElement.Update(); d3.Scale.Linear linear = new d3.Scale.Linear() { DomainStart = result.Min, DomainEnd = result.Max, RangeStart = 0, RangeEnd = 1 }; linear.Nice(); List <Bin> bins = HistogramCalculator.Bin( linear.DomainStart, linear.DomainEnd, linear.Step, rows, numerical ).ToList(); if (numerical.SortOption == SortOption.Descending) { bins = bins.OrderByDescending(b => b.Min).ToList(); } else { bins = bins.OrderBy(b => b.Min).ToList(); } HistogramElement.Data = bins .Select(d => new BarChartDatum() { Key = $"~{Formatter.Auto(d.Max)}", ColumnViewModel = numerical, Value = d.Rows.Count(), EnvelopeValue = d.Rows.Count(), Rows = null, EnvelopeRows = d.Rows }).ToList(); }