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

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

Introduction

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

Prototype

public RectangleEdge getRangeAxisEdge() 

Source Link

Document

Returns the edge for the primary range axis.

Usage

From source file:com.android.ddmuilib.log.event.OccurrenceRenderer.java

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

    // get the x value for the series/item.
    double x = timeDataSet.getX(series, item).doubleValue();

    // get the min/max of the range axis
    double yMin = rangeAxis.getLowerBound();
    double yMax = rangeAxis.getUpperBound();

    RectangleEdge domainEdge = plot.getDomainAxisEdge();
    RectangleEdge rangeEdge = plot.getRangeAxisEdge();

    // convert the coordinates to java2d.
    double x2D = domainAxis.valueToJava2D(x, dataArea, domainEdge);
    double yMin2D = rangeAxis.valueToJava2D(yMin, dataArea, rangeEdge);
    double yMax2D = rangeAxis.valueToJava2D(yMax, dataArea, rangeEdge);

    // get the paint information for the series/item
    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);

    Line2D line = null;// ww  w.  j  a v a2s.c om
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yMin2D, x2D, yMax2D, x2D);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(x2D, yMin2D, x2D, yMax2D);
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);
}

From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java

/**
 *
 * @param g2//from   w  ww .  j  a v  a2  s. co  m
 * @param chartPanel
 */
@Override
public void paintOverlay(Graphics2D g2, ChartPanel chartPanel) {
    if (visible) {
        Shape savedClip = g2.getClip();
        Rectangle2D dataArea = chartPanel.getScreenDataArea();
        g2.clip(dataArea);
        JFreeChart chart = chartPanel.getChart();
        XYPlot plot = (XYPlot) chart.getPlot();
        ValueAxis xAxis = plot.getDomainAxis();
        ValueAxis yAxis = plot.getRangeAxis();
        paint(g2, plot, dataArea, xAxis, yAxis, plot.getDomainAxisEdge(), plot.getRangeAxisEdge(), chartPanel);
        g2.setClip(savedClip);
    }
}

From source file:org.jax.maanova.plot.MaanovaChartPanel.java

/**
 * Convert the given point in java2d coordinates to chart coordinates.
 * @param java2DPoint the point to convert
 * @return the converted point/*from  w w w.  j  av  a  2 s.c om*/
 * @throws ClassCastException the plot isn't an XYPlot
 */
public Point2D toChartPoint(Point2D java2DPoint) throws ClassCastException {
    XYPlot plot = this.getChart().getXYPlot();
    Rectangle2D dataArea = this.chartRenderingInfo.getPlotInfo().getDataArea();

    double graphX = plot.getDomainAxis().java2DToValue(java2DPoint.getX(), dataArea, plot.getDomainAxisEdge());
    double graphY = plot.getRangeAxis().java2DToValue(java2DPoint.getY(), dataArea, plot.getRangeAxisEdge());

    return new Point2D.Double(graphX, graphY);
}

From source file:org.jax.maanova.plot.MaanovaChartPanel.java

/**
 * Convert the given rectangle in java2d coordinates to chart coordinates.
 * @param java2DRectangle the rectangle to convert
 * @return the converted rectangle//www  . ja v a  2 s . c  o m
 * @throws ClassCastException the plot isn't an XYPlot
 */
public Rectangle2D toChartRectangle(Rectangle2D java2DRectangle) throws ClassCastException {
    XYPlot plot = this.getChart().getXYPlot();
    Rectangle2D dataArea = this.chartRenderingInfo.getPlotInfo().getDataArea();

    double x1 = plot.getDomainAxis().java2DToValue(java2DRectangle.getMinX(), dataArea,
            plot.getDomainAxisEdge());
    double y1 = plot.getRangeAxis().java2DToValue(java2DRectangle.getMinY(), dataArea, plot.getRangeAxisEdge());
    double x2 = plot.getDomainAxis().java2DToValue(java2DRectangle.getMaxX(), dataArea,
            plot.getDomainAxisEdge());
    double y2 = plot.getRangeAxis().java2DToValue(java2DRectangle.getMaxY(), dataArea, plot.getRangeAxisEdge());

    return toNonNegativeWidthHeightRectangle(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1));
}

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 va2 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
        // 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:com.ivli.roim.controls.ChartControl.java

@Override
public void mouseDragged(MouseEvent e) {
    final XYPlot plot = getChart().getXYPlot();

    if (null != iEntity) {
        moveTo(plot.getRangeAxis().java2DToValue(e.getY(), getChartRenderingInfo().getPlotInfo().getDataArea(),
                plot.getRangeAxisEdge()));
    }//from  w w  w  .  j av  a  2  s . c om
    if (null != iMarker) {
        double domainX = plot.getDomainAxis().java2DToValue(e.getX(), getScreenDataArea(),
                plot.getDomainAxisEdge());
        iMarker.setValue(domainX);
    } else
        super.mouseDragged(e);
}

From source file:dbseer.gui.panel.DBSeerExplainChartPanel.java

@Override
public void mouseReleased(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON3) {
        displayPopupMenu(e.getX(), e.getY());
        return;//from  ww  w  .j  a  va2  s.co m
    }
    repaint();
    int smallX = Math.min(startX, endX);
    int smallY = Math.min(startY, endY);
    int bigX = Math.max(startX, endX);
    int bigY = Math.max(startY, endY);

    XYPlot plot = this.getChart().getXYPlot();
    Rectangle2D plotArea = this.getScreenDataArea();
    double chartSmallX = plot.getDomainAxis().java2DToValue(smallX, plotArea, plot.getDomainAxisEdge());
    double chartBigX = plot.getDomainAxis().java2DToValue(bigX, plotArea, plot.getDomainAxisEdge());
    double chartSmallY = plot.getRangeAxis().java2DToValue(smallY, plotArea, plot.getRangeAxisEdge());
    double chartBigY = plot.getRangeAxis().java2DToValue(bigY, plotArea, plot.getRangeAxisEdge());

    double minXValue = Math.min(chartSmallX, chartBigX);
    double maxXValue = Math.max(chartSmallX, chartBigX);
    double minYValue = Math.min(chartSmallY, chartBigY);
    double maxYValue = Math.max(chartSmallY, chartBigY);

    //testLog.append("Scanning: (" + smallX + ", " + smallY + "), (" + bigX + ", " + bigY + ")\n");
    //testLog.append("Scanning: X = [" + Math.min(chartSmallX, chartBigX) + ", " + Math.max(chartSmallX, chartBigX) + "]\n");
    //testLog.append("Scanning: Y = [" + Math.min(chartSmallY, chartBigY) + ", " + Math.max(chartSmallY, chartBigY) + "]\n");

    Set<XYItemEntity> foundItem = new HashSet<XYItemEntity>();

    XYDataset dataset = this.getChart().getXYPlot().getDataset();
    EntityCollection collection = this.getChartRenderingInfo().getEntityCollection();

    for (Object obj : collection.getEntities()) {
        if (obj instanceof XYItemEntity) {
            XYItemEntity entity = (XYItemEntity) obj;
            int series = entity.getSeriesIndex();
            int idx = entity.getItem();
            if (dataset.getX(series, idx).doubleValue() >= minXValue
                    && dataset.getX(series, idx).doubleValue() <= maxXValue
                    && dataset.getY(series, idx).doubleValue() >= minYValue
                    && dataset.getY(series, idx).doubleValue() <= maxYValue) {
                foundItem.add(entity);
            }
        }
    }

    //      for (int x = smallX; x <= bigX; ++x)
    //      {
    //         for (int y = smallY; y <= bigY; ++y)
    //         {
    //            ChartEntity entity = this.getEntityForPoint(x, y);
    //            if (entity instanceof XYItemEntity)
    //            {
    //               foundItem.add((XYItemEntity)entity);
    //            }
    //         }
    //      }

    selectedItems = foundItem;

    //      outlierRegion.clear();
    //      for (XYItemEntity entity : foundItem)
    //      {
    //         //testLog.append(entity.toString() + "\n");
    //         //testLog.append("Series = " + entity.getSeriesIndex() + ", ");
    //         //testLog.append("X = " + entity.getDataset().getX(entity.getSeriesIndex(), entity.getItem()) + ", ");
    //         //testLog.append("Y = " + entity.getDataset().getY(entity.getSeriesIndex(), entity.getItem()) + "\n");
    //         outlierRegion.add(entity.getDataset().getX(entity.getSeriesIndex(), entity.getItem()).doubleValue());
    //      }
    //
    //      Collections.sort(outlierRegion);
    //      if (!outlierRegion.isEmpty())
    //      {
    //         testLog.setText("");
    //         testLog.append("Outlier time selected = [");
    //         for (int i = 0; i < outlierRegion.size(); ++i)
    //         {
    //            testLog.append(outlierRegion.get(i).toString());
    //            if (i < outlierRegion.size() - 1)
    //            {
    //               testLog.append(" ");
    //            }
    //         }
    //         testLog.append("]\n");
    //      }
}

From source file:longMethod.jfreechart.drawItem.SamplingXYLineRenderer.java

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

    // 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.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private double calculateItemYPoint(int series, int item, Rectangle2D dataArea, ValueAxis rangeAxis,
        XYDataset dataSet, XYPlot plot) {
    double yValue = dataSet.getYValue(series, item);
    return rangeAxis.valueToJava2D(yValue, dataArea, plot.getRangeAxisEdge());
}

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();//from   w  ww. j  av  a2s .  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!");
    }
}