afreechart/src/main/java/org/afree/chart/plot/RingPlot.java
/**
     * Draws a single data item.
     *
     * @param canvas  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.
     */
Draws a single data item.
@param canvas  the graphics device (null 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.
Draws a single data item . @param canvas the graphics device ( null 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(Canvas canvas,
                            int section,
                            RectShape dataArea,
                            PiePlotState state,
                            int currentPass, int alpha) {
        canvas.save();
        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;
            }
            RectShape arcBounds = getArcBounds(state.getPieArea(),
                    state.getExplodedPieArea(), angle1, angle, ep);
            ArcShape arc = new ArcShape(arcBounds, angle1, angle,
                    true);
            double depth = this.sectionDepth / 2.0;
            RectangleInsets s = new RectangleInsets(UnitType.RELATIVE,
                depth, depth, depth, depth);
            RectShape innerArcBounds = new RectShape();
            innerArcBounds.setRect(arcBounds);
            s.trim(innerArcBounds);
            ArcShape arc2 = new ArcShape(innerArcBounds, angle1
                    + angle, -angle, true);
            LineShape separator = new LineShape(arc2.getEndPoint(),
                    arc.getStartPoint());
            if (currentPass == 0) {
                Paint shadowPaint = getShadowPaint();
                double shadowXOffset = getShadowXOffset();
                double shadowYOffset = getShadowYOffset();
                if (shadowPaint != null) {
                    Matrix mat = new Matrix();
                    mat.postTranslate((float)shadowXOffset, (float)shadowYOffset);
                    Path sArc1 = new Path(arc.getPath());
                    Path sArc2 = new Path(arc2.getPath());
                    sArc1.transform(mat);
                    sArc2.transform(mat);
                    canvas.clipPath(arc.getPath());
                    canvas.clipPath(arc2.getPath(), Op.XOR);
                    arc.fill(canvas, shadowPaint);
                }
            }
            else if (currentPass == 1) {
                canvas.save();
                Paint paint = PaintUtility.createPaint(Paint.ANTI_ALIAS_FLAG, lookupSectionPaintType(key));
                canvas.clipPath(arc.getPath());
                canvas.clipPath(arc2.getPath(), Op.XOR);
                arc.fill(canvas, paint);
                canvas.restore();
                PaintType outlinePaintType = lookupSectionOutlinePaintType(key);
                Float outlineStroke = lookupSectionOutlineStroke(key);
                PathEffect outlineEffect = lookupSectionOutlineEffect(key);
                Paint outlinePaint = PaintUtility.createPaint(Paint.ANTI_ALIAS_FLAG, outlinePaintType, outlineStroke, outlineEffect);
                if (outlinePaint != null && outlineStroke != null) {
                    outlinePaint.setStyle(Style.STROKE);
                    outlinePaint.setStrokeWidth(outlineStroke);
                    Path path = new Path();
                    path.arcTo(new RectF(arc.getMinX(), arc.getMinY(), arc.getMaxX(), arc.getMaxY()), (float)angle1, (float)angle);
                    path.lineTo(arc2.getStartPoint().x, arc2.getStartPoint().y);
                    path.arcTo(new RectF(arc2.getMinX(), arc2.getMinY(), arc2.getMaxX(), arc2.getMaxY()), (float)(angle1 + angle), (float)-angle);
                    path.close();
                    canvas.drawPath(path, outlinePaint);
                }
                if (state.getInfo() != null) {
                    EntityCollection entities = state.getEntityCollection();
                    if (entities != null) {
                        String tip = null;
                        String url = null;
                        PieSectionEntity entity = new PieSectionEntity(arc,
                                dataset, getPieIndex(), section, key, tip,
                                url);
                        entities.add(entity);
                    }
                }
            }
            else if (currentPass == 2) {
                if (this.separatorsVisible) {
                    LineShape extendedSeparator = extendLine(separator,
                        this.innerSeparatorExtension,
                        this.outerSeparatorExtension);
                    Paint paint = PaintUtility.createPaint(Paint.ANTI_ALIAS_FLAG, this.separatorPaintType, this.separatorStroke, this.separatorEffect);
                    extendedSeparator.draw(canvas, paint);
                }
            }
        }
        state.setLatestAngle(angle2);
        canvas.restore();
    }
protected void drawItem ( Canvas canvas , int section , RectShape dataArea , PiePlotState state , int currentPass , int alpha ) { canvas . save ( ) ; 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 ; } RectShape arcBounds = getArcBounds ( state . getPieArea ( ) , state . getExplodedPieArea ( ) , angle1 , angle , ep ) ; ArcShape arc = new ArcShape ( arcBounds , angle1 , angle , true ) ; double depth = this . sectionDepth / 2.0 ; RectangleInsets s = new RectangleInsets ( UnitType . RELATIVE , depth , depth , depth , depth ) ; RectShape innerArcBounds = new RectShape ( ) ; innerArcBounds . setRect ( arcBounds ) ; s . trim ( innerArcBounds ) ; ArcShape arc2 = new ArcShape ( innerArcBounds , angle1 + angle , - angle , true ) ; LineShape separator = new LineShape ( arc2 . getEndPoint ( ) , arc . getStartPoint ( ) ) ; if ( currentPass == 0 ) { Paint shadowPaint = getShadowPaint ( ) ; double shadowXOffset = getShadowXOffset ( ) ; double shadowYOffset = getShadowYOffset ( ) ; if ( shadowPaint != null ) { Matrix mat = new Matrix ( ) ; mat . postTranslate ( ( float ) shadowXOffset , ( float ) shadowYOffset ) ; Path sArc1 = new Path ( arc . getPath ( ) ) ; Path sArc2 = new Path ( arc2 . getPath ( ) ) ; sArc1 . transform ( mat ) ; sArc2 . transform ( mat ) ; canvas . clipPath ( arc . getPath ( ) ) ; canvas . clipPath ( arc2 . getPath ( ) , Op . XOR ) ; arc . fill ( canvas , shadowPaint ) ; } } else if ( currentPass == 1 ) { canvas . save ( ) ; Paint paint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , lookupSectionPaintType ( key ) ) ; canvas . clipPath ( arc . getPath ( ) ) ; canvas . clipPath ( arc2 . getPath ( ) , Op . XOR ) ; arc . fill ( canvas , paint ) ; canvas . restore ( ) ; PaintType outlinePaintType = lookupSectionOutlinePaintType ( key ) ; Float outlineStroke = lookupSectionOutlineStroke ( key ) ; PathEffect outlineEffect = lookupSectionOutlineEffect ( key ) ; Paint outlinePaint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , outlinePaintType , outlineStroke , outlineEffect ) ; if ( outlinePaint != null && outlineStroke != null ) { outlinePaint . setStyle ( Style . STROKE ) ; outlinePaint . setStrokeWidth ( outlineStroke ) ; Path path = new Path ( ) ; path . arcTo ( new RectF ( arc . getMinX ( ) , arc . getMinY ( ) , arc . getMaxX ( ) , arc . getMaxY ( ) ) , ( float ) angle1 , ( float ) angle ) ; path . lineTo ( arc2 . getStartPoint ( ) . x , arc2 . getStartPoint ( ) . y ) ; path . arcTo ( new RectF ( arc2 . getMinX ( ) , arc2 . getMinY ( ) , arc2 . getMaxX ( ) , arc2 . getMaxY ( ) ) , ( float ) ( angle1 + angle ) , ( float ) - angle ) ; path . close ( ) ; canvas . drawPath ( path , outlinePaint ) ; } if ( state . getInfo ( ) != null ) { EntityCollection entities = state . getEntityCollection ( ) ; if ( entities != null ) { String tip = null ; String url = null ; PieSectionEntity entity = new PieSectionEntity ( arc , dataset , getPieIndex ( ) , section , key , tip , url ) ; entities . add ( entity ) ; } } } else if ( currentPass == 2 ) { if ( this . separatorsVisible ) { LineShape extendedSeparator = extendLine ( separator , this . innerSeparatorExtension , this . outerSeparatorExtension ) ; Paint paint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , this . separatorPaintType , this . separatorStroke , this . separatorEffect ) ; extendedSeparator . draw ( canvas , paint ) ; } } } state . setLatestAngle ( angle2 ) ; canvas . restore ( ) ; }
Draws a single data item.
Draws a single data item .
// create the bounds for the inner arc // TODO: draw outline // add an entity for the pie section //                        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()); //                        }