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

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

Introduction

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

Prototype

public RectangleEdge getDomainAxisEdge() 

Source Link

Document

Returns the edge for the primary domain axis (taking into account the plot's orientation).

Usage

From source file:vteaexploration.plotgatetools.gates.PolygonGate.java

@Override
public void createInChartSpace(ChartPanel chart) {

    int[] x1Points = new int[vertices.size()];
    int[] y1Points = new int[vertices.size()];
    double xChartPoint;
    double yChartPoint;

    for (int i = 0; i <= vertices.size() - 1; i++) {
        x1Points[i] = (int) ((Point2D) vertices.get(i)).getX();
        y1Points[i] = (int) ((Point2D) vertices.get(i)).getY();
    }/*  w w w .  java2 s . co  m*/

    for (int index = 0; index < x1Points.length; index++) {

        Rectangle2D plotArea = chart.getScreenDataArea();
        XYPlot plot = (XYPlot) chart.getChart().getPlot();
        xChartPoint = plot.getDomainAxis().java2DToValue(x1Points[index], plotArea, plot.getDomainAxisEdge());
        yChartPoint = plot.getRangeAxis().java2DToValue(y1Points[index], plotArea, plot.getRangeAxisEdge());

        this.verticesInChartSpace.add(new Point2D.Double(xChartPoint, yChartPoint));
    }

}

From source file:org.geotools.renderer.chart.GeometryRenderer.java

void drawCoordinate(Coordinate c, Graphics2D g2, int series, int item, Rectangle2D dataArea, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis) {

    double tx = domainAxis.valueToJava2D(c.x, dataArea, plot.getDomainAxisEdge());
    double ty = rangeAxis.valueToJava2D(c.y, dataArea, plot.getRangeAxisEdge());

    Shape shape = getItemShape(series, item);
    shape = ShapeUtilities.createTranslatedShape(shape, tx, ty);

    if (fillCoordinates) {
        g2.fill(shape);//  www  .  jav  a  2s  . c  o  m
    } else {
        g2.draw(shape);
    }
}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

private double domainValueTo2D(ChartPanel chartPanel, XYPlot plot, double value) {
    ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Number x = plot.getDomainAxis().valueToJava2D(value, dataArea, plot.getDomainAxisEdge());

    return x.doubleValue();
}

From source file:org.operamasks.faces.render.graph.XYCurveAndShapeRenderer.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 ww w . j a  va  2  s  .co 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.
 */
protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset,
        int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {

    if (item != 0) {
        return;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    PlotOrientation orientation = plot.getOrientation();

    int itemCount = dataset.getItemCount(series);
    double[][] points = new double[itemCount][2];
    int count = 0;

    for (int i = 0; i < itemCount; i++) {
        double x = dataset.getXValue(series, i);
        double y = dataset.getYValue(series, i);
        double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
        if (!Double.isNaN(transX) && !Double.isNaN(transY)) {
            points[count][0] = transX;
            points[count][1] = transY;
            count++;
        }
    }

    if (count < 2) {
        return;
    }

    // sort points according to x axis
    Arrays.sort(points, new Comparator<double[]>() {
        public int compare(double[] a, double[] b) {
            return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0;
        }
    });

    // draw curve
    CubicSplineFunction2D f = new CubicSplineFunction2D(points, count);
    GeneralPath path = new GeneralPath();

    double startX = points[0][0];
    double startY = points[0][1];
    double endX = points[count - 1][0];
    double endY = points[count - 1][1];
    double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        if (drawArea) {
            path.moveTo((float) yz, (float) startX);
            path.lineTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
            path.lineTo((float) yz, (float) endX);
            path.closePath();
        } else {
            path.moveTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
        }
    } else {
        if (drawArea) {
            path.moveTo((float) startX, (float) yz);
            path.lineTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
            path.lineTo((float) endX, (float) yz);
            path.closePath();
        } else {
            path.moveTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
        }
    }

    Paint paint = getItemPaint(series, item);
    Stroke stroke = getItemStroke(series, item);

    if (drawArea) {
        g2.setPaint(paint);
        g2.fill(path);

        // create paint for outline
        if (paint instanceof Color) {
            paint = ((Color) paint).darker();
        } else if (paint instanceof GradientPaint) {
            paint = ((GradientPaint) paint).getColor1().darker();
        }
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(path);
}

From source file:MouseEventListener.java

@Override
public void chartMouseMoved(ChartMouseEvent arg0) {
    Double chartX;/*w w  w.ja  va2  s  .  co m*/
    Double chartT;

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    chartX = plot.getRangeAxis().java2DToValue(
            chartPanel.translateScreenToJava2D(arg0.getTrigger().getPoint()).getY(),
            chartPanel.getScreenDataArea(), plot.getRangeAxisEdge());
    chartT = plot.getDomainAxis().java2DToValue(
            chartPanel.translateScreenToJava2D(arg0.getTrigger().getPoint()).getX(),
            chartPanel.getScreenDataArea(), plot.getDomainAxisEdge());

    //simuladorGUI.actualizarPosicionCursor(chartX, chartT);

}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

private Number getDomainX(ChartPanel chartPanel, XYPlot plot, Point2D mousePoint) {
    ChartRenderingInfo info = chartPanel.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();
    Number x = plot.getDomainAxis().java2DToValue(mousePoint.getX(), dataArea, plot.getDomainAxisEdge());

    return x;/*  w  ww . j  a v  a2s. c o m*/
}

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;/*  w w w . j  a  v  a  2 s. c  om*/
    }
    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: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// w  w  w  .  j a  va 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.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java

/**
 * All parameters are domain coordinates that have to be translated to
 * Java2D points./*  w  w  w. j  ava2  s  .c  o  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.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/*from   ww  w.  ja  v  a 2 s  .  com*/
 * @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));
}