Search in sources :

Example 26 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class AverageNumberOfTenderersExcelControllerTest method averageNumberBidsExcelChart.

@Test
public void averageNumberBidsExcelChart() throws Exception {
    LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
    averageNumberOfTenderersExcelController.averageNumberBidsExcelChart(filter, mockHttpServletResponse);
    final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
    final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.barcol.toString());
    Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
    final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
    final List<XSSFChart> charts = drawing.getCharts();
    Assert.assertEquals("number of charts", 1, charts.size());
    final XSSFChart chart = charts.get(0);
    Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:avgNrBids:title"), chart.getTitle().getString());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("Check if we have 1 bar chart", 1, ctChart.getPlotArea().getBarChartArray().length);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) LangYearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Example 27 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class AverageTenderAndAwardsExcelControllerTest method bidTimelineExcelChart.

@Test
public void bidTimelineExcelChart() throws Exception {
    LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
    averageTenderAndAwardsExcelController.bidTimelineExcelChart(filter, mockHttpServletResponse);
    final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
    final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.stackedbar.toString());
    Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
    final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
    final List<XSSFChart> charts = drawing.getCharts();
    Assert.assertEquals("number of charts", 1, charts.size());
    final XSSFChart chart = charts.get(0);
    Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:bidPeriod:title"), chart.getTitle().getString());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("Check if we have 1 bar chart", 1, ctChart.getPlotArea().getBarChartArray().length);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) LangYearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Example 28 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class CostEffectivenessExcelControllerTest method costEffectivenessExcelChart.

@Test
public void costEffectivenessExcelChart() throws Exception {
    LangGroupingFilterPagingRequest filter = getLangGroupingFilterMockRequest();
    costEffectivenessExcelController.costEffectivenessExcelChart(filter, mockHttpServletResponse);
    final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
    final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.stackedcol.toString());
    Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
    final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
    final List<XSSFChart> charts = drawing.getCharts();
    Assert.assertEquals("number of charts", 1, charts.size());
    final XSSFChart chart = charts.get(0);
    Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:costEffectiveness:title"), chart.getTitle().getString());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("Check if we have 1 bar chart", 1, ctChart.getPlotArea().getBarChartArray().length);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) LangGroupingFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.LangGroupingFilterPagingRequest) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Example 29 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class TenderPercentagesExcelControllerTest method numberTendersUsingEBidExcelChart.

@Test
public void numberTendersUsingEBidExcelChart() throws Exception {
    LangYearFilterPagingRequest filter = getLangYearFilterMockRequest();
    tenderPercentagesExcelController.numberTendersUsingEBidExcelChart(filter, mockHttpServletResponse);
    final byte[] responseOutput = mockHttpServletResponse.getContentAsByteArray();
    final Workbook workbook = new XSSFWorkbook(new ByteArrayInputStream(responseOutput));
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.area.toString());
    Assert.assertNotNull("check chart type, sheet name should be the same as the type", sheet);
    final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
    final List<XSSFChart> charts = drawing.getCharts();
    Assert.assertEquals("number of charts", 1, charts.size());
    final XSSFChart chart = charts.get(0);
    Assert.assertEquals("chart title", translationService.getValue(filter.getLanguage(), "charts:nrEBid:title"), chart.getTitle().getString());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("Check if we have 1 area chart", 1, ctChart.getPlotArea().getAreaChartArray().length);
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) LangYearFilterPagingRequest(org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) ByteArrayInputStream(java.io.ByteArrayInputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Example 30 with XSSFChart

use of org.apache.poi.xssf.usermodel.XSSFChart in project ocvn by devgateway.

the class ExcelChartDefaultTest method createWorkbook.

@Test
public void createWorkbook() throws Exception {
    final ExcelChart excelChart = new ExcelChartDefault("line chart", ChartType.line, CATEGORIES, VALUES);
    excelChart.configureSeriesTitle(Arrays.asList("foo", "bar"));
    final Workbook workbook = excelChart.createWorkbook();
    Assert.assertNotNull(workbook);
    final Sheet sheet = workbook.getSheet(ChartType.line.toString());
    Assert.assertNotNull(sheet);
    final XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
    final List<XSSFChart> charts = drawing.getCharts();
    Assert.assertEquals("number of charts", 1, charts.size());
    final XSSFChart chart = charts.get(0);
    Assert.assertEquals("chart title", "line chart", chart.getTitle().getString());
    final CTChart ctChart = chart.getCTChart();
    Assert.assertEquals("We should not have any area chart", 0, ctChart.getPlotArea().getAreaChartArray().length);
    Assert.assertEquals("Check if we have 1 line chart", 1, ctChart.getPlotArea().getLineChartArray().length);
    Assert.assertEquals("Check that we have a legend and that it's position is bottom", STLegendPos.B, ctChart.getLegend().getLegendPos().getVal());
    // check the actual chart data
    final CTLineChart ctLineChart = ctChart.getPlotArea().getLineChartArray()[0];
    final CTLineSer[] ctLineSer = ctLineChart.getSerArray();
    Assert.assertEquals("Check number of CTLineSer", 2, ctLineSer.length);
    Assert.assertEquals("check first series title", "foo", ctLineSer[0].getTx().getV());
    Assert.assertEquals("check second series title", "bar", ctLineSer[1].getTx().getV());
    final CTAxDataSource cat1 = ctLineSer[0].getCat();
    Assert.assertEquals("check first category", "cat 1", cat1.getStrRef().getStrCache().getPtArray()[0].getV());
    Assert.assertEquals("check last category", "cat 5", cat1.getStrRef().getStrCache().getPtArray()[4].getV());
    final CTAxDataSource cat2 = ctLineSer[1].getCat();
    Assert.assertEquals("check first category", "cat 1", cat2.getStrRef().getStrCache().getPtArray()[0].getV());
    Assert.assertEquals("check last category", "cat 5", cat2.getStrRef().getStrCache().getPtArray()[4].getV());
    final CTNumDataSource val1 = ctLineSer[0].getVal();
    Assert.assertEquals("check first value", "5.0", val1.getNumRef().getNumCache().getPtArray()[0].getV());
    Assert.assertEquals("check last value", "6.0", val1.getNumRef().getNumCache().getPtArray()[4].getV());
    final CTNumDataSource val2 = ctLineSer[1].getVal();
    Assert.assertEquals("check first value", "20.0", val2.getNumRef().getNumCache().getPtArray()[0].getV());
    Assert.assertEquals("check last value", "14.0", val2.getNumRef().getNumCache().getPtArray()[4].getV());
    final List<? extends XSSFChartAxis> axis = chart.getAxis();
    Assert.assertEquals("number of axis", 2, axis.size());
    Assert.assertTrue("category axis", axis.get(0) instanceof XSSFCategoryAxis);
    Assert.assertTrue("value axis", axis.get(1) instanceof XSSFValueAxis);
}
Also used : CTNumDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTNumDataSource) XSSFCategoryAxis(org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis) XSSFValueAxis(org.apache.poi.xssf.usermodel.charts.XSSFValueAxis) Workbook(org.apache.poi.ss.usermodel.Workbook) CTAxDataSource(org.openxmlformats.schemas.drawingml.x2006.chart.CTAxDataSource) XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) CTLineChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineChart) CTChart(org.openxmlformats.schemas.drawingml.x2006.chart.CTChart) CTLineSer(org.openxmlformats.schemas.drawingml.x2006.chart.CTLineSer) Sheet(org.apache.poi.ss.usermodel.Sheet) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing) Test(org.junit.Test)

Aggregations

XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)32 Workbook (org.apache.poi.ss.usermodel.Workbook)19 Test (org.junit.Test)19 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)18 CTChart (org.openxmlformats.schemas.drawingml.x2006.chart.CTChart)18 Sheet (org.apache.poi.ss.usermodel.Sheet)17 XSSFDrawing (org.apache.poi.xssf.usermodel.XSSFDrawing)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 LangYearFilterPagingRequest (org.devgateway.ocds.web.rest.controller.request.LangYearFilterPagingRequest)13 ChartAxis (org.apache.poi.ss.usermodel.charts.ChartAxis)11 CTPlotArea (org.openxmlformats.schemas.drawingml.x2006.chart.CTPlotArea)11 CustomChartSeries (org.devgateway.toolkit.web.excelcharts.CustomChartSeries)7 CTValAx (org.openxmlformats.schemas.drawingml.x2006.chart.CTValAx)5 AddTrace (com.google.firebase.perf.metrics.AddTrace)3 SpreadsheetUtils.getCellRangeAddress (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getCellRangeAddress)3 SpreadsheetUtils.getMetricForChart (com.supercilex.robotscouter.data.client.spreadsheet.SpreadsheetUtils.getMetricForChart)3 PreferencesUtilsKt.setShouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.setShouldShowExportHint)3 PreferencesUtilsKt.shouldShowExportHint (com.supercilex.robotscouter.util.PreferencesUtilsKt.shouldShowExportHint)3 Chart (org.apache.poi.ss.usermodel.Chart)3 RichTextString (org.apache.poi.ss.usermodel.RichTextString)3