/** * Given graphical coordinates in the reference's coordinate system, returns x and y axis value as * a point via the {@link Axis#getValueForDisplay(double)} and {@link Axis#toNumericValue(Object)} * methods. * * @param minX lower X value (upper left point) * @param minY lower Y value (upper left point) * @param maxX upper X value (bottom right point) * @param maxY upper Y value (bottom right point) */ @SuppressWarnings( "unchecked" ) public Rectangle2D getDataCoordinates( double minX, double minY, double maxX, double maxY ) { if ( minX > maxX || minY > maxY ) { throw new IllegalArgumentException( "min > max for X and/or Y" ); } Axis xAxis = chart.getXAxis(); Axis yAxis = chart.getYAxis(); double xStart = getXShift( xAxis, referenceNode ); double yStart = getYShift( yAxis, referenceNode ); double minDataX = xAxis.toNumericValue( xAxis.getValueForDisplay( minX - xStart ) ); double maxDataX = xAxis.toNumericValue( xAxis.getValueForDisplay( maxX - xStart ) ); //The "low" Y data value is actually at the maxY graphical location as Y graphical axis gets //larger as you go down on the screen. double minDataY = yAxis.toNumericValue( yAxis.getValueForDisplay( maxY - yStart ) ); double maxDataY = yAxis.toNumericValue( yAxis.getValueForDisplay( minY - yStart ) ); return new Rectangle2D( minDataX, minDataY, maxDataX - minDataX, maxDataY - minDataY ); }
/** * Given graphical coordinates in the reference's coordinate system, returns x and y axis value as * a point via the {@link Axis#getValueForDisplay(double)} and {@link Axis#toNumericValue(Object)} * methods. */ @SuppressWarnings( "unchecked" ) public Point2D getDataCoordinates( double x, double y ) { Axis xAxis = chart.getXAxis(); Axis yAxis = chart.getYAxis(); double xStart = getXShift( xAxis, referenceNode ); double yStart = getYShift( yAxis, referenceNode ); return new Point2D( xAxis.toNumericValue( xAxis.getValueForDisplay( x - xStart ) ), yAxis.toNumericValue( yAxis.getValueForDisplay( y - yStart ) ) ); }