Example usage for org.jfree.chart.plot XYPlot getDomainAxisEdge

List of usage examples for org.jfree.chart.plot XYPlot getDomainAxisEdge

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getDomainAxisEdge.

Prototype

public RectangleEdge getDomainAxisEdge() 

Source Link

Document

Returns the edge for the primary domain axis (taking into account the plot's orientation).

Usage

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Draws the visual representation of a series as lines.
 *
 * @param g2  the graphics device./*from   ww  w . ja  v  a2s.  co  m*/
 * @param state  the renderer state.
 * @param dataArea  the area within which the data 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 crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
protected void drawVerticalSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
        PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, CrosshairState crosshairState, int pass) {

    State s = (State) state;
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double lowestVisibleX = domainAxis.getLowerBound();
    double highestVisibleX = domainAxis.getUpperBound();
    double width = dataArea.getWidth();
    double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth;
    double lowestVisibleY = rangeAxis.getLowerBound();
    double highestVisibleY = rangeAxis.getUpperBound();

    double lastX = Double.NEGATIVE_INFINITY;
    double lastY = 0.0;
    double highY = 0.0;
    double lowY = 0.0;
    double openY = 0.0;
    double closeY = 0.0;
    boolean lastIntervalDone = false;
    boolean currentPointVisible = false;
    boolean lastPointVisible = false;
    boolean lastPointGood = false;
    boolean lastPointInInterval = false;
    boolean pathStarted = false;
    for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) {
        double x = dataset.getXValue(series, itemIndex);
        double y = dataset.getYValue(series, itemIndex);
        if (!Double.isNaN(x) && !Double.isNaN(y)) {
            //System.out.println ("Breakpoint 736: pathStarted " + pathStarted);
            if (!pathStarted) {
                float startX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                float startY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                s.seriesPath.moveTo(startX, startY);
                pathStarted = true;
            }
            if ((Math.abs(x - lastX) > dX)) {
                //System.out.println ("Breakpoint 744: leaving interval ");
                //in any case, add the interval that we are about to leave to the intervalPath
                float intervalPathX = 0.0f;
                float intervalPathStartY = 0.0f;
                float intervalPathEndY = 0.0f;
                float seriesPathCurrentX = 0.0f;
                float seriesPathCurrentY = 0.0f;
                float seriesPathLastX = 0.0f;
                float seriesPathLastY = 0.0f;

                //first set some variables
                intervalPathX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalPathStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalPathEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                seriesPathCurrentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                seriesPathLastX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                seriesPathCurrentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                seriesPathLastY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                /*if((lowY - highY) < 1){
                lastPointInInterval = false;
                }*/
                //Double[] values = new Double[]{new Double(openY), new Double(closeY), new Double(highY), new Double(lowY), new Double(lastX)};
                /*MessageFormat mf = new MessageFormat("openY {0,number, integer},"
                    + " closeY {1,number, integer}"
                    + " highY {2,number, integer}"
                    + " lowY {3,number, integer}"
                    + "lastX {4,number, integer}");*/
                //String text = mf.format(values);
                //System.out.println("Breakpoint 772"  + text);
                boolean drawInterval = false;
                if (openY >= closeY) {
                    if (highY > openY || lowY < closeY) {
                        drawInterval = true;
                    }
                }
                if (openY < closeY) {
                    if (lowY < openY || highY > closeY) {
                        drawInterval = true;
                    }
                }
                //System.out.println("Breakpoint 784, drawInterval "  + drawInterval);
                if (drawInterval) {
                    s.intervalPath.moveTo(intervalPathX, intervalPathStartY);
                    s.intervalPath.lineTo(intervalPathX, intervalPathEndY);
                }
                lastIntervalDone = true;

                //now the series path
                currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY)
                        && (y <= highestVisibleY));
                if (!lastPointGood && !lastPointInInterval) {//last point not valid --
                    if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position
                        s.seriesPath.moveTo(seriesPathCurrentX, seriesPathCurrentY);
                    }
                } else {//last point valid
                    //if the last point was visible and not part of an interval,
                    //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line
                    //thus we only need to draw a line to the current position
                    if (lastPointInInterval && lastPointGood) {
                        s.seriesPath.lineTo(seriesPathLastX, seriesPathLastY);
                        s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY);
                    } //if the last point was not visible or part of an interval, we have just stored the y values of the last point
                      //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing
                      //and draw a line to the current position.
                    else {
                        s.seriesPath.lineTo(seriesPathCurrentX, seriesPathCurrentY);
                    }
                }
                lastPointVisible = currentPointVisible;
                lastX = x;
                lastY = y;
                highY = y;
                lowY = y;
                openY = y;
                closeY = y;
                lastPointInInterval = false;
            } else {
                lastIntervalDone = false;
                lastPointInInterval = true;
                highY = Math.max(highY, y);
                lowY = Math.min(lowY, y);
                closeY = y;
            }
            lastPointGood = true;
        } else {
            lastPointGood = false;
        }
    }
    // if this is the last item, draw the path ...
    // draw path, but first check whether we need to complete an interval
    if (!lastIntervalDone) {
        if (lowY < highY) {
            float intervalX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
            float intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
            float intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
            s.intervalPath.moveTo(intervalX, intervalStartY);
            s.intervalPath.lineTo(intervalX, intervalEndY);
        }
    }
    PathIterator pi = s.seriesPath.getPathIterator(null);
    g2.setStroke(getItemStroke(series, 0));
    g2.setPaint(getItemPaint(series, 0));
    g2.draw(s.seriesPath);
    g2.draw(s.intervalPath);
}

From source file:gda.plots.SimpleXYItemRenderer.java

/**
 * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer
 * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information
 * stored in the Renderer itself./*from w  ww.j a  v a 2  s .  c  o m*/
 * 
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area within which the data 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.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {
    SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series);

    if (!sxys.isVisible()) {
        return;
    }
    // setup for collecting optional entity info...
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    PlotOrientation orientation = plot.getOrientation();
    g2.setPaint(sxys.getPaint());
    g2.setStroke(sxys.getStroke());

    // get the data point
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);

    // Test
    x1 = xValueTransformer.transformValue(x1);

    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        return;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (sxys.isDrawLines()) {
        if (item > 0) {
            // get the previous data point...
            double x0 = dataset.getXValue(series, item - 1);
            double y0 = dataset.getYValue(series, item - 1);

            // Test
            // System.out.print("tranformed " + x0);
            x0 = xValueTransformer.transformValue(x0);
            // Message.debug(" to " + x0);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data
                    // point is within the threshold
                    int numX = dataset.getItemCount(series);
                    double minX = dataset.getXValue(series, 0);
                    double maxX = dataset.getXValue(series, numX - 1);
                    drawLine = (x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    if (orientation == PlotOrientation.HORIZONTAL) {
                        state.workingLine.setLine(transY0, transX0, transY1, transX1);
                    } else if (orientation == PlotOrientation.VERTICAL) {
                        state.workingLine.setLine(transX0, transY0, transX1, transY1);
                    }

                    if (state.workingLine.intersects(dataArea)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }

    if (sxys.isDrawMarkers()) {

        Shape shape = sxys.getSymbol();
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            g2.setPaint(sxys.getSymbolPaint());
            // Always use full stroke for drawing marker
            g2.setStroke(new BasicStroke());
            if (sxys.getFilled()) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
            g2.setPaint(sxys.getPaint());
            g2.setStroke(sxys.getStroke());
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        // use shape scale with transform??
        // double scale = getShapeScale(plot, series, item, transX1,
        // transY1);
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, transX1, transY1, (y1 < 0.0));
    }

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }

}

From source file:com.newatlanta.bluedragon.CustomClusteredXYBarRenderer.java

public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;

    Paint seriesPaint = getItemPaint(series, item);

    double value0;
    double value1;
    if (getUseYInterval()) {
        value0 = intervalDataset.getStartYValue(series, item);
        value1 = intervalDataset.getEndYValue(series, item);
    } else {/*w w w  . j  av a  2  s  . c  o m*/
        value0 = getBase();
        value1 = intervalDataset.getYValue(series, item);
    }
    if (Double.isNaN(value0) || Double.isNaN(value1)) {
        return;
    }

    double translatedValue0 = rangeAxis.valueToJava2D(value0, dataArea, plot.getRangeAxisEdge());
    double translatedValue1 = rangeAxis.valueToJava2D(value1, dataArea, plot.getRangeAxisEdge());

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    double x1 = intervalDataset.getStartXValue(series, item);
    double translatedX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);

    double x2 = intervalDataset.getEndXValue(series, item);
    double translatedX2 = domainAxis.valueToJava2D(x2, dataArea, xAxisLocation);

    double translatedWidth = Math.max(1, Math.abs(translatedX2 - translatedX1));
    double translatedHeight = Math.abs(translatedValue0 - translatedValue1);

    /*
     * With BlueDragon, this value is always false so it's safe to comment this
     * code out. if (this.centerBarAtStartValue) { translatedX1 -=
     * translatedWidth / 2; }
     */

    PlotOrientation orientation = plot.getOrientation();
    if (getMargin() > 0.0) {
        if (orientation == PlotOrientation.HORIZONTAL) {
            // BEGIN fix for horizontal bar charts that have a margin
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 - cut / 2;
            // END fix for horizontal bar charts that have a margin
        } else if (orientation == PlotOrientation.VERTICAL) {
            double cut = translatedWidth * getMargin();
            translatedWidth = translatedWidth - cut;
            translatedX1 = translatedX1 + cut / 2;
        }
    }

    int numSeries = dataset.getSeriesCount();
    double seriesBarWidth = translatedWidth / numSeries;

    Rectangle2D bar = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        bar = new Rectangle2D.Double(Math.min(translatedValue0, translatedValue1),
                translatedX1 - seriesBarWidth * (numSeries - series), translatedHeight, seriesBarWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {

        bar = new Rectangle2D.Double(translatedX1 + seriesBarWidth * series,
                Math.min(translatedValue0, translatedValue1), seriesBarWidth, translatedHeight);

    }
    g2.setPaint(seriesPaint);
    g2.fill(bar);
    if (isDrawBarOutline() && Math.abs(translatedX2 - translatedX1) > 3) {
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(bar);
    }

    // TODO: we need something better for the item labels
    if (isItemLabelVisible(series, item)) {
        // Change parameters passed to this method to call our local version
        drawItemLabel(g2, orientation, dataset, series, item, bar, value1 < 0.0);
    }

    // add an entity for the item...
    if (info != null) {
        EntityCollection entities = info.getOwner().getEntityCollection();
        if (entities != null) {
            String tip = null;
            XYToolTipGenerator generator = getToolTipGenerator(series, item);
            if (generator != null) {
                tip = generator.generateToolTip(dataset, series, item);
            }
            String url = null;
            if (getURLGenerator() != null) {
                url = getURLGenerator().generateURL(dataset, series, item);
            }
            XYItemEntity entity = new XYItemEntity(bar, dataset, series, item, tip, url);
            entities.add(entity);
        }
    }

}

From source file:org.rdv.viz.chart.FastXYItemRenderer.java

@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    boolean itemVisible = getItemVisible(series, item);

    // setup for collecting optional entity info...
    Shape entityArea = null;/*from w w w .  j a  v a  2s .  c  o  m*/
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        itemVisible = false;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (item == 0) {
            previousDrawnItem = 1;
        }

        if (getDrawSeriesLineAsPath()) {
            State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.setLastPointGood(false);
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                if (s.getSeriesIndex() == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...
            double x0 = dataset.getXValue(series, item - previousDrawnItem);
            double y0 = dataset.getYValue(series, item - previousDrawnItem);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    int numX = dataset.getItemCount(series);
                    double minX = dataset.getXValue(series, 0);
                    double maxX = dataset.getXValue(series, numX - 1);
                    if (getGapThresholdType() == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= getGapThreshold();
                    } else {
                        drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                    }
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    // Only draw line if it is more than a pixel away from the
                    // previous one
                    if ((transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2
                            || transY1 - transY0 < -2)) {
                        previousDrawnItem = 1;

                        if (orientation == PlotOrientation.HORIZONTAL) {
                            state.workingLine.setLine(transY0, transX0, transY1, transX1);
                        } else if (orientation == PlotOrientation.VERTICAL) {
                            state.workingLine.setLine(transX0, transY0, transX1, transY1);
                        }

                        if (state.workingLine.intersects(dataArea)) {
                            g2.draw(state.workingLine);
                        }
                    } else {
                        // Increase counter for the previous drawn item.
                        previousDrawnItem++;
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    // add a cursor to indicate the position of the last data item
    if (getCursorVisible() && item == dataset.getItemCount(series) - 1) {
        Line2D cursorX = new Line2D.Double(transX1 - DEFAULT_CURSOR_SIZE, transY1,
                transX1 + DEFAULT_CURSOR_SIZE, transY1);
        g2.draw(cursorX);
        Line2D cursorY = new Line2D.Double(transX1, transY1 - DEFAULT_CURSOR_SIZE, transX1,
                transY1 + DEFAULT_CURSOR_SIZE);
        g2.draw(cursorY);
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item...
    if (entities != null && dataArea.contains(xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

protected void drawSeriesLine(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea,
        PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
        int series, CrosshairState crosshairState, int pass) {

    State s = (State) state;
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double lowestVisibleX = domainAxis.getLowerBound();
    double highestVisibleX = domainAxis.getUpperBound();
    double width = (orientation == PlotOrientation.HORIZONTAL) ? dataArea.getHeight() : dataArea.getWidth();
    double dX = (highestVisibleX - lowestVisibleX) / width * lineWidth;
    double lowestVisibleY = rangeAxis.getLowerBound();
    double highestVisibleY = rangeAxis.getUpperBound();

    double lastX = Double.NEGATIVE_INFINITY;
    double lastY = 0.0;
    double highY = 0.0;
    double lowY = 0.0;
    double closeY = 0.0;
    boolean lastIntervalDone = false;
    boolean currentPointVisible = false;
    boolean lastPointVisible = false;
    boolean lastPointGood = false;
    boolean lastPointInInterval = false;
    int intervalCount = 0;
    int badPoints = 0;
    for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) {
        double x = dataset.getXValue(series, itemIndex);
        double y = dataset.getYValue(series, itemIndex);
        if (!Double.isNaN(x) && !Double.isNaN(y)) {
            if ((Math.abs(x - lastX) > dX)) {
                //System.out.println("Breakpoint 1: leaving interval");
                //in any case, add the interval that we are about to leave to the intervalPath
                float intervalStartX = 0.0f;
                float intervalEndX = 0.0f;
                float intervalStartY = 0.0f;
                float intervalEndY = 0.0f;
                float currentX = 0.0f;
                float currentY = 0.0f;
                float lastFX = 0.0f;
                float lastFY = 0.0f;

                //first set some variables
                if (orientation == PlotOrientation.VERTICAL) {
                    intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                    intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                    currentX = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                    lastFX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    currentY = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                    lastFY = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                } else {
                    intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                    intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                    intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                    currentX = (float) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
                    lastFX = (float) rangeAxis.valueToJava2D(closeY, dataArea, yAxisLocation);
                    currentY = (float) domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                    lastFY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                }/*ww  w.  j  av a 2 s. c o m*/
                if ((lowY - highY) < 1) {
                    //System.out.println("Breakpoint 2: setting lastPointInInterval");
                    lastPointInInterval = false;
                }
                //System.out.println("Breakpoint 3: lastPointInInterval: " +lastPointInInterval);
                if ((lowY < highY)) {
                    intervalCount++;
                    //System.out.println("Breakpoint 4: adding segment to interval path:" );
                    //System.out.println("xStart" + intervalStartX + ", yStart " + intervalStartY + ", xEnd " + intervalEndX + ", yEnd " + intervalEndY);
                    s.intervalPath.moveTo(intervalStartX, intervalStartY);
                    s.intervalPath.lineTo(intervalEndX, intervalEndY);
                    lastIntervalDone = true;
                }

                //now the series path
                currentPointVisible = ((x >= lowestVisibleX) && (x <= highestVisibleX) && (y >= lowestVisibleY)
                        && (y <= highestVisibleY));
                if (!lastPointGood) {//last point not valid --
                    badPoints++;
                    if (currentPointVisible) {//--> if the current position is visible move seriesPath cursor to the current position
                        s.seriesPath.moveTo(currentX, currentY);
                    }
                } else {//last point valid
                    //if the last point was visible and not part of an interval,
                    //we have already moved the seriesPath cursor to the last point, either with or without drawingh a line
                    //thus we only need to draw a line to the current position
                    if (lastPointVisible && !lastPointInInterval) {
                        s.seriesPath.lineTo(currentX, currentY);
                    } //if the last point was not visible or part of an interval, we have just stored the y values of the last point
                      //and not yet moved the seriesPath cursor. Thus, we need to move the cursor to the last point without drawing
                      //and draw a line to the current position.
                    else {
                        s.seriesPath.moveTo(lastFX, lastFY);
                        s.seriesPath.lineTo(currentX, currentY);
                    }
                }
                lastPointVisible = currentPointVisible;
                lastX = x;
                lastY = y;
                highY = y;
                lowY = y;
                closeY = y;
                lastPointInInterval = false;
            } else {
                lastIntervalDone = false;
                lastPointInInterval = true;
                highY = Math.max(highY, y);
                lowY = Math.min(lowY, y);
                closeY = y;
            }
            lastPointGood = true;
        } else {
            lastPointGood = false;
        }
    }
    // if this is the last item, draw the path ...
    // draw path, but first check whether we need to complete an interval
    if (!lastIntervalDone) {
        if (lowY < highY) {
            float intervalStartX = 0.0f;
            float intervalEndX = 0.0f;
            float intervalStartY = 0.0f;
            float intervalEndY = 0.0f;
            if (orientation == PlotOrientation.VERTICAL) {
                intervalStartX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalEndX = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalStartY = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalEndY = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
            } else {
                intervalStartX = (float) rangeAxis.valueToJava2D(lowY, dataArea, yAxisLocation);
                intervalEndX = (float) rangeAxis.valueToJava2D(highY, dataArea, yAxisLocation);
                intervalStartY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
                intervalEndY = (float) domainAxis.valueToJava2D(lastX, dataArea, xAxisLocation);
            }
            intervalCount++;
            s.intervalPath.moveTo(intervalStartX, intervalStartY);
            s.intervalPath.lineTo(intervalEndX, intervalEndY);
        }
    }
    PathIterator pi = s.seriesPath.getPathIterator(null);
    g2.setStroke(getItemStroke(series, 0));
    g2.setPaint(getItemPaint(series, 0));
    g2.draw(s.seriesPath);
    g2.draw(s.intervalPath);
    //System.out.println("Interval count " + intervalCount);
    //System.out.println("Bad points " + badPoints);
}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Draws the visual representation of a series as shapes.
 *
 * @param g2  the graphics device.//from  w w w. ja  va 2  s.  c  o  m
 * @param state  the renderer state.
 * @param dataArea  the area within which the data 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 crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 * @param drawShapes  a flag indicating whether shapes should be drawn
 * @param createEntities  a flag indicating whether entities should be
 * generated.
 */
protected void drawSeriesShapes(Graphics2D g2, State state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series,
        CrosshairState crosshairState, int pass, boolean drawShapes, boolean createEntities) {
    if (!drawShapes && !createEntities) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    double x = 0.0;
    double y = 0.0;
    double transX = 0.0;
    double transY = 0.0;
    boolean itemShapeFilled = getItemShapeFilled(series, 0);
    boolean drawOutlines = getDrawOutlines();
    Paint itemFillPaint = getUseFillPaint() ? getItemFillPaint(series, 0) : getItemPaint(series, 0);
    Paint itemOutlinePaint = getUseOutlinePaint() ? getItemOutlinePaint(series, 0) : getItemPaint(series, 0);
    Stroke itemOutlineStroke = getItemOutlineStroke(series, 0);
    Shape centeredShape = getItemShape(series, 0);
    /*
      if(centeredShape instanceof LinedShape){
    itemOutlinePaint = itemFillPaint;
    drawOutlines = true;
    itemShapeFilled = false;
      }
    */
    //draw items
    //and create entities
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);

    for (int itemIndex = state.getFirstItemIndex(); itemIndex <= state.getLastItemIndex(); itemIndex++) {
        if (state.itemVisible(series, itemIndex)) {
            x = dataset.getXValue(series, itemIndex);
            y = dataset.getYValue(series, itemIndex);
            transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
            if (orientation == PlotOrientation.HORIZONTAL) {
                double temp = transX;
                transX = transY;
                transY = temp;
            }
            updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                    orientation);

            Shape shape = ShapeUtilities.createTranslatedShape(centeredShape, transX, transY);

            if (drawShapes) {
                if (itemShapeFilled) {
                    g2.setPaint(itemFillPaint);
                    g2.fill(shape);
                }
                if (drawOutlines) {
                    g2.setPaint(itemOutlinePaint);
                    g2.setStroke(itemOutlineStroke);
                    g2.draw(shape);
                }
            }
            if (createEntities && entities != null) {
                addEntity(entities, shape, dataset, series, itemIndex, transX, transY);
            }
        }
    }
}

From source file:msi.gama.outputs.layers.charts.FastXYItemRenderer.java

/** {@inheritDoc} */
@Override//from  w  ww .j  ava 2 s.  c om
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    if (!getItemVisible(series, item)) {
        return;
    }
    // setup for collecting optional entity info...
    boolean bAddEntity = false;
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    final PlotOrientation orientation = plot.getOrientation();
    final Paint paint = getItemPaint(series, item);
    final Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (item == 0) {
            if (this.drawSeriesLineAsPath) {
                final State s = (State) state;
                s.seriesPath.reset();
                s.lastPointGood = false;
            }
            previousDrawnItem = 0;
        }

        if (this.drawSeriesLineAsPath) {
            final State s = (State) state;
            // update path to reflect latest point
            if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                // draw path
                g2.setStroke(getSeriesStroke(series));
                g2.setPaint(getSeriesPaint(series));
                g2.draw(s.seriesPath);
            }
        }

        else if (item != 0) {
            // get the previous data point...
            final double x0 = dataset.getXValue(series, item - previousDrawnItem);
            final double y0 = dataset.getYValue(series, item - previousDrawnItem);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    final int numX = dataset.getItemCount(series);
                    final double minX = dataset.getXValue(series, 0);
                    final double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold();
                    }
                }
                if (drawLine) {
                    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    // Only draw line if it is more than a pixel away from the previous one
                    if (transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2
                            || transY1 - transY0 < -2 || 0 == previousDrawnItem) {
                        previousDrawnItem = 1;

                        if (orientation == PlotOrientation.HORIZONTAL) {
                            state.workingLine.setLine(transY0, transX0, transY1, transX1);
                        } else if (orientation == PlotOrientation.VERTICAL) {
                            state.workingLine.setLine(transX0, transY0, transX1, transY1);
                        }

                        if (state.workingLine.intersects(dataArea)) {
                            g2.draw(state.workingLine);
                        }
                    } else {
                        // Increase counter for the previous drawn item.
                        previousDrawnItem++;
                        bAddEntity = false;
                    }
                }
            }
        }
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            bAddEntity = true;
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        final Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        double xx = transX1;
        double yy = transY1;
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY1;
            yy = transX1;
        }
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y1 < 0.0);
    }

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // add an entity for the item...
    if (entities != null && bAddEntity) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }
}

From source file:edu.dlnu.liuwenpeng.render.XYLineAndShapeRenderer.java

/**    
 * Draws the item (first pass). This method draws the lines    
 * connecting the items. Instead of drawing separate lines,    
 * a GeneralPath is constructed and drawn at the end of    
 * the series painting.    /*from   www. j a v a  2s.co  m*/
 *    
 * @param g2  the graphics device.    
 * @param state  the renderer state.    
 * @param plot  the plot (can be used to obtain standard color information    
 *              etc).    
 * @param dataset  the dataset.    
 * @param pass  the pass.    
 * @param series  the series index (zero-based).    
 * @param item  the item index (zero-based).    
 * @param domainAxis  the domain axis.    
 * @param rangeAxis  the range axis.    
 * @param dataArea  the area within which the data is being drawn.    
 */
protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset,
        int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    // get the data point...    
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    State s = (State) state;
    // update path to reflect latest point    
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        float x = (float) transX1;
        float y = (float) transY1;
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            x = (float) transY1;
            y = (float) transX1;
        }
        if (s.isLastPointGood()) {
            s.seriesPath.lineTo(x, y);
        } else {
            s.seriesPath.moveTo(x, y);
        }
        s.setLastPointGood(true);
    } else {
        s.setLastPointGood(false);
    }
    // if this is the last item, draw the path ...    
    if (item == dataset.getItemCount(series) - 1) {
        // draw path    
        drawFirstPassShape(g2, pass, series, item, s.seriesPath);
    }
}

From source file:org.trade.ui.chart.renderer.MACDItemRenderer.java

public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, double x0, double y0, double x1, double y1,
        int lastItem, int series, int item, CrosshairState crosshairState, int pass, int numX, double minX,
        double maxX, Paint color, XYDataset dataset) {

    boolean itemVisible = getItemVisible(series, item);

    // setup for collecting optional entity info...
    Shape entityArea = null;//from w w w.  java 2  s. c  o m
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    PlotOrientation orientation = plot.getOrientation();
    Paint paint = getItemPaint(series, item);
    paint = color;
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (this.drawSeriesLineAsPath) {
            State s = (State) state;
            if (s.getSeriesIndex() != series) {
                // we are starting a new series path
                s.seriesPath.reset();
                s.lastPointGood = false;
                s.setSeriesIndex(series);
            }

            // update path to reflect latest point
            if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == lastItem) {
                if (s.seriesIndex == series) {
                    // draw path
                    g2.setStroke(lookupSeriesStroke(series));
                    g2.setPaint(lookupSeriesPaint(series));
                    g2.draw(s.seriesPath);
                }
            }
        }

        else if (item != 0 && itemVisible) {
            // get the previous data point...

            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold());
                    }
                }
                if (drawLine) {
                    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

                    // only draw if we have good values
                    if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                            || Double.isNaN(transY1)) {
                        return;
                    }

                    if (orientation == PlotOrientation.HORIZONTAL) {
                        state.workingLine.setLine(transY0, transX0, transY1, transX1);
                    } else if (orientation == PlotOrientation.VERTICAL) {
                        state.workingLine.setLine(transX0, transY0, transX1, transY1);
                    }

                    if (state.workingLine.intersects(dataArea)) {
                        g2.draw(state.workingLine);
                    }
                }
            }
        }
    }

    // we needed to get this far even for invisible items, to ensure that
    // seriesPath updates happened, but now there is nothing more we need
    // to do for non-visible items...
    if (!itemVisible) {
        return;
    }

    if (getBaseShapesVisible()) {

        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1,
            orientation);

    // add an entity for the item...
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private Point2D.Double getPoint(int plotIndex, int seriesIndex, int dataIndex) {
    final TimeSeries timeSeries = this.getTimeSeries(plotIndex, seriesIndex);
    if (timeSeries == null) {
        // Possible this is candlestick?
        final XYPlot plot = this.chartJDialog.getPlot(plotIndex);
        if (plot.getDataset(seriesIndex) instanceof org.jfree.data.xy.DefaultHighLowDataset) {
            return this._getPointForCandlestick(plotIndex, seriesIndex, dataIndex);
        }//  www .j  a va2s.com
        return null;
    }

    if (dataIndex >= timeSeries.getItemCount()) {
        /* Not ready yet. */
        return null;
    }

    final ChartPanel chartPanel = this.chartJDialog.getChartPanel();
    final XYPlot plot = this.chartJDialog.getPlot(plotIndex);
    final ValueAxis domainAxis = plot.getDomainAxis();
    final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    final ValueAxis rangeAxis = plot.getRangeAxis();
    final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();

    final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(dataIndex);
    final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond();
    final double yValue = timeSeriesDataItem.getValue().doubleValue();
    final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(plotIndex)
            .getDataArea();
    final double xJava2D = domainAxis.valueToJava2D(xValue, plotArea, domainAxisEdge);
    final double yJava2D = rangeAxis.valueToJava2D(yValue, plotArea, rangeAxisEdge);
    // Use Double version, to avoid from losing precision.
    return new Point2D.Double(xJava2D, yJava2D);
}