Coverage Report - net.sf.statcvs.output.LOCChurnChartMaker
 
Classes in this File Line Coverage Branch Coverage Complexity
LOCChurnChartMaker
0%
0/46
0%
0/6
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.ChartImage;
 28  
 
 29  
 import org.jfree.chart.ChartFactory;
 30  
 import org.jfree.chart.JFreeChart;
 31  
 import org.jfree.chart.annotations.XYAnnotation;
 32  
 import org.jfree.chart.axis.DateAxis;
 33  
 import org.jfree.chart.axis.NumberAxis;
 34  
 import org.jfree.chart.plot.PlotOrientation;
 35  
 import org.jfree.chart.plot.XYPlot;
 36  
 import org.jfree.chart.renderer.xy.XYBarRenderer;
 37  
 import org.jfree.chart.renderer.xy.XYStepRenderer;
 38  
 import org.jfree.data.time.TimeSeries;
 39  
 import org.jfree.data.time.TimeSeriesCollection;
 40  
 import org.jfree.data.xy.IntervalXYDataset;
 41  
 
 42  
 /**
 43  
  * Class for producing Lines Of Code with Churn charts
 44  
  * 
 45  
  * @author Benoit Xhenseval (www.ObjectLab.co.uk)
 46  
  */
 47  
 public class LOCChurnChartMaker {
 48  
     private static final double LOWER_MARGIN = 0.40;
 49  0
     private ChartImage chartFile = null;
 50  0
 
 51  
     /**
 52  
      * Creates a Lines Of Code chart from a <tt>BasicTimeSeries</tt> and saves
 53  
      * it as PNG
 54  
      * 
 55  
      * @param churnSeries
 56  
      *            the Churn history
 57  
      * @param locSeries
 58  
      *            the LOC history
 59  
      * @param title
 60  
      *            the chart title
 61  
      * @param fileName
 62  
      *            the filename where the chart will be saved
 63  
      * @param width
 64  
      *            width of PNG in pixels
 65  
      * @param height
 66  
      *            height of PNG in pixels
 67  
      * @param annotations
 68  
      */
 69  
     public LOCChurnChartMaker(final ReportConfig config, final TimeSeries churnSeries, final TimeSeries locSeries, final String title, final String fileName,
 70  0
             final Dimension size, final List annotations) {
 71  0
         final TimeSeriesCollection collection = new TimeSeriesCollection(locSeries);
 72  0
         // collection.setDomainIsPointsInTime(false);
 73  0
         final TimeSeriesCollection churnCollection = new TimeSeriesCollection(churnSeries);
 74  0
         // churnCollection.setDomainIsPointsInTime(false);
 75  0
         final JFreeChart chart = createChart(collection, churnCollection, title, annotations);
 76  0
 
 77  0
         chartFile = config.createChartImage(fileName, title, chart, size);
 78  0
     }
 79  0
 
 80  
     public ChartImage toFile() {
 81  0
         return this.chartFile;
 82  0
     }
 83  
 
 84  
     private JFreeChart createChart(final TimeSeriesCollection locCollection, final TimeSeriesCollection churnSet, final String title, final List annotations) {
 85  0
         final String domain = Messages.getString("TIME_LOC_DOMAIN");
 86  0
         final String range = Messages.getString("TIME_LOC_RANGE");
 87  0
 
 88  0
         final IntervalXYDataset data = locCollection;
 89  0
         final boolean legend = true;// (locCollection.getSeriesCount() > 1);
 90  0
 
 91  0
         final JFreeChart chart = ChartFactory.createXYBarChart(ConfigurationOptions.getProjectName() + ":" + title, domain, true, range, data,
 92  0
                 PlotOrientation.VERTICAL, legend, false, false);
 93  
 
 94  0
         final XYPlot plot = chart.getXYPlot();
 95  0
         plot.setRenderer(new XYStepRenderer());
 96  0
 
 97  
         // new...
 98  0
         final NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
 99  0
         rangeAxis1.setLowerMargin(LOWER_MARGIN); // to leave room for volume bars
 100  0
 
 101  0
         final DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
 102  0
         domainAxis.setVerticalTickLabels(true);
 103  0
 
 104  
         // now add the churnSet
 105  0
         final NumberAxis rangeAxis2 = new NumberAxis(Messages.getString("CHURN_RANGE"));
 106  0
         rangeAxis2.setUpperMargin(1.00); // to leave room for price line
 107  0
         plot.setRangeAxis(1, rangeAxis2);
 108  0
         plot.setDataset(1, churnSet);
 109  0
         plot.setRangeAxis(1, rangeAxis2);
 110  0
         plot.mapDatasetToRangeAxis(1, 1);
 111  0
         final XYBarRenderer renderer2 = new XYBarRenderer(0.20);
 112  0
         plot.setRenderer(1, renderer2);
 113  0
 
 114  0
         if (annotations != null) {
 115  0
             for (final Iterator it = annotations.iterator(); it.hasNext();) {
 116  0
                 plot.addAnnotation((XYAnnotation) it.next());
 117  0
             }
 118  
         }
 119  
 
 120  0
         return chart;
 121  0
     }
 122  
 }