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.data.xy.DefaultTableXYDataset; |
23 |
|
import org.jfree.data.xy.XYDataset; |
24 |
|
import org.jfree.data.xy.XYSeries; |
25 |
|
|
26 |
|
import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException; |
27 |
|
import com.xpn.xwiki.plugin.charts.exceptions.GenerateException; |
28 |
|
import com.xpn.xwiki.plugin.charts.params.ChartParams; |
29 |
|
import com.xpn.xwiki.plugin.charts.source.DataSource; |
30 |
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 13 |
Complexity Density: 0.62 |
|
31 |
|
public class TableXYDatasetFactory |
32 |
|
{ |
33 |
|
private static TableXYDatasetFactory uniqueInstance = new TableXYDatasetFactory(); |
34 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
35 |
0 |
private TableXYDatasetFactory()... |
36 |
|
{ |
37 |
|
|
38 |
|
} |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
0 |
public static TableXYDatasetFactory getInstance()... |
41 |
|
{ |
42 |
0 |
return uniqueInstance; |
43 |
|
} |
44 |
|
|
|
|
| 0% |
Uncovered Elements: 40 (40) |
Complexity: 11 |
Complexity Density: 0.55 |
|
45 |
0 |
public XYDataset create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException... |
46 |
|
{ |
47 |
|
|
48 |
0 |
String dataSeries = params.getString(ChartParams.SERIES); |
49 |
|
|
50 |
0 |
DefaultTableXYDataset dataset = new DefaultTableXYDataset(); |
51 |
0 |
if (dataSeries.equals("columns")) { |
52 |
0 |
if (!dataSource.hasHeaderColumn()) { |
53 |
0 |
throw new GenerateException("Header column required"); |
54 |
|
} |
55 |
0 |
for (int column = 0; column < dataSource.getColumnCount(); column++) { |
56 |
0 |
XYSeries series = |
57 |
0 |
new XYSeries(dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column) |
58 |
|
: ("Series " + (column + 1)), false, false); |
59 |
0 |
for (int row = 0; row < dataSource.getRowCount(); row++) { |
60 |
0 |
series.add(Double.parseDouble(dataSource.getHeaderColumnValue(row)), dataSource |
61 |
|
.getCell(row, column)); |
62 |
|
} |
63 |
0 |
dataset.addSeries(series); |
64 |
|
} |
65 |
|
|
66 |
0 |
} else if (dataSeries.equals("rows")) { |
67 |
0 |
if (!dataSource.hasHeaderRow()) { |
68 |
0 |
throw new GenerateException("Header row required"); |
69 |
|
} |
70 |
0 |
for (int row = 0; row < dataSource.getRowCount(); row++) { |
71 |
0 |
XYSeries series = |
72 |
0 |
new XYSeries(dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row) |
73 |
|
: ("Series " + (row + 1)), false, false); |
74 |
0 |
for (int column = 0; column < dataSource.getColumnCount(); column++) { |
75 |
0 |
series.add(Double.parseDouble(dataSource.getHeaderRowValue(column)), dataSource |
76 |
|
.getCell(row, column)); |
77 |
|
} |
78 |
0 |
dataset.addSeries(series); |
79 |
|
} |
80 |
|
} else { |
81 |
0 |
throw new GenerateException("Invalid series parameter:" + dataSeries); |
82 |
|
} |
83 |
0 |
return dataset; |
84 |
|
} |
85 |
|
} |