Search in sources :

Example 6 with PivotTableData

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

the class PivotTableGeneratorTest method test2x2.

@Test
public void test2x2() {
    // test input data: user
    User user = new User();
    user.setLocale("fr");
    // test input data: PivotTableElement
    PivotTableReportElement element = new PivotTableReportElement();
    AdminDimension provinceDim = new AdminDimension(1);
    element.addRowDimension(provinceDim);
    Dimension partnerDim = new Dimension(DimensionType.Partner);
    element.addColDimension(partnerDim);
    // test input data: aggregated results
    List<Bucket> buckets = new ArrayList<Bucket>();
    buckets.add(newBucket(433, category(provinceDim, 2, "Sud Kivu"), category(partnerDim, 1, "IRC")));
    buckets.add(newBucket(1032, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 2, "Solidarites")));
    buckets.add(newBucket(310, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 1, "IRC")));
    buckets.add(newBucket(926, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 3, "AVSI")));
    // collaborator : PivotDAO
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(buckets));
    replay(dispatcher);
    // CLASS UNDER TEST!!
    PivotTableGenerator generator = new PivotTableGenerator(dispatcher);
    generator.generate(user, element, null, null);
    Assert.assertNotNull("element content", element.getContent());
    PivotTableData data = element.getContent().getData();
    Assert.assertEquals("rows", 2, data.getRootRow().getChildCount());
    Assert.assertEquals("rows sorted", "Nord Kivu", data.getRootRow().getChildren().get(0).getLabel());
    Assert.assertEquals("cols", 3, data.getRootColumn().getChildCount());
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.shared.command.result.Bucket) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 7 with PivotTableData

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

the class ItextReportRendererTest method manyColumns.

@Test
public void manyColumns() throws IOException {
    PivotTableData data = new PivotTableData();
    Dimension partner = new Dimension(DimensionType.Partner);
    Dimension year = new DateDimension(DateUnit.YEAR);
    EntityCategory avsi = new EntityCategory(100, "AVSI RRMP");
    Axis avsiRow = data.getRootRow().addChild(partner, avsi, avsi.getLabel(), comparator);
    for (int y = 2011; y < 2030; ++y) {
        Axis col = data.getRootColumn().addChild(year, new SimpleCategory("" + y), "" + y, comparator);
        avsiRow.setValue(col, (double) y);
    }
    PivotContent tableContent = new PivotContent(data, Lists.<FilterDescription>newArrayList());
    PivotTableReportElement table = new PivotTableReportElement();
    table.addRowDimension(partner);
    table.addColDimension(year);
    table.setContent(tableContent);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(table);
    renderToPdf(report, "narrowColumns.pdf");
    renderToRtf(report, "narrowColumns.rtf");
}
Also used : SimpleCategory(org.activityinfo.shared.report.content.SimpleCategory) ReportContent(org.activityinfo.shared.report.content.ReportContent) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) Report(org.activityinfo.shared.report.model.Report) PivotContent(org.activityinfo.shared.report.content.PivotContent) DateDimension(org.activityinfo.shared.report.model.DateDimension) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DateDimension(org.activityinfo.shared.report.model.DateDimension) Axis(org.activityinfo.shared.report.content.PivotTableData.Axis) Test(org.junit.Test)

Example 8 with PivotTableData

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

the class ItextReportRendererTest method nestedColumns.

@Test
public void nestedColumns() throws IOException {
    Dimension province = new AdminDimension(1);
    Dimension partner = new Dimension(DimensionType.Partner);
    Dimension year = new DateDimension(DateUnit.YEAR);
    Dimension month = new DateDimension(DateUnit.MONTH);
    EntityCategory avsi = new EntityCategory(100, "AVSI RRMP");
    PivotTableData data = new PivotTableData();
    Axis sudKivu = data.getRootColumn().addChild(province, new EntityCategory(1, "Sud Kivu"), "Sud Kivu", comparator);
    Axis y2010 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
    Axis y2011 = sudKivu.addChild(year, new SimpleCategory("2010"), "2010", comparator);
    Axis jan2010 = y2010.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
    Axis feb2010 = y2010.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
    Axis jan2011 = y2011.addChild(month, new SimpleCategory("Jan"), "Jan", comparator);
    Axis feb2011 = y2011.addChild(month, new SimpleCategory("Feb"), "Feb", comparator);
    Axis avsiRow = data.getRootRow().addChild(partner, avsi, avsi.getLabel(), comparator);
    avsiRow.setValue(jan2010, 1d);
    avsiRow.setValue(feb2010, 2d);
    avsiRow.setValue(jan2011, 3d);
    avsiRow.setValue(feb2011, 4d);
    PivotContent tableContent = new PivotContent(data, Lists.<FilterDescription>newArrayList());
    PivotTableReportElement table = new PivotTableReportElement();
    table.addRowDimension(partner);
    table.addColDimension(province);
    table.addColDimension(year);
    table.addColDimension(month);
    table.setContent(tableContent);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(table);
    renderToPdf(report, "nestedColumns.pdf");
    renderToRtf(report, "nestedColumns.rtf");
    renderToXls(report, "nestedColumns.xls");
}
Also used : SimpleCategory(org.activityinfo.shared.report.content.SimpleCategory) ReportContent(org.activityinfo.shared.report.content.ReportContent) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) DummyPivotTableData(org.activityinfo.server.report.DummyPivotTableData) Report(org.activityinfo.shared.report.model.Report) PivotContent(org.activityinfo.shared.report.content.PivotContent) DateDimension(org.activityinfo.shared.report.model.DateDimension) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DateDimension(org.activityinfo.shared.report.model.DateDimension) Axis(org.activityinfo.shared.report.content.PivotTableData.Axis) Test(org.junit.Test)

Example 9 with PivotTableData

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

the class ChartOFCView method show.

/**
 * Updates the view to the given PivotChartContent
 *
 * @param element
 */
@Override
public void show(PivotChartReportElement element) {
    PivotChartContent content = element.getContent();
    PivotTableData table = element.getContent().getData();
    if (gridPanel != null) {
        gridPanel.show(element);
    }
    List<PivotTableData.Axis> categories = table.getRootRow().getLeaves();
    List<PivotTableData.Axis> series = table.getRootColumn().getLeaves();
    ChartModel cm = new ChartModel();
    cm.setBackgroundColour(TRANSPARENT_BG);
    cm.setNumDecimals(0);
    cm.setDecimalSeparatorComma(true);
    cm.setXAxis(createXAxis(categories));
    cm.setYAxis(createYAxis(content, table));
    switch(element.getType()) {
        case Bar:
        case StackedBar:
        case ClusteredBar:
            addBarSeries(cm, categories, series);
            break;
        case Pie:
            addPieChart(cm, categories, series);
            break;
        case Line:
            addLineSeries(cm, categories, series);
            break;
    }
    setModel(cm);
}
Also used : PivotTableData(org.activityinfo.shared.report.content.PivotTableData) ChartModel(com.extjs.gxt.charts.client.model.ChartModel) XAxis(com.extjs.gxt.charts.client.model.axis.XAxis) YAxis(com.extjs.gxt.charts.client.model.axis.YAxis) PivotChartContent(org.activityinfo.shared.report.content.PivotChartContent)

Example 10 with PivotTableData

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

the class PivotGridPanel method show.

@Override
public void show(final PivotReportElement element) {
    if (grid != null) {
        removeAll();
    }
    this.element = element;
    PivotTableData data = element.getContent().getData();
    propertyMap = new HashMap<PivotTableData.Axis, String>();
    columnMap = new HashMap<Integer, PivotTableData.Axis>();
    columnModel = createColumnModel(data);
    store = new ListStore<PivotTableRow>();
    addRows(data.getRootRow(), 0);
    grid = new Grid<PivotTableRow>(store, columnModel);
    grid.setAutoExpandColumn("header");
    grid.setAutoExpandMin(150);
    grid.setSelectionModel(new CellSelectionModel<PivotGridPanel.PivotTableRow>());
    grid.addListener(Events.CellDoubleClick, new Listener<GridEvent<PivotTableRow>>() {

        @Override
        public void handleEvent(GridEvent<PivotTableRow> ge) {
            if (ge.getColIndex() != 0) {
            // eventBus.fireEvent(new
            // PivotCellEvent(AppEvents.DRILL_DOWN,
            // element,
            // ge.getModel().getRowAxis(),
            // columnMap.get(ge.getColIndex())));
            }
        }
    });
    add(grid);
    layout();
}
Also used : GridEvent(com.extjs.gxt.ui.client.event.GridEvent) PivotTableData(org.activityinfo.shared.report.content.PivotTableData)

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