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

📄 stackedbarrenderer3d.java

📁 大家打开看看啊, 很有用的东西
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            double translatedBase;
            double translatedValue;

            RectangleEdge location = plot.getRangeAxisEdge();
            if (xx > 0) {
                translatedBase = rangeAxis.translateValueToJava2D(positiveBase, adjusted, location);
                translatedValue = rangeAxis.translateValueToJava2D(positiveBase + xx, adjusted,
                                                                   location);
            }
            else {
                translatedBase = rangeAxis.translateValueToJava2D(negativeBase, adjusted, location);
                translatedValue = rangeAxis.translateValueToJava2D(negativeBase + xx, adjusted,
                                                                   location);
            }

            double y0 = Math.min(translatedBase, translatedValue);
            double y2 = Math.max(translatedBase, translatedValue);

            double x0 = x2 + getBarWidth();
            double x1 = x0 - getYOffset();
            double x3 = x2 - getYOffset();

            double y1 = y0 + getXOffset();
            double y3 = y2 + getXOffset();

            Rectangle2D bar = new Rectangle2D.Double(y0, x2, y2 - y0, x0 - x2);
            g2.setPaint(paint);
            g2.fill(bar);

            GeneralPath barR3d = null;
            GeneralPath barT3d = null;
            if ((x2 - y0) != 0) {
                if (xx > 0.0) {
                    barR3d = new GeneralPath();
                    barR3d.moveTo((float) y2, (float) x0);
                    barR3d.lineTo((float) y2, (float) x2);
                    barR3d.lineTo((float) y3, (float) x3);
                    barR3d.lineTo((float) y3, (float) x1);
                    barR3d.closePath();
                    if (paint instanceof Color) {
                        g2.setPaint(((Color) paint).darker());
                    }
                    g2.fill(barR3d);
                }
                
                barT3d = new GeneralPath();
                barT3d.moveTo((float) y0, (float) x2);
                barT3d.lineTo((float) y1, (float) x3);
                barT3d.lineTo((float) y3, (float) x3);
                barT3d.lineTo((float) y2, (float) x2);
                barT3d.closePath();
                if (paint instanceof Color) {
                    g2.setPaint(((Color) paint)); //.brighter());
                }
                g2.fill(barT3d);
            }

            if ((x0 - x2) > 3) {
                g2.setStroke(getItemStroke(row, column));
                g2.setPaint(getItemOutlinePaint(row, column));
                g2.draw(bar);
                if (barR3d != null) {
                    g2.draw(barR3d);
                }
                if (barT3d != null) {
                    g2.draw(barT3d);
                }
            }

            // collect entity and tool tip information...
            if (getInfo() != null) {
                EntityCollection entities = getInfo().getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    CategoryItemLabelGenerator 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 stacked bar (with 3D-effect) for a specific item.
     *
     * @param g2  the graphics device.
     * @param dataArea  the plot area.
     * @param plot  the plot.
     * @param domainAxis  the domain (category) axis.
     * @param rangeAxis  the range (value) axis.
     * @param dataset  the data.
     * @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) {

        Paint seriesPaint = getItemPaint(row, column);

        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());

        // BAR Y
        double positiveBase = 0.0;
        double negativeBase = 0.0;

        for (int i = 0; i < row; i++) {
            Number v = dataset.getValue(i, column);
            if (v != null) {
                double d = v.doubleValue();
                if (d > 0) {
                    positiveBase = positiveBase + d;
                }
                else {
                    negativeBase = negativeBase + d;
                }
            }
        }

        Number value = dataset.getValue(row, column);
        if (value != null) {

            double xx = value.doubleValue();
            double translatedBase;
            double translatedValue;

            RectangleEdge location = plot.getRangeAxisEdge();
            if (xx > 0) {
                translatedBase = rangeAxis.translateValueToJava2D(positiveBase, adjusted, location);
                translatedValue = rangeAxis.translateValueToJava2D(positiveBase + xx, adjusted,
                                                                   location);
            }
            else {
                translatedBase = rangeAxis.translateValueToJava2D(negativeBase, adjusted, location);
                translatedValue = rangeAxis.translateValueToJava2D(negativeBase + xx, adjusted,
                                                                   location);
            }

            double y0 = Math.max(translatedBase, translatedValue);
            double y2 = Math.min(translatedBase, translatedValue);

            double x1 = x0 + getBarWidth();
            double x2 = x0 + getXOffset();
            double x3 = x1 + getXOffset();

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

            Rectangle2D bar = new Rectangle2D.Double(x0, y2, x1 - x0, y0 - y2);
            g2.setPaint(seriesPaint);
            g2.fill(bar);

            GeneralPath barR3d = null;
            GeneralPath barT3d = null;
            if ((y0 - y2) != 0) {
                barR3d = new GeneralPath();
                barR3d.moveTo((float) x1, (float) y0);
                barR3d.lineTo((float) x1, (float) y2);
                barR3d.lineTo((float) x3, (float) y3);
                barR3d.lineTo((float) x3, (float) y1);
                barR3d.closePath();
                if (seriesPaint instanceof Color) {
                    g2.setPaint(((Color) seriesPaint).darker());
                }
                g2.fill(barR3d);

                if (xx > 0) {
                    barT3d = new GeneralPath();
                    barT3d.moveTo((float) x0, (float) y2);
                    barT3d.lineTo((float) x1, (float) y2);
                    barT3d.lineTo((float) x3, (float) y3);
                    barT3d.lineTo((float) x2, (float) y3);
                    barT3d.closePath();
                    if (seriesPaint instanceof Color) {
                        g2.setPaint(((Color) seriesPaint)); //.brighter());
                    }
                    g2.fill(barT3d);
                }
            }

            if ((x1 - x0) > 3) {
                g2.setStroke(getItemStroke(row, column));
                g2.setPaint(getItemOutlinePaint(row, column));
                g2.draw(bar);
                if (barR3d != null) {
                    g2.draw(barR3d);
                }
                if (barT3d != null) {
                    g2.draw(barT3d);
                }
            }

            // collect entity and tool tip information...
            if (getInfo() != null) {
                EntityCollection entities = getInfo().getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    CategoryItemLabelGenerator 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);
                }
            }
        }

    }

}

⌨️ 快捷键说明

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