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; |
21 |
|
|
22 |
|
import java.awt.Color; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.jfree.chart.JFreeChart; |
29 |
|
import org.xwiki.chart.ChartCustomizer; |
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
@since |
38 |
|
|
39 |
|
@Component |
40 |
|
@Named("color") |
41 |
|
@Singleton |
|
|
| 46.4% |
Uncovered Elements: 15 (28) |
Complexity: 7 |
Complexity Density: 0.44 |
|
42 |
|
public class ColorChartCustomizer implements ChartCustomizer |
43 |
|
{ |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
private static final String BACKGROUND_COLOR = "backgroundColor"; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
private static final String PLOT_BACKGROUND_COLOR = "plotBackgroundColor"; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private static final String PLOT_BORDER_COLOR = "plotBorderColor"; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private static final String BORDER_COLOR = "borderColor"; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
private static final String LEGEND_BACKGROUND_COLOR = "legendBackgroundColor"; |
68 |
|
|
|
|
| 54.5% |
Uncovered Elements: 10 (22) |
Complexity: 6 |
Complexity Density: 0.5 |
|
69 |
15 |
@Override... |
70 |
|
public void customize(JFreeChart jfchart, Map<String, String> parameters) |
71 |
|
{ |
72 |
|
|
73 |
15 |
DrawingSupplierFactory drawingSupplierFactory = new DrawingSupplierFactory(); |
74 |
15 |
jfchart.getPlot().setDrawingSupplier(drawingSupplierFactory.createDrawingSupplier(parameters)); |
75 |
|
|
76 |
|
|
77 |
15 |
if (parameters.get(PLOT_BACKGROUND_COLOR) != null) { |
78 |
0 |
jfchart.getPlot().setBackgroundPaint(convertColor(parameters.get(PLOT_BACKGROUND_COLOR))); |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
15 |
if (parameters.get(BACKGROUND_COLOR) != null) { |
83 |
0 |
jfchart.setBackgroundPaint(convertColor(parameters.get(BACKGROUND_COLOR))); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
15 |
if (parameters.get(LEGEND_BACKGROUND_COLOR) != null) { |
88 |
0 |
jfchart.getLegend().setBackgroundPaint(convertColor(parameters.get(LEGEND_BACKGROUND_COLOR))); |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
15 |
if (parameters.get(PLOT_BORDER_COLOR) != null) { |
93 |
0 |
jfchart.getPlot().setOutlinePaint(convertColor(parameters.get(PLOT_BORDER_COLOR))); |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
15 |
if (parameters.get(BORDER_COLOR) != null) { |
98 |
0 |
jfchart.setBorderPaint(convertColor(parameters.get(BORDER_COLOR))); |
99 |
|
} |
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
102 |
0 |
private Color convertColor(String colorInHex)... |
103 |
|
{ |
104 |
0 |
int red = Integer.parseInt(colorInHex.substring(0, 2), 16); |
105 |
0 |
int green = Integer.parseInt(colorInHex.substring(2, 4), 16); |
106 |
0 |
int blue = Integer.parseInt(colorInHex.substring(4, 6), 16); |
107 |
0 |
return new Color(red, green, blue); |
108 |
|
} |
109 |
|
} |