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

File PiePlotGenerator.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

2
9
1
1
70
37
3
0.33
9
1
3

Classes

Class Line # Actions
PiePlotGenerator 45 9 0% 3 1
0.916666791.7%
 

Contributing tests

This file is covered by 1 test. .

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.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    * A {@link PlotGenerator} for generating pie charts.
38    *
39    * @version $Id: f3469866611214a125f28c3d8e5cae64b227f993 $
40    * @since 2.0M1
41    */
42    @Component
43    @Named("pie")
44    @Singleton
 
45    public class PiePlotGenerator implements PlotGenerator
46    {
47    private static final String PIE_LABEL_FORMAT_KEY = "pie_label_format";
48   
 
49  7 toggle @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    // Allow customizing the label to use
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    }