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.Map;
22 import java.util.ResourceBundle;
23
24 import org.codehaus.mojo.dashboard.report.plugin.beans.FindBugsReportBean;
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 public class FindbugsPrioritiesPieChartStrategy extends AbstractPieChartStrategy
35 {
36
37
38
39
40
41
42
43
44 public FindbugsPrioritiesPieChartStrategy( ResourceBundle bundle, String title, IDashBoardReportBean dashboardReport )
45 {
46 super( bundle, title, dashboardReport );
47 }
48
49
50
51
52 public Paint[] getPaintColor()
53 {
54 return new Paint[] { ChartUtils.BLUE_LIGHT, ChartColor.RED, ChartUtils.YELLOW_LIGHT };
55 }
56
57
58
59
60 private float percent( int nbIteration, int nbTotal )
61 {
62 float percent = nbIteration * 100f / nbTotal;
63 percent *= 1000;
64 percent = (int) ( percent + .5 );
65 percent /= 1000;
66 return percent;
67 }
68
69 public void fillDataset()
70 {
71 if ( mDashboardReport instanceof FindBugsReportBean )
72 {
73 float percentVal = 0;
74 FindBugsReportBean findBugsReportBean = (FindBugsReportBean) mDashboardReport;
75
76 Map priorities = findBugsReportBean.getPriorities();
77 Iterator iterator = priorities.keySet().iterator();
78
79 while ( iterator.hasNext() )
80 {
81 String priority = (String) iterator.next();
82 Integer value = (Integer) priorities.get( priority );
83 percentVal = percent( value.intValue(), findBugsReportBean.getNbBugs() );
84
85 ( (DefaultPieDataset) this.defaultdataset ).setValue( priority + " = " + percentVal + "%", value.intValue() );
86 }
87 }
88
89 }
90
91 }