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

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

Introduction

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

Prototype

public int getDomainAxisIndex(ValueAxis axis) 

Source Link

Document

Returns the index of the given domain axis.

Usage

From source file:ste.travian.world.TileRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device./*  w  w w .j  a 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 (horizontal) axis.
 * @param rangeAxis  the range (vertical) 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.
 */
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) {

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double adjx = (this.dotWidth - 1) / 2.0;
    double adjy = (this.dotHeight - 1) / 2.0;
    if (Double.isNaN(y)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
    double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

    g2.setPaint(getItemPaint(series, item));
    if (orientation == PlotOrientation.HORIZONTAL) {
        g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    int xx = (int) transX;
    int yy = (int) transY;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = (int) transY;
        yy = (int) transX;
    }
    if (entities != null && dataArea.contains(xx, yy)) {
        addEntity(entities, null, dataset, series, item, (int) xx, (int) yy);
    }

}

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

/**
 * Draws the visual representation of a single data item.
 * //  w  w w .j  a v a2  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 (horizontal) axis.
 * @param rangeAxis
 *            the range (vertical) 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.
 * @see org.jfree.chart.renderer.xy.XYItemRenderer#drawItem(Graphics2D,
 *      XYItemRendererState, Rectangle2D, PlotRenderingInfo, XYPlot,
 *      ValueAxis, ValueAxis, XYDataset, int, int, CrosshairState, int)
 */
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) {

    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double adjx = (this.dotWidth - 1) / 2.0;
    double adjy = (this.dotHeight - 1) / 2.0;
    if (!Double.isNaN(y)) {
        RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
        double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

        g2.setPaint(getItemPaint(series, item));
        PlotOrientation orientation = plot.getOrientation();
        if (orientation == PlotOrientation.HORIZONTAL) {
            g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth);
        } else if (orientation == PlotOrientation.VERTICAL) {
            g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);

        PivotDataset pivotDataset = (PivotDataset) dataset;
        if (null != pivotDataset.getPivotSide(series, item)) {
            String ledgend = "Pivot";
            if (pivotDataset.getPivotSide(series, item).equals(Side.BOT)) {
                drawPivotArrow(g2, plot, dataArea, domainAxis, rangeAxis, item, info, 45d, x,
                        pivotDataset.getPivotValue(series, item), ledgend);
            } else {
                drawPivotArrow(g2, plot, dataArea, domainAxis, rangeAxis, item, info, -45d, x,
                        pivotDataset.getPivotValue(series, item), ledgend);
            }
        }
    }

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.XYDotRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @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 (horizontal) axis.
 * @param rangeAxis      the range (vertical) axis.
 * @param dataset        the dataset./*from ww  w .  j  ava 2  s . co m*/
 * @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.
 */
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) {

    // get the data point...
    final double x = dataset.getXValue(series, item);
    final double y = dataset.getYValue(series, item);
    final double adjx = (this.dotWidth - 1) / 2.0;
    final double adjy = (this.dotHeight - 1) / 2.0;
    if (!Double.isNaN(y)) {
        final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
        final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
        final double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
        final double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

        g2.setPaint(getItemPaint(series, item));
        final PlotOrientation orientation = plot.getOrientation();
        final Shape s;
        if (orientation == PlotOrientation.HORIZONTAL) {
            //noinspection SuspiciousNameCombination
            s = new Rectangle2D.Double(transY, transX, this.dotHeight, this.dotWidth);
        } else if (orientation == PlotOrientation.VERTICAL) {
            s = new Rectangle2D.Double(transX, transY, this.dotWidth, this.dotHeight);
        } else {
            throw new IllegalStateException("PlotOrientation is neither Horizontal nor Vertical");
        }
        g2.fill(s);

        final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);

        // collect entity and tool tip information...
        if (state.getInfo() != null) {
            final EntityCollection entities = state.getEntityCollection();
            if (entities != null) {
                String tip = null;
                final 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);
                }
                final XYItemEntity entity = new XYItemEntity(s, dataset, series, item, tip, url);
                entities.add(entity);
            }
        }
    }

}

From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java

/**
 * Draws the visual representation of a series as shapes.
 *
 * @param g2  the graphics device./* w  ww.  j  av  a 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:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @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 (horizontal) axis.
 * @param rangeAxis      the range (vertical) axis.
 * @param dataset        the dataset (a {@link edu.ucla.stat.SOCR.motionchart.MotionDataSet} is expected).
 * @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.
 *//*from   ww  w.j  av  a 2 s  . com*/
@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) {
    if (!(dataset instanceof MotionDataSet)) {
        throw new IllegalArgumentException("The dataset must be of type MotionDataSet.");
    }

    // return straight away if the item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();

    Ellipse2D.Double shape = (Ellipse2D.Double) getItemShape(series, item);

    if (shape.getWidth() != 0 && shape.getHeight() != 0) {
        Ellipse2D.Double circle = translateShape(shape, plot, dataArea);
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            currCircle = circle;
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterX(), circle.getCenterY(),
                        false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, circle.getCenterY(), circle.getCenterX(),
                        false);
            }
        }

        // add an entity if this info is being collected
        EntityCollection entities;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
            if (entities != null && circle.intersects(dataArea)) {
                addEntity(entities, circle, dataset, series, item, circle.getCenterX(), circle.getCenterY());
            }
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, shape.getCenterX(), shape.getCenterY(), domainAxisIndex,
                rangeAxisIndex, circle.getCenterX(), circle.getCenterY(), orientation);
    }
}

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.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) {
    if (!getItemVisible(series, item)) {
        return;//from w  w  w .j  a v a 2  s .  co m
    }

    double itemXValue = dataSet.getXValue(series, item);
    double itemYValue = dataSet.getYValue(series, item);
    if (Double.isNaN(itemYValue) || Double.isNaN(itemXValue)) {
        return;
    }

    double currentItemX = calculateItemXPoint(series, item, dataArea, domainAxis, dataSet, plot);
    double currentItemY = calculateItemYPoint(series, item, dataArea, rangeAxis, dataSet, plot);
    int previousItemIndex = item > 0 ? item - 1 : 0;
    double previousItemX = calculateItemXPoint(series, previousItemIndex, dataArea, domainAxis, dataSet, plot);
    double previousItemY = calculateItemYPoint(series, previousItemIndex, dataArea, rangeAxis, dataSet, plot);
    final int lastItemIndex = dataSet.getItemCount(series) - 1;
    int nextItemIndex = item < lastItemIndex ? item + 1 : lastItemIndex;
    double nextItemX = calculateItemXPoint(series, nextItemIndex, dataArea, domainAxis, dataSet, plot);
    double nextItemY = calculateItemYPoint(series, nextItemIndex, dataArea, rangeAxis, dataSet, plot);
    double zeroRangePoint = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());

    if (isAreaAndLinePass(pass)) {
        XYLineFillItemRendererState rendererState = (XYLineFillItemRendererState) state;
        renderLineArea(g2, info, plot, series, item, rendererState, dataSet, currentItemX, currentItemY,
                previousItemX, previousItemY, zeroRangePoint);
    } else if (isShapesAndLabelsPass(pass)) {
        Shape entityArea = renderShapeAndLabel(g2, dataArea, plot, dataSet, series, item, itemYValue,
                currentItemX, currentItemY, previousItemX, previousItemY, nextItemX, nextItemY, zeroRangePoint);

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, itemXValue, itemYValue, domainAxisIndex, rangeAxisIndex,
                currentItemX, currentItemY, plot.getOrientation());

        EntityCollection entityCollection = state.getEntityCollection();
        if (entityCollection != null) {
            addEntity(entityCollection, entityArea, dataSet, series, item, 0.0, 0.0);
        }
    } else {
        throw new IllegalStateException("Unknown pass: " + pass);
    }
}

From source file:gov.sandia.umf.platform.ui.jobs.Raster.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );/*  w  w w. ja  va2 s. com*/

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setRenderer(new XYDotRenderer() {
        public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state,
                java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis,
                ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState,
                int pass) {
            // Copied from org.jfree.chart.renderer.xy.XYDotRenderer.java and modified.
            // This would only need to be a couple of lines if they authors of jfreechart had not made dotWidth and dotHeight private members.
            // Yet another example of textbook OO programming gone awry. (Can anyone hear me scream?)

            if (!getItemVisible(series, item))
                return;

            int dotWidth = 1;

            double rasterLines = rangeAxis.getRange().getLength();
            int pixels = g2.getClipBounds().height;
            double height = pixels / rasterLines;
            if (height > 10)
                height -= 2;
            else if (height > 2)
                height -= 1;
            int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height)));

            double x = dataset.getXValue(series, item);
            double y = dataset.getYValue(series, item);
            if (Double.isNaN(y))
                return;
            double adjx = (dotWidth - 1) / 2.0;
            double adjy = (dotHeight - 1) / 2.0;

            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
            double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

            g2.setPaint(Color.black);
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL)
                g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth);
            else
                g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight);

            int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
            int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
            updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                    orientation);
        }
    });

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Integer units only

    return chart;
}

From source file:org.pentaho.platform.uifoundation.chart.BubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 * //from w  w w.j  av a2 s  . c om
 * @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 (horizontal) axis.
 * @param rangeAxis
 *          the range (vertical) axis.
 * @param dataset
 *          the dataset (an {@link XYZDataset} is expected).
 * @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(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) {

    PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

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

        // add an entity for the item...
        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(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.BubbleRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @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 (horizontal) axis.
 * @param rangeAxis      the range (vertical) axis.
 * @param dataset        the dataset (an {@link XYZDataset} is expected).
 * @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.
 *//*from   www  . j  av  a 2s . c  o m*/
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) {

    final PlotOrientation orientation = plot.getOrientation();

    // get the data point...
    final double x = dataset.getXValue(series, item);
    final double y = dataset.getYValue(series, item);
    double z = Double.NaN;
    if (dataset instanceof XYZDataset) {
        final XYZDataset xyzData = (XYZDataset) dataset;
        z = xyzData.getZValue(series, item);
    }
    if (!Double.isNaN(z)) {
        final RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
        final RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();
        final double transX = domainAxis.valueToJava2D(x, dataArea, domainAxisLocation);
        final double transY = rangeAxis.valueToJava2D(y, dataArea, rangeAxisLocation);

        double circleSize;

        circleSize = maxSize * (z / maxZ);

        circleSize = Math.abs(circleSize);

        Ellipse2D circle = null;
        if (orientation == PlotOrientation.VERTICAL) {
            circle = new Ellipse2D.Double(transX - circleSize / 2.0, transY - circleSize / 2.0, circleSize,
                    circleSize);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            circle = new Ellipse2D.Double(transY - circleSize / 2.0, transX - circleSize / 2.0, circleSize,
                    circleSize);
        }
        g2.setPaint(getItemPaint(series, item));
        g2.fill(circle);
        g2.setStroke(getItemOutlineStroke(series, item));
        g2.setPaint(getItemOutlinePaint(series, item));
        g2.draw(circle);

        if (isItemLabelVisible(series, item)) {
            if (orientation == PlotOrientation.VERTICAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transX, transY, false);
            } else if (orientation == PlotOrientation.HORIZONTAL) {
                drawItemLabel(g2, orientation, dataset, series, item, transY, transX, false);
            }
        }

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

        // add an entity for the item...
        if (entities != null) {
            String tip = null;
            final 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);
            }
            final XYItemEntity entity = new XYItemEntity(circle, dataset, series, item, tip, url);
            entities.add(entity);
        }

        final int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
        final int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
        updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                orientation);
    }

}

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

/**    
 * Draws the item shapes and adds chart entities (second pass). This method    
 * draws the shapes which mark the item positions. If <code>entities</code>    
 * is not <code>null</code> it will be populated with entity information    
 * for points that fall within the data area.    
 *    /*from ww  w. ja  v a2s .  c o m*/
 * @param g2  the graphics device.    
 * @param plot  the plot (can be used to obtain standard color    
 *              information etc).    
 * @param domainAxis  the domain axis.    
 * @param dataArea  the area within which the data is being drawn.    
 * @param rangeAxis  the range axis.    
 * @param dataset  the dataset.    
 * @param pass  the pass.    
 * @param series  the series index (zero-based).    
 * @param item  the item index (zero-based).    
 * @param crosshairState  the crosshair state.    
 * @param entities the entity collection.    
 */
protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item,
        ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState,
        EntityCollection entities) {

    Shape entityArea = null;

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

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

    if (getItemShapeVisible(series, item)) {
        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);
        }
        entityArea = shape;
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (this.useFillPaint) {
                    g2.setPaint(getItemFillPaint(series, item));
                } else {
                    g2.setPaint(getItemPaint(series, item));
                }
                //g2.fill(shape);    
            }
            if (this.drawOutlines) {
                if (getUseOutlinePaint()) {
                    g2.setPaint(getItemOutlinePaint(series, item));
                } else {
                    g2.setPaint(getItemPaint(series, item));
                }
                g2.setStroke(getItemOutlineStroke(series, item));
                // g2.draw(shape);    
            }
        }
    }

    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, but only if it falls within the data    
    // area...    
    if (entities != null && isPointInRect(dataArea, xx, yy)) {
        addEntity(entities, entityArea, dataset, series, item, xx, yy);
    }
}