Search in sources :

Example 21 with PieDataset

use of org.jfree.data.general.PieDataset in project cytoscape-impl by cytoscape.

the class PieLayer method createDataset.

// ==[ PRIVATE METHODS ]============================================================================================
@Override
protected PieDataset createDataset() {
    final List<Double> values = data.isEmpty() ? null : data.values().iterator().next();
    final PieDataset dataset = createPieDataset(values);
    if (showItemLabels && itemLabels != null) {
        final List<?> keys = dataset.getKeys();
        for (int i = 0; i < keys.size(); i++) {
            final String k = (String) keys.get(i);
            final String label = itemLabels.size() > i ? itemLabels.get(i) : null;
            labels.put(k, label);
        }
    }
    return dataset;
}
Also used : PieDataset(org.jfree.data.general.PieDataset)

Example 22 with PieDataset

use of org.jfree.data.general.PieDataset in project cytoscape-impl by cytoscape.

the class RingLayer method getChart.

@Override
@SuppressWarnings("unchecked")
protected JFreeChart getChart() {
    if (datasetList == null || chartList == null) {
        createDataset();
        final int total = datasetList.size();
        chartList = new ArrayList<JFreeChart>(total);
        if (total > 0) {
            int count = 0;
            for (final PieDataset ds : datasetList) {
                double sectionDepth = ((1.0 - hole) / (double) total) * (total - count);
                final JFreeChart chart = createChart(ds, sectionDepth, PieLayer.INTERIOR_GAP);
                chartList.add(chart);
                count++;
            }
        } else {
            // Just to show the "no data" text
            final JFreeChart chart = createChart(createPieDataset(Collections.EMPTY_LIST), 1.0, 0.0);
            chartList.add(chart);
        }
    }
    return chartList == null || chartList.isEmpty() ? null : chartList.get(0);
}
Also used : PieDataset(org.jfree.data.general.PieDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 23 with PieDataset

use of org.jfree.data.general.PieDataset in project MassBank-web by MassBank.

the class Contents method init.

public void init() throws ServletException {
    try {
        result = new SearchExecution(null).exec(new RecordIndexCount());
        // construct and show pie charts
        int MAX_DISP_DATA = 10;
        PieDataset siteGraphData = createDataset(result.mapSiteToRecordCount, MAX_DISP_DATA);
        PieDataset instGraphData = createDataset(result.mapInstrumentToRecordCount, MAX_DISP_DATA);
        PieDataset msGraphData = createDataset(result.mapMsTypeToRecordCount, MAX_DISP_DATA);
        int siteTopNum = (siteGraphData.getItemCount() < MAX_DISP_DATA) ? siteGraphData.getItemCount() : MAX_DISP_DATA;
        int instTopNum = (instGraphData.getItemCount() < MAX_DISP_DATA) ? instGraphData.getItemCount() : MAX_DISP_DATA;
        int msTopNum = (msGraphData.getItemCount() < MAX_DISP_DATA) ? msGraphData.getItemCount() : MAX_DISP_DATA;
        JFreeChart sitechart = drawDataset(siteGraphData, "Contributor top " + siteTopNum);
        JFreeChart instchart = drawDataset(instGraphData, "Instrument Type top " + instTopNum);
        JFreeChart mschart = drawDataset(msGraphData, "MS Type top " + msTopNum);
        SVGGraphics2D g2 = new SVGGraphics2D(900, 350);
        Rectangle r = new Rectangle(0, 0, 900, 350);
        sitechart.draw(g2, r);
        sitechartSVG = g2.getSVGElement();
        instchart.draw(g2, r);
        instchartSVG = g2.getSVGElement();
        mschart.draw(g2, r);
        mschartSVG = g2.getSVGElement();
        // get the current database timestamp
        timestamp = new DatabaseTimestamp();
    } catch (SQLException | ConfigurationException e) {
        logger.error(e.getMessage());
    }
}
Also used : RecordIndexCount(massbank.web.recordindex.RecordIndexCount) PieDataset(org.jfree.data.general.PieDataset) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) SQLException(java.sql.SQLException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) SearchExecution(massbank.web.SearchExecution) Rectangle(java.awt.Rectangle) SVGGraphics2D(org.jfree.graphics2d.svg.SVGGraphics2D) DatabaseTimestamp(massbank.db.DatabaseTimestamp) JFreeChart(org.jfree.chart.JFreeChart)

Example 24 with PieDataset

use of org.jfree.data.general.PieDataset 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)

Example 25 with PieDataset

use of org.jfree.data.general.PieDataset in project SIMVA-SoS by SESoS.

the class CategoryToPieDataset method equals.

/**
 * Tests this dataset for equality with an arbitrary object, returning
 * <code>true</code> if <code>obj</code> is a dataset containing the same
 * keys and values in the same order as this dataset.
 *
 * @param obj  the object to test (<code>null</code> permitted).
 *
 * @return A boolean.
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof PieDataset)) {
        return false;
    }
    PieDataset that = (PieDataset) obj;
    int count = getItemCount();
    if (that.getItemCount() != count) {
        return false;
    }
    for (int i = 0; i < count; i++) {
        Comparable k1 = getKey(i);
        Comparable k2 = that.getKey(i);
        if (!k1.equals(k2)) {
            return false;
        }
        Number v1 = getValue(i);
        Number v2 = that.getValue(i);
        if (v1 == null) {
            if (v2 != null) {
                return false;
            }
        } else {
            if (!v1.equals(v2)) {
                return false;
            }
        }
    }
    return true;
}
Also used : PieDataset(org.jfree.data.general.PieDataset)

Aggregations

PieDataset (org.jfree.data.general.PieDataset)26 JFreeChart (org.jfree.chart.JFreeChart)9 PiePlot (org.jfree.chart.plot.PiePlot)7 DefaultPieDataset (org.jfree.data.general.DefaultPieDataset)6 Paint (java.awt.Paint)5 CategoryDataset (org.jfree.data.category.CategoryDataset)4 RectangleInsets (org.jfree.ui.RectangleInsets)4 Rectangle (java.awt.Rectangle)3 Font (java.awt.Font)2 Shape (java.awt.Shape)2 Stroke (java.awt.Stroke)2 Arc2D (java.awt.geom.Arc2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 BigDecimal (java.math.BigDecimal)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 StandardPieSectionLabelGenerator (org.jfree.chart.labels.StandardPieSectionLabelGenerator)2 CategoryPlot (org.jfree.chart.plot.CategoryPlot)2 Plot (org.jfree.chart.plot.Plot)2 XYPlot (org.jfree.chart.plot.XYPlot)2