Skip to content
Snippets Groups Projects
Commit 0cf28985 authored by Vincent Massol's avatar Vincent Massol
Browse files

XWIKI-13153: Add ability to set background and border colors for various parts

XWIKI-13155: Add ability to hide the plot border and the legend
parent f5a64ec3
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,7 @@
* Allows implementing JFreeChart customizations (colors, fonts, etc) for the drawn graphs.
*
* @version $Id$
* @since 8.0RC1
* @since 7.4.3, 8.0RC1
*/
@Role
@Unstable
......
......@@ -33,7 +33,7 @@
* Customize chart colors.
*
* @version $Id$
* @since 8.0RC1
* @since 7.4.3, 8.0RC1
*/
@Component
@Named("color")
......@@ -50,6 +50,21 @@ public class ColorChartCustomizer implements ChartCustomizer
*/
private static final String PLOT_BACKGROUND_COLOR = "plotBackgroundColor";
/**
* Color of the plot border.
*/
private static final String PLOT_BORDER_COLOR = "plotBorderColor";
/**
* Color of the outer graph border.
*/
private static final String BORDER_COLOR = "borderColor";
/**
* Background color of the legend.
*/
private static final String LEGEND_BACKGROUND_COLOR = "legendBackgroundColor";
@Override
public void customize(JFreeChart jfchart, Map<String, String> parameters)
{
......@@ -66,6 +81,21 @@ public void customize(JFreeChart jfchart, Map<String, String> parameters)
if (parameters.get(BACKGROUND_COLOR) != null) {
jfchart.setBackgroundPaint(convertColor(parameters.get(BACKGROUND_COLOR)));
}
// Set the legend background color if specified
if (parameters.get(LEGEND_BACKGROUND_COLOR) != null) {
jfchart.getLegend().setBackgroundPaint(convertColor(parameters.get(LEGEND_BACKGROUND_COLOR)));
}
// Set the plot border color if specified
if (parameters.get(PLOT_BORDER_COLOR) != null) {
jfchart.getPlot().setOutlinePaint(convertColor(parameters.get(PLOT_BORDER_COLOR)));
}
// Set the graph border color if specified
if (parameters.get(BORDER_COLOR) != null) {
jfchart.setBorderPaint(convertColor(parameters.get(BORDER_COLOR)));
}
}
private Color convertColor(String colorInHex)
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.chart.internal;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jfree.chart.JFreeChart;
import org.xwiki.chart.ChartCustomizer;
import org.xwiki.component.annotation.Component;
/**
* Customize visiblity of items on the chart.
*
* @version $Id$
* @since 7.4.3, 8.0RC1
*/
@Component
@Named("visibility")
@Singleton
public class VisibilityChartCustomizer implements ChartCustomizer
{
/**
* Whether the plot border is visible or not.
*/
private static final String PLOT_BORDER_VISIBLE = "plotBorderVisible";
/**
* Whether the legend is visible or not.
*/
private static final String LEGEND_VISIBLE = "legendVisible";
@Override
public void customize(JFreeChart jfchart, Map<String, String> parameters)
{
if (parameters.get(PLOT_BORDER_VISIBLE) != null) {
jfchart.getPlot().setOutlineVisible(Boolean.parseBoolean(parameters.get(PLOT_BORDER_VISIBLE)));
}
if (parameters.get(LEGEND_VISIBLE) != null && !Boolean.parseBoolean(parameters.get(LEGEND_VISIBLE))) {
jfchart.removeLegend();
}
}
}
org.xwiki.chart.internal.DefaultChartGenerator
org.xwiki.chart.internal.ColorChartCustomizer
org.xwiki.chart.internal.VisibilityChartCustomizer
org.xwiki.chart.internal.plot.AreaPlotGenerator
org.xwiki.chart.internal.plot.Bar3DPlotGenerator
org.xwiki.chart.internal.plot.BarPlotGenerator
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment