View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.chart.time;
2   
3   /*
4    * Copyright 2007 David Vicente
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.text.NumberFormat;
20  import java.util.Date;
21  import java.util.Iterator;
22  import java.util.List;
23  import java.util.Locale;
24  import java.util.ResourceBundle;
25  
26  import org.codehaus.mojo.dashboard.report.plugin.beans.CloverReportBean;
27  import org.jfree.chart.axis.NumberAxis;
28  import org.jfree.chart.labels.StandardXYItemLabelGenerator;
29  import org.jfree.chart.labels.XYItemLabelGenerator;
30  import org.jfree.data.time.TimeSeries;
31  
32  public class CloverTimeChartStrategy extends AbstractTimeChartStrategy
33  {
34  
35      public CloverTimeChartStrategy( ResourceBundle bundle, String title, List results, String timeUnit, Date startDate,
36                                      Date endDate )
37      {
38          super( bundle, title, results, timeUnit, startDate, endDate );
39      }
40  
41      public void fillDataset()
42      {
43          TimeSeries s1 = new TimeSeries( this.bundle.getString( "report.clover.label.total" ), this.periodClass );
44          TimeSeries s2 = new TimeSeries( this.bundle.getString( "report.clover.label.conditionals" ), this.periodClass );
45          TimeSeries s3 = new TimeSeries( this.bundle.getString( "report.clover.label.statements" ), this.periodClass );
46          TimeSeries s4 = new TimeSeries( this.bundle.getString( "report.clover.label.methods" ), this.periodClass );
47          Iterator iter = mResults.iterator();
48          while ( iter.hasNext() )
49          {
50  
51              CloverReportBean clover = (CloverReportBean) iter.next();
52              Date date = clover.getDateGeneration();
53              int total = clover.getElements();
54              int covered = clover.getCoveredElements();
55              s1.addOrUpdate( getChartDate( this.timePeriod.normalize( date ) ),  ( covered / (double) total ) );
56              
57              int totalCond = clover.getConditionals();
58              int coveredCond = clover.getCoveredConditionals();
59              s2.addOrUpdate( getChartDate( this.timePeriod.normalize( date ) ), ( coveredCond / (double) totalCond ) );
60              
61              int totalStat = clover.getStatements();
62              int coveredStat = clover.getCoveredStatements();
63              s3.addOrUpdate( getChartDate( this.timePeriod.normalize( date ) ), ( coveredStat / (double) totalStat ) );
64              
65              int totalMeth = clover.getMethods();
66              int coveredMeth = clover.getCoveredMethods();
67              s4.addOrUpdate( getChartDate( this.timePeriod.normalize( date ) ), ( coveredMeth / (double) totalMeth ) );
68              
69          }
70  
71          defaultdataset.addSeries( s1 );
72          defaultdataset.addSeries( s2 );
73          defaultdataset.addSeries( s3 );
74          defaultdataset.addSeries( s4 );
75  
76      }
77      /**
78       * 
79       */
80      public NumberAxis getRangeAxis()
81      {
82          NumberAxis valueaxis = new NumberAxis();
83          valueaxis.setLowerMargin( 0.0D );
84          valueaxis.setUpperMargin(0.05D);
85          valueaxis.setRangeWithMargins( 0.0D, 1.0D );
86          valueaxis.setLabel( this.getYAxisLabel() );
87          valueaxis.setNumberFormatOverride( NumberFormat.getPercentInstance() );
88          return valueaxis;
89      }
90      /**
91       * 
92       */
93      public String getYAxisLabel()
94      {
95          return this.bundle.getString( "report.clover.label.coverage" );
96      }
97      
98      public XYItemLabelGenerator getLabelGenerator()
99      {
100         StandardXYItemLabelGenerator labelgenerator =
101             new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
102                                               this.timePeriod.getDateFormat(),
103                                               NumberFormat.getPercentInstance( Locale.getDefault() ) );
104         return labelgenerator;
105     }
106 
107 }