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.CoberturaReportBean;
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 CoberturaTimeChartStrategy extends AbstractTimeChartStrategy
33  {
34      private TimeSeries linecoverSerie;
35      private TimeSeries branchcoverSerie;
36  
37      public CoberturaTimeChartStrategy( ResourceBundle bundle, String title, List results, String timeUnit,
38                                         Date startDate, Date endDate )
39      {
40          super( bundle, title, results, timeUnit, startDate, endDate );
41      }
42  
43      public void fillDataset()
44      {
45          linecoverSerie = new TimeSeries( this.bundle.getString( "report.cobertura.label.linecover" ), this.periodClass );
46          branchcoverSerie = new TimeSeries( this.bundle.getString( "report.cobertura.label.branchcover" ), this.periodClass );
47  
48          Iterator iter = mResults.iterator();
49          while ( iter.hasNext() )
50          {
51              CoberturaReportBean cober = (CoberturaReportBean) iter.next();
52              Date date = cober.getDateGeneration();
53              linecoverSerie.addOrUpdate( getChartDate( this.timePeriod.normalize( date ) ), cober.getLineCoverRate() );
54              branchcoverSerie.addOrUpdate( getChartDate( this.timePeriod.normalize( date ) ), cober.getBranchCoverRate() );
55          }
56  
57          defaultdataset.addSeries( linecoverSerie );
58          defaultdataset.addSeries( branchcoverSerie );
59  
60      }
61  
62      public NumberAxis getRangeAxis()
63      {
64          NumberAxis valueaxis = new NumberAxis();
65          valueaxis.setLowerMargin( 0.0D );
66          valueaxis.setUpperMargin(0.099D);
67          valueaxis.setRangeWithMargins( 0.0D, 1.0D );
68          valueaxis.setLabel( this.getYAxisLabel() );
69          valueaxis.setNumberFormatOverride( NumberFormat.getPercentInstance() );
70          return valueaxis;
71      }
72  
73      public String getYAxisLabel()
74      {
75          return this.bundle.getString( "report.cobertura.label.coverage" );
76      }
77  
78      public XYItemLabelGenerator getLabelGenerator()
79      {
80          StandardXYItemLabelGenerator labelgenerator =
81              new StandardXYItemLabelGenerator( StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
82                                                this.timePeriod.getDateFormat(),
83                                                NumberFormat.getPercentInstance( Locale.getDefault() ) );
84          return labelgenerator;
85      }
86  
87  
88  }