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

File CategoryPlotFactory.java

 

Coverage histogram

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

Code metrics

20
19
3
1
90
56
13
0.68
6.33
3
4.33

Classes

Class Line # Actions
CategoryPlotFactory 36 19 0% 13 42
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 org.jfree.chart.axis.CategoryAxis;
23    import org.jfree.chart.axis.NumberAxis;
24    import org.jfree.chart.axis.ValueAxis;
25    import org.jfree.chart.plot.CategoryPlot;
26    import org.jfree.chart.plot.Plot;
27    import org.jfree.chart.renderer.category.CategoryItemRenderer;
28    import org.jfree.data.category.DefaultCategoryDataset;
29   
30    import com.xpn.xwiki.plugin.charts.ChartCustomizer;
31    import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException;
32    import com.xpn.xwiki.plugin.charts.exceptions.GenerateException;
33    import com.xpn.xwiki.plugin.charts.params.ChartParams;
34    import com.xpn.xwiki.plugin.charts.source.DataSource;
35   
 
36    public class CategoryPlotFactory
37    {
38    private static CategoryPlotFactory uniqueInstance = new CategoryPlotFactory();
39   
40    /**
41    * This class is not used directly but through area, bar and line (there is a sort of dynamic inheritance here)
42    */
 
43  0 toggle private CategoryPlotFactory()
44    {
45    // empty
46    }
47   
 
48  0 toggle public static CategoryPlotFactory getInstance()
49    {
50  0 return uniqueInstance;
51    }
52   
 
53  0 toggle public Plot create(DataSource dataSource, CategoryItemRenderer renderer, ChartParams params)
54    throws GenerateException, DataSourceException
55    {
56  0 String dataSeries = params.getString(ChartParams.SERIES);
57   
58  0 CategoryAxis domainAxis = new CategoryAxis();
59  0 ValueAxis rangeAxis = new NumberAxis();
60  0 ChartCustomizer.customizeCategoryAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX);
61  0 ChartCustomizer.customizeValueAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX);
62   
63  0 Class rendererClass = params.getClass(ChartParams.RENDERER);
64   
65  0 ChartCustomizer.customizeCategoryItemRenderer(renderer, params);
66   
67  0 DefaultCategoryDataset dataset = new DefaultCategoryDataset();
68   
69  0 if ("columns".equals(dataSeries)) {
70  0 for (int row = 0; row < dataSource.getRowCount(); row++) {
71  0 for (int column = 0; column < dataSource.getColumnCount(); column++) {
72  0 dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderRow() ? dataSource
73  0 .getHeaderRowValue(column) : ("Category " + (column + 1)), dataSource.hasHeaderColumn()
74    ? dataSource.getHeaderColumnValue(row) : ("Series " + (row + 1)));
75    }
76    }
77  0 } else if ("rows".equals(dataSeries)) {
78  0 for (int row = 0; row < dataSource.getRowCount(); row++) {
79  0 for (int column = 0; column < dataSource.getColumnCount(); column++) {
80  0 dataset.addValue(dataSource.getCell(row, column), dataSource.hasHeaderColumn() ? dataSource
81  0 .getHeaderColumnValue(row) : ("Category " + (row + 1)), dataSource.hasHeaderRow() ? dataSource
82    .getHeaderRowValue(column) : ("Series " + (column + 1)));
83    }
84    }
85    } else {
86  0 throw new GenerateException("Invalid series parameter: " + dataSeries);
87    }
88  0 return new CategoryPlot(dataset, domainAxis, rangeAxis, renderer);
89    }
90    }