ZoomEstimator extends Estimator { protected double calculateZoom(SampledXYSeries series, RectRegion visibleBounds) { RectRegion seriesBounds = series.getBounds(); final double ratio = seriesBounds.getxRegion().ratio(visibleBounds.getxRegion()).doubleValue(); final double maxFactor = series.getMaxZoomFactor(); final double factor = Math.abs(Math.round(maxFactor / ratio)); return factor > 0 ? factor : 1; }  @Override void run(XYPlot plot, XYSeriesBundle sf);  }
@Test public void testCalculateZoom() { ZoomEstimator estimator = spy(new ZoomEstimator()); SampledXYSeries series = spy(new SampledXYSeries(TestUtils .generateXYSeries("test series", 1000), 2, 100)); series.resample(); when(xyPlot.getBounds()) .thenReturn(new RectRegion(0, 1000, 0, 1000)); assertEquals(series.getMaxZoomFactor(), estimator.calculateZoom(series, new RectRegion(0, 1000, 0, 1000))); assertEquals(1d, estimator.calculateZoom(series, new RectRegion(0, 1, 0, 1))); }