| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 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 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public class LOCChurnChartMaker { |
| 48 | |
private static final double LOWER_MARGIN = 0.40; |
| 49 | 0 | private ChartImage chartFile = null; |
| 50 | 0 | |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 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 | |
| 73 | 0 | final TimeSeriesCollection churnCollection = new TimeSeriesCollection(churnSeries); |
| 74 | 0 | |
| 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; |
| 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 | |
|
| 98 | 0 | final NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis(); |
| 99 | 0 | rangeAxis1.setLowerMargin(LOWER_MARGIN); |
| 100 | 0 | |
| 101 | 0 | final DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); |
| 102 | 0 | domainAxis.setVerticalTickLabels(true); |
| 103 | 0 | |
| 104 | |
|
| 105 | 0 | final NumberAxis rangeAxis2 = new NumberAxis(Messages.getString("CHURN_RANGE")); |
| 106 | 0 | rangeAxis2.setUpperMargin(1.00); |
| 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 | |
} |