/*
 * 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.plot;

import java.util.Map;

import javax.inject.Named;
import javax.inject.Singleton;

import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.data.general.PieDataset;
import org.xwiki.chart.PlotGeneratorException;
import org.xwiki.chart.model.ChartModel;
import org.xwiki.component.annotation.Component;

/**
 * A {@link PlotGenerator} for generating pie charts.
 * 
 * @version $Id$
 * @since 2.0M1
 */
@Component
@Named("pie")
@Singleton
public class PiePlotGenerator implements PlotGenerator
{
    @Override
    public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException
    {
        PieDataset dataset;
        try {
            dataset = (PieDataset) model.getDataset();
        } catch (ClassCastException e) {
            throw new PlotGeneratorException("Incompatible dataset for the pie plot.");
        }

        return new PiePlot(dataset);
    }
}

@@ -927,16 +927,47 @@
 .plot;%0A%0A
+import java.text.NumberFormat;%0A
 import j
@@ -1040,16 +1040,80 @@
 leton;%0A%0A
+import org.jfree.chart.labels.StandardPieSectionLabelGenerator;%0A
 import o
@@ -1547,16 +1547,92 @@
 rator%0A%7B%0A
+    private static final String PIE_LABEL_FORMAT_KEY = %22pie_label_format%22;%0A%0A
     @Ove
@@ -1988,44 +1988,443 @@
   %7D%0A
-%0A        return new PiePlot(dataset)
+        PiePlot piePlot = new PiePlot(dataset);%0A%0A        // Allow customizing the label to use%0A        String pieLabelFormat = parameters.get(PIE_LABEL_FORMAT_KEY);%0A        if (pieLabelFormat != null) %7B%0A            piePlot.setLabelGenerator(%0A                new StandardPieSectionLabelGenerator(pieLabelFormat, NumberFormat.getNumberInstance(),%0A                    NumberFormat.getPercentInstance()));%0A        %7D%0A%0A        return piePlot
 ;%0A  

Allow customizing pie chart labels