Coverage Report - net.sf.statcvs.charts.CommitScatterChartMaker
 
Classes in this File Line Coverage Branch Coverage Complexity
CommitScatterChartMaker
0%
0/84
0%
0/36
2
 
 1  
 /*
 2  
     StatCvs - CVS statistics generation 
 3  
     Copyright (C) 2002  Lukasz Pekacki <lukasz@pekacki.de>
 4  
     http://statcvs.sf.net/
 5  
     
 6  
     This library is free software; you can redistribute it and/or
 7  
     modify it under the terms of the GNU Lesser General Public
 8  
     License as published by the Free Software Foundation; either
 9  
     version 2.1 of the License, or (at your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful,
 12  
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  
     Lesser General Public License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public
 17  
     License along with this library; if not, write to the Free Software
 18  
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19  
     
 20  
         Created on $Date: 2009/04/25 16:36:20 $ 
 21  
 */
 22  
 package net.sf.statcvs.charts;
 23  
 
 24  
 import java.awt.Color;
 25  
 import java.awt.Dimension;
 26  
 import java.awt.Font;
 27  
 import java.awt.Rectangle;
 28  
 import java.text.DecimalFormat;
 29  
 import java.util.ArrayList;
 30  
 import java.util.Calendar;
 31  
 import java.util.Collections;
 32  
 import java.util.Date;
 33  
 import java.util.Iterator;
 34  
 import java.util.List;
 35  
 import java.util.SortedSet;
 36  
 
 37  
 import net.sf.statcvs.Messages;
 38  
 import net.sf.statcvs.model.Author;
 39  
 import net.sf.statcvs.model.Repository;
 40  
 import net.sf.statcvs.model.Revision;
 41  
 import net.sf.statcvs.output.ReportConfig;
 42  
 
 43  
 import org.jfree.chart.JFreeChart;
 44  
 import org.jfree.chart.annotations.XYAnnotation;
 45  
 import org.jfree.chart.axis.DateAxis;
 46  
 import org.jfree.chart.axis.NumberAxis;
 47  
 import org.jfree.chart.axis.NumberTickUnit;
 48  
 import org.jfree.chart.plot.CombinedDomainXYPlot;
 49  
 import org.jfree.chart.plot.XYPlot;
 50  
 import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
 51  
 import org.jfree.chart.renderer.xy.XYItemRenderer;
 52  
 import org.jfree.data.time.Second;
 53  
 import org.jfree.data.time.TimeSeries;
 54  
 import org.jfree.data.time.TimeSeriesCollection;
 55  
 
 56  
 /**
 57  
  * Produces the commit scatter chart.
 58  
  * @author jentzsch
 59  
  * @author Richard Cyganiak (richard@cyganiak.de)
 60  
  */
 61  
 public class CommitScatterChartMaker {
 62  0
     private static final String CHART_NAME = "commitscatterauthors";
 63  0
     private final static Color ALL_COMMITS_COLOR = new Color(128, 128, 255);
 64  
     private final ReportConfig config;
 65  
     private final Repository repository;
 66  
     private final int width;
 67  
 
 68  
     /**
 69  
      * Creates a new CommitScatterChartMaker.
 70  
      * @param repository The repository to be analyzed
 71  
      * @param width The width of the chart in pixels
 72  0
      */
 73  0
     public CommitScatterChartMaker(final ReportConfig config, final int width) {
 74  0
         this.config = config;
 75  0
         this.repository = config.getRepository();
 76  0
         this.width = width;
 77  0
     }
 78  
 
 79  
     /**
 80  
      * @return An image file for the chart
 81  
      */
 82  0
     public ChartImage toFile() {
 83  0
         final DateAxis timeAxis = new DateAxis(Messages.getString("TIME_CSC_DOMAIN"));
 84  0
         timeAxis.setVerticalTickLabels(true);
 85  0
         final CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(timeAxis);
 86  0
         List annotations = SymbolicNameAnnotation.createAnnotations(repository.getSymbolicNames());
 87  0
         combinedPlot.add(createPlot(createTimeSeries(this.repository.getRevisions()), "All (" + Messages.getString("TIME_CSC_RANGE") + ")", ALL_COMMITS_COLOR,
 88  0
                 annotations));
 89  0
         annotations = SymbolicNameAnnotation.createAnnotations(repository.getSymbolicNames(), SymbolicNameAnnotation.STYLE_NO_LABELS);
 90  0
         final List authors = new ArrayList(this.repository.getAuthors());
 91  0
         Collections.sort(authors);
 92  0
         final Iterator it = authors.iterator();
 93  0
         while (it.hasNext()) {
 94  0
             final Author author = (Author) it.next();
 95  0
             final Color color = this.config.isDeveloper(author) ? Color.RED : Color.GRAY;
 96  0
             combinedPlot.add(createPlot(createTimeSeries(author.getRevisions()), author.getName(), color, annotations));
 97  0
         }
 98  0
         combinedPlot.setGap(10);
 99  0
         final JFreeChart chart = new JFreeChart(this.config.getProjectName() + ": " + Messages.getString("TIME_CSC_SUBTITLE"), JFreeChart.DEFAULT_TITLE_FONT,
 100  0
                 combinedPlot, false);
 101  
 
 102  0
         combinedPlot.setBackgroundPaint(ChartConfigUtil.getPlotColor(CHART_NAME));
 103  0
         chart.setBackgroundPaint(ChartConfigUtil.getBackgroundColor(CHART_NAME));
 104  0
         final XYItemRenderer renderer = combinedPlot.getRenderer();
 105  0
         ChartConfigUtil.configureShapes(CHART_NAME, renderer);
 106  0
         ChartConfigUtil.configureCopyrightNotice(CHART_NAME, chart);
 107  0
         ChartConfigUtil.configureChartBackgroungImage(CHART_NAME, chart);
 108  0
         ChartConfigUtil.configurePlotImage(CHART_NAME, chart);
 109  0
 
 110  0
         final Dimension dim = ChartConfigUtil.getDimension(CHART_NAME, config.getLargeChartSize());
 111  0
 
 112  0
         return this.config.createChartImage(CHART_NAME + ".png", Messages.getString("TIME_CSC_SUBTITLE"), chart, getSize(dim));
 113  0
     }
 114  0
 
 115  0
     private TimeSeries createTimeSeries(final SortedSet revisions) {
 116  0
         final TimeSeries result = new TimeSeries("Dummy", Second.class);
 117  0
         final Iterator it = revisions.iterator();
 118  0
         Date lastDate = new Date();
 119  0
         while (it.hasNext()) {
 120  0
             final Revision rev = (Revision) it.next();
 121  0
             if (lastDate != null) {
 122  0
                 final Calendar cal = Calendar.getInstance();
 123  0
                 cal.setTime(lastDate);
 124  0
                 final double lastDateSeconds = cal.get(Calendar.SECOND);
 125  0
                 cal.setTime(rev.getDate());
 126  0
                 final double dateSeconds = cal.get(Calendar.SECOND);
 127  0
                 if (lastDateSeconds == dateSeconds) {
 128  0
                     continue;
 129  0
                 }
 130  0
             }
 131  0
             lastDate = rev.getDate();
 132  0
             final Calendar cal = Calendar.getInstance();
 133  0
             cal.setTime(lastDate);
 134  0
             final double hour = cal.get(Calendar.HOUR_OF_DAY);
 135  0
             final double minutes = cal.get(Calendar.MINUTE);
 136  0
             result.add(new Second(lastDate), hour + minutes / 60.0);
 137  0
         }
 138  0
         return result;
 139  0
     }
 140  0
 
 141  0
     private XYPlot createPlot(final TimeSeries series, final String label, final Color color, final List annotations) {
 142  0
         final NumberAxis valueAxis = new NumberAxis(label);
 143  0
         valueAxis.setTickUnit(new NumberTickUnit(6.0, new DecimalFormat("0")));
 144  0
         valueAxis.setAutoRangeIncludesZero(false);
 145  0
         valueAxis.setRange(0.0, 24.0);
 146  0
         valueAxis.setLabelFont(new Font("SansSerif", Font.PLAIN, 9));
 147  0
         final XYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES);
 148  0
         renderer.setShape(new Rectangle(new Dimension(2, 2)));
 149  0
         final XYPlot result = new XYPlot(new TimeSeriesCollection(series), null, valueAxis, renderer);
 150  0
         result.getRenderer().setSeriesPaint(0, color);
 151  0
         final Iterator it = annotations.iterator();
 152  0
         while (it.hasNext()) {
 153  0
             final XYAnnotation annotation = (XYAnnotation) it.next();
 154  0
             result.addAnnotation(annotation);
 155  0
         }
 156  0
         return result;
 157  
     }
 158  0
 
 159  
     private Dimension getSize(final Dimension dim) {
 160  0
         return new Dimension(dim.width, 70 * (this.repository.getAuthors().size() + 1) + 110);
 161  
     }
 162  
 }