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 org.jfree.chart.axis.CategoryAxis; |
23 |
|
import org.jfree.chart.axis.NumberAxis; |
24 |
|
import org.jfree.chart.axis.ValueAxis; |
25 |
|
import org.jfree.chart.plot.CategoryPlot; |
26 |
|
import org.jfree.chart.plot.Plot; |
27 |
|
import org.jfree.chart.renderer.category.CategoryItemRenderer; |
28 |
|
import org.jfree.data.category.DefaultCategoryDataset; |
29 |
|
|
30 |
|
import com.xpn.xwiki.plugin.charts.ChartCustomizer; |
31 |
|
import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException; |
32 |
|
import com.xpn.xwiki.plugin.charts.exceptions.GenerateException; |
33 |
|
import com.xpn.xwiki.plugin.charts.params.ChartParams; |
34 |
|
import com.xpn.xwiki.plugin.charts.source.DataSource; |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 13 |
Complexity Density: 0.68 |
|
36 |
|
public class CategoryPlotFactory |
37 |
|
{ |
38 |
|
private static CategoryPlotFactory uniqueInstance = new CategoryPlotFactory(); |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
43 |
0 |
private CategoryPlotFactory()... |
44 |
|
{ |
45 |
|
|
46 |
|
} |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
0 |
public static CategoryPlotFactory getInstance()... |
49 |
|
{ |
50 |
0 |
return uniqueInstance; |
51 |
|
} |
52 |
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 11 |
Complexity Density: 0.61 |
|
53 |
0 |
public Plot create(DataSource dataSource, CategoryItemRenderer renderer, ChartParams params)... |
54 |
|
throws GenerateException, DataSourceException |
55 |
|
{ |
56 |
0 |
String dataSeries = params.getString(ChartParams.SERIES); |
57 |
|
|
58 |
0 |
CategoryAxis domainAxis = new CategoryAxis(); |
59 |
0 |
ValueAxis rangeAxis = new NumberAxis(); |
60 |
0 |
ChartCustomizer.customizeCategoryAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX); |
61 |
0 |
ChartCustomizer.customizeValueAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX); |
62 |
|
|
63 |
0 |
Class rendererClass = params.getClass(ChartParams.RENDERER); |
64 |
|
|
65 |
0 |
ChartCustomizer.customizeCategoryItemRenderer(renderer, params); |
66 |
|
|
67 |
0 |
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); |
68 |
|
|
69 |
0 |
if ("columns".equals(dataSeries)) { |
70 |
0 |
for (int row = 0; row < dataSource.getRowCount(); row++) { |
71 |
0 |
for (int column = 0; column < dataSource.getColumnCount(); column++) { |
72 |
0 |
dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderRow() ? dataSource |
73 |
0 |
.getHeaderRowValue(column) : ("Category " + (column + 1)), dataSource.hasHeaderColumn() |
74 |
|
? dataSource.getHeaderColumnValue(row) : ("Series " + (row + 1))); |
75 |
|
} |
76 |
|
} |
77 |
0 |
} else if ("rows".equals(dataSeries)) { |
78 |
0 |
for (int row = 0; row < dataSource.getRowCount(); row++) { |
79 |
0 |
for (int column = 0; column < dataSource.getColumnCount(); column++) { |
80 |
0 |
dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderColumn() ? dataSource |
81 |
0 |
.getHeaderColumnValue(row) : ("Category " + (row + 1)), dataSource.hasHeaderRow() ? dataSource |
82 |
|
.getHeaderRowValue(column) : ("Series " + (column + 1))); |
83 |
|
} |
84 |
|
} |
85 |
|
} else { |
86 |
0 |
throw new GenerateException("Invalid series parameter: " + dataSeries); |
87 |
|
} |
88 |
0 |
return new CategoryPlot(dataset, domainAxis, rangeAxis, renderer); |
89 |
|
} |
90 |
|
} |