1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.chart.internal

File ColorChartCustomizer.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

10
16
2
1
109
47
7
0.44
8
2
3.5

Classes

Class Line # Actions
ColorChartCustomizer 42 16 0% 7 15
0.464285746.4%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Customize chart colors.
34    *
35    * @version $Id: cacf79870b0e0a1b401d7509f84916a45921ed7d $
36    * @since 7.4.3
37    * @since 8.0RC1
38    */
39    @Component
40    @Named("color")
41    @Singleton
 
42    public class ColorChartCustomizer implements ChartCustomizer
43    {
44    /**
45    * Background color of the non-chart area.
46    */
47    private static final String BACKGROUND_COLOR = "backgroundColor";
48   
49    /**
50    * Background color of the plot area.
51    */
52    private static final String PLOT_BACKGROUND_COLOR = "plotBackgroundColor";
53   
54    /**
55    * Color of the plot border.
56    */
57    private static final String PLOT_BORDER_COLOR = "plotBorderColor";
58   
59    /**
60    * Color of the outer graph border.
61    */
62    private static final String BORDER_COLOR = "borderColor";
63   
64    /**
65    * Background color of the legend.
66    */
67    private static final String LEGEND_BACKGROUND_COLOR = "legendBackgroundColor";
68   
 
69  15 toggle @Override
70    public void customize(JFreeChart jfchart, Map<String, String> parameters)
71    {
72    // Set the default colors to use if the user has specified some colors.
73  15 DrawingSupplierFactory drawingSupplierFactory = new DrawingSupplierFactory();
74  15 jfchart.getPlot().setDrawingSupplier(drawingSupplierFactory.createDrawingSupplier(parameters));
75   
76    // Set any plot background color if the user has specified one
77  15 if (parameters.get(PLOT_BACKGROUND_COLOR) != null) {
78  0 jfchart.getPlot().setBackgroundPaint(convertColor(parameters.get(PLOT_BACKGROUND_COLOR)));
79    }
80   
81    // Set the non-plot area background color if specified
82  15 if (parameters.get(BACKGROUND_COLOR) != null) {
83  0 jfchart.setBackgroundPaint(convertColor(parameters.get(BACKGROUND_COLOR)));
84    }
85   
86    // Set the legend background color if specified
87  15 if (parameters.get(LEGEND_BACKGROUND_COLOR) != null) {
88  0 jfchart.getLegend().setBackgroundPaint(convertColor(parameters.get(LEGEND_BACKGROUND_COLOR)));
89    }
90   
91    // Set the plot border color if specified
92  15 if (parameters.get(PLOT_BORDER_COLOR) != null) {
93  0 jfchart.getPlot().setOutlinePaint(convertColor(parameters.get(PLOT_BORDER_COLOR)));
94    }
95   
96    // Set the graph border color if specified
97  15 if (parameters.get(BORDER_COLOR) != null) {
98  0 jfchart.setBorderPaint(convertColor(parameters.get(BORDER_COLOR)));
99    }
100    }
101   
 
102  0 toggle 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    }