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());
}
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;
}
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);
}
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();
}
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);
}
Aggregations