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

📄 layeredbarrenderer.java

📁 jfreechart安装程序和使用说明
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        int seriesCount = getRowCount();

        // draw the bar...
        double shift = 0.0;
        double rectHeight = 0.0;
        if (getSeriesBarWidth(row, state) != state.getBarWidth()) {
            rectHeight = getSeriesBarWidth(row, state) * state.getBarWidth();
            rectY = rectY + (1 - getSeriesBarWidth(row, state)) * state.getBarWidth() / 2;
        } 
        else {
            rectHeight = state.getBarWidth();
            if (seriesCount > 1) {
                shift = rectHeight * 0.20 / (seriesCount - 1);
            }
        }

        Rectangle2D bar = new Rectangle2D.Double(rectX, 
                                                (rectY + ((seriesCount - 1 - row) * shift)),
                                                rectWidth,
                                                (rectHeight - (seriesCount - 1 - row) * shift * 2));

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

        // draw the outline...
        if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
            Stroke stroke = getItemOutlineStroke(row, column);
            Paint paint = getItemOutlinePaint(row, column);
            if (stroke != null && paint != null) {
                g2.setStroke(stroke);
                g2.setPaint(paint);
                g2.draw(bar);
            }
        }

        CategoryLabelGenerator generator = getLabelGenerator(row, column);
        if (generator != null && isItemLabelVisible(row, column)) {
            drawItemLabel(g2, data, row, column, plot, generator, bar, (transX1 > transX2));
        }        

        // collect entity and tool tip information...
        if (state.getInfo() != null) {
            EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
            if (entities != null) {
                String tip = null;
                CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
                if (tipster != null) {
                    tip = tipster.generateToolTip(data, row, column);
                }
                String url = null;
                if (getItemURLGenerator(row, column) != null) {
                    url = getItemURLGenerator(row, column).generateURL(data, row, column);
                }
                CategoryItemEntity entity = new CategoryItemEntity(bar, tip, url, data, row,
                                                               data.getColumnKey(column), column);
                entities.addEntity(entity);
            }
        }
    }

    /**
     * Draws the bar for a single (series, category) data item.
     *
     * @param g2  the graphics device.
     * @param state  the renderer state.
     * @param dataArea  the data area.
     * @param plot  the plot.
     * @param domainAxis  the domain axis.
     * @param rangeAxis  the range axis.
     * @param data  the data.
     * @param row  the row index (zero-based).
     * @param column  the column index (zero-based).
     */
    protected void drawVerticalItem(Graphics2D g2,
                                    CategoryItemRendererState state,
                                    Rectangle2D dataArea,
                                    CategoryPlot plot,
                                    CategoryAxis domainAxis,
                                    ValueAxis rangeAxis,
                                    CategoryDataset data,
                                    int row,
                                    int column) {

        // nothing is drawn for null values...
        Number dataValue = data.getValue(row, column);
        if (dataValue == null) {
            return;
        }

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

        int seriesCount = getRowCount();

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

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

        RectangleEdge edge = plot.getRangeAxisEdge();
        double transY1 = rangeAxis.valueToJava2D(base, dataArea, edge);
        double transY2 = rangeAxis.valueToJava2D(value, dataArea, edge);
        double rectY = Math.min(transY2, transY1);

        double rectWidth = state.getBarWidth();
        double rectHeight = Math.abs(transY2 - transY1);

        // draw the bar...
        double shift = 0.0;
        rectWidth = 0.0;
        if (getSeriesBarWidth(row, state) != state.getBarWidth()) {
            rectWidth = getSeriesBarWidth(row, state) * state.getBarWidth();
            rectX = rectX + (1 - getSeriesBarWidth(row, state)) * state.getBarWidth() / 2;
        } 
        else {
            rectWidth = state.getBarWidth();
            if (seriesCount > 1) {
                // needs to be improved !!!
                shift = rectWidth * 0.20 / (seriesCount - 1);
            }
        }

        Rectangle2D bar = new Rectangle2D.Double(
                                                (rectX + ((seriesCount - 1 - row) * shift)),
                                                rectY,
                                                (rectWidth - (seriesCount - 1 - row) * shift * 2),
                                                rectHeight);
        g2.setPaint(getItemPaint(row, column));
        g2.fill(bar);

        // draw the outline...
        if (isDrawBarOutline() && state.getBarWidth() > BAR_OUTLINE_WIDTH_THRESHOLD) {
            Stroke stroke = getItemOutlineStroke(row, column);
            Paint paint = getItemOutlinePaint(row, column);
            if (stroke != null && paint != null) {
                g2.setStroke(stroke);
                g2.setPaint(paint);
                g2.draw(bar);
            }
        }

        // draw the item labels if there are any...
        double transX1 = rangeAxis.valueToJava2D(base, dataArea, edge);
        double transX2 = rangeAxis.valueToJava2D(value, dataArea, edge);

        CategoryLabelGenerator generator = getLabelGenerator(row, column);
        if (generator != null && isItemLabelVisible(row, column)) {
            drawItemLabel(g2, data, row, column, plot, generator, bar, (transX1 > transX2));
        }        

        // collect entity and tool tip information...
        if (state.getInfo() != null) {
            EntityCollection entities = state.getInfo().getOwner().getEntityCollection();
            if (entities != null) {
                String tip = null;
                CategoryToolTipGenerator tipster = getToolTipGenerator(row, column);
                if (tipster != null) {
                    tip = tipster.generateToolTip(data, row, column);
                }
                String url = null;
                if (getItemURLGenerator(row, column) != null) {
                    url = getItemURLGenerator(row, column).generateURL(data, row, column);
                }
                CategoryItemEntity entity = new CategoryItemEntity(
                    bar, tip, url, data, row, data.getColumnKey(column), column
                );
                entities.addEntity(entity);
            }
        }
    }

    /**
     * Returns the bar width for a series.
     *
     * @param series  the series index (zero based).
     * @param state  the renderer state.
     *
     * @return The width for the series (1.0=100%, it is the maximum).
     */
    public double getSeriesBarWidth(int series, CategoryItemRendererState state) {

        if (this.seriesBarWidthList.get(series) != null) {
            return  ((Number) this.seriesBarWidthList.get(series)).doubleValue();
        }
        else {
            return state.getBarWidth();
        }
    }

    /**
     * Sets the width of the bars of a series.
     *
     * @param series  the series index (zero based).
     * @param width  the width of the series bar in percentage (1.0=100%, it is the maximum).
     */ 
    public void setSeriesBarWidth(int series, double width) {
        this.seriesBarWidthList.set(series, new Double(width));
    }

}

⌨️ 快捷键说明

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