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

📄 barrenderer.java

📁 这是一个segy数据显示程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        this.negativeItemLabelPositionFallback = position;        notifyListeners(new RendererChangeEvent(this));    }        /**     * Returns the lower clip value.     * <P>     * This value is recalculated in the initialise() method.     *     * @return The value.     */    public double getLowerClip() {        return this.lowerClip;    }    /**     * Returns the upper clip value.     * <P>     * This value is recalculated in the initialise() method.     *     * @return The value.     */    public double getUpperClip() {        return this.upperClip;    }    /**     * Initialises the renderer and returns a state object that will be passed to subsequent calls      * to the drawItem method.     * <p>     * This method gets called once at the start of the process of drawing a chart.     *     * @param g2  the graphics device.     * @param dataArea  the area in which the data is to be plotted.     * @param plot  the plot.     * @param rendererIndex  the renderer index.     * @param info  collects chart rendering information for return to caller.     *      * @return The renderer state.     *     */    public CategoryItemRendererState initialise(Graphics2D g2,                                                Rectangle2D dataArea,                                                CategoryPlot plot,                                                int rendererIndex,                                                PlotRenderingInfo info) {        CategoryItemRendererState state = super.initialise(g2, dataArea, plot, rendererIndex, info);        // get the clipping values...        ValueAxis rangeAxis = getRangeAxis(plot, rendererIndex);        this.lowerClip = rangeAxis.getRange().getLowerBound();        this.upperClip = rangeAxis.getRange().getUpperBound();        // calculate the bar width        calculateBarWidth(plot, dataArea, rendererIndex, state);        return state;            }        /**     * Calculates the bar width and stores it in the renderer state.     *      * @param plot  the plot.     * @param dataArea  the data area.     * @param rendererIndex  the renderer index.     * @param state  the renderer state.     */    protected void calculateBarWidth(CategoryPlot plot,                                      Rectangle2D dataArea,                                      int rendererIndex,                                     CategoryItemRendererState state) {                                                 CategoryAxis domainAxis = getDomainAxis(plot, rendererIndex);        CategoryDataset dataset = plot.getDataset(rendererIndex);        if (dataset != null) {            int columns = dataset.getColumnCount();            int rows = dataset.getRowCount();            double space = 0.0;            PlotOrientation orientation = plot.getOrientation();            if (orientation == PlotOrientation.HORIZONTAL) {                space = dataArea.getHeight();            }            else if (orientation == PlotOrientation.VERTICAL) {                space = dataArea.getWidth();            }            double maxWidth = space * getMaxBarWidth();            double categoryMargin = 0.0;            double currentItemMargin = 0.0;            if (columns > 1) {                categoryMargin = domainAxis.getCategoryMargin();            }            if (rows > 1) {                currentItemMargin = getItemMargin();            }            double used = space * (1 - domainAxis.getLowerMargin() - domainAxis.getUpperMargin()                                     - categoryMargin - currentItemMargin);            if ((rows * columns) > 0) {                state.setBarWidth(Math.min(used / (rows * columns), maxWidth));            }            else {                state.setBarWidth(Math.min(used, maxWidth));            }        }    }    /**     * Calculates the coordinate of the first "side" of a bar.  This will be the minimum      * x-coordinate for a vertical bar, and the minimum y-coordinate for a horizontal bar.     *      * @param plot  the plot.     * @param orientation  the plot orientation.     * @param dataArea  the data area.     * @param domainAxis  the domain axis.     * @param state  the renderer state (has the bar width precalculated).     * @param row  the row index.     * @param column  the column index.     *      * @return the coordinate.     */    protected double calculateBarW0(CategoryPlot plot,                                     PlotOrientation orientation,                                     Rectangle2D dataArea,                                    CategoryAxis domainAxis,                                    CategoryItemRendererState state,                                    int row,                                    int column) {        // calculate bar width...        double space = 0.0;        if (orientation == PlotOrientation.HORIZONTAL) {            space = dataArea.getHeight();        }        else {            space = dataArea.getWidth();        }        double barW0 = domainAxis.getCategoryStart(            column, getColumnCount(), dataArea, plot.getDomainAxisEdge()        );        int seriesCount = getRowCount();        int categoryCount = getColumnCount();        if (seriesCount > 1) {            double seriesGap = space * getItemMargin() / (categoryCount * (seriesCount - 1));            double seriesW = calculateSeriesWidth(space, domainAxis, categoryCount, seriesCount);            barW0 = barW0 + row * (seriesW + seriesGap)                           + (seriesW / 2.0) - (state.getBarWidth() / 2.0);        }        else {            barW0 = domainAxis.getCategoryMiddle(                column, getColumnCount(), dataArea, plot.getDomainAxisEdge()            ) - state.getBarWidth() / 2.0;        }        return barW0;    }        /**     * Calculates the coordinates for the length of a single bar.     *      * @param value  the value represented by the bar.     *      * @return the coordinates for each end of the bar (or <code>null</code> if the bar is not     *         visible for the current axis range).     */    protected double[] calculateBarL0L1(double value) {        double base = 0.0;        double lclip = getLowerClip();        double uclip = getUpperClip();        if (uclip <= 0.0) {  // cases 1, 2, 3 and 4            if (value >= uclip) {                return null; // 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 null; // bar is not visible            }            base = lclip;            if (value >= uclip) {                value = uclip;            }        }        return new double[] {base, value};    }    /**     * 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 dataset  the dataset.     * @param row  the row index (zero-based).     * @param column  the column index (zero-based).     */    public void drawItem(Graphics2D g2,                         CategoryItemRendererState state,                         Rectangle2D dataArea,                         CategoryPlot plot,                         CategoryAxis domainAxis,                         ValueAxis rangeAxis,                         CategoryDataset dataset,                         int row,                         int column) {        // nothing is drawn for null values...        Number dataValue = dataset.getValue(row, column);        if (dataValue == null) {            return;        }                double value = dataValue.doubleValue();                PlotOrientation orientation = plot.getOrientation();        double barW0 = calculateBarW0(plot, orientation, dataArea, domainAxis, state, row, column);        double[] barL0L1 = calculateBarL0L1(value);        if (barL0L1 == null) {            return;  // the bar is not visible        }                RectangleEdge edge = plot.getRangeAxisEdge();        double transL0 = rangeAxis.valueToJava2D(barL0L1[0], dataArea, edge);        double transL1 = rangeAxis.valueToJava2D(barL0L1[1], dataArea, edge);        double barL0 = Math.min(transL0, transL1);        double barLength = Math.max(Math.abs(transL1 - transL0), getMinimumBarLength());        // draw the bar...        Rectangle2D bar = null;        if (orientation == PlotOrientation.HORIZONTAL) {            bar = new Rectangle2D.Double(barL0, barW0, barLength, state.getBarWidth());        }        else {            bar = new Rectangle2D.Double(barW0, barL0, state.getBarWidth(), barLength);        }        Paint itemPaint = getItemPaint(row, column);        if (getGradientPaintTransformer() != null && itemPaint instanceof GradientPaint) {            GradientPaint gp = (GradientPaint) itemPaint;            itemPaint = getGradientPaintTransformer().transform(gp, bar);        }        g2.setPaint(itemPaint);        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, dataset, row, column, plot, generator, bar, (value < 0.0));        }                                // 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(dataset, row, column);                }                String url = null;                if (getItemURLGenerator(row, column) != null) {                    url = getItemURLGenerator(row, column).generateURL(dataset, row, column);

⌨️ 快捷键说明

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