Example usage for org.jfree.chart.axis ValueAxis lengthToJava2D

List of usage examples for org.jfree.chart.axis ValueAxis lengthToJava2D

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis lengthToJava2D.

Prototype

public double lengthToJava2D(double length, Rectangle2D area, RectangleEdge edge) 

Source Link

Document

Converts a length in data coordinates into the corresponding length in Java2D coordinates.

Usage

From source file:net.sf.mzmine.chartbasics.ChartLogicsFX.java

/**
 * Data width to pixel width on screen/*w  ww .j  a  va  2s .  c  o  m*/
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcWidthOnScreen(ChartViewer myChart, double dataWidth, ValueAxis axis,
        RectangleEdge axisEdge) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();

    // width 2D
    return axis.lengthToJava2D(dataWidth, dataArea, axisEdge);
}

From source file:net.sf.mzmine.chartbasics.ChartLogics.java

/**
 * Data width to pixel width on screen/*from  w w  w. ja  v a 2s.c  o m*/
 * 
 * @param myChart
 * @param dataWidth width of data
 * @param axis for width calculation
 * @return
 */
public static double calcWidthOnScreen(ChartPanel myChart, double dataWidth, ValueAxis axis,
        RectangleEdge axisEdge) {
    XYPlot plot = (XYPlot) myChart.getChart().getPlot();
    ChartRenderingInfo info = myChart.getChartRenderingInfo();
    Rectangle2D dataArea = info.getPlotInfo().getDataArea();

    double width2D = axis.lengthToJava2D(dataWidth, dataArea, axisEdge);

    return width2D;
}

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  w w .  j av  a  2  s .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:edu.ucla.stat.SOCR.motionchart.MotionBubbleRenderer.java

/**
 * Translates the shape so that it displays correctly given the plot and dataArea.
 *
 * @param shape     the shape to translate
 * @param plot      the plot that will be used to translate the shape
 * @param dataArea  the dataArea that the shape will be translated to
 * @return          The translated shape
 *//*from   w  w w  .j  av a  2 s. c  o  m*/
@SuppressWarnings({ "SuspiciousNameCombination" })
protected Ellipse2D.Double translateShape(Ellipse2D.Double shape, XYPlot plot, Rectangle2D dataArea) {
    Ellipse2D.Double circle = null;

    //double x = shape.getCenterX();
    //double y = shape.getCenterY();
    double z = shape.getWidth();

    PlotOrientation orientation = plot.getOrientation();

    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();
    RectangleEdge domainAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge rangeAxisLocation = plot.getRangeAxisEdge();

    double transX1 = domainAxis.valueToJava2D(shape.getX(), dataArea, domainAxisLocation);
    double transX2 = domainAxis.valueToJava2D(shape.getX() + shape.getWidth(), dataArea, domainAxisLocation);
    //The upper-left corner is the lower-left on the graph (screen origin vs. graph origin)
    double transY1 = rangeAxis.valueToJava2D(shape.getY() + shape.getHeight(), dataArea, rangeAxisLocation);
    double transY2 = rangeAxis.valueToJava2D(shape.getY(), dataArea, rangeAxisLocation);

    double width = z * domainAxis.getRange().getLength() * domainZoomMultiplier * SIZE_MULTIPLIER;
    double height = z * rangeAxis.getRange().getLength() * rangeZoomMultiplier * SIZE_MULTIPLIER;
    double transWidth = domainAxis.lengthToJava2D(width, dataArea, domainAxisLocation);//transX2 - transX1;
    double transHeight = rangeAxis.lengthToJava2D(height, dataArea, rangeAxisLocation);//transY2 - transY1;

    double transX = (transX1 + transX2) / 2.0;
    double transY = (transY1 + transY2) / 2.0;

    switch (getScaleType()) {
    case SCALE_ON_DOMAIN_AXIS:
        transHeight = transWidth;
        break;
    case SCALE_ON_RANGE_AXIS:
        transWidth = transHeight;
        break;
    default:
        break;
    }
    transWidth = Math.abs(transWidth);
    transHeight = Math.abs(transHeight);

    if (orientation == PlotOrientation.VERTICAL) {
        circle = new Ellipse2D.Double(transX - transWidth / 2.0, transY - transHeight / 2.0, transWidth,
                transHeight);
    } else if (orientation == PlotOrientation.HORIZONTAL) {
        circle = new Ellipse2D.Double(transY - transHeight / 2.0, transX - transWidth / 2.0, transHeight,
                transWidth);
    }

    return circle;
}