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

File LinePlotFactory.java

 

Coverage histogram

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

Code metrics

6
21
3
1
103
54
9
0.43
7
3
3

Classes

Class Line # Actions
LinePlotFactory 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.XYItemRenderer;
27    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
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 LinePlotFactory implements PlotFactory
36    {
37    private static LinePlotFactory uniqueInstance = new LinePlotFactory();
38   
 
39  0 toggle private LinePlotFactory()
40    {
41    // empty
42    }
43   
 
44  0 toggle public static LinePlotFactory 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 XYLineAndShapeRenderer();
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   
85    // private boolean hasNumericHeader(DataSource dataSource,
86    // ChartParams params) throws DataSourceException {
87    // String dataSeries = params.getString(ChartParams.SERIES);
88    // try {
89    // if (dataSeries.equals("rows") && dataSource.hasHeaderRow()) {
90    // for (int column = 0; column<dataSource.getColumnCount(); column++) {
91    // Double.parseDouble(dataSource.getHeaderRowValue(column));
92    // }
93    // return true;
94    // } else if (dataSeries.equals("columns") && dataSource.hasHeaderColumn()) {
95    // for (int row = 0; row<dataSource.getRowCount(); row++) {
96    // Double.parseDouble(dataSource.getHeaderColumnValue(row));
97    // }
98    // return true;
99    // }
100    // } catch (NumberFormatException e) { /* ignore */ }
101    // return false;
102    // }
103    }