1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
package net.sf.statsvn.output; |
22 | |
|
23 | |
import java.awt.Dimension; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.List; |
26 | |
|
27 | |
import net.sf.statcvs.Messages; |
28 | |
import net.sf.statcvs.charts.ChartImage; |
29 | |
import net.sf.statcvs.output.ConfigurationOptions; |
30 | |
import net.sf.statcvs.output.ReportConfig; |
31 | |
|
32 | |
import org.jfree.chart.ChartFactory; |
33 | |
import org.jfree.chart.JFreeChart; |
34 | |
import org.jfree.chart.annotations.XYAnnotation; |
35 | |
import org.jfree.chart.axis.DateAxis; |
36 | |
import org.jfree.chart.axis.NumberAxis; |
37 | |
import org.jfree.chart.plot.PlotOrientation; |
38 | |
import org.jfree.chart.plot.XYPlot; |
39 | |
import org.jfree.chart.renderer.xy.XYBarRenderer; |
40 | |
import org.jfree.chart.renderer.xy.XYStepRenderer; |
41 | |
import org.jfree.data.time.TimeSeries; |
42 | |
import org.jfree.data.time.TimeSeriesCollection; |
43 | |
import org.jfree.data.xy.IntervalXYDataset; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
public class LOCChurnChartMaker { |
51 | |
private static final double LOWER_MARGIN = 0.40; |
52 | 0 | private ChartImage chartFile = null; |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public LOCChurnChartMaker(final ReportConfig config, final TimeSeries churnSeries, final TimeSeries locSeries, final String title, final String fileName, |
73 | 0 | final Dimension size, final List annotations) { |
74 | 0 | final TimeSeriesCollection collection = new TimeSeriesCollection(locSeries); |
75 | |
|
76 | 0 | final TimeSeriesCollection churnCollection = new TimeSeriesCollection(churnSeries); |
77 | |
|
78 | 0 | final JFreeChart chart = createChart(collection, churnCollection, title, annotations); |
79 | |
|
80 | 0 | chartFile = config.createChartImage(fileName, title, chart, size); |
81 | 0 | } |
82 | |
|
83 | |
public ChartImage toFile() { |
84 | 0 | return this.chartFile; |
85 | |
} |
86 | |
|
87 | |
private JFreeChart createChart(final TimeSeriesCollection locCollection, final TimeSeriesCollection churnSet, final String title, final List annotations) { |
88 | 0 | final String domain = Messages.getString("TIME_LOC_DOMAIN"); |
89 | 0 | final String range = Messages.getString("TIME_LOC_RANGE"); |
90 | |
|
91 | 0 | final IntervalXYDataset data = locCollection; |
92 | 0 | final boolean legend = true; |
93 | |
|
94 | 0 | final JFreeChart chart = ChartFactory.createXYBarChart(ConfigurationOptions.getProjectName() + ":" + title, domain, true, range, data, |
95 | |
PlotOrientation.VERTICAL, legend, false, false); |
96 | |
|
97 | 0 | final XYPlot plot = chart.getXYPlot(); |
98 | 0 | plot.setRenderer(new XYStepRenderer()); |
99 | |
|
100 | |
|
101 | 0 | final NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis(); |
102 | 0 | rangeAxis1.setLowerMargin(LOWER_MARGIN); |
103 | |
|
104 | 0 | final DateAxis domainAxis = (DateAxis) plot.getDomainAxis(); |
105 | 0 | domainAxis.setVerticalTickLabels(true); |
106 | |
|
107 | |
|
108 | 0 | final NumberAxis rangeAxis2 = new NumberAxis(Messages.getString("CHURN_RANGE")); |
109 | 0 | rangeAxis2.setUpperMargin(1.00); |
110 | 0 | plot.setRangeAxis(1, rangeAxis2); |
111 | 0 | plot.setDataset(1, churnSet); |
112 | 0 | plot.setRangeAxis(1, rangeAxis2); |
113 | 0 | plot.mapDatasetToRangeAxis(1, 1); |
114 | 0 | final XYBarRenderer renderer2 = new XYBarRenderer(0.20); |
115 | 0 | plot.setRenderer(1, renderer2); |
116 | |
|
117 | 0 | if (annotations != null) { |
118 | 0 | for (final Iterator it = annotations.iterator(); it.hasNext();) { |
119 | 0 | plot.addAnnotation((XYAnnotation) it.next()); |
120 | |
} |
121 | |
} |
122 | |
|
123 | 0 | return chart; |
124 | |
} |
125 | |
} |