Coverage Report - net.sf.statcvs.charts.ModuleSizePieChartMaker
 
Classes in this File Line Coverage Branch Coverage Complexity
ModuleSizePieChartMaker
0%
0/42
0%
0/4
2
 
 1  
 package net.sf.statcvs.charts;
 2  
 
 3  
 import java.awt.Color;
 4  
 import java.awt.Dimension;
 5  
 import java.text.NumberFormat;
 6  
 import java.util.ArrayList;
 7  
 import java.util.Iterator;
 8  
 import java.util.List;
 9  
 
 10  
 import net.sf.statcvs.model.Module;
 11  
 import net.sf.statcvs.output.ReportConfig;
 12  
 import net.sf.statcvs.util.IntegerMap;
 13  
 
 14  
 import org.jfree.chart.ChartFactory;
 15  
 import org.jfree.chart.JFreeChart;
 16  
 import org.jfree.chart.plot.PiePlot;
 17  
 import org.jfree.chart.title.TextTitle;
 18  
 import org.jfree.data.general.DefaultPieDataset;
 19  
 
 20  
 /**
 21  
  * Class for producing directory pie charts
 22  
  * @author jentzsch
 23  
  * @author Richard Cyganiak (richard@cyganiak.de)
 24  
  * @version $Id: ModuleSizePieChartMaker.java,v 1.2 2009/08/31 19:16:35 benoitx Exp $
 25  
  */
 26  
 public class ModuleSizePieChartMaker {
 27  
     private static final int SLICE_MIN_PERCENT = 5;
 28  
 
 29  
     private final ReportConfig config;
 30  
     private final String title;
 31  
     private final String subTitle;
 32  
     private final String fileName;
 33  0
     private final List files = new ArrayList();
 34  
     private final String chartName;
 35  
 
 36  
     /**
 37  
      * Creates a new PieChartMaker
 38  
      * @param config The report configuration to use
 39  
      * @param directories The set of directories to consider
 40  
      * @param title The chart title
 41  
      * @param fileName The file name for chart
 42  
      */
 43  0
     public ModuleSizePieChartMaker(final String chartName, final ReportConfig config, final String title, final String subTitle, final String fileName) {
 44  0
         this.chartName = chartName;
 45  0
         this.config = config;
 46  0
         this.title = title;
 47  0
         this.subTitle = subTitle;
 48  0
         this.fileName = fileName;
 49  0
     }
 50  
 
 51  
     public ChartImage toFile() {
 52  0
         final DefaultPieDataset data = new DefaultPieDataset();
 53  
 
 54  0
         final IntegerMap dirSizes = new IntegerMap();
 55  0
         Iterator it = config.getRepository().getModules().values().iterator();
 56  0
         int total = 0;
 57  0
         while (it.hasNext()) {
 58  0
             final Module module = (Module) it.next();
 59  
 
 60  0
             dirSizes.addInt(module.getName(), module.getCurrentLinesOfCode());
 61  0
             total += module.getCurrentLinesOfCode();
 62  
         }
 63  0
         it = dirSizes.iteratorSortedByValue();
 64  0
         final NumberFormat nf = NumberFormat.getNumberInstance();
 65  0
         final NumberFormat nf2 = NumberFormat.getPercentInstance();
 66  0
         while (it.hasNext()) {
 67  0
             final String modName = (String) it.next();
 68  0
             final Integer loc = dirSizes.getInteger(modName);
 69  0
             final double percent = (double) loc.intValue() / (double) total;
 70  0
             final String dirName = modName + " = " + nf.format(loc) + " (" + nf2.format(percent) + ")";
 71  0
             data.setValue(dirName, loc);
 72  
         }
 73  
 
 74  0
         final JFreeChart chart = ChartFactory.createPieChart(this.config.getProjectName() + ": " + title, data, false, false, false);
 75  0
         final ArrayList arrayList = new ArrayList();
 76  0
         arrayList.add(new TextTitle(subTitle));
 77  0
         chart.setSubtitles(arrayList);
 78  0
         final PiePlot plot = (PiePlot) chart.getPlot();
 79  0
         plot.setShadowPaint(null);
 80  0
         plot.setLabelShadowPaint(null);
 81  0
         plot.setLabelOutlinePaint(Color.LIGHT_GRAY);
 82  0
         plot.setForegroundAlpha(0.8f);
 83  0
         plot.setSectionOutlinePaint(Color.BLACK);
 84  
 
 85  0
         plot.setBackgroundPaint(ChartConfigUtil.getPlotColor(chartName));
 86  0
         chart.setBackgroundPaint(ChartConfigUtil.getBackgroundColor(chartName));
 87  0
         ChartConfigUtil.configureCopyrightNotice(chartName, chart);
 88  0
         ChartConfigUtil.configureChartBackgroungImage(chartName, chart);
 89  0
         ChartConfigUtil.configurePlotImage(chartName, chart);
 90  
 
 91  0
         final Dimension dim = ChartConfigUtil.getDimension(chartName, config.getLargeChartSize());
 92  
 
 93  0
         return this.config.createChartImage(this.fileName, this.title, chart, dim);
 94  
     }
 95  
 }