Example usage for org.jfree.data.xy XYDataset getYValue

List of usage examples for org.jfree.data.xy XYDataset getYValue

Introduction

In this page you can find the example usage for org.jfree.data.xy XYDataset getYValue.

Prototype

public double getYValue(int series, int item);

Source Link

Document

Returns the y-value (as a double primitive) for an item within a series.

Usage

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

private double binSearch(XYDataset d, int si, double x, int begin, int end) {
    if (begin >= end) {
        return d.getYValue(si, end);
    }/* w  w  w.ja v a2 s  .c  o m*/
    int mid = (begin + end) / 2;
    double vmid = d.getXValue(si, mid);
    if (x == vmid) {
        return d.getYValue(si, mid);
    } else if (x < vmid) {
        return binSearch(d, si, x, begin, mid - 1);
    } else {
        return binSearch(d, si, x, mid + 1, end);
    }
}

From source file:net.sf.maltcms.common.charts.api.overlay.SelectionOverlay.java

private Shape generate(Dataset ds, int seriesIndex, int itemIndex) {
    if (ds instanceof XYDataset) {
        XYDataset xyds = (XYDataset) ds;
        double width = 10.0d;
        double height = 10.0d;
        double x = xyds.getXValue(seriesIndex, itemIndex) - (width / 2.0d);
        double y = xyds.getYValue(seriesIndex, itemIndex);
        Ellipse2D.Double e = new Ellipse2D.Double(x, y, width, height);
        return e;
    } else if (ds instanceof CategoryDataset) {
        CategoryDataset cds = (CategoryDataset) ds;
        double width = 10.0d;
        double height = 10.0d;
        double y = cds.getValue(seriesIndex, itemIndex).doubleValue();
        Ellipse2D.Double e = new Ellipse2D.Double(itemIndex, y, width, height);
        return e;
    }//from   ww  w . j  a v  a 2s .c  om
    throw new IllegalArgumentException("Unsupported dataset type: " + ds.getClass());
}

From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java

/**
 * @see drawSecondaryPass// w w w  .j  ava  2  s . c om
 */
private void drawFeedBackNode(final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, //
        final int series, final int item, final ValueAxis domainAxis, final Rectangle2D dataArea,
        final ValueAxis rangeAxis, //
        final CrosshairState crosshairState, final EntityCollection entities) {

    // get the data point...
    final double x1 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item);
    final double y1 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item);
    if (Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

    final PlotOrientation orientation = plot.getOrientation();
    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 (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);
        }
        if (shape.intersects(dataArea)) {
            g2.setPaint(getFeedbackNodePaint());
            g2.fill(shape);
        }
    }

    double xx = transX1;
    double yy = transY1;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = transY1;
        yy = transX1;
    }
    drawFeedbackItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0));
}

From source file:de.laures.cewolf.jfree.XYSplineRenderer.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.
 *
 * @param g2  the graphics device./*from   ww w  .  j  ava  2 s.c o  m*/
 * @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 points
    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);

    // collect points
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        ControlPoint p = new ControlPoint(
                plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transY1 : (float) transX1,
                plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transX1 : (float) transY1);
        if (!this.points.contains(p)) {
            this.points.add(p);
        }
    }
    if (item == dataset.getItemCount(series) - 1) {
        State s = (State) state;
        // construct path
        if (this.points.size() > 1) {
            // we need at least two points to draw something
            ControlPoint cp0 = (ControlPoint) this.points.get(0);
            s.seriesPath.moveTo(cp0.x, cp0.y);
            if (this.points.size() == 2) {
                // we need at least 3 points to spline. Draw simple line for two points
                ControlPoint cp1 = (ControlPoint) this.points.get(1);
                s.seriesPath.lineTo(cp1.x, cp1.y);
            } else {
                // construct spline
                int np = this.points.size(); // number of points
                float[] d = new float[np]; // Newton form coefficients
                float[] x = new float[np]; // x-coordinates of nodes
                float y;
                float t;
                float[] a = new float[np];
                float t1;
                float t2;
                float[] h = new float[np];

                for (int i = 0; i < np; i++) {
                    ControlPoint cpi = (ControlPoint) this.points.get(i);
                    x[i] = cpi.x;
                    d[i] = cpi.y;
                }

                for (int i = 1; i <= np - 1; i++) {
                    h[i] = x[i] - x[i - 1];
                }
                float[] sub = new float[np - 1];
                float[] diag = new float[np - 1];
                float[] sup = new float[np - 1];

                for (int i = 1; i <= np - 2; i++) {
                    diag[i] = (h[i] + h[i + 1]) / 3;
                    sup[i] = h[i + 1] / 6;
                    sub[i] = h[i] / 6;
                    a[i] = (d[i + 1] - d[i]) / h[i + 1] - (d[i] - d[i - 1]) / h[i];
                }
                solveTridiag(sub, diag, sup, a, np - 2);

                // note that a[0]=a[np-1]=0
                // draw
                s.seriesPath.moveTo(x[0], d[0]);
                for (int i = 1; i <= np - 1; i++) {
                    // loop over intervals between nodes
                    for (int j = 1; j <= this.precision; j++) {
                        t1 = (h[i] * j) / this.precision;
                        t2 = h[i] - t1;
                        y = ((-a[i - 1] / 6 * (t2 + h[i]) * t1 + d[i - 1]) * t2
                                + (-a[i] / 6 * (t1 + h[i]) * t2 + d[i]) * t1) / h[i];
                        t = x[i - 1] + t1;
                        s.seriesPath.lineTo(t, y);
                    }
                }
            }
            // draw path
            drawFirstPassShape(g2, pass, series, item, s.seriesPath);
        }

        // reset points vector
        this.points = new Vector();
    }
}

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

protected Object[] createItemArray(XYDataset dataset, int series, int item) {
    Object[] result = new Object[5];
    result[0] = dataset.getSeriesKey(series).toString();

    double x = dataset.getXValue(series, item);
    if (Double.isNaN(x) && dataset.getX(series, item) == null) {
        result[1] = "null"; //this.nullXString;
    } else {/*from w  w w.  j ava 2  s.c  o  m*/
        if (this.getXDateFormat() != null) {
            result[1] = this.getXDateFormat().format(new Date((long) x));
        } else {
            result[1] = this.getXFormat().format(x);
        }
    }

    double y = dataset.getYValue(series, item);
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[2] = "null"; //this.nullYString;
    } else {
        if (this.getYDateFormat() != null) {
            result[2] = this.getYDateFormat().format(new Date((long) y));
        } else {
            result[2] = this.getYFormat().format(y);
        }
        double total = calculateYTotal(dataset, series);
        double percent = y / total;
        result[3] = NumberFormat.getPercentInstance().format(percent);
        if (this.getYFormat() != null) {
            result[4] = this.getYFormat().format(total);
        } else if (this.getYDateFormat() != null) {
            //result[4] = this.getDateFormat().format(total);
        }
    }
    return result;
}

From source file:no.met.jtimeseries.chart.XYSplineRenderer.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   w  ww  .j  av a 2s  .c o 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.
 */
@Override
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 points
    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);

    // collect points
    if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
        ControlPoint p = new ControlPoint(
                plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transY1 : (float) transX1,
                plot.getOrientation() == PlotOrientation.HORIZONTAL ? (float) transX1 : (float) transY1);
        if (!this.points.contains(p)) {
            this.points.add(p);
        }
    }
    if (item == dataset.getItemCount(series) - 1) {
        State s = (State) state;
        // construct path
        if (this.points.size() > 1) {
            // we need at least two points to draw something
            ControlPoint cp0 = this.points.get(0);
            s.seriesPath.moveTo(cp0.x, cp0.y);
            if (this.points.size() == 2) {
                // we need at least 3 points to spline. Draw simple line
                // for two points
                ControlPoint cp1 = this.points.get(1);
                s.seriesPath.lineTo(cp1.x, cp1.y);
            } else {
                // construct spline
                int np = this.points.size(); // number of points
                float[] d = new float[np]; // Newton form coefficients
                float[] x = new float[np]; // x-coordinates of nodes
                float y;
                float t;
                float oldy = 0;
                float oldt = 0;

                float[] a = new float[np];
                float t1;
                float t2;
                float[] h = new float[np];

                for (int i = 0; i < np; i++) {
                    ControlPoint cpi = this.points.get(i);
                    x[i] = cpi.x;
                    d[i] = cpi.y;
                }

                for (int i = 1; i <= np - 1; i++) {
                    h[i] = x[i] - x[i - 1];
                }
                float[] sub = new float[np - 1];
                float[] diag = new float[np - 1];
                float[] sup = new float[np - 1];

                for (int i = 1; i <= np - 2; i++) {
                    diag[i] = (h[i] + h[i + 1]) / 3;
                    sup[i] = h[i + 1] / 6;
                    sub[i] = h[i] / 6;
                    a[i] = (d[i + 1] - d[i]) / h[i + 1] - (d[i] - d[i - 1]) / h[i];
                }
                solveTridiag(sub, diag, sup, a, np - 2);

                // note that a[0]=a[np-1]=0
                // draw
                oldt = x[0];
                oldy = d[0];
                s.seriesPath.moveTo(oldt, oldy);
                for (int i = 1; i <= np - 1; i++) {
                    // loop over intervals between nodes
                    for (int j = 1; j <= this.precision; j++) {
                        t1 = (h[i] * j) / this.precision;
                        t2 = h[i] - t1;
                        y = ((-a[i - 1] / 6 * (t2 + h[i]) * t1 + d[i - 1]) * t2
                                + (-a[i] / 6 * (t1 + h[i]) * t2 + d[i]) * t1) / h[i];
                        t = x[i - 1] + t1;
                        s.seriesPath.lineTo(t, y);
                        oldt = t;
                        oldy = y;
                    }
                }
            }
            // draw path
            drawFirstPassShape(g2, pass, series, item, s.seriesPath);
        }

        // reset points vector
        this.points = new Vector<ControlPoint>();
    }
}

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

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device./*  w w  w .j  a  v a2  s  .c om*/
 * @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);
        }
    }

}

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 2  s  .  c o  m
 * @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:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.CompassRenderer.java

@Override
public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot,
        XYDataset dataset, int seriesIndex) {

    // compute the right color for the paint
    int length = GuiUtils.getAvailableColors().length;
    Color color = GuiUtils.getAvailableColors()[index % length];
    // get all the data points
    int numPoints = dataset.getItemCount(seriesIndex);
    // set STroke and Paint of the graphics
    g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175));

    // iterate through the points of the dataset
    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i); // the angle at the center         
        double radius = dataset.getYValue(seriesIndex, i); // the frequency

        Point p0 = plot.translateToJava2D(0, 0, plot.getAxis(), dataArea);
        Point p1 = plot.translateToJava2D(theta, radius, plot.getAxis(), dataArea);

        Line2D line = new Line2D.Double(p0, p1);
        g2.draw(line);/*  w  w  w  . ja  va  2s .c o m*/
    }
}

From source file:com.stableapps.anglewraparounddemo.AngleWrapDemoMain.java

/**
 * Creates a sample chart.//from  ww w  . j a  v a 2s .  c om
 *
 * @return a sample chart.
 */
private JFreeChart createChart() {
    final XYDataset direction = createAngleDataset(600);
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Time", "Date", "Direction", direction, true,
            true, false);

    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // configure the range axis to provide a fix set of TickUnits depending on size of chart
    NumberAxis rangeAxis = new NumberAxis() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public NumberTickUnit getTickUnit() {
            NumberTickUnit tickUnit = super.getTickUnit();
            if (tickUnit.getSize() < 15) {
                return tickUnit;
            } else if (tickUnit.getSize() < 45) {
                return new NumberTickUnit(45);
            } else if (tickUnit.getSize() < 90) {
                return new NumberTickUnit(90);
            } else if (tickUnit.getSize() < 180) {
                return new NumberTickUnit(180);
            } else {
                return new NumberTickUnit(360);
            }
        }

    };
    rangeAxis.setAutoRangeIncludesZero(false);
    plot.setRangeAxis(rangeAxis);

    final OverflowCondition overflowCondition = new OverflowCondition() {
        @Override
        public boolean isOverflow(double y0, double x0, double y1, double x1) {
            return Math.abs(y1 - y0) > 180;
        }
    };
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) {
        /**
         *
         */
        private static final long serialVersionUID = 1L;
        double min = 0;
        double max = 360;
        LinearInterpolator interpolator = new LinearInterpolator();

        @Override
        protected void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset,
                int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea) {
            if (item == 0) {
                return;
            }

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

            double x0 = dataset.getXValue(series, item - 1);
            double y0 = dataset.getYValue(series, item - 1);
            if (Double.isNaN(y0) || Double.isNaN(x0)) {
                return;
            }

            if (overflowCondition.isOverflow(y0, x0, y1, x1)) {
                boolean overflowAtMax = y1 < y0;
                if (overflowAtMax) {
                    LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) },
                            new double[] { x0, x1 });
                    double xmid = lf.value(max);
                    drawPrimaryLine(state, g2, plot, x0, y0, xmid, max, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                    drawPrimaryLine(state, g2, plot, xmid, min, x1, y1, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                } else {
                    LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 },
                            new double[] { x1, x0 });
                    double xmid = lf.value(min);
                    drawPrimaryLine(state, g2, plot, x0, y0, xmid, min, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                    drawPrimaryLine(state, g2, plot, xmid, max, x1, y1, pass, series, item, domainAxis,
                            rangeAxis, dataArea);
                }
            } else {
                drawPrimaryLine(state, g2, plot, x0, y0, x1, y1, pass, series, item, domainAxis, rangeAxis,
                        dataArea);
            }

        }

        private void drawPrimaryLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double x0,
                double y0, double x1, double y1, int pass, int series, int item, ValueAxis domainAxis,
                ValueAxis rangeAxis, Rectangle2D dataArea) {
            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
            double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);
            double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
            double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
            // only draw if we have good values
            if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                    || Double.isNaN(transY1)) {
                return;
            }
            PlotOrientation orientation = plot.getOrientation();
            boolean visible;
            if (orientation == PlotOrientation.HORIZONTAL) {
                state.workingLine.setLine(transY0, transX0, transY1, transX1);
            } else if (orientation == PlotOrientation.VERTICAL) {
                state.workingLine.setLine(transX0, transY0, transX1, transY1);
            }
            visible = LineUtilities.clipLine(state.workingLine, dataArea);
            if (visible) {
                drawFirstPassShape(g2, pass, series, item, state.workingLine);
            }
        }

        @Override
        protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot,
                XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea) {

            // get the data point...
            State s = (State) state;
            try {
                double x1 = dataset.getXValue(series, item);
                double y1 = dataset.getYValue(series, item);
                if (Double.isNaN(x1) && Double.isNaN(y1)) {
                    s.setLastPointGood(false);
                    return;
                }

                if (!s.isLastPointGood()) {
                    ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                    s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                    s.setLastPointGood(true);
                    return;
                }

                double x0 = dataset.getXValue(series, item - 1);
                double y0 = dataset.getYValue(series, item - 1);
                if (overflowCondition.isOverflow(y0, x0, y1, x1)) {
                    boolean overflowAtMax = y1 < y0;
                    if (overflowAtMax) {
                        LinearFunction lf = interpolator.interpolate(new double[] { y0, y1 + (max - min) },
                                new double[] { x0, x1 });
                        double xmid = lf.value(max);
                        ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid,
                                max);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, min);
                        s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                    } else {
                        LinearFunction lf = interpolator.interpolate(new double[] { y1 - (max - min), y0 },
                                new double[] { x1, x0 });
                        double xmid = lf.value(min);
                        ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid,
                                min);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, xmid, max);
                        s.seriesPath.moveTo(xy.getLeft(), xy.getRight());
                        xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                        s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                    }
                } else {
                    ImmutablePair<Float, Float> xy = translate(plot, domainAxis, rangeAxis, dataArea, x1, y1);
                    s.seriesPath.lineTo(xy.getLeft(), xy.getRight());
                }

                s.setLastPointGood(true);
            } finally {
                // if this is the last item, draw the path ...
                if (item == s.getLastItemIndex()) {
                    // draw path
                    drawFirstPassShape(g2, pass, series, item, s.seriesPath);
                }

            }
        }

        private ImmutablePair<Float, Float> translate(XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis,
                Rectangle2D dataArea, double x, double y) {
            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX1 = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
            double transY1 = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
            // update path to reflect latest point
            float xtrans = (float) transX1;
            float ytrans = (float) transY1;
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL) {
                xtrans = (float) transY1;
                ytrans = (float) transX1;
            }
            return new ImmutablePair<>(xtrans, ytrans);
        }
    };
    renderer.setDrawSeriesLineAsPath(true);
    plot.setRenderer(0, renderer);

    return chart;
}