GovernmentOutcomeChartDataManagerImpl.java

  1. /*
  2.  * Copyright 2010-2025 James Pether Sörling
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *
  16.  *  $Id$
  17.  *  $HeadURL$
  18. */
  19. package com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl;

  20. import java.util.Collections;
  21. import java.util.List;
  22. import java.util.Map;

  23. import org.dussan.vaadin.dcharts.DCharts;
  24. import org.dussan.vaadin.dcharts.base.elements.XYseries;
  25. import org.dussan.vaadin.dcharts.data.DataSeries;
  26. import org.dussan.vaadin.dcharts.options.Series;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.stereotype.Service;

  29. import com.hack23.cia.service.external.esv.api.EsvApi;
  30. import com.hack23.cia.service.external.esv.api.GovernmentOperationPeriodOutcome;
  31. import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.GovernmentOutcomeChartDataManager;
  32. import com.vaadin.ui.AbstractOrderedLayout;

  33. /**
  34.  * The Class GovernmentOutcomeChartDataManagerImpl.
  35.  */
  36. @Service
  37. public final class GovernmentOutcomeChartDataManagerImpl extends AbstractChartDataManagerImpl
  38.         implements GovernmentOutcomeChartDataManager {

  39.     /** The esv api. */
  40.     @Autowired
  41.     private EsvApi esvApi;

  42.     /**
  43.      * Instantiates a new government outcome chart data manager impl.
  44.      */
  45.     public GovernmentOutcomeChartDataManagerImpl() {
  46.         super();
  47.     }

  48.     /**
  49.      * Creates the period data.
  50.      *
  51.      * @param outcomeMap the outcome map
  52.      * @param variables the variables
  53.      * @param chartDataSeries the chart data series
  54.      * @param chartSeries the chart series
  55.      */
  56.     private static void createPeriodData(final Map<String, List<GovernmentOperationPeriodOutcome>> outcomeMap, final GovernmentOperationPeriodOutcome.Variables variables,final DataSeries chartDataSeries,
  57.             final Series chartSeries) {
  58.         chartSeries.addSeries(new XYseries().setLabel(variables.toString()));
  59.         chartDataSeries.newSeries();

  60.         final List<GovernmentOperationPeriodOutcome> list = outcomeMap.get(variables.toString());
  61.         Collections.sort(list);
  62.         for (final GovernmentOperationPeriodOutcome entry : list) {

  63.             chartDataSeries.add(entry.getPeriod() + "-01", entry.getValue());
  64.         }
  65.     }

  66.     /**
  67.      * Creates the government outcome chart.
  68.      *
  69.      * @param layout the layout
  70.      */
  71.     @Override
  72.     public void createGovernmentOutcomeChart(final AbstractOrderedLayout layout) {
  73.         final Map<String, List<GovernmentOperationPeriodOutcome>> outcomeMap = esvApi.getReport();
  74.         final DataSeries chartDataSeries = new DataSeries();
  75.         final Series chartSeries = new Series();

  76.         createPeriodData(outcomeMap,GovernmentOperationPeriodOutcome.Variables.TOTAL_REVENUE, chartDataSeries, chartSeries);
  77.         createPeriodData(outcomeMap,GovernmentOperationPeriodOutcome.Variables.TOTAL_EXPENDITURES, chartDataSeries, chartSeries);

  78.         addChart(layout, "GovernmentOperationPeriodOutcome",
  79.                 new DCharts().setDataSeries(chartDataSeries)
  80.                         .setOptions(getChartOptions().createOptionsXYDateFloatLogYAxisLegendOutside(chartSeries)).show(),
  81.                 true);

  82.     }

  83. }