1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.charts.plots; |
21 |
|
|
22 |
|
import java.lang.reflect.Constructor; |
23 |
|
|
24 |
|
import org.jfree.chart.axis.DateAxis; |
25 |
|
import org.jfree.chart.axis.NumberAxis; |
26 |
|
import org.jfree.chart.plot.Plot; |
27 |
|
import org.jfree.chart.plot.XYPlot; |
28 |
|
import org.jfree.chart.renderer.xy.XYItemRenderer; |
29 |
|
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; |
30 |
|
import org.jfree.data.xy.XYDataset; |
31 |
|
|
32 |
|
import com.xpn.xwiki.plugin.charts.ChartCustomizer; |
33 |
|
import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException; |
34 |
|
import com.xpn.xwiki.plugin.charts.exceptions.GenerateException; |
35 |
|
import com.xpn.xwiki.plugin.charts.params.ChartParams; |
36 |
|
import com.xpn.xwiki.plugin.charts.source.DataSource; |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 5 |
Complexity Density: 0.26 |
|
38 |
|
public class TimePlotFactory implements PlotFactory |
39 |
|
{ |
40 |
|
private static TimePlotFactory uniqueInstance = new TimePlotFactory(); |
41 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
42 |
0 |
private TimePlotFactory()... |
43 |
|
{ |
44 |
|
|
45 |
|
} |
46 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
0 |
public static TimePlotFactory getInstance()... |
48 |
|
{ |
49 |
0 |
return uniqueInstance; |
50 |
|
} |
51 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 3 |
Complexity Density: 0.17 |
|
52 |
0 |
@Override... |
53 |
|
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException |
54 |
|
{ |
55 |
|
|
56 |
0 |
Class rendererClass = params.getClass(ChartParams.RENDERER); |
57 |
0 |
XYItemRenderer renderer; |
58 |
0 |
if (rendererClass != null) { |
59 |
0 |
try { |
60 |
0 |
Constructor ctor = rendererClass.getConstructor(new Class[] {}); |
61 |
0 |
renderer = (XYItemRenderer) ctor.newInstance(new Object[] {}); |
62 |
|
} catch (Throwable e) { |
63 |
0 |
throw new GenerateException(e); |
64 |
|
} |
65 |
|
} else { |
66 |
0 |
renderer = new XYLineAndShapeRenderer(); |
67 |
|
} |
68 |
0 |
ChartCustomizer.customizeXYItemRenderer(renderer, params); |
69 |
|
|
70 |
0 |
DateAxis domainAxis = new DateAxis(); |
71 |
0 |
ChartCustomizer.customizeDateAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX); |
72 |
|
|
73 |
0 |
NumberAxis rangeAxis = new NumberAxis(); |
74 |
0 |
rangeAxis.setAutoRangeIncludesZero(false); |
75 |
0 |
ChartCustomizer.customizeNumberAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX); |
76 |
|
|
77 |
0 |
XYDataset dataset = TimeSeriesCollectionFactory.getInstance().create(dataSource, params); |
78 |
|
|
79 |
0 |
XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer); |
80 |
|
|
81 |
0 |
ChartCustomizer.customizeXYPlot(plot, params); |
82 |
|
|
83 |
0 |
return plot; |
84 |
|
} |
85 |
|
} |