1 package org.codehaus.mojo.dashboard.report.plugin.chart.time;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.util.Date;
20 import java.util.List;
21 import java.util.ResourceBundle;
22
23 import org.codehaus.mojo.dashboard.report.plugin.chart.AbstractChartStrategy;
24 import org.codehaus.mojo.dashboard.report.plugin.utils.TimePeriod;
25 import org.jfree.chart.axis.NumberAxis;
26 import org.jfree.chart.labels.StandardXYItemLabelGenerator;
27 import org.jfree.chart.labels.XYItemLabelGenerator;
28 import org.jfree.data.general.Dataset;
29 import org.jfree.data.time.Day;
30 import org.jfree.data.time.Hour;
31 import org.jfree.data.time.Minute;
32 import org.jfree.data.time.Month;
33 import org.jfree.data.time.RegularTimePeriod;
34 import org.jfree.data.time.TimeSeriesCollection;
35 import org.jfree.data.time.Week;
36
37 public abstract class AbstractTimeChartStrategy extends AbstractChartStrategy
38 {
39
40
41
42
43 public static String xAxisLabel = "Date";
44
45
46
47
48 public static String yAxisLabel = "Values";
49
50
51
52
53 protected TimeSeriesCollection defaultdataset = new TimeSeriesCollection();
54
55
56
57
58 protected ResourceBundle bundle;
59
60
61
62
63 protected List mResults;
64
65
66
67
68 protected TimePeriod timePeriod;
69
70
71
72
73 protected Class periodClass;
74
75
76
77
78 private Date startDate;
79
80
81
82
83 private Date endDate;
84
85
86
87
88
89
90
91
92
93
94
95 public AbstractTimeChartStrategy( ResourceBundle bundle, String title, List results, String timeUnit,
96 Date startDate, Date endDate )
97 {
98 this.setTitle( title );
99 this.bundle = bundle;
100 this.mResults = results;
101 this.startDate = startDate;
102 this.endDate = endDate;
103 retreivePeriodClass( timeUnit );
104
105 }
106
107
108
109
110
111 public Dataset getDataset()
112 {
113 fillDataset();
114 if ( defaultdataset.getSeriesCount() > 0 )
115 {
116 this.setDatasetEmpty( false );
117 }
118 return defaultdataset;
119 }
120
121
122
123
124 public String getXAxisLabel()
125 {
126 return AbstractTimeChartStrategy.xAxisLabel;
127 }
128
129
130
131
132 public String getYAxisLabel()
133 {
134 return AbstractTimeChartStrategy.yAxisLabel;
135 }
136
137
138
139
140
141 private void retreivePeriodClass( String timeUnit )
142 {
143 this.timePeriod = TimePeriod.getPeriod( timeUnit );
144
145 periodClass = null;
146 if ( timePeriod.equals( TimePeriod.MINUTE ) )
147 {
148 periodClass = Minute.class;
149 }
150 else if ( timePeriod.equals( TimePeriod.HOUR ) )
151 {
152 periodClass = Hour.class;
153 }
154 else if ( timePeriod.equals( TimePeriod.DAY ) )
155 {
156 periodClass = Day.class;
157 }
158 else if ( timePeriod.equals( TimePeriod.WEEK ) )
159 {
160 periodClass = Week.class;
161 }
162 else if ( timePeriod.equals( TimePeriod.MONTH ) )
163 {
164 periodClass = Month.class;
165 }
166 else
167 {
168 periodClass = Day.class;
169 }
170 }
171
172
173
174
175
176
177 protected RegularTimePeriod getChartDate( Date keyDate )
178 {
179 RegularTimePeriod chartDate = null;
180 if ( timePeriod.equals( TimePeriod.MINUTE ) )
181 {
182 chartDate = new Minute( keyDate );
183 }
184 else if ( timePeriod.equals( TimePeriod.HOUR ) )
185 {
186 chartDate = new Hour( keyDate );
187 }
188 else if ( timePeriod.equals( TimePeriod.DAY ) )
189 {
190 chartDate = new Day( keyDate );
191 }
192 else if ( timePeriod.equals( TimePeriod.WEEK ) )
193 {
194 chartDate = new Week( keyDate );
195 }
196 else if ( timePeriod.equals( TimePeriod.MONTH ) )
197 {
198 chartDate = new Month( keyDate );
199 }
200 else
201 {
202 chartDate = new Hour( keyDate );
203 }
204 return chartDate;
205 }
206
207
208
209
210
211 public TimePeriod getTimePeriod()
212 {
213 return timePeriod;
214 }
215
216
217
218
219
220 public NumberAxis getRangeAxis()
221 {
222 NumberAxis valueaxis = new NumberAxis();
223 valueaxis.setLowerMargin( 0.0D );
224 valueaxis.setUpperMargin( 0.25D );
225 valueaxis.setLabel( this.getYAxisLabel() );
226 return valueaxis;
227 }
228
229
230
231
232
233 public Date getEndDate()
234 {
235 return endDate;
236 }
237
238
239
240
241
242 public Date getStartDate()
243 {
244 return startDate;
245 }
246
247
248
249
250
251 public XYItemLabelGenerator getLabelGenerator()
252 {
253 return new StandardXYItemLabelGenerator();
254 }
255 }