Search in sources :

Example 1 with PieToolTipGenerator

use of org.jfree.chart.labels.PieToolTipGenerator in project SIMVA-SoS by SESoS.

the class PiePlot3D method draw.

/**
 * Draws the plot on a Java 2D graphics device (such as the screen or a
 * printer).  This method is called by the
 * {@link org.jfree.chart.JFreeChart} class, you don't normally need
 * to call it yourself.
 *
 * @param g2  the graphics device.
 * @param plotArea  the area within which the plot should be drawn.
 * @param anchor  the anchor point.
 * @param parentState  the state from the parent plot, if there is one.
 * @param info  collects info about the drawing
 *              (<code>null</code> permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D anchor, PlotState parentState, PlotRenderingInfo info) {
    // adjust for insets...
    RectangleInsets insets = getInsets();
    insets.trim(plotArea);
    Rectangle2D originalPlotArea = (Rectangle2D) plotArea.clone();
    if (info != null) {
        info.setPlotArea(plotArea);
        info.setDataArea(plotArea);
    }
    drawBackground(g2, plotArea);
    Shape savedClip = g2.getClip();
    g2.clip(plotArea);
    Graphics2D savedG2 = g2;
    BufferedImage dataImage = null;
    if (getShadowGenerator() != null) {
        dataImage = new BufferedImage((int) plotArea.getWidth(), (int) plotArea.getHeight(), BufferedImage.TYPE_INT_ARGB);
        g2 = dataImage.createGraphics();
        g2.translate(-plotArea.getX(), -plotArea.getY());
        g2.setRenderingHints(savedG2.getRenderingHints());
        originalPlotArea = (Rectangle2D) plotArea.clone();
    }
    // adjust the plot area by the interior spacing value
    double gapPercent = getInteriorGap();
    double labelPercent = 0.0;
    if (getLabelGenerator() != null) {
        labelPercent = getLabelGap() + getMaximumLabelWidth();
    }
    double gapHorizontal = plotArea.getWidth() * (gapPercent + labelPercent) * 2.0;
    double gapVertical = plotArea.getHeight() * gapPercent * 2.0;
    if (DEBUG_DRAW_INTERIOR) {
        double hGap = plotArea.getWidth() * getInteriorGap();
        double vGap = plotArea.getHeight() * getInteriorGap();
        double igx1 = plotArea.getX() + hGap;
        double igx2 = plotArea.getMaxX() - hGap;
        double igy1 = plotArea.getY() + vGap;
        double igy2 = plotArea.getMaxY() - vGap;
        g2.setPaint(Color.lightGray);
        g2.draw(new Rectangle2D.Double(igx1, igy1, igx2 - igx1, igy2 - igy1));
    }
    double linkX = plotArea.getX() + gapHorizontal / 2;
    double linkY = plotArea.getY() + gapVertical / 2;
    double linkW = plotArea.getWidth() - gapHorizontal;
    double linkH = plotArea.getHeight() - gapVertical;
    // make the link area a square if the pie chart is to be circular...
    if (isCircular()) {
        // is circular?
        double min = Math.min(linkW, linkH) / 2;
        linkX = (linkX + linkX + linkW) / 2 - min;
        linkY = (linkY + linkY + linkH) / 2 - min;
        linkW = 2 * min;
        linkH = 2 * min;
    }
    PiePlotState state = initialise(g2, plotArea, this, null, info);
    // the link area defines the dog leg points for the linking lines to
    // the labels
    Rectangle2D linkAreaXX = new Rectangle2D.Double(linkX, linkY, linkW, linkH * (1 - this.depthFactor));
    state.setLinkArea(linkAreaXX);
    if (DEBUG_DRAW_LINK_AREA) {
        g2.setPaint(Color.blue);
        g2.draw(linkAreaXX);
        g2.setPaint(Color.yellow);
        g2.draw(new Ellipse2D.Double(linkAreaXX.getX(), linkAreaXX.getY(), linkAreaXX.getWidth(), linkAreaXX.getHeight()));
    }
    // the explode area defines the max circle/ellipse for the exploded pie
    // sections.
    // it is defined by shrinking the linkArea by the linkMargin factor.
    double hh = linkW * getLabelLinkMargin();
    double vv = linkH * getLabelLinkMargin();
    Rectangle2D explodeArea = new Rectangle2D.Double(linkX + hh / 2.0, linkY + vv / 2.0, linkW - hh, linkH - vv);
    state.setExplodedPieArea(explodeArea);
    // the pie area defines the circle/ellipse for regular pie sections.
    // it is defined by shrinking the explodeArea by the explodeMargin
    // factor.
    double maximumExplodePercent = getMaximumExplodePercent();
    double percent = maximumExplodePercent / (1.0 + maximumExplodePercent);
    double h1 = explodeArea.getWidth() * percent;
    double v1 = explodeArea.getHeight() * percent;
    Rectangle2D pieArea = new Rectangle2D.Double(explodeArea.getX() + h1 / 2.0, explodeArea.getY() + v1 / 2.0, explodeArea.getWidth() - h1, explodeArea.getHeight() - v1);
    // the link area defines the dog-leg point for the linking lines to
    // the labels
    int depth = (int) (pieArea.getHeight() * this.depthFactor);
    Rectangle2D linkArea = new Rectangle2D.Double(linkX, linkY, linkW, linkH - depth);
    state.setLinkArea(linkArea);
    state.setPieArea(pieArea);
    state.setPieCenterX(pieArea.getCenterX());
    state.setPieCenterY(pieArea.getCenterY() - depth / 2.0);
    state.setPieWRadius(pieArea.getWidth() / 2.0);
    state.setPieHRadius((pieArea.getHeight() - depth) / 2.0);
    // get the data source - return if null;
    PieDataset dataset = getDataset();
    if (DatasetUtilities.isEmptyOrNull(getDataset())) {
        drawNoDataMessage(g2, plotArea);
        g2.setClip(savedClip);
        drawOutline(g2, plotArea);
        return;
    }
    // if too any elements
    if (dataset.getKeys().size() > plotArea.getWidth()) {
        String text = localizationResources.getString("Too_many_elements");
        Font sfont = new Font("dialog", Font.BOLD, 10);
        g2.setFont(sfont);
        FontMetrics fm = g2.getFontMetrics(sfont);
        int stringWidth = fm.stringWidth(text);
        g2.drawString(text, (int) (plotArea.getX() + (plotArea.getWidth() - stringWidth) / 2), (int) (plotArea.getY() + (plotArea.getHeight() / 2)));
        return;
    }
    // effect.
    if (isCircular()) {
        double min = Math.min(plotArea.getWidth(), plotArea.getHeight()) / 2;
        plotArea = new Rectangle2D.Double(plotArea.getCenterX() - min, plotArea.getCenterY() - min, 2 * min, 2 * min);
    }
    // get a list of keys...
    List sectionKeys = dataset.getKeys();
    if (sectionKeys.isEmpty()) {
        return;
    }
    // establish the coordinates of the top left corner of the drawing area
    double arcX = pieArea.getX();
    double arcY = pieArea.getY();
    // g2.clip(clipArea);
    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    double totalValue = DatasetUtilities.calculatePieDatasetTotal(dataset);
    double runningTotal = 0;
    if (depth < 0) {
        // if depth is negative don't draw anything
        return;
    }
    ArrayList arcList = new ArrayList();
    Arc2D.Double arc;
    Paint paint;
    Paint outlinePaint;
    Stroke outlineStroke;
    Iterator iterator = sectionKeys.iterator();
    while (iterator.hasNext()) {
        Comparable currentKey = (Comparable) iterator.next();
        Number dataValue = dataset.getValue(currentKey);
        if (dataValue == null) {
            arcList.add(null);
            continue;
        }
        double value = dataValue.doubleValue();
        if (value <= 0) {
            arcList.add(null);
            continue;
        }
        double startAngle = getStartAngle();
        double direction = getDirection().getFactor();
        double angle1 = startAngle + (direction * (runningTotal * 360)) / totalValue;
        double angle2 = startAngle + (direction * (runningTotal + value) * 360) / totalValue;
        if (Math.abs(angle2 - angle1) > getMinimumArcAngleToDraw()) {
            arcList.add(new Arc2D.Double(arcX, arcY + depth, pieArea.getWidth(), pieArea.getHeight() - depth, angle1, angle2 - angle1, Arc2D.PIE));
        } else {
            arcList.add(null);
        }
        runningTotal += value;
    }
    Shape oldClip = g2.getClip();
    Ellipse2D top = new Ellipse2D.Double(pieArea.getX(), pieArea.getY(), pieArea.getWidth(), pieArea.getHeight() - depth);
    Ellipse2D bottom = new Ellipse2D.Double(pieArea.getX(), pieArea.getY() + depth, pieArea.getWidth(), pieArea.getHeight() - depth);
    Rectangle2D lower = new Rectangle2D.Double(top.getX(), top.getCenterY(), pieArea.getWidth(), bottom.getMaxY() - top.getCenterY());
    Rectangle2D upper = new Rectangle2D.Double(pieArea.getX(), top.getY(), pieArea.getWidth(), bottom.getCenterY() - top.getY());
    Area a = new Area(top);
    a.add(new Area(lower));
    Area b = new Area(bottom);
    b.add(new Area(upper));
    Area pie = new Area(a);
    pie.intersect(b);
    Area front = new Area(pie);
    front.subtract(new Area(top));
    Area back = new Area(pie);
    back.subtract(new Area(bottom));
    // draw the bottom circle
    int[] xs;
    int[] ys;
    int categoryCount = arcList.size();
    for (int categoryIndex = 0; categoryIndex < categoryCount; categoryIndex++) {
        arc = (Arc2D.Double) arcList.get(categoryIndex);
        if (arc == null) {
            continue;
        }
        Comparable key = getSectionKey(categoryIndex);
        paint = lookupSectionPaint(key);
        outlinePaint = lookupSectionOutlinePaint(key);
        outlineStroke = lookupSectionOutlineStroke(key);
        g2.setPaint(paint);
        g2.fill(arc);
        g2.setPaint(outlinePaint);
        g2.setStroke(outlineStroke);
        g2.draw(arc);
        g2.setPaint(paint);
        Point2D p1 = arc.getStartPoint();
        // draw the height
        xs = new int[] { (int) arc.getCenterX(), (int) arc.getCenterX(), (int) p1.getX(), (int) p1.getX() };
        ys = new int[] { (int) arc.getCenterY(), (int) arc.getCenterY() - depth, (int) p1.getY() - depth, (int) p1.getY() };
        Polygon polygon = new Polygon(xs, ys, 4);
        g2.setPaint(java.awt.Color.lightGray);
        g2.fill(polygon);
        g2.setPaint(outlinePaint);
        g2.setStroke(outlineStroke);
        g2.draw(polygon);
        g2.setPaint(paint);
    }
    g2.setPaint(Color.gray);
    g2.fill(back);
    g2.fill(front);
    // cycle through once drawing only the sides at the back...
    int cat = 0;
    iterator = arcList.iterator();
    while (iterator.hasNext()) {
        Arc2D segment = (Arc2D) iterator.next();
        if (segment != null) {
            Comparable key = getSectionKey(cat);
            paint = lookupSectionPaint(key);
            outlinePaint = lookupSectionOutlinePaint(key);
            outlineStroke = lookupSectionOutlineStroke(key);
            drawSide(g2, pieArea, segment, front, back, paint, outlinePaint, outlineStroke, false, true);
        }
        cat++;
    }
    // cycle through again drawing only the sides at the front...
    cat = 0;
    iterator = arcList.iterator();
    while (iterator.hasNext()) {
        Arc2D segment = (Arc2D) iterator.next();
        if (segment != null) {
            Comparable key = getSectionKey(cat);
            paint = lookupSectionPaint(key);
            outlinePaint = lookupSectionOutlinePaint(key);
            outlineStroke = lookupSectionOutlineStroke(key);
            drawSide(g2, pieArea, segment, front, back, paint, outlinePaint, outlineStroke, true, false);
        }
        cat++;
    }
    g2.setClip(oldClip);
    // draw the sections at the top of the pie (and set up tooltips)...
    Arc2D upperArc;
    for (int sectionIndex = 0; sectionIndex < categoryCount; sectionIndex++) {
        arc = (Arc2D.Double) arcList.get(sectionIndex);
        if (arc == null) {
            continue;
        }
        upperArc = new Arc2D.Double(arcX, arcY, pieArea.getWidth(), pieArea.getHeight() - depth, arc.getAngleStart(), arc.getAngleExtent(), Arc2D.PIE);
        Comparable currentKey = (Comparable) sectionKeys.get(sectionIndex);
        paint = lookupSectionPaint(currentKey, true);
        outlinePaint = lookupSectionOutlinePaint(currentKey);
        outlineStroke = lookupSectionOutlineStroke(currentKey);
        g2.setPaint(paint);
        g2.fill(upperArc);
        g2.setStroke(outlineStroke);
        g2.setPaint(outlinePaint);
        g2.draw(upperArc);
        // add a tooltip for the section...
        if (info != null) {
            EntityCollection entities = info.getOwner().getEntityCollection();
            if (entities != null) {
                String tip = null;
                PieToolTipGenerator tipster = getToolTipGenerator();
                if (tipster != null) {
                    // @mgs: using the method's return value was missing
                    tip = tipster.generateToolTip(dataset, currentKey);
                }
                String url = null;
                if (getURLGenerator() != null) {
                    url = getURLGenerator().generateURL(dataset, currentKey, getPieIndex());
                }
                PieSectionEntity entity = new PieSectionEntity(upperArc, dataset, getPieIndex(), sectionIndex, currentKey, tip, url);
                entities.add(entity);
            }
        }
    }
    List keys = dataset.getKeys();
    Rectangle2D adjustedPlotArea = new Rectangle2D.Double(originalPlotArea.getX(), originalPlotArea.getY(), originalPlotArea.getWidth(), originalPlotArea.getHeight() - depth);
    if (getSimpleLabels()) {
        drawSimpleLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state);
    } else {
        drawLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state);
    }
    if (getShadowGenerator() != null) {
        BufferedImage shadowImage = getShadowGenerator().createDropShadow(dataImage);
        g2 = savedG2;
        g2.drawImage(shadowImage, (int) plotArea.getX() + getShadowGenerator().calculateOffsetX(), (int) plotArea.getY() + getShadowGenerator().calculateOffsetY(), null);
        g2.drawImage(dataImage, (int) plotArea.getX(), (int) plotArea.getY(), null);
    }
    g2.setClip(savedClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, originalPlotArea);
}
Also used : Shape(java.awt.Shape) ArrayList(java.util.ArrayList) Arc2D(java.awt.geom.Arc2D) BufferedImage(java.awt.image.BufferedImage) Ellipse2D(java.awt.geom.Ellipse2D) Font(java.awt.Font) Point2D(java.awt.geom.Point2D) FontMetrics(java.awt.FontMetrics) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Polygon(java.awt.Polygon) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity) Stroke(java.awt.Stroke) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D) Area(java.awt.geom.Area) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) PieDataset(org.jfree.data.general.PieDataset) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleInsets(org.jfree.ui.RectangleInsets)

Example 2 with PieToolTipGenerator

use of org.jfree.chart.labels.PieToolTipGenerator in project SIMVA-SoS by SESoS.

the class ChartFactory method createMultiplePieChart3D.

/**
 * Creates a chart that displays multiple pie plots.  The chart object
 * returned by this method uses a {@link MultiplePiePlot} instance as the
 * plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param order  the order that the data is extracted (by row or by column)
 *               (<code>null</code> not permitted).
 * @param legend  include a legend?
 * @param tooltips  generate tooltips?
 * @param urls  generate URLs?
 *
 * @return A chart.
 */
public static JFreeChart createMultiplePieChart3D(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls) {
    ParamChecks.nullNotPermitted(order, "order");
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(order);
    plot.setBackgroundPaint(null);
    plot.setOutlineStroke(null);
    JFreeChart pieChart = new JFreeChart(new PiePlot3D(null));
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(seriesTitle);
    pieChart.removeLegend();
    pieChart.setBackgroundPaint(null);
    plot.setPieChart(pieChart);
    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }
    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PieURLGenerator(org.jfree.chart.urls.PieURLGenerator) StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PiePlot3D(org.jfree.chart.plot.PiePlot3D) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) Font(java.awt.Font)

Example 3 with PieToolTipGenerator

use of org.jfree.chart.labels.PieToolTipGenerator in project SIMVA-SoS by SESoS.

the class ChartFactory method createMultiplePieChart.

/**
 * Creates a chart that displays multiple pie plots.  The chart object
 * returned by this method uses a {@link MultiplePiePlot} instance as the
 * plot.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param order  the order that the data is extracted (by row or by column)
 *               (<code>null</code> not permitted).
 * @param legend  include a legend?
 * @param tooltips  generate tooltips?
 * @param urls  generate URLs?
 *
 * @return A chart.
 */
public static JFreeChart createMultiplePieChart(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls) {
    ParamChecks.nullNotPermitted(order, "order");
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    plot.setDataExtractOrder(order);
    plot.setBackgroundPaint(null);
    plot.setOutlineStroke(null);
    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setToolTipGenerator(tooltipGenerator);
    }
    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        PiePlot pp = (PiePlot) plot.getPieChart().getPlot();
        pp.setURLGenerator(urlGenerator);
    }
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;
}
Also used : StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PieURLGenerator(org.jfree.chart.urls.PieURLGenerator) StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot)

Example 4 with PieToolTipGenerator

use of org.jfree.chart.labels.PieToolTipGenerator in project pentaho-platform by pentaho.

the class JFreeChartEngine method createPieDatasetChart.

private static JFreeChart createPieDatasetChart(final PieDatasetChartDefinition chartDefinition) {
    // TODO Make the following accessible from the chartDefinition
    boolean tooltips = true;
    boolean urls = true;
    // -----------------------------------------------------------
    String title = chartDefinition.getTitle();
    boolean legend = chartDefinition.isLegendIncluded();
    PiePlot plot = null;
    plot = chartDefinition.isThreeD() ? new PiePlot3D(chartDefinition) : new PiePlot(chartDefinition);
    JFreeChartEngine.updatePlot(plot, chartDefinition);
    JFreeChart pieChart = new JFreeChart(title, chartDefinition.getTitleFont(), plot, legend);
    // $NON-NLS-1$ //$NON-NLS-2$
    TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    pieChart.setTitle(title);
    pieChart.setBackgroundPaint(chartDefinition.getChartBackgroundPaint());
    if (tooltips) {
        PieToolTipGenerator tooltipGenerator = new StandardPieToolTipGenerator();
        plot.setToolTipGenerator(tooltipGenerator);
    }
    if (urls) {
        PieURLGenerator urlGenerator = new StandardPieURLGenerator();
        plot.setURLGenerator(urlGenerator);
    }
    return pieChart;
}
Also used : TextTitle(org.jfree.chart.title.TextTitle) StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PieURLGenerator(org.jfree.chart.urls.PieURLGenerator) StandardPieURLGenerator(org.jfree.chart.urls.StandardPieURLGenerator) PiePlot3D(org.jfree.chart.plot.PiePlot3D) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) PiePlot(org.jfree.chart.plot.PiePlot) MultiplePiePlot(org.jfree.chart.plot.MultiplePiePlot) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font)

Example 5 with PieToolTipGenerator

use of org.jfree.chart.labels.PieToolTipGenerator in project SIMVA-SoS by SESoS.

the class RingPlot method drawItem.

/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
@Override
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) {
    PieDataset dataset = getDataset();
    Number n = dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    Rotation direction = getDirection();
    if (direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    } else if (direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    } else {
        throw new IllegalStateException("Rotation type not recognised.");
    }
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        Comparable key = getSectionKey(section);
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(key) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.OPEN);
        // create the bounds for the inner arc
        double depth = this.sectionDepth / 2.0;
        RectangleInsets s = new RectangleInsets(UnitType.RELATIVE, depth, depth, depth, depth);
        Rectangle2D innerArcBounds = new Rectangle2D.Double();
        innerArcBounds.setRect(arcBounds);
        s.trim(innerArcBounds);
        // calculate inner arc in reverse direction, for later
        // GeneralPath construction
        Arc2D.Double arc2 = new Arc2D.Double(innerArcBounds, angle1 + angle, -angle, Arc2D.OPEN);
        GeneralPath path = new GeneralPath();
        path.moveTo((float) arc.getStartPoint().getX(), (float) arc.getStartPoint().getY());
        path.append(arc.getPathIterator(null), false);
        path.append(arc2.getPathIterator(null), true);
        path.closePath();
        Line2D separator = new Line2D.Double(arc2.getEndPoint(), arc.getStartPoint());
        if (currentPass == 0) {
            Paint shadowPaint = getShadowPaint();
            double shadowXOffset = getShadowXOffset();
            double shadowYOffset = getShadowYOffset();
            if (shadowPaint != null && getShadowGenerator() == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(path, (float) shadowXOffset, (float) shadowYOffset);
                g2.setPaint(shadowPaint);
                g2.fill(shadowArc);
            }
        } else if (currentPass == 1) {
            Paint paint = lookupSectionPaint(key);
            g2.setPaint(paint);
            g2.fill(path);
            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (getSectionOutlinesVisible() && outlinePaint != null && outlineStroke != null) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(path);
            }
            if (section == 0) {
                String nstr = null;
                if (this.centerTextMode.equals(CenterTextMode.VALUE)) {
                    nstr = this.centerTextFormatter.format(n);
                } else if (this.centerTextMode.equals(CenterTextMode.FIXED)) {
                    nstr = this.centerText;
                }
                if (nstr != null) {
                    g2.setFont(this.centerTextFont);
                    g2.setPaint(this.centerTextColor);
                    TextUtilities.drawAlignedString(nstr, g2, (float) dataArea.getCenterX(), (float) dataArea.getCenterY(), TextAnchor.CENTER);
                }
            }
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    PieToolTipGenerator toolTipGenerator = getToolTipGenerator();
                    if (toolTipGenerator != null) {
                        tip = toolTipGenerator.generateToolTip(dataset, key);
                    }
                    String url = null;
                    PieURLGenerator urlGenerator = getURLGenerator();
                    if (urlGenerator != null) {
                        url = urlGenerator.generateURL(dataset, key, getPieIndex());
                    }
                    PieSectionEntity entity = new PieSectionEntity(path, dataset, getPieIndex(), section, key, tip, url);
                    entities.add(entity);
                }
            }
        } else if (currentPass == 2) {
            if (this.separatorsVisible) {
                Line2D extendedSeparator = LineUtilities.extendLine(separator, this.innerSeparatorExtension, this.outerSeparatorExtension);
                g2.setStroke(this.separatorStroke);
                g2.setPaint(this.separatorPaint);
                g2.draw(extendedSeparator);
            }
        }
    }
    state.setLatestAngle(angle2);
}
Also used : PieURLGenerator(org.jfree.chart.urls.PieURLGenerator) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Rotation(org.jfree.util.Rotation) Arc2D(java.awt.geom.Arc2D) Line2D(java.awt.geom.Line2D) PieToolTipGenerator(org.jfree.chart.labels.PieToolTipGenerator) PieDataset(org.jfree.data.general.PieDataset) EntityCollection(org.jfree.chart.entity.EntityCollection) RectangleInsets(org.jfree.ui.RectangleInsets) PieSectionEntity(org.jfree.chart.entity.PieSectionEntity)

Aggregations

PieToolTipGenerator (org.jfree.chart.labels.PieToolTipGenerator)5 PieURLGenerator (org.jfree.chart.urls.PieURLGenerator)4 Font (java.awt.Font)3 StandardPieToolTipGenerator (org.jfree.chart.labels.StandardPieToolTipGenerator)3 MultiplePiePlot (org.jfree.chart.plot.MultiplePiePlot)3 PiePlot (org.jfree.chart.plot.PiePlot)3 StandardPieURLGenerator (org.jfree.chart.urls.StandardPieURLGenerator)3 Paint (java.awt.Paint)2 Shape (java.awt.Shape)2 Stroke (java.awt.Stroke)2 Arc2D (java.awt.geom.Arc2D)2 Rectangle2D (java.awt.geom.Rectangle2D)2 EntityCollection (org.jfree.chart.entity.EntityCollection)2 PieSectionEntity (org.jfree.chart.entity.PieSectionEntity)2 PiePlot3D (org.jfree.chart.plot.PiePlot3D)2 TextTitle (org.jfree.chart.title.TextTitle)2 PieDataset (org.jfree.data.general.PieDataset)2 RectangleInsets (org.jfree.ui.RectangleInsets)2 AlphaComposite (java.awt.AlphaComposite)1 BasicStroke (java.awt.BasicStroke)1