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

File AbstractCategoryPlotGenerator.java

 

Coverage histogram

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

Code metrics

6
13
1
1
75
37
4
0.31
13
1
4

Classes

Class Line # Actions
AbstractCategoryPlotGenerator 39 13 0% 4 6
0.770%
 

Contributing tests

This file is covered by 4 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.CategoryAxis;
25    import org.jfree.chart.axis.ValueAxis;
26    import org.jfree.chart.plot.CategoryPlot;
27    import org.jfree.chart.plot.Plot;
28    import org.jfree.chart.renderer.category.CategoryItemRenderer;
29    import org.jfree.data.category.CategoryDataset;
30    import org.xwiki.chart.PlotGeneratorException;
31    import org.xwiki.chart.model.ChartModel;
32   
33    /**
34    * Generate Plots for Category data sets.
35    *
36    * @version $Id: 358ee427e5c36607cf6a74438af33aae60de219e $
37    * @since 4.1M1
38    */
 
39    public abstract class AbstractCategoryPlotGenerator implements PlotGenerator
40    {
 
41  5 toggle @Override
42    public Plot generate(ChartModel model, Map<String, String> parameters) throws PlotGeneratorException
43    {
44  5 CategoryDataset dataset;
45  5 CategoryAxis domainAxis;
46  5 ValueAxis rangeAxis;
47   
48  5 if (model.getDataset() instanceof CategoryDataset) {
49  5 dataset = (CategoryDataset) model.getDataset();
50    } else {
51  0 throw new PlotGeneratorException("Incompatible dataset for category plot.");
52    }
53   
54  5 if (model.getAxis(0) instanceof CategoryAxis) {
55  5 domainAxis = (CategoryAxis) model.getAxis(0);
56    } else {
57  0 throw new PlotGeneratorException("Incompatible axis 0 for category plot.");
58    }
59   
60  5 if (model.getAxis(1) instanceof ValueAxis) {
61  5 rangeAxis = (ValueAxis) model.getAxis(1);
62    } else {
63  0 throw new PlotGeneratorException("Incompatible axis 1 for category plot.");
64    }
65   
66  5 return new CategoryPlot(dataset, domainAxis, rangeAxis, getRenderer(parameters));
67    }
68   
69    /**
70    * @param parameters used to configure the renderer
71    * @return an {@link CategoryItemRenderer} to be used for plotting the chart.
72    */
73    protected abstract CategoryItemRenderer getRenderer(Map<String, String> parameters);
74   
75    }