Search in sources :

Example 1 with ChartModel

use of org.xwiki.chart.model.ChartModel in project xwiki-platform by xwiki.

the class TableCategoryDatasetBuilderTest method testBuildCategoryDataset.

@Test
public void testBuildCategoryDataset() throws Exception {
    String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "line", "range", "B2-D3"), null);
    ChartModel chartModel = getDataSource().getChartModel();
    Dataset dataset = chartModel.getDataset();
    Assert.assertTrue(dataset instanceof CategoryDataset);
    Assert.assertTrue(chartModel.getAxis(0) instanceof CategoryAxis);
    Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
    CategoryDataset categoryDataset = (CategoryDataset) dataset;
    Assert.assertTrue(categoryDataset.getRowKey(0).equals(" row 1 "));
    Assert.assertTrue(categoryDataset.getRowKey(1).equals(" row 2 "));
    Assert.assertTrue(categoryDataset.getColumnKey(0).equals(" column 2 "));
    Assert.assertTrue(categoryDataset.getColumnKey(1).equals(" column 3 "));
    Assert.assertTrue(categoryDataset.getColumnKey(2).equals(" column 4"));
    Assert.assertTrue(categoryDataset.getValue(0, 0).intValue() == 12);
    Assert.assertTrue(categoryDataset.getValue(0, 1).intValue() == 13);
    Assert.assertTrue(categoryDataset.getValue(0, 2).intValue() == 14);
    Assert.assertTrue(categoryDataset.getValue(1, 0).intValue() == 22);
    Assert.assertTrue(categoryDataset.getValue(1, 1).intValue() == 23);
    Assert.assertTrue(categoryDataset.getValue(1, 2).intValue() == 24);
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) Dataset(org.jfree.data.general.Dataset) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

Example 2 with ChartModel

use of org.xwiki.chart.model.ChartModel in project xwiki-platform by xwiki.

the class TableCategoryDatasetBuilderTest method testBuildCategoryDatasetColumnsSeries.

@Test
public void testBuildCategoryDatasetColumnsSeries() throws Exception {
    String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "line", "range", "B2-D3", "series", "columns"), null);
    ChartModel chartModel = getDataSource().getChartModel();
    Dataset dataset = chartModel.getDataset();
    Assert.assertTrue(dataset instanceof CategoryDataset);
    Assert.assertTrue(chartModel.getAxis(0) instanceof CategoryAxis);
    Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
    CategoryDataset categoryDataset = (CategoryDataset) dataset;
    Assert.assertTrue(categoryDataset.getColumnKey(0).equals(" row 1 "));
    Assert.assertTrue(categoryDataset.getColumnKey(1).equals(" row 2 "));
    Assert.assertTrue(categoryDataset.getRowKey(0).equals(" column 2 "));
    Assert.assertTrue(categoryDataset.getRowKey(1).equals(" column 3 "));
    Assert.assertTrue(categoryDataset.getRowKey(2).equals(" column 4"));
    Assert.assertTrue(categoryDataset.getValue(0, 0).intValue() == 12);
    Assert.assertTrue(categoryDataset.getValue(1, 0).intValue() == 13);
    Assert.assertTrue(categoryDataset.getValue(2, 0).intValue() == 14);
    Assert.assertTrue(categoryDataset.getValue(0, 1).intValue() == 22);
    Assert.assertTrue(categoryDataset.getValue(1, 1).intValue() == 23);
    Assert.assertTrue(categoryDataset.getValue(2, 1).intValue() == 24);
}
Also used : CategoryAxis(org.jfree.chart.axis.CategoryAxis) CategoryDataset(org.jfree.data.category.CategoryDataset) Dataset(org.jfree.data.general.Dataset) CategoryDataset(org.jfree.data.category.CategoryDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

Example 3 with ChartModel

use of org.xwiki.chart.model.ChartModel in project xwiki-platform by xwiki.

the class TableTimeTableXYBuilderTest method testBuildTimeTableXY.

@Test
public void testBuildTimeTableXY() throws Exception {
    String content = "| Date | column 2 | column 3 | column 4\n" + "| 2012-01-01 10:30:10 | 12 | 13 | 14 \n" + "| 2012-01-01 10:30:20 |  22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "xy_line_and_shape", "dataset", "timetable_xy", "range", "A2-D3", "locale", "en_US", "date_format", "yyyy-MM-dd kk:mm:ss", "domain_axis_type", "date"), null);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss", new Locale("en"));
    ChartModel chartModel = getDataSource().getChartModel();
    Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset);
    Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis);
    Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
    TimeTableXYDataset dataset = (TimeTableXYDataset) chartModel.getDataset();
    Assert.assertTrue(dataset.getSeriesCount() == 3);
    Assert.assertTrue(dataset.getSeriesKey(0).equals(" column 2 "));
    Assert.assertTrue(dataset.getSeriesKey(1).equals(" column 3 "));
    Assert.assertTrue(dataset.getSeriesKey(2).equals(" column 4"));
    Assert.assertTrue(dataset.getTimePeriod(0).getStart().equals(new Date(0)));
    Assert.assertTrue(dataset.getTimePeriod(0).getEnd().equals(dateFormat.parse("2012-01-01 10:30:10")));
    Assert.assertTrue(dataset.getTimePeriod(1).getStart().equals(dateFormat.parse("2012-01-01 10:30:10")));
    Assert.assertTrue(dataset.getTimePeriod(1).getEnd().equals(dateFormat.parse("2012-01-01 10:30:20")));
}
Also used : Locale(java.util.Locale) DateAxis(org.jfree.chart.axis.DateAxis) TimeTableXYDataset(org.jfree.data.time.TimeTableXYDataset) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartModel(org.xwiki.chart.model.ChartModel) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Test(org.junit.Test)

Example 4 with ChartModel

use of org.xwiki.chart.model.ChartModel in project xwiki-platform by xwiki.

the class TableTimeTableXYBuilderTest method testYearInterval.

@Test
public void testYearInterval() throws Exception {
    String content = "| Date | column 2 | column 3 | column 4\n" + "| 1970  | 12 | 13 | 14 \n" + "| 1971 |  22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "xy_line_and_shape", "dataset", "timetable_xy", "range", "A2-D3", "locale", "en_US", "date_format", "yyyy", "domain_axis_type", "date", "time_period", "year"), null);
    ChartModel chartModel = getDataSource().getChartModel();
    Assert.assertTrue(chartModel.getDataset() instanceof TimeTableXYDataset);
    Assert.assertTrue(chartModel.getAxis(0) instanceof DateAxis);
    Assert.assertTrue(chartModel.getAxis(1) instanceof ValueAxis);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) TimeTableXYDataset(org.jfree.data.time.TimeTableXYDataset) ValueAxis(org.jfree.chart.axis.ValueAxis) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

Example 5 with ChartModel

use of org.xwiki.chart.model.ChartModel in project xwiki-platform by xwiki.

the class TablePieDatasetBuilderTest method testBuildPieDataset.

@Test
public void testBuildPieDataset() throws Exception {
    String content = "| column 1 | column 2 | column 3 | column 4\n" + "| row 1 | 12 | 13 | 14 \n" + "| row 2 | 22 | 23 | 24 \n";
    setUpContentExpectation(content);
    getDataSource().buildDataset(content, map("type", "pie", "range", "B2-D3"), null);
    ChartModel chartModel = getDataSource().getChartModel();
    Dataset dataset = chartModel.getDataset();
    Assert.assertTrue(dataset instanceof PieDataset);
    PieDataset pieDataset = (PieDataset) dataset;
    Assert.assertTrue(pieDataset.getKey(0).equals(" row 1 "));
    Assert.assertTrue(pieDataset.getKey(1).equals(" row 2 "));
    Assert.assertTrue(pieDataset.getValue(0).intValue() == 12);
    Assert.assertTrue(pieDataset.getValue(1).intValue() == 22);
}
Also used : PieDataset(org.jfree.data.general.PieDataset) Dataset(org.jfree.data.general.Dataset) PieDataset(org.jfree.data.general.PieDataset) ChartModel(org.xwiki.chart.model.ChartModel) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ChartModel (org.xwiki.chart.model.ChartModel)6 ValueAxis (org.jfree.chart.axis.ValueAxis)4 Dataset (org.jfree.data.general.Dataset)4 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 DateAxis (org.jfree.chart.axis.DateAxis)2 CategoryDataset (org.jfree.data.category.CategoryDataset)2 PieDataset (org.jfree.data.general.PieDataset)2 TimeTableXYDataset (org.jfree.data.time.TimeTableXYDataset)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Locale (java.util.Locale)1