afreechart/src/main/java/org/afree/chart/renderer/xy/HighLowRenderer.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) {
        double x = dataset.getXValue(series, item);
        if (!domainAxis.getRange().contains(x)) {
            return;    
        }
        double xx = domainAxis.valueToJava2D(x, dataArea,
                plot.getDomainAxisEdge());
        Shape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }
        PlotOrientation orientation = plot.getOrientation();
        RectangleEdge location = plot.getRangeAxisEdge();
        PaintType itemPaintType = getItemPaintType(series, item);
        float stroke = getItemStroke(series, item);
        PathEffect effect = getItemEffect(series, item);
        if (dataset instanceof OHLCDataset) {
            OHLCDataset hld = (OHLCDataset) dataset;
            double yHigh = hld.getHighValue(series, item);
            double yLow = hld.getLowValue(series, item);
            if (!Double.isNaN(yHigh) && !Double.isNaN(yLow)) {
                double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea,
                        location);
                double yyLow = rangeAxis.valueToJava2D(yLow, dataArea,
                        location);
                Paint itemPaint = PaintUtility.createPaint(
                        Paint.ANTI_ALIAS_FLAG,
                        itemPaintType,
                        stroke,
                        effect);
                if (orientation == PlotOrientation.HORIZONTAL) {
                    new LineShape(yyLow, xx, yyHigh, xx).draw(canvas, itemPaint);
                    entityArea = new RectShape(Math.min(yyLow, yyHigh),
                            xx - 1.0, Math.abs(yyHigh - yyLow), 2.0);
                }
                else if (orientation == PlotOrientation.VERTICAL) {
                    new LineShape(xx, yyLow, xx, yyHigh).draw(canvas, itemPaint);
                    entityArea = new RectShape(xx - 1.0,
                            Math.min(yyLow, yyHigh), 2.0,
                            Math.abs(yyHigh - yyLow));
                }
            }
            double delta = getTickLength();
            if (domainAxis.isInverted()) {
                delta = -delta;
            }
            if (getDrawOpenTicks()) {
                double yOpen = hld.getOpenValue(series, item);
                if (!Double.isNaN(yOpen)) {
                    double yyOpen = rangeAxis.valueToJava2D(yOpen, dataArea,
                            location);
                    PaintType paintType;
                    if (this.openTickPaintType != null) {
                        paintType = this.openTickPaintType;
                    }
                    else {
                        paintType = itemPaintType;
                    }
                    Paint paint = PaintUtility.createPaint(
                            Paint.ANTI_ALIAS_FLAG,
                            paintType,
                            stroke,
                            effect);
                    if (orientation == PlotOrientation.HORIZONTAL) {
                        new LineShape(yyOpen, xx + delta, yyOpen,
                                xx).draw(canvas, paint);
                    }
                    else if (orientation == PlotOrientation.VERTICAL) {
                        new LineShape(xx - delta, yyOpen, xx,
                                yyOpen).draw(canvas, paint);
                    }
                }
            }
            if (getDrawCloseTicks()) {
                double yClose = hld.getCloseValue(series, item);
                if (!Double.isNaN(yClose)) {
                    double yyClose = rangeAxis.valueToJava2D(
                        yClose, dataArea, location);
                    PaintType paintType;
                    if (this.closeTickPaintType != null) {
                        paintType = this.closeTickPaintType;
                    }
                    else {
                        paintType = itemPaintType;
                    }
                    Paint paint = PaintUtility.createPaint(
                            Paint.ANTI_ALIAS_FLAG,
                            paintType,
                            stroke,
                            effect);
                    if (orientation == PlotOrientation.HORIZONTAL) {
                        new LineShape(yyClose, xx, yyClose,
                                xx - delta).draw(canvas, paint);
                    }
                    else if (orientation == PlotOrientation.VERTICAL) {
                        new LineShape(xx, yyClose, xx + delta,
                                yyClose).draw(canvas, paint);
                    }
                }
            }
        }
        else {
            if (item > 0) {
                double x0 = dataset.getXValue(series, item - 1);
                double y0 = dataset.getYValue(series, item - 1);
                double y = dataset.getYValue(series, item);
                if (Double.isNaN(x0) || Double.isNaN(y0) || Double.isNaN(y)) {
                    return;
                }
                double xx0 = domainAxis.valueToJava2D(x0, dataArea,
                        plot.getDomainAxisEdge());
                double yy0 = rangeAxis.valueToJava2D(y0, dataArea, location);
                double yy = rangeAxis.valueToJava2D(y, dataArea, location);
                Paint itemPaint = PaintUtility.createPaint(
                        Paint.ANTI_ALIAS_FLAG,
                        itemPaintType,
                        stroke,
                        effect);
                if (orientation == PlotOrientation.HORIZONTAL) {
                    new LineShape(yy0, xx0, yy, xx).draw(canvas, itemPaint);
                }
                else if (orientation == PlotOrientation.VERTICAL) {
                    new LineShape(xx0, yy0, xx, yy).draw(canvas, itemPaint);
                }
            }
        }
        if (entities != null) {
            addEntity(entities, entityArea, 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 ) { double x = dataset . getXValue ( series , item ) ; if ( ! domainAxis . getRange ( ) . contains ( x ) ) { return ; } double xx = domainAxis . valueToJava2D ( x , dataArea , plot . getDomainAxisEdge ( ) ) ; Shape entityArea = null ; EntityCollection entities = null ; if ( info != null ) { entities = info . getOwner ( ) . getEntityCollection ( ) ; } PlotOrientation orientation = plot . getOrientation ( ) ; RectangleEdge location = plot . getRangeAxisEdge ( ) ; PaintType itemPaintType = getItemPaintType ( series , item ) ; float stroke = getItemStroke ( series , item ) ; PathEffect effect = getItemEffect ( series , item ) ; if ( dataset instanceof OHLCDataset ) { OHLCDataset hld = ( OHLCDataset ) dataset ; double yHigh = hld . getHighValue ( series , item ) ; double yLow = hld . getLowValue ( series , item ) ; if ( ! Double . isNaN ( yHigh ) && ! Double . isNaN ( yLow ) ) { double yyHigh = rangeAxis . valueToJava2D ( yHigh , dataArea , location ) ; double yyLow = rangeAxis . valueToJava2D ( yLow , dataArea , location ) ; Paint itemPaint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , itemPaintType , stroke , effect ) ; if ( orientation == PlotOrientation . HORIZONTAL ) { new LineShape ( yyLow , xx , yyHigh , xx ) . draw ( canvas , itemPaint ) ; entityArea = new RectShape ( Math . min ( yyLow , yyHigh ) , xx - 1.0 , Math . abs ( yyHigh - yyLow ) , 2.0 ) ; } else if ( orientation == PlotOrientation . VERTICAL ) { new LineShape ( xx , yyLow , xx , yyHigh ) . draw ( canvas , itemPaint ) ; entityArea = new RectShape ( xx - 1.0 , Math . min ( yyLow , yyHigh ) , 2.0 , Math . abs ( yyHigh - yyLow ) ) ; } } double delta = getTickLength ( ) ; if ( domainAxis . isInverted ( ) ) { delta = - delta ; } if ( getDrawOpenTicks ( ) ) { double yOpen = hld . getOpenValue ( series , item ) ; if ( ! Double . isNaN ( yOpen ) ) { double yyOpen = rangeAxis . valueToJava2D ( yOpen , dataArea , location ) ; PaintType paintType ; if ( this . openTickPaintType != null ) { paintType = this . openTickPaintType ; } else { paintType = itemPaintType ; } Paint paint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , paintType , stroke , effect ) ; if ( orientation == PlotOrientation . HORIZONTAL ) { new LineShape ( yyOpen , xx + delta , yyOpen , xx ) . draw ( canvas , paint ) ; } else if ( orientation == PlotOrientation . VERTICAL ) { new LineShape ( xx - delta , yyOpen , xx , yyOpen ) . draw ( canvas , paint ) ; } } } if ( getDrawCloseTicks ( ) ) { double yClose = hld . getCloseValue ( series , item ) ; if ( ! Double . isNaN ( yClose ) ) { double yyClose = rangeAxis . valueToJava2D ( yClose , dataArea , location ) ; PaintType paintType ; if ( this . closeTickPaintType != null ) { paintType = this . closeTickPaintType ; } else { paintType = itemPaintType ; } Paint paint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , paintType , stroke , effect ) ; if ( orientation == PlotOrientation . HORIZONTAL ) { new LineShape ( yyClose , xx , yyClose , xx - delta ) . draw ( canvas , paint ) ; } else if ( orientation == PlotOrientation . VERTICAL ) { new LineShape ( xx , yyClose , xx + delta , yyClose ) . draw ( canvas , paint ) ; } } } } else { if ( item > 0 ) { double x0 = dataset . getXValue ( series , item - 1 ) ; double y0 = dataset . getYValue ( series , item - 1 ) ; double y = dataset . getYValue ( series , item ) ; if ( Double . isNaN ( x0 ) || Double . isNaN ( y0 ) || Double . isNaN ( y ) ) { return ; } double xx0 = domainAxis . valueToJava2D ( x0 , dataArea , plot . getDomainAxisEdge ( ) ) ; double yy0 = rangeAxis . valueToJava2D ( y0 , dataArea , location ) ; double yy = rangeAxis . valueToJava2D ( y , dataArea , location ) ; Paint itemPaint = PaintUtility . createPaint ( Paint . ANTI_ALIAS_FLAG , itemPaintType , stroke , effect ) ; if ( orientation == PlotOrientation . HORIZONTAL ) { new LineShape ( yy0 , xx0 , yy , xx ) . draw ( canvas , itemPaint ) ; } else if ( orientation == PlotOrientation . VERTICAL ) { new LineShape ( xx0 , yy0 , xx , yy ) . draw ( canvas , itemPaint ) ; } } } if ( entities != null ) { addEntity ( entities , entityArea , 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 .
// the x value is not within the axis range // setup for collecting optional entity info... // not a HighLowDataset, so just draw a line connecting this point // with the previous point...