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

File TableXYDatasetFactory.java

 

Coverage histogram

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

Code metrics

20
21
3
1
85
56
13
0.62
7
3
4.33

Classes

Class Line # Actions
TableXYDatasetFactory 31 21 0% 13 44
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 org.jfree.data.xy.DefaultTableXYDataset;
23    import org.jfree.data.xy.XYDataset;
24    import org.jfree.data.xy.XYSeries;
25   
26    import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException;
27    import com.xpn.xwiki.plugin.charts.exceptions.GenerateException;
28    import com.xpn.xwiki.plugin.charts.params.ChartParams;
29    import com.xpn.xwiki.plugin.charts.source.DataSource;
30   
 
31    public class TableXYDatasetFactory
32    {
33    private static TableXYDatasetFactory uniqueInstance = new TableXYDatasetFactory();
34   
 
35  0 toggle private TableXYDatasetFactory()
36    {
37    // empty
38    }
39   
 
40  0 toggle public static TableXYDatasetFactory getInstance()
41    {
42  0 return uniqueInstance;
43    }
44   
 
45  0 toggle public XYDataset create(DataSource dataSource, ChartParams params) throws GenerateException, DataSourceException
46    {
47    // String type = params.getStringParam("type");
48  0 String dataSeries = params.getString(ChartParams.SERIES);
49   
50  0 DefaultTableXYDataset dataset = new DefaultTableXYDataset();
51  0 if (dataSeries.equals("columns")) {
52  0 if (!dataSource.hasHeaderColumn()) {
53  0 throw new GenerateException("Header column required");
54    }
55  0 for (int column = 0; column < dataSource.getColumnCount(); column++) {
56  0 XYSeries series =
57  0 new XYSeries(dataSource.hasHeaderRow() ? dataSource.getHeaderRowValue(column)
58    : ("Series " + (column + 1)), false, false);
59  0 for (int row = 0; row < dataSource.getRowCount(); row++) {
60  0 series.add(Double.parseDouble(dataSource.getHeaderColumnValue(row)), dataSource
61    .getCell(row, column));
62    }
63  0 dataset.addSeries(series);
64    }
65   
66  0 } else if (dataSeries.equals("rows")) {
67  0 if (!dataSource.hasHeaderRow()) {
68  0 throw new GenerateException("Header row required");
69    }
70  0 for (int row = 0; row < dataSource.getRowCount(); row++) {
71  0 XYSeries series =
72  0 new XYSeries(dataSource.hasHeaderColumn() ? dataSource.getHeaderColumnValue(row)
73    : ("Series " + (row + 1)), false, false);
74  0 for (int column = 0; column < dataSource.getColumnCount(); column++) {
75  0 series.add(Double.parseDouble(dataSource.getHeaderRowValue(column)), dataSource
76    .getCell(row, column));
77    }
78  0 dataset.addSeries(series);
79    }
80    } else {
81  0 throw new GenerateException("Invalid series parameter:" + dataSeries);
82    }
83  0 return dataset;
84    }
85    }