Example usage for org.jfree.chart.renderer.xy XYItemRendererState getInfo

List of usage examples for org.jfree.chart.renderer.xy XYItemRendererState getInfo

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYItemRendererState getInfo.

Prototype

public PlotRenderingInfo getInfo() 

Source Link

Document

Returns the plot rendering info.

Usage

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.// w  w  w. j a  v a  2s .  c  om
 * @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:umontreal.iro.lecuyer.charts.EmpiricalRenderer.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 axis.//w  ww.  j  av  a  2s  .  c  om
 * @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.
 */
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;
    PlotOrientation orientation = plot.getOrientation();
    java.awt.Paint seriesPaint = getItemPaint(series, item);
    java.awt.Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(seriesPaint);
    g2.setStroke(seriesStroke);
    double x0 = dataset.getXValue(series, item);
    double y0 = dataset.getYValue(series, item);
    if (java.lang.Double.isNaN(y0))
        return;
    org.jfree.ui.RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    org.jfree.ui.RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    double x1 = 0, y1 = 0;
    if (item < dataset.getItemCount(series) - 1) {
        x1 = dataset.getXValue(series, item + 1);
        y1 = dataset.getYValue(series, item + 1);
    } else {
        x1 = dataArea.getMaxX();
        y1 = dataArea.getMaxY();
    }

    boolean useFillPaint = getUseFillPaint();
    ;
    boolean drawOutlines = getDrawOutlines();
    if (!java.lang.Double.isNaN(y0)) {
        double transX1;
        double transY1;
        if (item < dataset.getItemCount(series) - 1) {
            transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
            transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
        } else {
            transX1 = x1;
            transY1 = y1;
        }
        Line2D line = state.workingLine;
        if (orientation == PlotOrientation.HORIZONTAL) {
            line.setLine(transY0, transX0, transY0, transX1);
            g2.draw(line);
        } else if (orientation == PlotOrientation.VERTICAL) {
            line.setLine(transX0, transY0, transX1, transY0);
            g2.draw(line);
        }
    }
    if (getItemShapeVisible(series, item)) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL)
            shape = ShapeUtilities.createTranslatedShape(shape, transY0, transX0);
        else if (orientation == PlotOrientation.VERTICAL)
            shape = ShapeUtilities.createTranslatedShape(shape, transX0, transY0);
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                if (useFillPaint)
                    g2.setPaint(getItemFillPaint(series, item));
                else
                    g2.setPaint(getItemPaint(series, item));
                g2.fill(shape);
            }
            if (drawOutlines) {
                if (getUseOutlinePaint())
                    g2.setPaint(getItemOutlinePaint(series, item));
                else
                    g2.setPaint(getItemPaint(series, item));
                g2.setStroke(getItemOutlineStroke(series, item));
                g2.draw(shape);
            }
        }
    }
    if (isItemLabelVisible(series, item)) {
        double xx = transX0;
        double yy = transY0;
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY0;
            yy = transX0;
        }
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y0 < 0.0D);
    }
    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x0, y0, domainAxisIndex, rangeAxisIndex, transX0, transY0,
            orientation);
    if (state.getInfo() != null) {
        EntityCollection entities = state.getEntityCollection();
        if (entities != null) {
            int r = getDefaultEntityRadius();
            java.awt.Shape shape = orientation != PlotOrientation.VERTICAL
                    ? ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transY0 - (double) r,
                            transX0 - (double) r, 2 * r, 2 * r)))
                    : ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transX0 - (double) r,
                            transY0 - (double) r, 2 * r, 2 * r)));
            if (shape != 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(shape, dataset, series, item, tip, url);
                entities.add(entity);
            }
        }
    }
}

From source file:de.hdm.uls.loadtests.ui.XYLineAndAreaRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device./*from  w  ww .jav a 2s.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 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) {

    if (!getItemVisible(series, item)) {
        return;
    }
    XYAreaRendererState areaState = (XYAreaRendererState) state;

    // get the data point...
    double x1 = dataset.getXValue(series, item);
    double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(y1)) {
        y1 = 0.0;
    }
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, plot.getDomainAxisEdge());
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, plot.getRangeAxisEdge());

    // get the previous point and the next point so we can calculate a
    // "hot spot" for the area (used by the chart entity)...
    int itemCount = dataset.getItemCount(series);
    double x0 = dataset.getXValue(series, Math.max(item - 1, 0));
    double y0 = dataset.getYValue(series, Math.max(item - 1, 0));
    if (Double.isNaN(y0)) {
        y0 = 0.0;
    }
    double transX0 = domainAxis.valueToJava2D(x0, dataArea, plot.getDomainAxisEdge());
    double transY0 = rangeAxis.valueToJava2D(y0, dataArea, plot.getRangeAxisEdge());

    double x2 = dataset.getXValue(series, Math.min(item + 1, itemCount - 1));
    double y2 = dataset.getYValue(series, Math.min(item + 1, itemCount - 1));
    if (Double.isNaN(y2)) {
        y2 = 0.0;
    }
    double transX2 = domainAxis.valueToJava2D(x2, dataArea, plot.getDomainAxisEdge());
    double transY2 = rangeAxis.valueToJava2D(y2, dataArea, plot.getRangeAxisEdge());

    double transZero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
    Polygon hotspot = null;
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        hotspot = new Polygon();
        hotspot.addPoint((int) transZero, (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) ((transY0 + transY1) / 2.0), (int) ((transX0 + transX1) / 2.0));
        hotspot.addPoint((int) transY1, (int) transX1);
        hotspot.addPoint((int) ((transY1 + transY2) / 2.0), (int) ((transX1 + transX2) / 2.0));
        hotspot.addPoint((int) transZero, (int) ((transX1 + transX2) / 2.0));
    } else { // vertical orientation
        hotspot = new Polygon();
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) transZero);
        hotspot.addPoint((int) ((transX0 + transX1) / 2.0), (int) ((transY0 + transY1) / 2.0));
        hotspot.addPoint((int) transX1, (int) transY1);
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) ((transY1 + transY2) / 2.0));
        hotspot.addPoint((int) ((transX1 + transX2) / 2.0), (int) transZero);
    }

    if (item == 0) { // create a new area polygon for the series
        areaState.area = new Polygon();
        // the first point is (x, 0)
        double zero = rangeAxis.valueToJava2D(0.0, dataArea, plot.getRangeAxisEdge());
        if (plot.getOrientation() == PlotOrientation.VERTICAL) {
            areaState.area.addPoint((int) transX1, (int) zero);
        } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
            areaState.area.addPoint((int) zero, (int) transX1);
        }
    }

    // Add each point to Area (x, y)
    if (plot.getOrientation() == PlotOrientation.VERTICAL) {
        areaState.area.addPoint((int) transX1, (int) transY1);
    } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        areaState.area.addPoint((int) transY1, (int) transX1);
    }

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

    Shape shape = null;
    if (getPlotShapes()) {
        shape = getItemShape(series, item);
        if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        }
        g2.draw(shape);
    }

    if (getPlotLines()) {
        if (item > 0) {
            if (plot.getOrientation() == PlotOrientation.VERTICAL) {
                areaState.line.setLine(transX0, transY0, transX1, transY1);
            } else if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
                areaState.line.setLine(transY0, transX0, transY1, transX1);
            }
            g2.draw(areaState.line);
        }
    }

    // Check if the item is the last item for the series.
    // and number of items > 0.  We can't draw an area for a single point.
    if (getPlotArea() && item > 0 && item == (itemCount - 1)) {

        if (orientation == PlotOrientation.VERTICAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transX1, (int) transZero);
        } else if (orientation == PlotOrientation.HORIZONTAL) {
            // Add the last point (x,0)
            areaState.area.addPoint((int) transZero, (int) transX1);
        }

        Paint fillPaint = getItemFillPaint(series, item);
        if (fillPaint instanceof GradientPaint) {
            GradientPaint gp = (GradientPaint) fillPaint;
            GradientPaintTransformer t = new StandardGradientPaintTransformer();
            fillPaint = t.transform(gp, areaState.area.getBounds());
        }
        g2.setPaint(fillPaint);
        g2.fill(areaState.area);

        // draw an outline around the Area.
        if (isOutline()) {
            g2.setStroke(getItemOutlineStroke(series, item));
            g2.setPaint(getItemOutlinePaint(series, item));
            g2.draw(areaState.area);
        }
    }

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

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

}