afreechart/src/main/java/org/afree/chart/renderer/xy/XYBarRenderer.java
/**
     * Draws the visual representation of a single data item.
     *
     * @param canvas  the graphics device.
     * @param state  the renderer state.
     * @param dataArea  the area within which the plot is being drawn.
     * @param info  collects information about the drawing.
     * @param plot  the plot (can be used to obtain standard color
     *              information etc).
     * @param domainAxis  the domain axis.
     * @param rangeAxis  the range axis.
     * @param dataset  the dataset.
     * @param series  the series index (zero-based).
     * @param item  the item index (zero-based).
     * @param crosshairState  crosshair information for the plot
     *                        (<code>null</code> permitted).
     * @param pass  the pass index.
     */
Draws the visual representation of a single data item.
@param canvas  the graphics device.
@param state  the renderer state.
@param dataArea  the area within which the plot is being drawn.
@param info  collects information about the drawing.
@param plot  the plot (can be used to obtain standard color
information etc).
@param domainAxis  the domain axis.
@param rangeAxis  the range axis.
@param dataset  the dataset.
@param series  the series index (zero-based).
@param item  the item index (zero-based).
@param crosshairState  crosshair information for the plot
(null permitted).
@param pass  the pass index.
Draws the visual representation of a single data item . @param canvas the graphics device . @param state the renderer state . @param dataArea the area within which the plot is being drawn . @param info collects information about the drawing . @param plot the plot ( can be used to obtain standard color information etc ) . @param domainAxis the domain axis . @param rangeAxis the range axis . @param dataset the dataset . @param series the series index ( zero - based ) . @param item the item index ( zero - based ) . @param crosshairState crosshair information for the plot ( null permitted ) . @param pass the pass index .
public void drawItem(Canvas canvas,
                         XYItemRendererState state,
                         RectShape dataArea,
                         PlotRenderingInfo info,
                         XYPlot plot,
                         ValueAxis domainAxis,
                         ValueAxis rangeAxis,
                         XYDataset dataset,
                         int series,
                         int item,
                         CrosshairState crosshairState,
                         int pass) {
        if (!getItemVisible(series, item)) {
            return;
        }
        IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
        double value0;
        double value1;
        if (this.useYInterval) {
            value0 = intervalDataset.getStartYValue(series, item);
            value1 = intervalDataset.getEndYValue(series, item);
        }
        else {
            value0 = this.base;
            value1 = intervalDataset.getYValue(series, item);
        }
        if (Double.isNaN(value0) || Double.isNaN(value1)) {
            return;
        }
        if (value0 <= value1) {
            if (!rangeAxis.getRange().intersects(value0, value1)) {
                return;
            }
        }
        else {
            if (!rangeAxis.getRange().intersects(value1, value0)) {
                return;
            }
        }
        double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea,
                plot.getRangeAxisEdge());
        double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea,
                plot.getRangeAxisEdge());
        double bottom = Math.min(translatedValue0, translatedValue1);
        double top = Math.max(translatedValue0, translatedValue1);
        double startX = intervalDataset.getStartXValue(series, item);
        if (Double.isNaN(startX)) {
            return;
        }
        double endX = intervalDataset.getEndXValue(series, item);
        if (Double.isNaN(endX)) {
            return;
        }
        if (startX <= endX) {
            if (!domainAxis.getRange().intersects(startX, endX)) {
                return;
            }
        }
        else {
            if (!domainAxis.getRange().intersects(endX, startX)) {
                return;
            }
        }
        if (this.barAlignmentFactor >= 0.0 && this.barAlignmentFactor <= 1.0) {
            double x = intervalDataset.getXValue(series, item);
            double interval = endX - startX;
            startX = x - interval * this.barAlignmentFactor;
            endX = startX + interval;
        }
        RectangleEdge location = plot.getDomainAxisEdge();
        double translatedStartX = domainAxis.valueToJava2D(startX, dataArea,
                location);
        double translatedEndX = domainAxis.valueToJava2D(endX, dataArea,
                location);
        double translatedWidth = Math.max(1, Math.abs(translatedEndX
                - translatedStartX));
        double left = Math.min(translatedStartX, translatedEndX);
        if (getMargin() > 0.0) {
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            left = left + cut / 2;
        }
        RectShape bar = null;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            bottom = Math.max(bottom, dataArea.getMinX());
            top = Math.min(top, dataArea.getMaxX());
            bar = new RectShape(
                bottom, left, top - bottom, translatedWidth);
        }
        else if (orientation == PlotOrientation.VERTICAL) {
            bottom = Math.max(bottom, dataArea.getMinY());
            top = Math.min(top, dataArea.getMaxY());
            bar = new RectShape(left, bottom, translatedWidth,
                    top - bottom);
        }
        boolean positive = (value1 > 0.0);
        boolean inverted = rangeAxis.isInverted();
        RectangleEdge barBase;
        if (orientation == PlotOrientation.HORIZONTAL) {
            if (positive && inverted || !positive && !inverted) {
                barBase = RectangleEdge.RIGHT;
            }
            else {
                barBase = RectangleEdge.LEFT;
            }
        }
        else {
            if (positive && !inverted || !positive && inverted) {
                barBase = RectangleEdge.BOTTOM;
            }
            else {
                barBase = RectangleEdge.TOP;
            }
        }
        if (getShadowsVisible()) {
            this.barPainter.paintBarShadow(canvas, this, series, item, bar, barBase,
                !this.useYInterval);
        }
        this.barPainter.paintBar(canvas, this, series, item, bar, barBase);
        if (isItemLabelVisible(series, item)) {
            XYItemLabelGenerator generator = getItemLabelGenerator(series,
                    item);
            drawItemLabel(canvas, dataset, series, item, plot, generator, bar,
                    value1 < 0.0);
        }
        double x1 = (startX + endX) / 2.0;
        double y1 = dataset.getYValue(series, item);
        double transX1 = domainAxis.valueToJava2D(x1, dataArea, location);
        double transY1 = rangeAxis.valueToJava2D(y1, dataArea,
                plot.getRangeAxisEdge());
        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
                rangeAxisIndex, transX1, transY1, plot.getOrientation());
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            addEntity(entities, bar, dataset, series, item, 0.0, 0.0);
        }
    }
public void drawItem ( Canvas canvas , XYItemRendererState state , RectShape dataArea , PlotRenderingInfo info , XYPlot plot , ValueAxis domainAxis , ValueAxis rangeAxis , XYDataset dataset , int series , int item , CrosshairState crosshairState , int pass ) { if ( ! getItemVisible ( series , item ) ) { return ; } IntervalXYDataset intervalDataset = ( IntervalXYDataset ) dataset ; double value0 ; double value1 ; if ( this . useYInterval ) { value0 = intervalDataset . getStartYValue ( series , item ) ; value1 = intervalDataset . getEndYValue ( series , item ) ; } else { value0 = this . base ; value1 = intervalDataset . getYValue ( series , item ) ; } if ( Double . isNaN ( value0 ) || Double . isNaN ( value1 ) ) { return ; } if ( value0 <= value1 ) { if ( ! rangeAxis . getRange ( ) . intersects ( value0 , value1 ) ) { return ; } } else { if ( ! rangeAxis . getRange ( ) . intersects ( value1 , value0 ) ) { return ; } } double translatedValue0 = rangeAxis . valueToJava2D ( value0 , dataArea , plot . getRangeAxisEdge ( ) ) ; double translatedValue1 = rangeAxis . valueToJava2D ( value1 , dataArea , plot . getRangeAxisEdge ( ) ) ; double bottom = Math . min ( translatedValue0 , translatedValue1 ) ; double top = Math . max ( translatedValue0 , translatedValue1 ) ; double startX = intervalDataset . getStartXValue ( series , item ) ; if ( Double . isNaN ( startX ) ) { return ; } double endX = intervalDataset . getEndXValue ( series , item ) ; if ( Double . isNaN ( endX ) ) { return ; } if ( startX <= endX ) { if ( ! domainAxis . getRange ( ) . intersects ( startX , endX ) ) { return ; } } else { if ( ! domainAxis . getRange ( ) . intersects ( endX , startX ) ) { return ; } } if ( this . barAlignmentFactor >= 0.0 && this . barAlignmentFactor <= 1.0 ) { double x = intervalDataset . getXValue ( series , item ) ; double interval = endX - startX ; startX = x - interval * this . barAlignmentFactor ; endX = startX + interval ; } RectangleEdge location = plot . getDomainAxisEdge ( ) ; double translatedStartX = domainAxis . valueToJava2D ( startX , dataArea , location ) ; double translatedEndX = domainAxis . valueToJava2D ( endX , dataArea , location ) ; double translatedWidth = Math . max ( 1 , Math . abs ( translatedEndX - translatedStartX ) ) ; double left = Math . min ( translatedStartX , translatedEndX ) ; if ( getMargin ( ) > 0.0 ) { double cut = translatedWidth * getMargin ( ) ; translatedWidth = translatedWidth - cut ; left = left + cut / 2 ; } RectShape bar = null ; PlotOrientation orientation = plot . getOrientation ( ) ; if ( orientation == PlotOrientation . HORIZONTAL ) { bottom = Math . max ( bottom , dataArea . getMinX ( ) ) ; top = Math . min ( top , dataArea . getMaxX ( ) ) ; bar = new RectShape ( bottom , left , top - bottom , translatedWidth ) ; } else if ( orientation == PlotOrientation . VERTICAL ) { bottom = Math . max ( bottom , dataArea . getMinY ( ) ) ; top = Math . min ( top , dataArea . getMaxY ( ) ) ; bar = new RectShape ( left , bottom , translatedWidth , top - bottom ) ; } boolean positive = ( value1 > 0.0 ) ; boolean inverted = rangeAxis . isInverted ( ) ; RectangleEdge barBase ; if ( orientation == PlotOrientation . HORIZONTAL ) { if ( positive && inverted || ! positive && ! inverted ) { barBase = RectangleEdge . RIGHT ; } else { barBase = RectangleEdge . LEFT ; } } else { if ( positive && ! inverted || ! positive && inverted ) { barBase = RectangleEdge . BOTTOM ; } else { barBase = RectangleEdge . TOP ; } } if ( getShadowsVisible ( ) ) { this . barPainter . paintBarShadow ( canvas , this , series , item , bar , barBase , ! this . useYInterval ) ; } this . barPainter . paintBar ( canvas , this , series , item , bar , barBase ) ; if ( isItemLabelVisible ( series , item ) ) { XYItemLabelGenerator generator = getItemLabelGenerator ( series , item ) ; drawItemLabel ( canvas , dataset , series , item , plot , generator , bar , value1 < 0.0 ) ; } double x1 = ( startX + endX ) / 2.0 ; double y1 = dataset . getYValue ( series , item ) ; double transX1 = domainAxis . valueToJava2D ( x1 , dataArea , location ) ; double transY1 = rangeAxis . valueToJava2D ( y1 , dataArea , plot . getRangeAxisEdge ( ) ) ; int domainAxisIndex = plot . getDomainAxisIndex ( domainAxis ) ; int rangeAxisIndex = plot . getRangeAxisIndex ( rangeAxis ) ; updateCrosshairValues ( crosshairState , x1 , y1 , domainAxisIndex , rangeAxisIndex , transX1 , transY1 , plot . getOrientation ( ) ) ; EntityCollection entities = state . getEntityCollection ( ) ; if ( entities != null ) { addEntity ( entities , bar , dataset , series , item , 0.0 , 0.0 ) ; } }
Draws the visual representation of a single data item.
Draws the visual representation of a single data item .
// is there an alignment adjustment to be made? // clip left and right bounds to data area // clip top and bottom bounds to data area // update the crosshair point