1 package org.codehaus.mojo.dashboard.report.plugin.chart;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.awt.Paint;
20 import java.util.Iterator;
21 import java.util.ResourceBundle;
22
23 import org.codehaus.mojo.dashboard.report.plugin.beans.CheckstyleError;
24 import org.codehaus.mojo.dashboard.report.plugin.beans.CheckstyleReportBean;
25 import org.codehaus.mojo.dashboard.report.plugin.beans.IDashBoardReportBean;
26 import org.codehaus.mojo.dashboard.report.plugin.utils.ChartUtils;
27 import org.jfree.chart.ChartColor;
28 import org.jfree.data.general.DefaultPieDataset;
29
30
31
32
33
34
35 public class CheckstyleErrorsPieChartStrategy extends AbstractPieChartStrategy
36 {
37
38
39
40
41
42
43
44
45 public CheckstyleErrorsPieChartStrategy( ResourceBundle bundle, String title, IDashBoardReportBean dashboardReport )
46 {
47 super( bundle, title, dashboardReport );
48 }
49
50
51
52
53 public Paint[] getPaintColor()
54 {
55 return new Paint[] { ChartUtils.BLUE_LIGHT, ChartColor.RED, ChartUtils.YELLOW_LIGHT };
56 }
57
58
59
60
61 private float percent( int nbIteration, int nbTotal )
62 {
63 float percent = nbIteration * 100f / nbTotal;
64 percent *= 1000;
65 percent = (int) ( percent + .5 );
66 percent /= 1000;
67 return percent;
68 }
69
70 public void fillDataset()
71 {
72 if ( mDashboardReport instanceof CheckstyleReportBean )
73 {
74 float percentVal = 0;
75 int nbItInfPercent = 0;
76 CheckstyleReportBean checkstyleReportBean = (CheckstyleReportBean) mDashboardReport;
77 CheckstyleError error = new CheckstyleError();
78 Iterator iterator = checkstyleReportBean.getErrors().iterator();
79
80 while ( iterator.hasNext() )
81 {
82 error = (CheckstyleError) iterator.next();
83 percentVal = percent( error.getNbIteration(), checkstyleReportBean.getNbTotal() );
84
85 if ( percentVal > 1 )
86 {
87 ( (DefaultPieDataset) this.defaultdataset ).setValue(
88 error.getMessage() + " = " + percentVal + "%",
89 error.getNbIteration() );
90 }
91 else
92 {
93 nbItInfPercent += error.getNbIteration();
94 }
95 }
96
97 if ( nbItInfPercent > 0 )
98 {
99 percentVal = percent( nbItInfPercent, checkstyleReportBean.getNbTotal() );
100 ( (DefaultPieDataset) this.defaultdataset ).setValue(
101 this.bundle.getString( "chart.checkstyle.violations.others.label" )
102 + " = " + percentVal + "%",
103 nbItInfPercent );
104 }
105 }
106
107 }
108
109 }