Coverage Report - net.sf.statcvs.output.LOCChurnChartMaker
 
Classes in this File Line Coverage Branch Coverage Complexity
LOCChurnChartMaker
0%
0/60
0%
0/10
1.667
 
 1  
 /*
 2  
  StatCVS - CVS statistics generation 
 3  
  Copyright (C) 2006 Benoit Xhenseval
 4  
  
 5  
  This library is free software; you can redistribute it and/or
 6  
  modify it under the terms of the GNU Lesser General Public
 7  
  License as published by the Free Software Foundation; either
 8  
  version 2.1 of the License, or (at your option) any later version.
 9  
 
 10  
  This library is distributed in the hope that it will be useful,
 11  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  
  Lesser General Public License for more details.
 14  
 
 15  
  You should have received a copy of the GNU Lesser General Public
 16  
  License along with this library; if not, write to the Free Software
 17  
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  
  
 19  
  */
 20  
 package net.sf.statcvs.output;
 21  
 
 22  
 import java.awt.Dimension;
 23  
 import java.util.Iterator;
 24  
 import java.util.List;
 25  
 
 26  
 import net.sf.statcvs.Messages;
 27  
 import net.sf.statcvs.charts.ChartConfigUtil;
 28  
 import net.sf.statcvs.charts.ChartImage;
 29  
 
 30  
 import org.jfree.chart.ChartFactory;
 31  
 import org.jfree.chart.JFreeChart;
 32  
 import org.jfree.chart.annotations.XYAnnotation;
 33  
 import org.jfree.chart.axis.DateAxis;
 34  
 import org.jfree.chart.axis.NumberAxis;
 35  
 import org.jfree.chart.plot.PlotOrientation;
 36  
 import org.jfree.chart.plot.XYPlot;
 37  
 import org.jfree.chart.renderer.xy.XYBarRenderer;
 38  
 import org.jfree.chart.renderer.xy.XYItemRenderer;
 39  
 import org.jfree.chart.renderer.xy.XYStepRenderer;
 40  
 import org.jfree.data.time.TimeSeries;
 41  
 import org.jfree.data.time.TimeSeriesCollection;
 42  
 import org.jfree.data.xy.IntervalXYDataset;
 43  
 
 44  
 /**
 45  
  * Class for producing Lines Of Code with Churn charts
 46  
  * 
 47  
  * @author Benoit Xhenseval (www.ObjectLab.co.uk)
 48  
  */
 49  0
 public class LOCChurnChartMaker {
 50  0
     private static final double LOWER_MARGIN = 0.40;
 51  0
     private ChartImage chartFile = null;
 52  
     private final String chartName;
 53  
 
 54  
     /**
 55  
      * Creates a Lines Of Code chart from a <tt>BasicTimeSeries</tt> and saves
 56  
      * it as PNG
 57  
      * @param chartName 
 58  
      * 
 59  
      * @param churnSeries
 60  
      *            the Churn history
 61  
      * @param locSeries
 62  
      *            the LOC history
 63  
      * @param title
 64  
      *            the chart title
 65  
      * @param fileName
 66  
      *            the filename where the chart will be saved
 67  
      * @param width
 68  
      *            width of PNG in pixels
 69  
      * @param height
 70  0
      *            height of PNG in pixels
 71  0
      * @param annotations
 72  0
      */
 73  0
     public LOCChurnChartMaker(final String chartName, final ReportConfig config, final TimeSeries churnSeries, final TimeSeries locSeries, final String title,
 74  0
             final String fileName, final List annotations) {
 75  0
         this.chartName = chartName;
 76  0
         final TimeSeriesCollection collection = new TimeSeriesCollection(locSeries);
 77  0
         // collection.setDomainIsPointsInTime(false);
 78  0
         final TimeSeriesCollection churnCollection = new TimeSeriesCollection(churnSeries);
 79  0
         // churnCollection.setDomainIsPointsInTime(false);
 80  0
         final JFreeChart chart = createChart(collection, churnCollection, title, annotations);
 81  0
 
 82  0
         final Dimension dim = ChartConfigUtil.getDimension(chartName, config.getLargeChartSize());
 83  
 
 84  0
         chartFile = config.createChartImage(fileName, title, chart, dim);
 85  0
     }
 86  0
 
 87  0
     public ChartImage toFile() {
 88  0
         return this.chartFile;
 89  0
     }
 90  0
 
 91  0
     private JFreeChart createChart(final TimeSeriesCollection locCollection, final TimeSeriesCollection churnSet, final String title, final List annotations) {
 92  0
         final String domain = Messages.getString("TIME_LOC_DOMAIN");
 93  0
         final String range = Messages.getString("TIME_LOC_RANGE");
 94  0
 
 95  0
         final IntervalXYDataset data = locCollection;
 96  0
         final boolean legend = true;// (locCollection.getSeriesCount() > 1);
 97  
 
 98  0
         final JFreeChart chart = ChartFactory.createXYBarChart(ConfigurationOptions.getProjectName() + ":" + title, domain, true, range, data,
 99  0
                 PlotOrientation.VERTICAL, legend, false, false);
 100  0
 
 101  0
         final XYPlot plot = chart.getXYPlot();
 102  0
         plot.setRenderer(new XYStepRenderer());
 103  0
 
 104  
         // new...
 105  0
         final NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
 106  0
         rangeAxis1.setLowerMargin(LOWER_MARGIN); // to leave room for volume bars
 107  0
 
 108  0
         final DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
 109  0
         domainAxis.setVerticalTickLabels(true);
 110  0
 
 111  0
         // now add the churnSet
 112  0
         final NumberAxis rangeAxis2 = new NumberAxis(Messages.getString("CHURN_RANGE"));
 113  0
         rangeAxis2.setUpperMargin(1.00); // to leave room for price line
 114  0
         plot.setRangeAxis(1, rangeAxis2);
 115  0
         plot.setDataset(1, churnSet);
 116  0
         plot.setRangeAxis(1, rangeAxis2);
 117  0
         plot.mapDatasetToRangeAxis(1, 1);
 118  0
         final XYBarRenderer renderer2 = new XYBarRenderer(0.20);
 119  0
         plot.setRenderer(1, renderer2);
 120  0
 
 121  0
         if (annotations != null) {
 122  0
             for (final Iterator it = annotations.iterator(); it.hasNext();) {
 123  0
                 plot.addAnnotation((XYAnnotation) it.next());
 124  
             }
 125  
         }
 126  
 
 127  0
         plot.setBackgroundPaint(ChartConfigUtil.getPlotColor(chartName));
 128  0
         chart.setBackgroundPaint(ChartConfigUtil.getBackgroundColor(chartName));
 129  0
         final XYItemRenderer renderer = plot.getRenderer();
 130  0
         ChartConfigUtil.configureStroke(chartName, renderer, data);
 131  0
         ChartConfigUtil.configureShapes(chartName, renderer);
 132  
 
 133  0
         return chart;
 134  
     }
 135  
 }