1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.chart.internal.plot; |
21 |
|
|
22 |
|
import java.text.NumberFormat; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.jfree.chart.labels.StandardPieSectionLabelGenerator; |
29 |
|
import org.jfree.chart.plot.PiePlot; |
30 |
|
import org.jfree.chart.plot.Plot; |
31 |
|
import org.jfree.data.general.PieDataset; |
32 |
|
import org.xwiki.chart.PlotGeneratorException; |
33 |
|
import org.xwiki.chart.model.ChartModel; |
34 |
|
import org.xwiki.component.annotation.Component; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@Named("pie") |
44 |
|
@Singleton |
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.33 |
|
45 |
|
public class PiePlotGenerator implements PlotGenerator |
46 |
|
{ |
47 |
|
private static final String PIE_LABEL_FORMAT_KEY = "pie_label_format"; |
48 |
|
|
|
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
49 |
7 |
@Override... |
50 |
|
public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException |
51 |
|
{ |
52 |
7 |
PieDataset dataset; |
53 |
7 |
try { |
54 |
7 |
dataset = (PieDataset) model.getDataset(); |
55 |
|
} catch (ClassCastException e) { |
56 |
0 |
throw new PlotGeneratorException("Incompatible dataset for the pie plot."); |
57 |
|
} |
58 |
7 |
PiePlot piePlot = new PiePlot(dataset); |
59 |
|
|
60 |
|
|
61 |
7 |
String pieLabelFormat = parameters.get(PIE_LABEL_FORMAT_KEY); |
62 |
7 |
if (pieLabelFormat != null) { |
63 |
6 |
piePlot.setLabelGenerator( |
64 |
|
new StandardPieSectionLabelGenerator(pieLabelFormat, NumberFormat.getNumberInstance(), |
65 |
|
NumberFormat.getPercentInstance())); |
66 |
|
} |
67 |
|
|
68 |
7 |
return piePlot; |
69 |
|
} |
70 |
|
} |