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

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

Introduction

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

Prototype

@Override
public PlotOrientation getOrientation() 

Source Link

Document

Returns the orientation of the plot.

Usage

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private Polygon createEntityArea(XYPlot plot, double previousItemX, double previousItemY, double currentItemX,
        double currentItemY, double nextItemX, double nextItemY, double zeroPoint) {
    Polygon entityAreaPolygon = new Polygon();
    final int halfwayPrevX = (int) ((previousItemX + currentItemX) / 2.0);
    final int halfwayPrevY = (int) ((previousItemY + currentItemY) / 2.0);
    final int halfwayNextY = (int) ((currentItemY + nextItemY) / 2.0);
    final int halfwayNextX = (int) ((currentItemX + nextItemX) / 2.0);
    if (plot.getOrientation() == PlotOrientation.HORIZONTAL) {
        entityAreaPolygon.addPoint((int) zeroPoint, halfwayPrevX);
        entityAreaPolygon.addPoint(halfwayPrevY, halfwayPrevX);
        entityAreaPolygon.addPoint((int) currentItemY, (int) currentItemX);
        entityAreaPolygon.addPoint(halfwayNextY, halfwayNextX);
        entityAreaPolygon.addPoint((int) zeroPoint, halfwayNextX);
    } else {//from  w w  w. j  av  a2 s.  c o  m
        entityAreaPolygon.addPoint(halfwayPrevX, (int) zeroPoint);
        entityAreaPolygon.addPoint(halfwayPrevX, halfwayPrevY);
        entityAreaPolygon.addPoint((int) currentItemX, (int) currentItemY);
        entityAreaPolygon.addPoint(halfwayNextX, halfwayNextY);
        entityAreaPolygon.addPoint(halfwayNextX, (int) zeroPoint);
    }

    return entityAreaPolygon;
}

From source file:no.met.jtimeseries.chart.XYCardinalSplineRenderer.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//from   www  .  j  a  va  2 s . com
 *            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
        // we need at least two points to draw something
        if (this.points.size() > 1) {
            ControlPoint cp0 = this.points.get(0);
            s.seriesPath.moveTo(cp0.x, cp0.y);
            // we need at least 2 points to spline. Draw simple line
            // for less then 2 points
            if (this.points.size() == 2) {
                ControlPoint cp1 = this.points.get(1);
                s.seriesPath.lineTo(cp1.x, cp1.y);

            } else {
                // construct spline
                // number of intervals (i.e. parametric curve would be
                // evaluted n+1 times)
                // set the minimum resolution
                int minimumN = 1;
                int maximumN = 4;

                // add two more points at the top and the end for drawing the curve between the first two and last two points
                this.points.add(0, this.points.get(0));
                this.points.add(this.points.get(this.points.size() - 1));

                // set the minimum distance when using minimumN
                double smallDistance = Math.pow(Math.pow(points.get(3).x - points.get(0).x, 2)
                        + Math.pow(points.get(3).y - points.get(0).y, 2), 0.5);

                double currentDistance;
                double currentN;

                List<ControlPoint> newPoints;
                for (int i = 0; i < this.points.size() - 3; i++) {
                    currentDistance = Math.pow(Math.pow(points.get(i + 3).x - points.get(i).x, 2)
                            + Math.pow(points.get(i + 3).y - points.get(i).y, 2), 0.5);
                    currentN = minimumN * currentDistance / smallDistance;
                    currentN = currentN > maximumN ? maximumN : currentN;
                    newPoints = evaluateCardinal2DAtNplusOneValues(this.points.get(i), this.points.get(i + 1),
                            this.points.get(i + 2), this.points.get(i + 3), tension, (int) currentN);
                    for (int j = 0; j < newPoints.size(); j++) {
                        s.seriesPath.lineTo(newPoints.get(j).x, newPoints.get(j).y);
                    }
                }
            }
            s.seriesPath.lineTo(points.get(points.size() - 1).x, points.get(points.size() - 1).y);
            // draw path
            drawFirstPassShape(g2, pass, series, item, s.seriesPath);

        }

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

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

/**
 * All parameters are domain coordinates that have to be translated to
 * Java2D points./*from   w  w  w  . j  a v a 2s.co m*/
 */
private void drawFeedbackEdge(final double x0, final double y0, final double x1, final double y1,
        final XYItemRendererState state, final Graphics2D g2, final XYPlot plot, final ValueAxis domainAxis,
        final ValueAxis rangeAxis, final Rectangle2D dataArea) {
    if (Double.isNaN(y0) || Double.isNaN(x0) || Double.isNaN(y1) || Double.isNaN(x1)) {
        return;
    }

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

    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
    final double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

    final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    final 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;
    }

    final PlotOrientation orientation = plot.getOrientation();
    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.setStroke(getFeedbackStroke());
        g2.setPaint(getFeedbackEdgePaint());
        g2.draw(state.workingLine);
    }

}

From source file:org.jfree.experimental.chart.renderer.xy.VectorRenderer.java

/**
 * Draws the block representing the specified item.
 * /* ww  w.  j av  a  2s  .c  o  m*/
 * @param g2  the graphics device.
 * @param state  the state.
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the x-axis.
 * @param rangeAxis  the y-axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @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) {

    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double dx = 0.0;
    double dy = 0.0;
    if (dataset instanceof VectorXYDataset) {
        dx = ((VectorXYDataset) dataset).getDeltaXValue(series, item);
        dy = ((VectorXYDataset) dataset).getDeltaYValue(series, item);
    }
    double xx0 = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
    double yy0 = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge());
    double xx1 = domainAxis.valueToJava2D(x + dx, dataArea, plot.getDomainAxisEdge());
    double yy1 = rangeAxis.valueToJava2D(y + dy, dataArea, plot.getRangeAxisEdge());
    Line2D line;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation.equals(PlotOrientation.HORIZONTAL)) {
        line = new Line2D.Double(yy0, xx0, yy1, xx1);
    } else {
        line = new Line2D.Double(xx0, yy0, xx1, yy1);
    }
    g2.setPaint(getItemPaint(series, item));
    g2.setStroke(getItemStroke(series, item));
    g2.draw(line);

    // calculate the arrow head and draw it...
    double dxx = (xx1 - xx0);
    double dyy = (yy1 - yy0);
    double bx = xx0 + (1.0 - this.baseLength) * dxx;
    double by = yy0 + (1.0 - this.baseLength) * dyy;

    double cx = xx0 + (1.0 - this.headLength) * dxx;
    double cy = yy0 + (1.0 - this.headLength) * dyy;

    double angle = 0.0;
    if (dxx != 0.0) {
        angle = Math.PI / 2.0 - Math.atan(dyy / dxx);
    }
    double deltaX = 2.0 * Math.cos(angle);
    double deltaY = 2.0 * Math.sin(angle);

    double leftx = cx + deltaX;
    double lefty = cy - deltaY;
    double rightx = cx - deltaX;
    double righty = cy + deltaY;

    GeneralPath p = new GeneralPath();
    p.moveTo((float) xx1, (float) yy1);
    p.lineTo((float) rightx, (float) righty);
    p.lineTo((float) bx, (float) by);
    p.lineTo((float) leftx, (float) lefty);
    p.closePath();
    g2.draw(p);

}

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  . j ava 2s  .com
    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:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private void drawOutline(Shape entity, Graphics2D g2, Color fill, Color stroke, ChartPanel chartPanel,
        boolean scale, float alpha) {
    if (entity != null) {
        //System.out.println("Drawing entity with bbox: "+entity.getBounds2D());
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        Color c = g2.getColor();//w w  w .  j a  v a  2s.c om
        Composite comp = g2.getComposite();
        g2.clip(dataArea);
        g2.setColor(fill);
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        JFreeChart chart = chartPanel.getChart();
        XYPlot plot = (XYPlot) chart.getPlot();
        ValueAxis xAxis = plot.getDomainAxis();
        ValueAxis yAxis = plot.getRangeAxis();
        RectangleEdge xAxisEdge = plot.getDomainAxisEdge();
        RectangleEdge yAxisEdge = plot.getRangeAxisEdge();
        Rectangle2D entityBounds = entity.getBounds2D();
        double viewX = xAxis.valueToJava2D(entityBounds.getCenterX(), dataArea, xAxisEdge);
        double viewY = yAxis.valueToJava2D(entityBounds.getCenterY(), dataArea, yAxisEdge);
        double viewW = xAxis.lengthToJava2D(entityBounds.getWidth(), dataArea, xAxisEdge);
        double viewH = yAxis.lengthToJava2D(entityBounds.getHeight(), dataArea, yAxisEdge);
        PlotOrientation orientation = plot.getOrientation();

        //transform model to origin (0,0) in model coordinates
        AffineTransform toOrigin = AffineTransform.getTranslateInstance(-entityBounds.getCenterX(),
                -entityBounds.getCenterY());
        //transform from origin (0,0) to model location
        AffineTransform toModelLocation = AffineTransform.getTranslateInstance(entityBounds.getCenterX(),
                entityBounds.getCenterY());
        //transform from model scale to view scale
        double scaleX = viewW / entityBounds.getWidth();
        double scaleY = viewH / entityBounds.getHeight();
        Logger.getLogger(getClass().getName()).log(Level.FINE, "Scale x: {0} Scale y: {1}",
                new Object[] { scaleX, scaleY });
        AffineTransform toViewScale = AffineTransform.getScaleInstance(scaleX, scaleY);
        AffineTransform toViewLocation = AffineTransform.getTranslateInstance(viewX, viewY);
        AffineTransform flipTransform = AffineTransform.getScaleInstance(1.0f, -1.0f);
        AffineTransform modelToView = new AffineTransform(toOrigin);
        modelToView.preConcatenate(flipTransform);
        modelToView.preConcatenate(toViewScale);
        modelToView.preConcatenate(toViewLocation);
        //
        //            if (orientation == PlotOrientation.HORIZONTAL) {
        //                entity = ShapeUtilities.createTranslatedShape(entity, viewY,
        //                        viewX);
        //            } else if (orientation == PlotOrientation.VERTICAL) {
        //                entity = ShapeUtilities.createTranslatedShape(entity, viewX,
        //                        viewY);
        //            }
        FlatteningPathIterator iter = new FlatteningPathIterator(modelToView.createTransformedShape(entity)
                .getPathIterator(AffineTransform.getTranslateInstance(0, 0)), 5);
        Path2D.Float path = new Path2D.Float();
        path.append(iter, false);

        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
        g2.fill(path);
        if (stroke != null) {
            g2.setColor(stroke);
            g2.draw(path);
        }
        g2.setComposite(comp);
        g2.setColor(c);
        g2.setClip(savedClip);
    } else {
        Logger.getLogger(getClass().getName()).info("Entity is null!");
    }
}

From source file:net.sf.mzmine.modules.visualization.metamsecorrelate.visual.pseudospectra.PseudoSpectraRenderer.java

@Override
protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot,
        XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) {
    //super.drawItemLabel(g2, dataset, series, item, plot, generator, bar, negative);  

    if (generator != null) {
        String label = generator.generateLabel(dataset, series, item);

        if (label != null) {
            Font labelFont = getItemLabelFont(series, item);
            Paint paint = getItemLabelPaint(series, item);
            g2.setFont(labelFont);/*from  w w w  .j a va2  s .  c  o  m*/
            g2.setPaint(paint);

            // get the label position..
            ItemLabelPosition position;
            if (!negative) {
                position = getPositiveItemLabelPosition(series, item);
            } else {
                position = getNegativeItemLabelPosition(series, item);
            }

            // work out the label anchor point...
            Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar,
                    plot.getOrientation());

            // split by \n
            String symbol = "\n";
            String[] splitted = label.split(symbol);

            if (splitted.length > 1) {
                FontRenderContext frc = g2.getFontRenderContext();
                GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,");
                int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight();
                // draw more than one row
                for (int i = 0; i < splitted.length; i++) {
                    int offset = -height * (splitted.length - i - 1);
                    TextUtilities.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(),
                            (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(),
                            position.getRotationAnchor());
                }
            } else {
                // one row 
                TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(),
                        (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(),
                        position.getRotationAnchor());
            }
        }
    }

}

From source file:no.met.jtimeseries.chart.XYHybridSplineRenderer.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/*from  w  w  w  .  ja va  2 s . c  o m*/
 *            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

                // add some cardinal spline control points
                this.points = addCardinalSplinePoints(this.points, tension);

                // applying standard 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:longMethod.jfreechart.drawItem.SamplingXYLineRenderer.java

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

    // do nothing if item is not visible
    if (!getItemVisible(series, item)) {
        return;
    }
    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.lastPointGood) {
            if ((Math.abs(x - s.lastX) > s.dX)) {
                s.seriesPath.lineTo(x, y);
                if (s.lowY < s.highY) {
                    s.intervalPath.moveTo((float) s.lastX, (float) s.lowY);
                    s.intervalPath.lineTo((float) s.lastX, (float) s.highY);
                }
                s.lastX = x;
                s.openY = y;
                s.highY = y;
                s.lowY = y;
                s.closeY = y;
            } else {
                s.highY = Math.max(s.highY, y);
                s.lowY = Math.min(s.lowY, y);
                s.closeY = y;
            }
        } else {
            s.seriesPath.moveTo(x, y);
            s.lastX = x;
            s.openY = y;
            s.highY = y;
            s.lowY = y;
            s.closeY = y;
        }
        s.lastPointGood = true;
    } else {
        s.lastPointGood = false;
    }
    // if this is the last item, draw the path ...
    if (item == s.getLastItemIndex()) {
        // draw path
        PathIterator pi = s.seriesPath.getPathIterator(null);
        int count = 0;
        while (!pi.isDone()) {
            count++;
            pi.next();
        }
        g2.setStroke(getItemStroke(series, item));
        g2.setPaint(getItemPaint(series, item));
        g2.draw(s.seriesPath);
        g2.draw(s.intervalPath);
    }
}

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  ww.j a v  a 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);
            }
        }
    }

}