/** * Returns the Y axis area in the reference's coordinate space. */ public Rectangle2D getYAxisArea() { return getComponentArea( chart.getYAxis() ); }
/** * Returns the plot area in the reference's coordinate space. */ public Rectangle2D getPlotArea() { Axis<?> xAxis = chart.getXAxis(); Axis<?> yAxis = chart.getYAxis(); double xStart = getXShift( xAxis, referenceNode ); double yStart = getYShift( yAxis, referenceNode ); //If the direct method to get the width (which is based on its Node dimensions) is not found to //be appropriate, an alternative method is commented. // double width = xAxis.getDisplayPosition( xAxis.toRealValue( xAxis.getUpperBound() ) ); double width = xAxis.getWidth(); // double height = yAxis.getDisplayPosition( yAxis.toRealValue( yAxis.getLowerBound() ) ); double height = yAxis.getHeight(); return new Rectangle2D( xStart, yStart, width, height ); }
public ChartPanManager(XYChart<?, ?> chart ) { handlerManager = new EventHandlerManager( chart ); xAxis = (ValueAxis<?>) chart.getXAxis(); yAxis = (ValueAxis<?>) chart.getYAxis(); chartInfo = new XYChartInfo( chart, chart ); handlerManager.addEventHandler( false, MouseEvent.DRAG_DETECTED, new EventHandler<MouseEvent>() { @Override public void handle( MouseEvent mouseEvent ) { if ( passesFilter( mouseEvent ) ) startDrag( mouseEvent ); } } ); handlerManager.addEventHandler( false, MouseEvent.MOUSE_DRAGGED, new EventHandler<MouseEvent>() { @Override public void handle( MouseEvent mouseEvent ) { drag( mouseEvent ); } } ); handlerManager.addEventHandler( false, MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() { @Override public void handle( MouseEvent mouseEvent ) { release(); } } ); }
/** * 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 ) ) ); }
/** * 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 ); }
@Override public void handle( MouseEvent event ) { if ( event.getClickCount() == 2 && event.getButton() == MouseButton.PRIMARY ) { double x = event.getX(); double y = event.getY(); if ( !chartInfo.getXAxisArea().contains( x, y ) ) chartInfo.getChart().getYAxis().setAutoRanging( true ); if ( !chartInfo.getYAxisArea().contains( x, y ) ) chartInfo.getChart().getXAxis().setAutoRanging( true ); } } };
this.selectRect = selectRect; this.xAxis = (ValueAxis<?>) chart.getXAxis(); this.yAxis = (ValueAxis<?>) chart.getYAxis(); chartInfo = new XYChartInfo( chart, chartPane );