/** * Returns the index of the subplot that contains the specified * (x, y) point (the "source" point). The source point will usually * come from a mouse click on a {@link org.jfree.chart.ChartPanel}, * and this method is then used to determine the subplot that * contains the source point. * * @param source the source point (in Java2D space, <code>null</code> not * permitted). * * @return The subplot index (or -1 if no subplot contains * <code>source</code>). */ public int getSubplotIndex(Point2D source) { if (source == null) { throw new IllegalArgumentException("Null 'source' argument."); } int subplotCount = getSubplotCount(); for (int i = 0; i < subplotCount; i++) { PlotRenderingInfo info = getSubplotInfo(i); Rectangle2D area = info.getDataArea(); if (area.contains(source)) { return i; } } return -1; }
/** * Returns the index of the subplot that contains the specified * (x, y) point (the "source" point). The source point will usually * come from a mouse click on a {@link org.jfree.chart.ChartPanel}, * and this method is then used to determine the subplot that * contains the source point. * * @param source the source point (in Java2D space, {@code null} not * permitted). * * @return The subplot index (or -1 if no subplot contains {@code source}). */ public int getSubplotIndex(Point2D source) { Args.nullNotPermitted(source, "source"); int subplotCount = getSubplotCount(); for (int i = 0; i < subplotCount; i++) { PlotRenderingInfo info = getSubplotInfo(i); Rectangle2D area = info.getDataArea(); if (area.contains(source)) { return i; } } return -1; }
/** * Returns the data area (the area inside the axes) for the plot or subplot, * with the current scaling applied. * * @param x the x-coordinate (for subplot selection). * @param y the y-coordinate (for subplot selection). * * @return The scaled data area. */ public Rectangle2D getScreenDataArea(int x, int y) { PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D result; if (plotInfo.getSubplotCount() == 0) { result = getScreenDataArea(); } else { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D(new Point(x, y)); int subplotIndex = plotInfo.getSubplotIndex(selectOrigin); if (subplotIndex == -1) { return null; } result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea()); } return result; }
/** * Returns the data area (the area inside the axes) for the plot or subplot, * with the current scaling applied. * * @param x the x-coordinate (for subplot selection). * @param y the y-coordinate (for subplot selection). * * @return The scaled data area. */ public Rectangle2D getScreenDataArea(int x, int y) { PlotRenderingInfo plotInfo = this.info.getPlotInfo(); Rectangle2D result; if (plotInfo.getSubplotCount() == 0) { result = getScreenDataArea(); } else { // get the origin of the zoom selection in the Java2D space used for // drawing the chart (that is, before any scaling to fit the panel) Point2D selectOrigin = translateScreenToJava2D(new Point(x, y)); int subplotIndex = plotInfo.getSubplotIndex(selectOrigin); if (subplotIndex == -1) { return null; } result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea()); } return result; }