Search in sources :

Example 1 with CategoryToPieDataset

use of org.jfree.data.category.CategoryToPieDataset in project SIMVA-SoS by SESoS.

the class MultiplePiePlot method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).
 *
 * @param g2  the graphics device.
 * @param area  the area within which the plot should be drawn.
 * @param anchor  the anchor point (<code>null</code> permitted).
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing.
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // adjust the drawing area for the plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);
    drawBackground(g2, area);
    drawOutline(g2, area);
    // check that there is some data to display...
    if (DatasetUtilities.isEmptyOrNull(this.dataset)) {
        drawNoDataMessage(g2, area);
        return;
    }
    int pieCount;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        pieCount = this.dataset.getRowCount();
    } else {
        pieCount = this.dataset.getColumnCount();
    }
    // the columns variable is always >= rows
    int displayCols = (int) Math.ceil(Math.sqrt(pieCount));
    int displayRows = (int) Math.ceil((double) pieCount / (double) displayCols);
    // swap rows and columns to match plotArea shape
    if (displayCols > displayRows && area.getWidth() < area.getHeight()) {
        int temp = displayCols;
        displayCols = displayRows;
        displayRows = temp;
    }
    prefetchSectionPaints();
    int x = (int) area.getX();
    int y = (int) area.getY();
    int width = ((int) area.getWidth()) / displayCols;
    int height = ((int) area.getHeight()) / displayRows;
    int row = 0;
    int column = 0;
    int diff = (displayRows * displayCols) - pieCount;
    int xoffset = 0;
    Rectangle rect = new Rectangle();
    for (int pieIndex = 0; pieIndex < pieCount; pieIndex++) {
        rect.setBounds(x + xoffset + (width * column), y + (height * row), width, height);
        String title;
        if (this.dataExtractOrder == TableOrder.BY_ROW) {
            title = this.dataset.getRowKey(pieIndex).toString();
        } else {
            title = this.dataset.getColumnKey(pieIndex).toString();
        }
        this.pieChart.setTitle(title);
        PieDataset piedataset;
        PieDataset dd = new CategoryToPieDataset(this.dataset, this.dataExtractOrder, pieIndex);
        if (this.limit > 0.0) {
            piedataset = DatasetUtilities.createConsolidatedPieDataset(dd, this.aggregatedItemsKey, this.limit);
        } else {
            piedataset = dd;
        }
        PiePlot piePlot = (PiePlot) this.pieChart.getPlot();
        piePlot.setDataset(piedataset);
        piePlot.setPieIndex(pieIndex);
        // update the section colors to match the global colors...
        for (int i = 0; i < piedataset.getItemCount(); i++) {
            Comparable key = piedataset.getKey(i);
            Paint p;
            if (key.equals(this.aggregatedItemsKey)) {
                p = this.aggregatedItemsPaint;
            } else {
                p = (Paint) this.sectionPaints.get(key);
            }
            piePlot.setSectionPaint(key, p);
        }
        ChartRenderingInfo subinfo = null;
        if (info != null) {
            subinfo = new ChartRenderingInfo();
        }
        this.pieChart.draw(g2, rect, subinfo);
        if (info != null) {
            assert subinfo != null;
            info.getOwner().getEntityCollection().addAll(subinfo.getEntityCollection());
            info.addSubplotInfo(subinfo.getPlotInfo());
        }
        ++column;
        if (column == displayCols) {
            column = 0;
            ++row;
            if (row == displayRows - 1 && diff != 0) {
                xoffset = (diff * width) / 2;
            }
        }
    }
}
Also used : CategoryToPieDataset(org.jfree.data.category.CategoryToPieDataset) PieDataset(org.jfree.data.general.PieDataset) Rectangle(java.awt.Rectangle) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) RectangleInsets(org.jfree.ui.RectangleInsets) CategoryToPieDataset(org.jfree.data.category.CategoryToPieDataset) Paint(java.awt.Paint) Paint(java.awt.Paint)

Aggregations

Paint (java.awt.Paint)1 Rectangle (java.awt.Rectangle)1 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)1 CategoryToPieDataset (org.jfree.data.category.CategoryToPieDataset)1 PieDataset (org.jfree.data.general.PieDataset)1 RectangleInsets (org.jfree.ui.RectangleInsets)1