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

File TimePlotFactory.java

 

Coverage histogram

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

Code metrics

2
19
3
1
85
51
5
0.26
6.33
3
1.67

Classes

Class Line # Actions
TimePlotFactory 38 19 0% 5 24
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.axis.DateAxis;
25    import org.jfree.chart.axis.NumberAxis;
26    import org.jfree.chart.plot.Plot;
27    import org.jfree.chart.plot.XYPlot;
28    import org.jfree.chart.renderer.xy.XYItemRenderer;
29    import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
30    import org.jfree.data.xy.XYDataset;
31   
32    import com.xpn.xwiki.plugin.charts.ChartCustomizer;
33    import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException;
34    import com.xpn.xwiki.plugin.charts.exceptions.GenerateException;
35    import com.xpn.xwiki.plugin.charts.params.ChartParams;
36    import com.xpn.xwiki.plugin.charts.source.DataSource;
37   
 
38    public class TimePlotFactory implements PlotFactory
39    {
40    private static TimePlotFactory uniqueInstance = new TimePlotFactory();
41   
 
42  0 toggle private TimePlotFactory()
43    {
44    // empty
45    }
46   
 
47  0 toggle public static TimePlotFactory getInstance()
48    {
49  0 return uniqueInstance;
50    }
51   
 
52  0 toggle @Override
53    public Plot create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException
54    {
55   
56  0 Class rendererClass = params.getClass(ChartParams.RENDERER);
57  0 XYItemRenderer renderer;
58  0 if (rendererClass != null) {
59  0 try {
60  0 Constructor ctor = rendererClass.getConstructor(new Class[] {});
61  0 renderer = (XYItemRenderer) ctor.newInstance(new Object[] {});
62    } catch (Throwable e) {
63  0 throw new GenerateException(e);
64    }
65    } else {
66  0 renderer = new XYLineAndShapeRenderer();
67    }
68  0 ChartCustomizer.customizeXYItemRenderer(renderer, params);
69   
70  0 DateAxis domainAxis = new DateAxis();
71  0 ChartCustomizer.customizeDateAxis(domainAxis, params, ChartParams.AXIS_DOMAIN_PREFIX);
72   
73  0 NumberAxis rangeAxis = new NumberAxis();
74  0 rangeAxis.setAutoRangeIncludesZero(false); // override default
75  0 ChartCustomizer.customizeNumberAxis(rangeAxis, params, ChartParams.AXIS_RANGE_PREFIX);
76   
77  0 XYDataset dataset = TimeSeriesCollectionFactory.getInstance().create(dataSource, params);
78   
79  0 XYPlot plot = new XYPlot(dataset, domainAxis, rangeAxis, renderer);
80   
81  0 ChartCustomizer.customizeXYPlot(plot, params);
82   
83  0 return plot;
84    }
85    }