Beispiel #1
0
        //TODO: The GetFullCategoryYearDictionary and GetGoogleChartDataTable functions are probably fine in this Extension class, but the ToGoogleChart functions are more about display and probably could be in a better location
        public static GoogleChartJson ToGoogleChart(this IEnumerable <ProjectGrantAllocationExpenditure> projectGrantAllocationExpenditures,
                                                    Func <ProjectGrantAllocationExpenditure, string> filterFunction,
                                                    List <string> filterValues,
                                                    Func <ProjectGrantAllocationExpenditure, IComparable> sortFunction,
                                                    List <int> rangeOfYears,
                                                    string chartContainerID,
                                                    string chartTitle,
                                                    GoogleChartType googleChartType,
                                                    bool isStacked)
        {
            var fullCategoryYearDictionary = GetFullCategoryYearDictionary(projectGrantAllocationExpenditures, filterFunction, filterValues, sortFunction, rangeOfYears);
            var googleChartDataTable       = GetGoogleChartDataTable(fullCategoryYearDictionary, rangeOfYears, googleChartType);
            var googleChartAxis            = new GoogleChartAxis("Annual Expenditures", MeasurementUnitTypeEnum.Dollars, GoogleChartAxisLabelFormat.Short);
            var googleChartConfiguration   = new GoogleChartConfiguration(chartTitle,
                                                                          isStacked,
                                                                          googleChartType,
                                                                          googleChartDataTable,
                                                                          new GoogleChartAxis(FieldDefinition.ReportingYear.GetFieldDefinitionLabel(), null, null),
                                                                          new List <GoogleChartAxis> {
                googleChartAxis
            });
            var googleChart = new GoogleChartJson(chartTitle, chartContainerID, googleChartConfiguration,
                                                  googleChartType, googleChartDataTable, null);

            return(googleChart);
        }
Beispiel #2
0
        public ViewResult FundingStatus()
        {
            var firmaPage       = FirmaPageTypeEnum.FundingStatusHeader.GetFirmaPage();
            var firmaPageFooter = FirmaPageTypeEnum.FundingStatusFooter.GetFirmaPage();

            // set up Funding Summary pie chart
            var summaryChartTitle       = "NTA Funding Summary";
            var summaryChartContainerID = summaryChartTitle.Replace(" ", "");
            var googlePieChartSlices    = ProjectModelExtensions.GetFundingStatusPieChartSlices();
            var googleChartDataTable    = ProjectModelExtensions.GetFundingStatusSummaryGoogleChartDataTable(googlePieChartSlices);
            var summaryConfiguration    = new GooglePieChartConfiguration(summaryChartTitle, MeasurementUnitTypeEnum.Dollars, googlePieChartSlices, GoogleChartType.PieChart, googleChartDataTable)
            {
                PieSliceText = "value-and-percentage"
            };

            summaryConfiguration.ChartArea.Top = 60;
            var summaryGoogleChart = new GoogleChartJson(summaryChartTitle, summaryChartContainerID, summaryConfiguration,
                                                         GoogleChartType.PieChart, googleChartDataTable, null);

            summaryGoogleChart.CanConfigureChart = false;

            // set up Funding by Owner Org Type column chart
            var statusByOrgTypeChartTitle = "NTA Funding Status by NTA Owner Organization Type";
            var orgTypeChartContainerID   = statusByOrgTypeChartTitle.Replace(" ", "");
            var googleChartAxisHorizontal = new GoogleChartAxis("NTA Organization Type", null, null)
            {
                Gridlines = new GoogleChartGridlinesOptions(-1, "transparent")
            };
            var googleChartAxis          = new GoogleChartAxis("Total Budget", MeasurementUnitTypeEnum.Dollars, GoogleChartAxisLabelFormat.Decimal);
            var googleChartAxisVerticals = new List <GoogleChartAxis> {
                googleChartAxis
            };
            var orgTypeToAmounts            = ProjectModelExtensions.GetFundingForAllProjectsByOwnerOrgType(CurrentFirmaSession);
            var orgTypeGoogleChartDataTable = ProjectModelExtensions.GetFundingStatusByOwnerOrgTypeGoogleChartDataTable(orgTypeToAmounts);
            var orgTypeChartConfig          = new GoogleChartConfiguration(statusByOrgTypeChartTitle, true, GoogleChartType.ColumnChart, orgTypeGoogleChartDataTable, googleChartAxisHorizontal, googleChartAxisVerticals);

            // need to ignore null GoogleChartSeries so the custom colors match up to the column chart correctly
            orgTypeChartConfig.SetSeriesIgnoringNullGoogleChartSeries(orgTypeGoogleChartDataTable);
            orgTypeChartConfig.Tooltip = new GoogleChartTooltip(true);
            orgTypeChartConfig.Legend.SetLegendPosition(GoogleChartLegendPosition.None);
            var orgTypeGoogleChart = new GoogleChartJson(statusByOrgTypeChartTitle, orgTypeChartContainerID, orgTypeChartConfig, GoogleChartType.ColumnChart, orgTypeGoogleChartDataTable, orgTypeToAmounts.Keys.Select(x => x.OrganizationTypeName).ToList());

            orgTypeGoogleChart.CanConfigureChart = false;

            var viewData = new FundingStatusViewData(CurrentFirmaSession, firmaPage, firmaPageFooter, summaryGoogleChart, orgTypeGoogleChart);

            return(RazorView <FundingStatus, FundingStatusViewData>(viewData));
        }
Beispiel #3
0
        public static GoogleChartConfiguration GetDefaultPerformanceMeasureChartConfigurationJson(
            PerformanceMeasure performanceMeasure)
        {
            var googleChartType           = GoogleChartType.ColumnChart;
            var googleChartAxisHorizontal =
                new GoogleChartAxis("Reporting Year", null, null)
            {
                Gridlines = new GoogleChartGridlinesOptions(-1, "transparent")
            };
            var googleChartAxisVerticals = new List <GoogleChartAxis>();
            var defaultSubcategoryChartConfigurationJson = new GoogleChartConfiguration(
                performanceMeasure.PerformanceMeasureDisplayName, true, googleChartType, googleChartAxisHorizontal,
                googleChartAxisVerticals);

            return(defaultSubcategoryChartConfigurationJson);
        }
        public static GoogleChartConfiguration GetTargetsPerformanceMeasureChartConfigurationJson(this PerformanceMeasure performanceMeasure)
        {
            var googleChartType           = GoogleChartType.ColumnChart;
            var googleChartAxisHorizontal =
                new GoogleChartAxis("Year", null, null)
            {
                Gridlines = new GoogleChartGridlinesOptions(-1, "transparent")
            };
            var googleChartAxisVerticals = new List <GoogleChartAxis>();
            var chartSeries = GoogleChartSeries.GetDefaultGoogleChartSeriesForChartsWithTargets();
            var defaultSubcategoryChartConfigurationJson = new GoogleChartConfiguration(
                performanceMeasure.PerformanceMeasureDisplayName, true, googleChartType, googleChartAxisHorizontal,
                googleChartAxisVerticals, "bars", chartSeries);

            return(defaultSubcategoryChartConfigurationJson);
        }
        public static GoogleChartConfiguration GetDefaultPerformanceMeasureChartConfigurationJson(this PerformanceMeasure performanceMeasure)
        {
            //override to catch any config setups for performance measures with targets
            if (performanceMeasure.HasTargets())
            {
                return(GetTargetsPerformanceMeasureChartConfigurationJson(performanceMeasure));
            }
            var googleChartType           = GoogleChartType.ColumnChart;
            var googleChartAxisHorizontal =
                new GoogleChartAxis("Year", null, null)
            {
                Gridlines = new GoogleChartGridlinesOptions(-1, "transparent")
            };
            var googleChartAxisVerticals = new List <GoogleChartAxis>();
            var defaultSubcategoryChartConfigurationJson = new GoogleChartConfiguration(
                performanceMeasure.PerformanceMeasureDisplayName, true, googleChartType, googleChartAxisHorizontal,
                googleChartAxisVerticals);

            return(defaultSubcategoryChartConfigurationJson);
        }
        public ActionResult ResetChartConfiguration(PerformanceMeasurePrimaryKey performanceMeasurePrimaryKey,
                                                    int performanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration chartConfiguration,
                                                    ConfirmDialogFormViewModel viewModel)
        {
            var performanceMeasure = performanceMeasurePrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                SetErrorForDisplay("Error resetting chart configuration.");
                return(ViewResetChartConfiguration(performanceMeasure, viewModel));
            }

            var performanceMeasureSubcategory = performanceMeasure.PerformanceMeasureSubcategories.Single(x =>
                                                                                                          x.PerformanceMeasureSubcategoryID == performanceMeasureSubcategoryID);
            GoogleChartConfiguration defaultSubcategoryChartConfigurationJson =
                performanceMeasure.GetDefaultPerformanceMeasureChartConfigurationJson();

            switch (chartConfiguration)
            {
            case PerformanceMeasureSubcategoryChartConfiguration.ChartConfiguration:
                performanceMeasureSubcategory.ChartConfigurationJson =
                    JObject.FromObject(defaultSubcategoryChartConfigurationJson).ToString();
                performanceMeasureSubcategory.GoogleChartTypeID = GoogleChartType.ColumnChart.GoogleChartTypeID;
                break;

            case PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration:
                performanceMeasureSubcategory.CumulativeChartConfigurationJson =
                    JObject.FromObject(defaultSubcategoryChartConfigurationJson).ToString();
                performanceMeasureSubcategory.CumulativeGoogleChartTypeID =
                    GoogleChartType.ColumnChart.GoogleChartTypeID;
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          $"Invalid PerformanceMeasureSubcategoryChartConfiguration: '{chartConfiguration}'");
            }

            return(new ModalDialogFormJsonResult());
        }
Beispiel #7
0
        public static List <GoogleChartJson> MakeGoogleChartJsons(PerformanceMeasure performanceMeasure, GeospatialArea geospatialArea, List <ProjectPerformanceMeasureReportingPeriodValue> projectPerformanceMeasureReportingPeriodValues)
        {
            var performanceMeasureSubcategoryOptionReportedValues = projectPerformanceMeasureReportingPeriodValues.SelectMany(x => x.PerformanceMeasureSubcategoryOptionReportedValues).GroupBy(x => x.PerformanceMeasureSubcategory);
            // This was changed to only use the performance measure reporting period from the actuals. Requested in PF#1901: https://projects.sitkatech.com/projects/projectfirma/cards/1901
            var performanceMeasureReportingPeriods = performanceMeasure.GetPerformanceMeasureReportingPeriodsFromActuals();
            var googleChartJsons = new List <GoogleChartJson>();

            bool hasTargets = performanceMeasure.HasTargets();
            bool hasGeospatialAreaTargets = false;

            if (geospatialArea != null)
            {
                hasGeospatialAreaTargets = performanceMeasure.GetGeospatialAreaTargetValueType(geospatialArea) != PerformanceMeasureTargetValueType.NoTarget;
            }

            if (performanceMeasureSubcategoryOptionReportedValues.Any())
            {
                foreach (var groupedBySubcategory in performanceMeasureSubcategoryOptionReportedValues.Where(x => x.Key.ShowOnChart()))
                {
                    var performanceMeasureSubcategory = groupedBySubcategory.Key;
                    Check.RequireNotNull(performanceMeasureSubcategory.ChartConfigurationJson, "All PerformanceMeasure Subcategories need to have a Google Chart Configuration Json");
                    var groupedBySubcategoryOption = groupedBySubcategory.GroupBy(c => new Tuple <string, int>(c.ChartName, c.SortOrder)).ToList(); // Item1 is ChartName, Item2 is SortOrder
                    var chartColumns = performanceMeasure.HasRealSubcategories() ? groupedBySubcategoryOption.OrderBy(x => x.Key.Item2).Select(x => x.Key.Item1).ToList() : new List <string> {
                        performanceMeasure.GetDisplayName()
                    };

                    var reverseTooltipOrder = performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ColumnChart || performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ComboChart;

                    var googleChartDataTable = GetGoogleChartDataTableWithReportingPeriodsAsHorizontalAxis(performanceMeasure, performanceMeasureReportingPeriods, hasTargets, hasGeospatialAreaTargets, geospatialArea, groupedBySubcategoryOption, chartColumns, performanceMeasure.IsSummable, reverseTooltipOrder, false);
                    var legendTitle          = performanceMeasure.HasRealSubcategories() ? performanceMeasureSubcategory.PerformanceMeasureSubcategoryDisplayName : performanceMeasure.GetDisplayName();
                    var chartName            = $"{performanceMeasure.GetJavascriptSafeChartUniqueName()}PerformanceMeasureSubcategory{performanceMeasureSubcategory.PerformanceMeasureSubcategoryID}";
                    var saveConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x =>
                                                                                                                 x.SaveChartConfiguration(performanceMeasure,
                                                                                                                                          performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.ChartConfiguration));

                    var resetConfigurationUrl =
                        SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x =>
                                                                                          x.ResetChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.ChartConfiguration));

                    GoogleChartConfiguration chartConfiguration;
                    GoogleChartType          chartType;
                    if (hasGeospatialAreaTargets)
                    {
                        chartConfiguration = JsonConvert.DeserializeObject <GoogleChartConfiguration>(performanceMeasureSubcategory.GeospatialAreaTargetChartConfigurationJson);
                        chartType          = performanceMeasureSubcategory.GeospatialAreaTargetGoogleChartType;
                    }
                    else
                    {
                        chartConfiguration = JsonConvert.DeserializeObject <GoogleChartConfiguration>(performanceMeasureSubcategory.ChartConfigurationJson);
                        chartType          = performanceMeasureSubcategory.GoogleChartType;
                    }
                    if (performanceMeasureSubcategory.PerformanceMeasure.IsSummable)
                    {
                        chartConfiguration.Tooltip = new GoogleChartTooltip(true);
                    }

                    chartConfiguration.Series =
                        GoogleChartSeries.CalculateChartSeriesFromCurrentChartSeries(chartConfiguration.Series,
                                                                                     performanceMeasure, geospatialArea);

                    var googleChartJson = new GoogleChartJson(legendTitle, chartName, chartConfiguration,
                                                              chartType, googleChartDataTable,
                                                              chartColumns, saveConfigurationUrl, resetConfigurationUrl, false);
                    googleChartJsons.Add(googleChartJson);
                }

                // Add Cumulative charts if appropriate
                if (performanceMeasure.CanBeChartedCumulatively)
                {
                    foreach (var groupedBySubcategory in performanceMeasureSubcategoryOptionReportedValues.Where(x => x.Key.ShowOnCumulativeChart()))
                    {
                        var performanceMeasureSubcategory = groupedBySubcategory.Key;
                        var groupedBySubcategoryOption    = groupedBySubcategory.GroupBy(c => new Tuple <string, int>(c.ChartName, c.SortOrder)).ToList(); // Item1 is ChartName, Item2 is SortOrder
                        var chartColumns = performanceMeasure.HasRealSubcategories() ? groupedBySubcategoryOption.OrderBy(x => x.Key.Item2).Select(x => x.Key.Item1).ToList() : new List <string> {
                            performanceMeasure.GetDisplayName()
                        };

                        var reverseTooltipOrder  = performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ColumnChart || performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ComboChart;
                        var googleChartDataTable = GetGoogleChartDataTableWithReportingPeriodsAsHorizontalAxis(performanceMeasure, performanceMeasureReportingPeriods, hasTargets, hasGeospatialAreaTargets, geospatialArea, groupedBySubcategoryOption, chartColumns, performanceMeasure.IsSummable, reverseTooltipOrder, true);
                        var legendTitle          = performanceMeasure.HasRealSubcategories() ? performanceMeasureSubcategory.PerformanceMeasureSubcategoryDisplayName : performanceMeasure.GetDisplayName();
                        var chartName            = $"{performanceMeasure.GetJavascriptSafeChartUniqueName()}PerformanceMeasureSubcategory{performanceMeasureSubcategory.PerformanceMeasureSubcategoryID}Cumulative";
                        var saveConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.SaveChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                        var resetConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.ResetChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                        var chartConfiguration = !string.IsNullOrEmpty(performanceMeasureSubcategory.CumulativeChartConfigurationJson) ? JsonConvert.DeserializeObject <GoogleChartConfiguration>(performanceMeasureSubcategory.CumulativeChartConfigurationJson) : GoogleChartConfiguration.GetGoogleChartConfigurationFromJsonObject(performanceMeasureSubcategory.ChartConfigurationJson);

                        if (performanceMeasureSubcategory.PerformanceMeasure.IsSummable)
                        {
                            chartConfiguration.Tooltip = new GoogleChartTooltip(true);
                        }

                        chartConfiguration.Series =
                            GoogleChartSeries.CalculateChartSeriesFromCurrentChartSeries(chartConfiguration.Series,
                                                                                         performanceMeasure, geospatialArea);

                        var googleChartJson = new GoogleChartJson(legendTitle, chartName, chartConfiguration, performanceMeasureSubcategory.CumulativeGoogleChartType ?? GoogleChartType.ColumnChart, googleChartDataTable, chartColumns, saveConfigurationUrl, resetConfigurationUrl, true);
                        googleChartJsons.Add(googleChartJson);
                    }
                }
            }
            else if (performanceMeasure.HasTargets())
            {
                //build chart for just for targets if there is no project data
                var performanceMeasureSubcategory = performanceMeasure.PerformanceMeasureSubcategories.First();
                var legendTitle        = performanceMeasure.GetDisplayName();
                var chartName          = $"{performanceMeasure.GetJavascriptSafeChartUniqueName()}PerformanceMeasureSubcategory{performanceMeasureSubcategory.PerformanceMeasureSubcategoryID}";
                var chartConfiguration = performanceMeasure.GetDefaultPerformanceMeasureChartConfigurationJson();
                chartConfiguration.Series =
                    GoogleChartSeries.CalculateChartSeriesFromCurrentChartSeries(chartConfiguration.Series,
                                                                                 performanceMeasure, geospatialArea);
                var chartColumns = new List <string> {
                    performanceMeasure.GetDisplayName()
                };
                var reverseTooltipOrder  = performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ColumnChart || performanceMeasureSubcategory.GoogleChartType == GoogleChartType.ComboChart;
                var googleChartDataTable = GetGoogleChartDataTableWithReportingPeriodsAsHorizontalAxis(performanceMeasure, performanceMeasureReportingPeriods, true, false, null, new List <IGrouping <Tuple <string, int>, PerformanceMeasureReportingPeriodSubcategoryOptionReportedValue> >(), chartColumns, false, reverseTooltipOrder, false);
                var saveConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.SaveChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                var resetConfigurationUrl = SitkaRoute <PerformanceMeasureController> .BuildUrlFromExpression(x => x.ResetChartConfiguration(performanceMeasure, performanceMeasureSubcategory.PerformanceMeasureSubcategoryID, PerformanceMeasureSubcategoryChartConfiguration.CumulativeConfiguration));

                var googleChartJson = new GoogleChartJson(legendTitle, chartName, chartConfiguration, GoogleChartType.LineChart, googleChartDataTable, chartColumns, saveConfigurationUrl, resetConfigurationUrl, false);
                googleChartJsons.Add(googleChartJson);
            }

            return(googleChartJsons);
        }