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

File AreaPlotFactory.java

 

Coverage histogram

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

Code metrics

6
21
3
1
84
54
9
0.43
7
3
3

Classes

Class Line # Actions
AreaPlotFactory 35 21 0% 9 30
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.Plot;
25    import org.jfree.chart.renderer.category.CategoryItemRenderer;
26    import org.jfree.chart.renderer.xy.XYAreaRenderer;
27    import org.jfree.chart.renderer.xy.XYItemRenderer;
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 AreaPlotFactory implements PlotFactory
36    {
37    private static AreaPlotFactory uniqueInstance = new AreaPlotFactory();
38   
 
39  0 toggle private AreaPlotFactory()
40    {
41    // empty
42    }
43   
 
44  0 toggle public static AreaPlotFactory 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 Class rendererClass = params.getClass(ChartParams.RENDERER);
53  0 if (rendererClass == null || XYItemRenderer.class.isAssignableFrom(rendererClass)) {
54  0 XYItemRenderer renderer;
55  0 if (rendererClass != null) {
56  0 try {
57  0 Constructor ctor = rendererClass.getConstructor(new Class[] {});
58  0 renderer = (XYItemRenderer) ctor.newInstance(new Object[] {});
59    } catch (Throwable e) {
60  0 throw new GenerateException(e);
61    }
62    } else {
63  0 renderer = new XYAreaRenderer();
64    }
65  0 ChartCustomizer.customizeXYItemRenderer(renderer, params);
66   
67  0 return XYPlotFactory.getInstance().create(dataSource, renderer, params);
68  0 } else if (CategoryItemRenderer.class.isAssignableFrom(rendererClass)) {
69  0 CategoryItemRenderer renderer;
70  0 try {
71  0 Constructor ctor = rendererClass.getConstructor(new Class[] {});
72  0 renderer = (CategoryItemRenderer) ctor.newInstance(new Object[] {});
73    } catch (Throwable e) {
74  0 throw new GenerateException(e);
75    }
76   
77  0 ChartCustomizer.customizeCategoryItemRenderer(renderer, params);
78   
79  0 return CategoryPlotFactory.getInstance().create(dataSource, renderer, params);
80    } else {
81  0 throw new GenerateException("Incompatible renderer class: " + rendererClass);
82    }
83    }
84    }