1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.chart.internal.plot

File AbstractXYPlotGenerator.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

6
13
1
1
73
36
4
0.31
13
1
4

Classes

Class Line # Actions
AbstractXYPlotGenerator 38 13 0% 4 6
0.770%
 

Contributing tests

This file is covered by 3 tests. .

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 org.xwiki.chart.internal.plot;
21   
22    import java.util.Map;
23   
24    import org.jfree.chart.axis.ValueAxis;
25    import org.jfree.chart.plot.Plot;
26    import org.jfree.chart.plot.XYPlot;
27    import org.jfree.chart.renderer.xy.XYItemRenderer;
28    import org.jfree.data.xy.XYDataset;
29    import org.xwiki.chart.PlotGeneratorException;
30    import org.xwiki.chart.model.ChartModel;
31   
32    /**
33    * Generate Plots for XY data sets.
34    *
35    * @version $Id: f826b3c0167d49e1dc75eadfd6d0ffbcc73423e3 $
36    * @since 4.2M1
37    */
 
38    public abstract class AbstractXYPlotGenerator implements PlotGenerator
39    {
 
40  3 toggle @Override
41    public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException
42    {
43  3 XYDataset dataset;
44  3 ValueAxis domainAxis;
45  3 ValueAxis rangeAxis;
46   
47  3 if (model.getDataset() instanceof XYDataset) {
48  3 dataset = (XYDataset) model.getDataset();
49    } else {
50  0 throw new PlotGeneratorException("Incompatible dataset for xy plot.");
51    }
52   
53  3 if (model.getAxis(0) instanceof ValueAxis) {
54  3 domainAxis = (ValueAxis) model.getAxis(0);
55    } else {
56  0 throw new PlotGeneratorException("Incompatible axis 0 for xy plot.");
57    }
58   
59  3 if (model.getAxis(1) instanceof ValueAxis) {
60  3 rangeAxis = (ValueAxis) model.getAxis(1);
61    } else {
62  0 throw new PlotGeneratorException("Incompatible axis 1 for xy plot.");
63    }
64   
65  3 return new XYPlot(dataset, domainAxis, rangeAxis, getRenderer(parameters));
66    }
67   
68    /**
69    * @param parameters used to configure the renderer
70    * @return an {@link XYItemRenderer} to be used for plotting the chart.
71    */
72    protected abstract XYItemRenderer getRenderer(Map<String, String> parameters);
73    }