Java Code Examples for org.jfree.util.Rotation#ANTICLOCKWISE

The following examples show how to use org.jfree.util.Rotation#ANTICLOCKWISE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.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()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example 2
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example 3
Source File: PiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.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()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example 4
Source File: PiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example 5
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.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()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example 6
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example 7
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.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()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example 8
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example 9
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.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()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example 10
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.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()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example 11
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example 12
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.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()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example 13
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        if (this.direction == Rotation.CLOCKWISE) {
            angle1 = state.getLatestAngle();
            angle2 = angle1 - value / state.getTotal() * 360.0;
        } else if (this.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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}