private static GoogleChartDataTable GetGoogleChartDataTable(Dictionary <string, Dictionary <int, decimal> > fullCategoryYearDictionary, List <int> rangeOfYears, GoogleChartType columnDisplayType) { var googleChartRowCs = new List <GoogleChartRowC>(); var sortedYearCategoryDictionary = fullCategoryYearDictionary.OrderBy(x => x.Value.Sum(y => y.Value)).ThenBy(x => x.Key).ToList(); foreach (var year in rangeOfYears.OrderBy(x => x)) { var googleChartRowVs = new List <GoogleChartRowV> { new GoogleChartRowV(year, year.ToString()) }; googleChartRowVs.AddRange( sortedYearCategoryDictionary .Select(x => x.Key) .Select(category => fullCategoryYearDictionary[category][year]) .Select(value => new GoogleChartRowV(value, GoogleChartJson.GetFormattedValue((double)value, MeasurementUnitType.Dollars)))); googleChartRowCs.Add(new GoogleChartRowC(googleChartRowVs)); } var columnLabel = FieldDefinition.ReportingYear.GetFieldDefinitionLabel(); var googleChartColumns = new List <GoogleChartColumn> { new GoogleChartColumn(columnLabel, columnLabel, "string") }; googleChartColumns.AddRange( sortedYearCategoryDictionary.Select( x => new GoogleChartColumn(x.Key, x.Key, "number", new GoogleChartSeries(columnDisplayType, GoogleChartAxisType.Primary), null, null))); return(new GoogleChartDataTable(googleChartColumns, googleChartRowCs)); }
public static GoogleChartDataTable GetGoogleChartDataTableWithReportingPeriodsAsHorixontalAxis(PerformanceMeasure performanceMeasure, ICollection <PerformanceMeasureReportingPeriod> performanceMeasureReportingPeriods, bool hasTargets, IReadOnlyCollection <IGrouping <Tuple <string, int>, PerformanceMeasureReportingPeriodSubcategoryOptionReportedValue> > groupedBySubcategoryOption, IEnumerable <string> subcategoryOptions, bool hasToolTipWithTotal) { var googleChartRowCs = new List <GoogleChartRowC>(); foreach (var performanceMeasureReportingPeriod in performanceMeasureReportingPeriods.OrderBy(x => x.PerformanceMeasureReportingPeriodBeginDate)) { var googleChartRowVs = new List <GoogleChartRowV> { new GoogleChartRowV(performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodLabel) }; if (hasTargets) { googleChartRowVs.Add(new GoogleChartRowV(performanceMeasureReportingPeriod.TargetValue, GetFormattedTargetValue(performanceMeasureReportingPeriod, performanceMeasure))); } if (hasToolTipWithTotal) { googleChartRowVs.Add(new GoogleChartRowV(null, FormattedDataTooltip(groupedBySubcategoryOption, performanceMeasureReportingPeriod, performanceMeasure.MeasurementUnitType))); } googleChartRowVs.AddRange(groupedBySubcategoryOption.OrderBy(x => x.Key.Item2).Select(x => { var calendarYearReportedValue = x.Where(isorv => isorv.PerformanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodLabel == performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodLabel) .Sum(isorv => isorv.ReportedValue) ?? 0; return(new GoogleChartRowV(calendarYearReportedValue, GoogleChartJson.GetFormattedValue(calendarYearReportedValue, performanceMeasure.MeasurementUnitType))); })); googleChartRowCs.Add(new GoogleChartRowC(googleChartRowVs)); } // reporting period is going to be the first column and it will be our horizontal axis var googleChartColumns = new List <GoogleChartColumn> { new GoogleChartColumn("Reporting Period", GoogleChartColumnDataType.String) }; if (hasTargets) { // GoogleChartType for targets is always LINE; we also always render the target line first to stay consistent googleChartColumns.Add(new GoogleChartColumn(GetTargetColumnLabel(performanceMeasureReportingPeriods), GoogleChartColumnDataType.Number)); } // add column with row tooltip if (hasToolTipWithTotal) { googleChartColumns.Add(new GoogleChartColumn(GoogleChartColumnDataType.String.ColumnDataType, "tooltip", new GoogleChartProperty())); } // all the subcategory option values are individual columns and series and they will be on the vertical axis googleChartColumns.AddRange(subcategoryOptions.Select(x => new GoogleChartColumn(x, GoogleChartColumnDataType.Number))); var googleChartDataTable = new GoogleChartDataTable(googleChartColumns, googleChartRowCs); return(googleChartDataTable); }
private static string GetFormattedGeospatialAreaTargetValue(PerformanceMeasureReportingPeriod performanceMeasureReportingPeriod, PerformanceMeasure performanceMeasure, GeospatialArea geospatialArea) { return($"{GoogleChartJson.GetFormattedValue(performanceMeasureReportingPeriod.GetGeospatialAreaTargetValue(performanceMeasure, geospatialArea), performanceMeasure.MeasurementUnitType)} ({performanceMeasureReportingPeriod.GetGeospatialAreaTargetValueLabel(performanceMeasure, geospatialArea)})"); }
public static GoogleChartDataTable GetGoogleChartDataTableWithReportingPeriodsAsHorizontalAxis(PerformanceMeasure performanceMeasure, ICollection <PerformanceMeasureReportingPeriod> performanceMeasureReportingPeriods, bool hasTargets, bool hasGeospatialAreaTargets, GeospatialArea geospatialArea, IReadOnlyCollection <IGrouping <Tuple <string, int>, PerformanceMeasureReportingPeriodSubcategoryOptionReportedValue> > groupedBySubcategoryOption, IEnumerable <string> chartColumns, bool hasToolTipWithTotal, bool reverseTooltipOrder, bool showCumulativeResults) { var googleChartRowCs = new List <GoogleChartRowC>(); foreach (var performanceMeasureReportingPeriod in performanceMeasureReportingPeriods.OrderBy(x => x.PerformanceMeasureReportingPeriodCalendarYear)) { var googleChartRowVs = new List <GoogleChartRowV> { new GoogleChartRowV(performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodLabel) }; var firstReportingPeriod = performanceMeasureReportingPeriods.OrderBy(x => x.PerformanceMeasureReportingPeriodCalendarYear).First(); var targetValue = performanceMeasureReportingPeriod.GetTargetValue(performanceMeasure); var geospatialAreaTargetValue = hasGeospatialAreaTargets ? performanceMeasureReportingPeriod.GetGeospatialAreaTargetValue(performanceMeasure, geospatialArea) : null; if (hasToolTipWithTotal) { var targetValueDescription = performanceMeasureReportingPeriod.GetTargetValueLabel(performanceMeasure); var geospatialAreaTargetValueDescription = hasGeospatialAreaTargets ? performanceMeasureReportingPeriod.GetGeospatialAreaTargetValueLabel(performanceMeasure, geospatialArea) : string.Empty; var formattedDataTooltip = FormattedDataTooltip(groupedBySubcategoryOption, performanceMeasureReportingPeriod, performanceMeasure.MeasurementUnitType, reverseTooltipOrder, targetValue, targetValueDescription, geospatialAreaTargetValue, geospatialAreaTargetValueDescription, showCumulativeResults, firstReportingPeriod); googleChartRowVs.Add(new GoogleChartRowV(null, formattedDataTooltip)); } if (hasTargets) { googleChartRowVs.Add(new GoogleChartRowV(targetValue, GetFormattedTargetValue(performanceMeasureReportingPeriod, performanceMeasure))); } if (hasGeospatialAreaTargets) { googleChartRowVs.Add(new GoogleChartRowV(geospatialAreaTargetValue, GetFormattedGeospatialAreaTargetValue(performanceMeasureReportingPeriod, performanceMeasure, geospatialArea))); } googleChartRowVs.AddRange(groupedBySubcategoryOption.OrderBy(x => x.Key.Item2).Select(x => { double calendarYearReportedValue; if (showCumulativeResults) { calendarYearReportedValue = x.Where(pmsorv => pmsorv.PerformanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodCalendarYear <= performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodCalendarYear) .Sum(pmsorv => pmsorv.ReportedValue) ?? 0; } else { calendarYearReportedValue = x.Where(pmsorv => pmsorv.PerformanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodCalendarYear == performanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodCalendarYear) .Sum(pmsorv => pmsorv.ReportedValue) ?? 0; } return(new GoogleChartRowV(calendarYearReportedValue, GoogleChartJson.GetFormattedValue(calendarYearReportedValue, performanceMeasure.MeasurementUnitType))); })); googleChartRowCs.Add(new GoogleChartRowC(googleChartRowVs)); } // reporting period is going to be the first column and it will be our horizontal axis var googleChartColumns = new List <GoogleChartColumn> { new GoogleChartColumn("Reporting Period", GoogleChartColumnDataType.String) }; // add column with row tooltip if (hasToolTipWithTotal) { googleChartColumns.Add(new GoogleChartColumn(GoogleChartColumnDataType.String.ColumnDataType, "tooltip", new GoogleChartProperty())); } if (hasTargets) { // GoogleChartType for targets is always LINE; we also always render the target line first to stay consistent googleChartColumns.Add(new GoogleChartColumn(GetTargetColumnLabel(performanceMeasure), GoogleChartColumnDataType.Number)); } if (hasGeospatialAreaTargets) { // GoogleChartType for targets is always LINE; we also always render the target line first to stay consistent googleChartColumns.Add(new GoogleChartColumn(GetGeospatialAreaTargetColumnLabel(performanceMeasure, geospatialArea), GoogleChartColumnDataType.Number)); } // all the subcategory option values are individual columns and series and they will be on the vertical axis googleChartColumns.AddRange(chartColumns.Select(x => new GoogleChartColumn(x, GoogleChartColumnDataType.Number))); var googleChartDataTable = new GoogleChartDataTable(googleChartColumns, googleChartRowCs); return(googleChartDataTable); }
private static string GetFormattedTargetValue(PerformanceMeasureReportingPeriod performanceMeasureReportingPeriod, PerformanceMeasure performanceMeasure) { return($"{GoogleChartJson.GetFormattedValue(performanceMeasureReportingPeriod.TargetValue, performanceMeasure.MeasurementUnitType)} ({performanceMeasureReportingPeriod.TargetValueDescription})"); }
private static GoogleChartDataTable GetGoogleChartDataTableWithReportingPeriodsAsVerticalAxis(PerformanceMeasure performanceMeasure, bool hasTargets, ICollection <PerformanceMeasureReportingPeriod> performanceMeasureReportingPeriods, IEnumerable <IGrouping <Tuple <string, int>, PerformanceMeasureReportingPeriodSubcategoryOptionReportedValue> > groupedBySubcategoryOption) { var googleChartRowCs = new List <GoogleChartRowC>(); var targetRowVs = new List <GoogleChartRowV>(); if (hasTargets) { targetRowVs.Add(new GoogleChartRowV(GetTargetColumnLabel(performanceMeasureReportingPeriods))); targetRowVs.AddRange(performanceMeasureReportingPeriods.OrderBy(x => x.PerformanceMeasureReportingPeriodBeginDate) .Select(x => new GoogleChartRowV(x.TargetValue, GetFormattedTargetValue(x, performanceMeasure)))); googleChartRowCs.Add(new GoogleChartRowC(targetRowVs)); } foreach (var performanceMeasureSubcategoryOption in groupedBySubcategoryOption.OrderBy(x => x.Key.Item2)) { var googleChartRowVs = new List <GoogleChartRowV> { new GoogleChartRowV(performanceMeasureSubcategoryOption.Key.Item1) }; googleChartRowVs.AddRange(performanceMeasureSubcategoryOption.OrderBy(x => x.PerformanceMeasureReportingPeriod.PerformanceMeasureReportingPeriodBeginDate).Select(irviso => new GoogleChartRowV(irviso.ReportedValue, GoogleChartJson.GetFormattedValue(irviso.ReportedValue, performanceMeasure.MeasurementUnitType)))); googleChartRowCs.Add(new GoogleChartRowC(googleChartRowVs)); } var googleChartColumns = new List <GoogleChartColumn> { new GoogleChartColumn(performanceMeasure.DisplayName, GoogleChartColumnDataType.String) }; googleChartColumns.AddRange(performanceMeasureReportingPeriods.OrderBy(x => x.PerformanceMeasureReportingPeriodBeginDate).Select(x => new GoogleChartColumn(x.PerformanceMeasureReportingPeriodID.ToString(), x.PerformanceMeasureReportingPeriodLabel, GoogleChartColumnDataType.Number.ColumnDataType))); var googleChartDataTable = new GoogleChartDataTable(googleChartColumns, googleChartRowCs); return(googleChartDataTable); }