示例#1
0
  /**
   * Handle the case where a plot implements the {@link Zoomable} interface.
   *
   * @param zoomable the zoomable plot.
   * @param e the mouse wheel event.
   */
  private void handleZoomable(Zoomable zoomable, MouseWheelEvent e) {
    // don't zoom unless the mouse pointer is in the plot's data area
    ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
    PlotRenderingInfo pinfo = info.getPlotInfo();
    Point2D p = this.chartPanel.translateScreenToJava2D(e.getPoint());
    if (!pinfo.getDataArea().contains(p)) {
      return;
    }

    Plot plot = (Plot) zoomable;
    // do not notify while zooming each axis
    boolean notifyState = plot.isNotify();
    plot.setNotify(false);
    int clicks = e.getWheelRotation();
    double zf = 1.0 + this.zoomFactor;
    if (clicks < 0) {
      zf = 1.0 / zf;
    }
    if (chartPanel.isDomainZoomable()) {
      zoomable.zoomDomainAxes(zf, pinfo, p, true);
    }
    if (chartPanel.isRangeZoomable()) {
      zoomable.zoomRangeAxes(zf, pinfo, p, true);
    }
    plot.setNotify(notifyState); // this generates the change event too
  }
 /**
  * Returns the data area (the area inside the axes) for the plot or subplot.
  *
  * @param point the selection point (for subplot selection).
  * @return The data area.
  */
 public Rectangle2D findDataArea(Point2D point) {
   PlotRenderingInfo plotInfo = this.info.getPlotInfo();
   Rectangle2D result;
   if (plotInfo.getSubplotCount() == 0) {
     result = plotInfo.getDataArea();
   } else {
     int subplotIndex = plotInfo.getSubplotIndex(point);
     if (subplotIndex == -1) {
       return null;
     }
     result = plotInfo.getSubplotInfo(subplotIndex).getDataArea();
   }
   return result;
 }