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

📄 barrenderer3d.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                double seriesGap = dataArea.getHeight() * getItemMargin()
                                   / (categoryCount * (seriesCount - 1));
                y2 = y2 + row * (getBarWidth() + seriesGap);
            }
            else {
                y2 = y2 + row * getBarWidth();
            }

            // HEIGHT
            double y0 = y2 + getBarWidth();

            double y1 = y0 - getYOffset();
            double y3 = y2 - getYOffset();

            // draw the bar...
            if (plot.getForegroundAlpha() == 1.0) {
                g2.setClip(hiddenClip);
            }
            Rectangle2D bar = new Rectangle2D.Double(x0, y2, x2 - x0, y0 - y2);

            g2.setPaint(getItemPaint(row, column));
            g2.fill(bar);

            hiddenClip.subtract(new Area(bar));
            GeneralPath bar3dRight = null;
            GeneralPath bar3dTop = null;
            if ((x2 - x0) != 0) {
                bar3dRight = new GeneralPath();

                bar3dRight.moveTo((float) x2, (float) y2);
                bar3dRight.lineTo((float) x2, (float) y0);
                bar3dRight.lineTo((float) x3, (float) y1);
                bar3dRight.lineTo((float) x3, (float) y3);
                bar3dRight.closePath();

                g2.fill(bar3dRight);
                hiddenClip.subtract(new Area(bar3dRight));

                bar3dTop = new GeneralPath();

                bar3dTop.moveTo((float) x0, (float) y2);
                bar3dTop.lineTo((float) x1, (float) y3);
                bar3dTop.lineTo((float) x3, (float) y3);
                bar3dTop.lineTo((float) x2, (float) y2);
                bar3dTop.closePath();
                g2.fill(bar3dTop);
                hiddenClip.subtract(new Area(bar3dTop));
            }

            if (getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
                g2.setStroke(getItemStroke(row, column));
                g2.setPaint(getItemOutlinePaint(row, column));
                g2.draw(bar);
                if (bar3dRight != null) {
                    g2.draw(bar3dRight);
                }
                if (bar3dTop != null) {
                    g2.draw(bar3dTop);
                }

            }

            CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
            if (generator != null && isItemLabelVisible(row, column)) {
                drawItemLabel(g2, dataset, row, column, plot, generator, bar, (transX1 > transX2));
            }        

            // collect entity and tool tip information...
            if (getInfo() != null) {
                EntityCollection entities = getInfo().getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    generator = getItemLabelGenerator(row, column);
                    if (generator != null) {
                        tip = generator.generateToolTip(dataset, row, column);
                    }
                    String url = null;
                    if (getItemURLGenerator(row, column) != null) {
                        url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
                    }
                    CategoryItemEntity entity = new CategoryItemEntity(
                        bar, tip, url, dataset, row, dataset.getColumnKey(column), column);
                    entities.addEntity(entity);
                }
            }

        }

    }

    /**
     * Draws a 3D bar to represent one data item.
     *
     * @param g2  the graphics device.
     * @param dataArea  the area for plotting the data.
     * @param plot  the plot.
     * @param domainAxis  the domain axis.
     * @param rangeAxis  the range axis.
     * @param dataset  the dataset.
     * @param row  the row index (zero-based).
     * @param column  the column index (zero-based).
     */
    protected void drawVerticalItem(Graphics2D g2,
                                    Rectangle2D dataArea,
                                    CategoryPlot plot,
                                    CategoryAxis domainAxis,
                                    ValueAxis rangeAxis,
                                    CategoryDataset dataset,
                                    int row,
                                    int column) {

        // check the value we are plotting...
        Number value = dataset.getValue(row, column);
        if (value != null) {

            Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX(),
                                                          dataArea.getY() + getYOffset(),
                                                          dataArea.getWidth() - getXOffset(),
                                                          dataArea.getHeight() - getYOffset());

            // BAR X
            double x0 = domainAxis.getCategoryStart(column, getColumnCount(), adjusted,
                                                    plot.getDomainAxisEdge());

            int seriesCount = getRowCount();
            int categoryCount = getColumnCount();
            if (seriesCount > 1) {
                double seriesGap = adjusted.getWidth() * getItemMargin()
                                   / (categoryCount * (seriesCount - 1));
                x0 = x0 + row * (getBarWidth() + seriesGap);
            }
            else {
                x0 = x0 + row * getBarWidth();
            }

            // BAR Y
            double y = value.doubleValue();
            double base = 0.0;
            double lclip = getLowerClip();
            double uclip = getUpperClip();

            if (uclip <= 0.0) {  // cases 1, 2, 3 and 4
                if (y >= uclip) {
                    return; // bar is not visible
                }
                base = uclip;
                if (y <= lclip) {
                    y = lclip;
                }
            }
            else {
                if (lclip <= 0.0) { // cases 5, 6, 7 and 8
                    if (y >= uclip) {
                       y = uclip;
                    }
                    else {
                        if (y <= lclip) {
                            y = lclip;
                        }
                    }
                }
                else { // cases 9, 10, 11 and 12
                    if (y <= lclip) {
                        return; // bar is not visible
                    }
                    base = lclip;
                    if (y >= uclip) {
                        y = uclip;
                    }
                }
            }

            RectangleEdge edge = plot.getRangeAxisEdge();
            double transY1 = rangeAxis.translateValueToJava2D(base, adjusted, edge);
            double transY2 = rangeAxis.translateValueToJava2D(y, adjusted, edge);
            double y2 = Math.min(transY1, transY2);

            double x1 = x0 + getBarWidth();
            double y0 = Math.max(transY1, transY2);

            double x2 = x0 + this.xOffset;
            double x3 = x1 + this.xOffset;
            double y1 = y0 - this.yOffset;
            double y3 = y2 - this.yOffset;

            Rectangle2D bar = new Rectangle2D.Double(x0, y2, x1 - x0, y0 - y2);
            Paint itemPaint = getItemPaint(row, column);
            g2.setPaint(itemPaint);
            g2.fill(bar);

            GeneralPath bar3dRight = null;
            GeneralPath bar3dTop = null;
            if ((y0 - y2) != 0) {
                bar3dRight = new GeneralPath();
                bar3dRight.moveTo((float) x1, (float) y2);
                bar3dRight.lineTo((float) x1, (float) y0);
                bar3dRight.lineTo((float) x3, (float) y1);
                bar3dRight.lineTo((float) x3, (float) y3);
                bar3dRight.closePath();

                if (itemPaint instanceof Color) {
                    g2.setPaint(((Color) itemPaint).darker());
                }
                g2.fill(bar3dRight);
            }

            bar3dTop = new GeneralPath();
            bar3dTop.moveTo((float) x0, (float) y2);
            bar3dTop.lineTo((float) x2, (float) y3);
            bar3dTop.lineTo((float) x3, (float) y3);
            bar3dTop.lineTo((float) x1, (float) y2);
            bar3dTop.closePath();
            g2.fill(bar3dTop);

            if (getBarWidth() > 3) {
                g2.setStroke(getItemStroke(row, column));
                g2.setPaint(getItemOutlinePaint(row, column));
                g2.draw(bar);
                if (bar3dRight != null) {
                    g2.draw(bar3dRight);
                }
                if (bar3dTop != null) {
                    g2.draw(bar3dTop);
                }
            }

            CategoryItemLabelGenerator generator = getItemLabelGenerator(row, column);
            if (generator != null && isItemLabelVisible(row, column)) {
                drawItemLabel(g2, dataset, row, column, plot, generator, bar, (transY1 > transY2));
            }        

            // collect entity and tool tip information...
            if (getInfo() != null) {
                EntityCollection entities = getInfo().getEntityCollection();
                if (entities != null) {
                    GeneralPath barOutline = new GeneralPath();
                    barOutline.moveTo((float) x0, (float) y0);
                    barOutline.lineTo((float) x0, (float) y2);
                    barOutline.lineTo((float) x2, (float) y3);
                    barOutline.lineTo((float) x3, (float) y3);
                    barOutline.lineTo((float) x3, (float) y1);
                    barOutline.lineTo((float) x1, (float) y0);
                    barOutline.closePath();

                    String tip = null;
                    generator = getItemLabelGenerator(row, column);
                    if (generator != null) {
                        tip = generator.generateToolTip(dataset, row, column);
                    }
                    String url = null;
                    if (getItemURLGenerator(row, column) != null) {
                        url = getItemURLGenerator(row, column).generateURL(dataset, row, column);
                    }
                    CategoryItemEntity entity = new CategoryItemEntity(
                        barOutline, tip, url, dataset, row, dataset.getColumnKey(column), column
                    );
                    entities.addEntity(entity);
                }
            }
        }

    }

    /**
     * Provides serialization support.
     *
     * @param stream  the output stream.
     *
     * @throws IOException  if there is an I/O error.
     */
    private void writeObject(ObjectOutputStream stream) throws IOException {
        stream.defaultWriteObject();
        SerialUtilities.writePaint(this.wallPaint, stream);
    }

    /**
     * Provides serialization support.
     *
     * @param stream  the input stream.
     *
     * @throws IOException  if there is an I/O error.
     * @throws ClassNotFoundException  if there is a classpath problem.
     */
    private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
        stream.defaultReadObject();
        this.wallPaint = SerialUtilities.readPaint(stream);
    }


}

⌨️ 快捷键说明

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