1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.charts.plots

File PiePlotFactory.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

14
26
3
1
91
63
11
0.42
8.67
3
3.67

Classes

Class Line # Actions
PiePlotFactory 35 26 0% 11 43
0.00%
 

Contributing tests

No tests hitting this source file were found.

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 com.xpn.xwiki.plugin.charts.plots;
21   
22    import java.lang.reflect.Constructor;
23   
24    import org.jfree.chart.plot.PiePlot;
25    import org.jfree.chart.plot.Plot;
26    import org.jfree.data.general.DefaultPieDataset;
27    import org.jfree.data.general.PieDataset;
28   
29    import com.xpn.xwiki.plugin.charts.ChartCustomizer;
30    import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException;
31    import com.xpn.xwiki.plugin.charts.exceptions.GenerateException;
32    import com.xpn.xwiki.plugin.charts.params.ChartParams;
33    import com.xpn.xwiki.plugin.charts.source.DataSource;
34   
 
35    public class PiePlotFactory implements PlotFactory
36    {
37    private static PiePlotFactory uniqueInstance = new PiePlotFactory();
38   
 
39  0 toggle private PiePlotFactory()
40    {
41    // empty
42    }
43   
 
44  0 toggle public static PiePlotFactory getInstance()
45    {
46  0 return uniqueInstance;
47    }
48   
 
49  0 toggle @Override
50    public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException
51    {
52  0 DefaultPieDataset dataset = new DefaultPieDataset();
53  0 String dataSeries = params.getString(ChartParams.SERIES);
54  0 if (dataSeries.equals("columns")) {
55  0 for (int row = 0; row < dataSource.getRowCount(); row++) {
56  0 if (dataSource.hasHeaderColumn()) {
57  0 String category = dataSource.getHeaderColumnValue(row);
58  0 dataset.setValue(category, dataSource.getCell(row, 0));
59    } else {
60  0 dataset.setValue("Category " + (row + 1), dataSource.getCell(row, 0));
61    }
62    }
63  0 } else if (dataSeries.equals("rows")) {
64  0 for (int column = 0; column < dataSource.getColumnCount(); column++) {
65  0 if (dataSource.hasHeaderRow()) {
66  0 String category = dataSource.getHeaderRowValue(column);
67  0 dataset.setValue(category, dataSource.getCell(0, column));
68    } else {
69  0 dataset.setValue("Category " + (column + 1), dataSource.getCell(0, column));
70    }
71    }
72    } else {
73  0 throw new GenerateException("Invalid series parameter:" + dataSeries);
74    }
75   
76  0 Class plotClass = params.getClass(ChartParams.RENDERER);
77  0 PiePlot plot;
78  0 if (plotClass != null) {
79  0 try {
80  0 Constructor ctor = plotClass.getConstructor(new Class[] {PieDataset.class});
81  0 plot = (PiePlot) ctor.newInstance(new Object[] {dataset});
82    } catch (Throwable e) {
83  0 throw new GenerateException(e);
84    }
85    } else {
86  0 plot = new PiePlot(dataset);
87    }
88  0 ChartCustomizer.customizePiePlot(plot, params);
89  0 return plot;
90    }
91    }