View Javadoc
1   /*
2    * Copyright 2014 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  
21  import java.util.List;
22  
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  
30  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotPartySummary;
31  import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenVoteDataBallotSummary;
32  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.BallotChartDataManager;
33  import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.ChartOptions;
34  import com.vaadin.ui.AbstractOrderedLayout;
35  import com.vaadin.ui.TabSheet.Tab;
36  
37  /**
38   * The Class BallotChartDataManagerImpl.
39   */
40  @Service
41  public final class BallotChartDataManagerImpl extends AbstractChartDataManagerImpl implements BallotChartDataManager {
42  
43  	/** The chart options. */
44  	@Autowired
45  	private ChartOptions chartOptions;
46  
47  	/**
48  	 * Instantiates a new ballot chart data manager impl.
49  	 */
50  	public BallotChartDataManagerImpl() {
51  		super();
52  	}
53  
54  
55  	@Override
56  	public void createChart(final Tab tab,final AbstractOrderedLayout content,final ViewRiksdagenVoteDataBallotSummary viewRiksdagenVoteDataBallotSummary) {
57  		final DataSeries dataSeries = new DataSeries();
58  
59  		dataSeries.newSeries().add("Yes", viewRiksdagenVoteDataBallotSummary.getYesVotes());
60  		dataSeries.newSeries().add("No", viewRiksdagenVoteDataBallotSummary.getNoVotes());
61  		dataSeries.newSeries().add("Abstain", viewRiksdagenVoteDataBallotSummary.getAbstainVotes());
62  		dataSeries.newSeries().add("Absent", viewRiksdagenVoteDataBallotSummary.getAbsentVotes());
63  
64  		final String caption = "Summary : " +viewRiksdagenVoteDataBallotSummary.getEmbeddedId().getIssue() + " " + viewRiksdagenVoteDataBallotSummary.getEmbeddedId().getConcern();
65  		tab.setCaption(caption);
66  
67  		addChart(content,caption, new DCharts().setDataSeries(dataSeries).setOptions(chartOptions.createOptionsDonoutChart()).show());
68  	}
69  
70  
71  
72  	@Override
73  	public void createChart(final Tab tab,final AbstractOrderedLayout content,final List<ViewRiksdagenVoteDataBallotPartySummary> partyList) {
74  		final DataSeries dataSeries = new DataSeries();
75  
76  		final Series series = new Series();
77  
78  		series.addSeries(new XYseries().setLabel("Yes"));
79  		series.addSeries(new XYseries().setLabel("No"));
80  		series.addSeries(new XYseries().setLabel("Abstain"));
81  		series.addSeries(new XYseries().setLabel("Absent"));
82  
83  		String caption=null;
84  		for (final ViewRiksdagenVoteDataBallotPartySummary viewRiksdagenVoteDataBallotPartySummary : partyList) {
85  			if (caption == null) {
86  				caption = "Party Summary : " + viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getIssue() + " " + viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getConcern();
87  				content.setCaption(caption);
88  				tab.setCaption(caption);
89  			}
90  
91  			dataSeries.newSeries()
92  			.add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()), viewRiksdagenVoteDataBallotPartySummary.getPartyYesVotes())
93  			.add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()),viewRiksdagenVoteDataBallotPartySummary.getPartyNoVotes())
94  			.add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()),viewRiksdagenVoteDataBallotPartySummary.getPartyAbstainVotes())
95  			.add(getPartyName(viewRiksdagenVoteDataBallotPartySummary.getEmbeddedId().getParty()),viewRiksdagenVoteDataBallotPartySummary.getPartyAbsentVotes());
96  		}
97  
98  
99  		addChart(content,caption + " ( 4 circles Yes/No/Abstain/Absent votes by party )", new DCharts().setDataSeries(dataSeries).setOptions(chartOptions.createOptionsDonoutChartWithSeries(series)).show());
100 	}
101 
102 
103 }