Search in sources :

Example 6 with PivotTableData

use of org.activityinfo.legacy.shared.reports.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, dummyFilter(), 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.legacy.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) PivotTableReportElement(org.activityinfo.legacy.shared.reports.model.PivotTableReportElement) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 7 with PivotTableData

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

the class PivotTableDataBuilder method build.

public PivotTableData build(List<Dimension> rowDims, List<Dimension> colDims, List<Bucket> buckets) {
    PivotTableData table = new PivotTableData();
    Map<Dimension, Comparator<PivotTableData.Axis>> comparators = createComparators(Iterables.concat(rowDims, colDims));
    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.legacy.shared.reports.content.PivotTableData) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) DefinedCategoryComparator(org.activityinfo.legacy.shared.impl.pivot.order.DefinedCategoryComparator) CategoryComparator(org.activityinfo.legacy.shared.impl.pivot.order.CategoryComparator)

Example 8 with PivotTableData

use of org.activityinfo.legacy.shared.reports.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) {
    if (isRendered()) {
        el().unmask();
    }
    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.legacy.shared.reports.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.legacy.shared.reports.content.PivotChartContent)

Example 9 with PivotTableData

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

the class PivotGridPanel method show.

@Override
public void show(final PivotReportElement element) {
    if (isRendered()) {
        el().unmask();
    }
    if (grid != null) {
        removeAll();
    }
    PivotTableData data = element.getContent().getData();
    propertyMap = new HashMap<>();
    columnMap = new HashMap<>();
    columnModel = createColumnModel(data);
    store = new ListStore<>();
    addRows(data.getRootRow(), 0);
    grid = new Grid<>(store, columnModel);
    grid.setAutoExpandColumn("header");
    grid.setAutoExpandMin(150);
    grid.setView(new PivotGridView());
    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) {
                PivotTableData.Axis row = ge.getModel().getRowAxis();
                PivotTableData.Axis column = columnMap.get(ge.getColIndex());
                if (row.getCell(column) != null) {
                    drillDownEditor.drillDown(element, row, column);
                }
            }
        }
    });
    add(grid);
    layout();
}
Also used : GridEvent(com.extjs.gxt.ui.client.event.GridEvent) PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData)

Example 10 with PivotTableData

use of org.activityinfo.legacy.shared.reports.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.legacy.shared.reports.content.PivotTableData) PieChart2D(org.krysalis.jcharts.nonAxisChart.PieChart2D) ChartFont(org.krysalis.jcharts.properties.util.ChartFont)

Aggregations

PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)12 Filter (org.activityinfo.legacy.shared.command.Filter)2 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)2 FilterDescription (org.activityinfo.legacy.shared.reports.content.FilterDescription)2 PivotChartContent (org.activityinfo.legacy.shared.reports.content.PivotChartContent)2 PivotContent (org.activityinfo.legacy.shared.reports.content.PivotContent)2 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)2 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)2 ChartModel (com.extjs.gxt.charts.client.model.ChartModel)1 XAxis (com.extjs.gxt.charts.client.model.axis.XAxis)1 YAxis (com.extjs.gxt.charts.client.model.axis.YAxis)1 GridEvent (com.extjs.gxt.ui.client.event.GridEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)1 PivotTableDataBuilder (org.activityinfo.legacy.shared.impl.pivot.PivotTableDataBuilder)1 CategoryComparator (org.activityinfo.legacy.shared.impl.pivot.order.CategoryComparator)1 DefinedCategoryComparator (org.activityinfo.legacy.shared.impl.pivot.order.DefinedCategoryComparator)1 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)1 DispatcherSync (org.activityinfo.server.command.DispatcherSync)1