⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pieplot3d.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                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;
        outlinePaint = getSectionOutlinePaint(0);
        arc = new Arc2D.Double(
            arcX, arcY + depth, pieArea.getWidth(), pieArea.getHeight() - depth,
            0, 360, Arc2D.PIE
        );

        int categoryCount = arcList.size();
        for (int categoryIndex = 0; categoryIndex < categoryCount; categoryIndex++) {
            arc = (Arc2D.Double) arcList.get(categoryIndex);
            if (arc == null) {
                continue;
            }
            paint = getSectionPaint(categoryIndex);
            outlinePaint = getSectionOutlinePaint(categoryIndex);
            outlineStroke = getSectionOutlineStroke(categoryIndex);
            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) {
                paint = getSectionPaint(cat);
                outlinePaint = getSectionOutlinePaint(cat);
                outlineStroke = getSectionOutlineStroke(cat);
                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) {
                paint = getSectionPaint(cat);
                outlinePaint = getSectionOutlinePaint(cat);
                outlineStroke = getSectionOutlineStroke(cat);
                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);
            
            paint = getSectionPaint(sectionIndex);
            outlinePaint = getSectionOutlinePaint(sectionIndex);
            outlineStroke = getSectionOutlineStroke(sectionIndex);
            g2.setPaint(paint);
            g2.fill(upperArc);
            g2.setStroke(outlineStroke);
            g2.setPaint(outlinePaint);
            g2.draw(upperArc);

           // add a tooltip for the section...
            Comparable currentKey = (Comparable) sectionKeys.get(sectionIndex);
            if (info != null) {
                EntityCollection entities = info.getOwner().getEntityCollection();
                if (entities != null) {
                    if (getToolTipGenerator() == null) {
                        setToolTipGenerator(new StandardPieItemLabelGenerator());
                    }
                    String tip = getToolTipGenerator().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.addEntity(entity);
                }
            }
            List keys = dataset.getKeys();
            Rectangle2D adjustedPlotArea = new Rectangle2D.Double(
                originalPlotArea.getX(), originalPlotArea.getY(), 
                originalPlotArea.getWidth(), originalPlotArea.getHeight() - depth
            );
            drawLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state);
        }

        g2.setClip(savedClip);
        g2.setComposite(originalComposite);
        drawOutline(g2, originalPlotArea);

    }

    /**
     * Draws the side of a pie section.
     *
     * @param g2  the graphics device.
     * @param plotArea  the plot area.
     * @param arc  the arc.
     * @param front  the front of the pie.
     * @param back  the back of the pie.
     * @param paint  the color.
     * @param outlinePaint  the outline paint.
     * @param outlineStroke  the outline stroke.
     * @param drawFront  draw the front?
     * @param drawBack  draw the back?
     */
    protected void drawSide(Graphics2D g2,
                            Rectangle2D plotArea, 
                            Arc2D arc, 
                            Area front, 
                            Area back,
                            Paint paint, 
                            Paint outlinePaint,
                            Stroke outlineStroke,
                            boolean drawFront, 
                            boolean drawBack) {

        double start = arc.getAngleStart();
        double extent = arc.getAngleExtent();
        double end = start + extent;

        g2.setStroke(outlineStroke);
        
        // for CLOCKWISE charts, the extent will be negative...
        if (extent < 0.0) {

            if (isAngleAtFront(start)) {  // start at front

                if (!isAngleAtBack(end)) {

                    if (extent > -180.0) {  // the segment is entirely at the front of the chart
                        if (drawFront) {
                            Area side = new Area(
                                new Rectangle2D.Double(
                                    arc.getEndPoint().getX(), plotArea.getY(),
                                    arc.getStartPoint().getX() - arc.getEndPoint().getX(),
                                    plotArea.getHeight()
                                )
                            );
                            side.intersect(front);
                            g2.setPaint(paint);
                            g2.fill(side);
                            g2.setPaint(outlinePaint);
                            g2.draw(side);
                        }
                    }
                    else {  // the segment starts at the front, and wraps all the way around
                            // the back and finishes at the front again
                        Area side1 = new Area(
                            new Rectangle2D.Double(
                                plotArea.getX(), plotArea.getY(),
                                arc.getStartPoint().getX() - plotArea.getX(), plotArea.getHeight()
                            )
                        );
                        side1.intersect(front);

                        Area side2 = new Area(
                            new Rectangle2D.Double(
                                arc.getEndPoint().getX(), plotArea.getY(),
                                plotArea.getMaxX() - arc.getEndPoint().getX(),
                                plotArea.getHeight()
                            )
                        );

                        side2.intersect(front);
                        g2.setPaint(paint);
                        if (drawFront) {
                            g2.fill(side1);
                            g2.fill(side2);
                        }

                        if (drawBack) {
                            g2.fill(back);
                        }

                        g2.setPaint(outlinePaint);
                        if (drawFront) {
                            g2.draw(side1);
                            g2.draw(side2);
                        }

                        if (drawBack) {
                            g2.draw(back);
                        }

                    }
                }
                else {  // starts at the front, finishes at the back (going around the left side)

                    if (drawBack) {
                        Area side2 = new Area(
                            new Rectangle2D.Double(
                                plotArea.getX(), plotArea.getY(),
                                arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight()
                            )
                        );
                        side2.intersect(back);
                        g2.setPaint(paint);
                        g2.fill(side2);
                        g2.setPaint(outlinePaint);
                        g2.draw(side2);
                    }

                    if (drawFront) {
                        Area side1 = new Area(
                            new Rectangle2D.Double(
                                plotArea.getX(), plotArea.getY(),
                                arc.getStartPoint().getX() - plotArea.getX(),
                                plotArea.getHeight()
                            )
                        );
                        side1.intersect(front);
                        g2.setPaint(paint);
                        g2.fill(side1);
                        g2.setPaint(outlinePaint);
                        g2.draw(side1);
                    }
                }
            }
            else {  // the segment starts at the back (still extending CLOCKWISE)

                if (!isAngleAtFront(end)) {
                    if (extent > -180.0) {  // whole segment stays at the back
                        if (drawBack) {
                            Area side = new Area(
                                new Rectangle2D.Double(
                                    arc.getStartPoint().getX(), plotArea.getY(),
                                    arc.getEndPoint().getX() - arc.getStartPoint().getX(),
                                    plotArea.getHeight()
                                )
                            );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -