Search in sources :

Example 11 with PivotTableData

use of org.activityinfo.shared.report.content.PivotTableData in project activityinfo by bedatadriven.

the class ExcelPivotTableRenderer method render.

@Override
public void render(Workbook book, PivotTableReportElement element) {
    /* Generate the actual pivot table data */
    final PivotTableData table = element.getContent().getData();
    /* Generate the excel sheet */
    new BaseExcelTableRenderer<PivotTableReportElement, PivotTableData.Axis>(book, element) {

        @Override
        public List<FilterDescription> generateFilterDescriptions() {
            return element.getContent().getFilterDescriptions();
        }

        private CellStyle[] rowHeaderStyles;

        @Override
        public void generate() {
            /* Initialize Cell Styles */
            initColHeaderStyles(table.getRootColumn());
            initRowHeaderStyles();
            /* Generate the column headers */
            generateColumnHeaders(1, table.getRootColumn());
            int headerHeight = rowIndex;
            /* Create the rows */
            // row headers are in column 1
            sheet.setColumnWidth(0, 40 * 256);
            generateRows(table.getRootRow().getChildList(), 0);
            /* Finalize the sheet */
            sheet.setRowSumsBelow(false);
            sheet.createFreezePane(1, headerHeight);
        }

        protected void initRowHeaderStyles() {
            int depth = table.getRootRow().getDepth();
            rowHeaderStyles = new CellStyle[depth];
            for (int i = 0; i != depth; ++i) {
                CellStyle style = book.createCellStyle();
                style.setIndention((short) i);
                style.setWrapText(true);
                Font font = createBaseFont();
                if (i + 1 != depth) {
                    /* Has sub headers */
                    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
                } else {
                    font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
                }
                style.setFont(font);
                rowHeaderStyles[i] = style;
            }
        }

        protected void generateRows(List<PivotTableData.Axis> rows, int indent) {
            for (PivotTableData.Axis pivotRow : rows) {
                Row row = sheet.createRow(rowIndex++);
                Cell headerCell = row.createCell(0);
                headerCell.setCellValue(factory.createRichTextString(pivotRow.getLabel()));
                headerCell.setCellStyle(rowHeaderStyles[indent]);
                if (pivotRow.isLeaf()) {
                    for (Entry<PivotTableData.Axis, Integer> entry : colIndexMap.entrySet()) {
                        PivotTableData.Cell pivotCell = pivotRow.getCell(entry.getKey());
                        if (pivotCell != null) {
                            Cell cell = row.createCell(entry.getValue());
                            cell.setCellValue(pivotCell.getValue());
                        }
                    }
                } else {
                    int groupStart = rowIndex;
                    generateRows(pivotRow.getChildList(), indent + 1);
                    int groupEnd = rowIndex;
                    sheet.groupRow(groupStart, groupEnd);
                }
            }
        }
    };
}
Also used : FilterDescription(org.activityinfo.shared.report.content.FilterDescription) Font(org.apache.poi.ss.usermodel.Font) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) List(java.util.List) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Cell(org.apache.poi.ss.usermodel.Cell)

Example 12 with PivotTableData

use of org.activityinfo.shared.report.content.PivotTableData in project activityinfo by bedatadriven.

the class ChartRendererJC method createAxisChart.

protected Chart createAxisChart(PivotChartReportElement element, boolean includeTitle, int width, int height, int dpi) throws IOException, ChartDataException, PropertyException {
    PivotTableData table = element.getContent().getData();
    // find our categories and series leaves
    List<PivotTableData.Axis> categories = table.getRootRow().getLeaves();
    List<PivotTableData.Axis> series = table.getRootColumn().getLeaves();
    IAxisDataSeries dataSeries = new DataSeries(toLabelArray(element.getContent(), categories), element.getContent().getXAxisTitle(), element.getContent().getYAxisTitle(), includeTitle ? element.getTitle() : null);
    dataSeries.addIAxisPlotDataSet(new AxisChartDataSet(toDataArray(categories, series), toLabelArray(element.getContent(), series), computePaints(series), computeChartType(element), computeAxisChartProperties(dpi, element)));
    return new AxisChart(dataSeries, computeChartProperties(dpi), computeAxisProperties(dpi, element.getContent()), computeLegendProperties(element, dpi, series), width, height);
}
Also used : AxisChart(org.krysalis.jcharts.axisChart.AxisChart) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) IAxisDataSeries(org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries) DataSeries(org.krysalis.jcharts.chartData.DataSeries) IAxisDataSeries(org.krysalis.jcharts.chartData.interfaces.IAxisDataSeries) AxisChartDataSet(org.krysalis.jcharts.chartData.AxisChartDataSet)

Example 13 with PivotTableData

use of org.activityinfo.shared.report.content.PivotTableData in project activityinfo by bedatadriven.

the class ChartRendererJC method createPieChart.

/**
 * Creates a JChart PieChart from our report element
 */
protected Chart createPieChart(PivotChartReportElement element, boolean includeTitle, int width, int height, int dpi) throws IOException, ChartDataException {
    PivotTableData table = element.getContent().getData();
    List<PivotTableData.Axis> categories = table.getRootCategory().getLeaves();
    PivotTableData.Axis series = table.getRootSeries().getLeaves().get(0);
    PieChart2DProperties pieProps = new PieChart2DProperties();
    pieProps.setValueLabelFont(new ChartFont(new Font(SANS_SERIF, Font.PLAIN, fontSize(10, dpi)), Color.black));
    pieProps.setShowGrouping(true);
    pieProps.setPieLabelType(PieLabelType.VALUE_LABELS);
    pieProps.setBorderChartStroke(ChartStroke.DEFAULT_ZERO_LINE);
    PieChartDataSet dataSet = new PieChartDataSet(includeTitle ? element.getTitle() : null, toDataArray(categories, series), toLabelArray(element.getContent(), categories), computePaints(categories), pieProps);
    LegendProperties legendProps = computeLegendProperties(element, dpi, categories);
    ChartProperties chartProps = computeChartProperties(dpi);
    return new PieChart2D(dataSet, legendProps, chartProps, width, height);
}
Also used : ChartFont(org.krysalis.jcharts.properties.util.ChartFont) PieChartDataSet(org.krysalis.jcharts.chartData.PieChartDataSet) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) PieChart2D(org.krysalis.jcharts.nonAxisChart.PieChart2D) PieChart2DProperties(org.krysalis.jcharts.properties.PieChart2DProperties) LegendProperties(org.krysalis.jcharts.properties.LegendProperties) ChartProperties(org.krysalis.jcharts.properties.ChartProperties) LineChartProperties(org.krysalis.jcharts.properties.LineChartProperties) ClusteredBarChartProperties(org.krysalis.jcharts.properties.ClusteredBarChartProperties) BarChartProperties(org.krysalis.jcharts.properties.BarChartProperties) StackedBarChartProperties(org.krysalis.jcharts.properties.StackedBarChartProperties) ChartFont(org.krysalis.jcharts.properties.util.ChartFont) Font(com.google.code.appengine.awt.Font)

Example 14 with PivotTableData

use of org.activityinfo.shared.report.content.PivotTableData in project activityinfo by bedatadriven.

the class GeneratePivotTableHandler method buildResult.

protected PivotContent buildResult(PivotTableReportElement model, PivotResult result) {
    PivotTableDataBuilder builder = new PivotTableDataBuilder();
    PivotTableData data = builder.build(model, model.getRowDimensions(), model.getColumnDimensions(), result.getBuckets());
    PivotContent content = new PivotContent();
    content.setEffectiveFilter(model.getFilter());
    content.setData(data);
    return content;
}
Also used : PivotTableData(org.activityinfo.shared.report.content.PivotTableData) PivotContent(org.activityinfo.shared.report.content.PivotContent) PivotTableDataBuilder(org.activityinfo.shared.command.handler.pivot.PivotTableDataBuilder)

Example 15 with PivotTableData

use of org.activityinfo.shared.report.content.PivotTableData in project activityinfo by bedatadriven.

the class PivotTableDataBuilder method build.

public PivotTableData build(PivotReportElement<?> element, List<Dimension> rowDims, List<Dimension> colDims, List<Bucket> buckets) {
    PivotTableData table = new PivotTableData();
    Map<Dimension, Comparator<PivotTableData.Axis>> comparators = createComparators(element.allDimensions());
    for (Bucket bucket : buckets) {
        PivotTableData.Axis column = colDims.isEmpty() ? table.getRootColumn() : find(table.getRootColumn(), colDims.iterator(), comparators, bucket);
        PivotTableData.Axis row = rowDims.isEmpty() ? table.getRootRow() : find(table.getRootRow(), rowDims.iterator(), comparators, bucket);
        row.setValue(column, bucket.doubleValue());
    }
    return table;
}
Also used : PivotTableData(org.activityinfo.shared.report.content.PivotTableData) Bucket(org.activityinfo.shared.command.result.Bucket) Dimension(org.activityinfo.shared.report.model.Dimension) CategoryComparator(org.activityinfo.shared.command.handler.pivot.order.CategoryComparator) Comparator(java.util.Comparator) DefinedCategoryComparator(org.activityinfo.shared.command.handler.pivot.order.DefinedCategoryComparator)

Aggregations

PivotTableData (org.activityinfo.shared.report.content.PivotTableData)15 PivotContent (org.activityinfo.shared.report.content.PivotContent)4 Dimension (org.activityinfo.shared.report.model.Dimension)4 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)3 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 DummyPivotTableData (org.activityinfo.server.report.DummyPivotTableData)2 Filter (org.activityinfo.shared.command.Filter)2 Bucket (org.activityinfo.shared.command.result.Bucket)2 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)2 FilterDescription (org.activityinfo.shared.report.content.FilterDescription)2 PivotChartContent (org.activityinfo.shared.report.content.PivotChartContent)2 Axis (org.activityinfo.shared.report.content.PivotTableData.Axis)2 ReportContent (org.activityinfo.shared.report.content.ReportContent)2 SimpleCategory (org.activityinfo.shared.report.content.SimpleCategory)2 DateDimension (org.activityinfo.shared.report.model.DateDimension)2 Report (org.activityinfo.shared.report.model.Report)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Row (org.apache.poi.ss.usermodel.Row)2