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.plot.PiePlot; |
25 |
|
import org.jfree.chart.plot.Plot; |
26 |
|
import org.jfree.data.general.DefaultPieDataset; |
27 |
|
import org.jfree.data.general.PieDataset; |
28 |
|
|
29 |
|
import com.xpn.xwiki.plugin.charts.ChartCustomizer; |
30 |
|
import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException; |
31 |
|
import com.xpn.xwiki.plugin.charts.exceptions.GenerateException; |
32 |
|
import com.xpn.xwiki.plugin.charts.params.ChartParams; |
33 |
|
import com.xpn.xwiki.plugin.charts.source.DataSource; |
34 |
|
|
|
|
| 0% |
Uncovered Elements: 43 (43) |
Complexity: 11 |
Complexity Density: 0.42 |
|
35 |
|
public class PiePlotFactory implements PlotFactory |
36 |
|
{ |
37 |
|
private static PiePlotFactory uniqueInstance = new PiePlotFactory(); |
38 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
39 |
0 |
private PiePlotFactory()... |
40 |
|
{ |
41 |
|
|
42 |
|
} |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
44 |
0 |
public static PiePlotFactory getInstance()... |
45 |
|
{ |
46 |
0 |
return uniqueInstance; |
47 |
|
} |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 9 |
Complexity Density: 0.36 |
|
49 |
0 |
@Override... |
50 |
|
public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException |
51 |
|
{ |
52 |
0 |
DefaultPieDataset dataset = new DefaultPieDataset(); |
53 |
0 |
String dataSeries = params.getString(ChartParams.SERIES); |
54 |
0 |
if (dataSeries.equals("columns")) { |
55 |
0 |
for (int row = 0; row < dataSource.getRowCount(); row++) { |
56 |
0 |
if (dataSource.hasHeaderColumn()) { |
57 |
0 |
String category = dataSource.getHeaderColumnValue(row); |
58 |
0 |
dataset.setValue(category, dataSource.getCell(row, 0)); |
59 |
|
} else { |
60 |
0 |
dataset.setValue("Category " + (row + 1), dataSource.getCell(row, 0)); |
61 |
|
} |
62 |
|
} |
63 |
0 |
} else if (dataSeries.equals("rows")) { |
64 |
0 |
for (int column = 0; column < dataSource.getColumnCount(); column++) { |
65 |
0 |
if (dataSource.hasHeaderRow()) { |
66 |
0 |
String category = dataSource.getHeaderRowValue(column); |
67 |
0 |
dataset.setValue(category, dataSource.getCell(0, column)); |
68 |
|
} else { |
69 |
0 |
dataset.setValue("Category " + (column + 1), dataSource.getCell(0, column)); |
70 |
|
} |
71 |
|
} |
72 |
|
} else { |
73 |
0 |
throw new GenerateException("Invalid series parameter:" + dataSeries); |
74 |
|
} |
75 |
|
|
76 |
0 |
Class plotClass = params.getClass(ChartParams.RENDERER); |
77 |
0 |
PiePlot plot; |
78 |
0 |
if (plotClass != null) { |
79 |
0 |
try { |
80 |
0 |
Constructor ctor = plotClass.getConstructor(new Class[] {PieDataset.class}); |
81 |
0 |
plot = (PiePlot) ctor.newInstance(new Object[] {dataset}); |
82 |
|
} catch (Throwable e) { |
83 |
0 |
throw new GenerateException(e); |
84 |
|
} |
85 |
|
} else { |
86 |
0 |
plot = new PiePlot(dataset); |
87 |
|
} |
88 |
0 |
ChartCustomizer.customizePiePlot(plot, params); |
89 |
0 |
return plot; |
90 |
|
} |
91 |
|
} |