@Test public void testOriginFixedMode() throws Exception { plot.addSeries(series1, new LineAndPointFormatter()); plot.centerOnDomainOrigin(5, 2, BoundaryMode.FIXED); plot.calculateMinMaxVals(); assertEquals(3.0, plot.getCalculatedMinX()); assertEquals(7.0, plot.getCalculatedMaxX()); }
@Test public void testConfigure() throws Exception { HashMap<String, String> params = new HashMap<String, String>(); String param1 = "this is a test."; String param2 = Plot.RenderMode.USE_BACKGROUND_THREAD.toString(); String param3 = "#FF0000"; params.put("title", param1); params.put("renderMode", param2); params.put("backgroundPaint.color", param3); params.put("graphWidget.domainTickLabelPaint.color", param3); Configurator.configure(RuntimeEnvironment.application, plot, params); assertEquals(param1, plot.getTitle()); assertEquals(Plot.RenderMode.USE_BACKGROUND_THREAD, plot.getRenderMode()); assertEquals(Color.parseColor(param3), plot.getBackgroundPaint().getColor()); assertEquals( Color.parseColor(param3), plot.getGraphWidget().getDomainTickLabelPaint().getColor()); }
@Test public void testOriginAutoMode() throws Exception { plot.addSeries(series1, new LineAndPointFormatter()); plot.centerOnDomainOrigin(5); plot.calculateMinMaxVals(); assertEquals(10.0, plot.getCalculatedMaxX()); // symmetry is @ 10, not 9 assertEquals(0.0, plot.getCalculatedMinX()); plot.centerOnRangeOrigin(50); plot.calculateMinMaxVals(); assertEquals(100.0, plot.getCalculatedMaxY()); assertEquals(0.0, plot.getCalculatedMinY()); }
@Test public void testOnRender() throws Exception { AdvancedLineAndPointRenderer.Formatter formatter = spy(new AdvancedLineAndPointRenderer.Formatter()); AdvancedLineAndPointRenderer renderer = formatter.getRendererInstance(xyPlot); doReturn(renderer.getClass()).when(formatter).getRendererClass(); doReturn(renderer).when(formatter).getRendererInstance(any(XYPlot.class)); XYSeries s = new SimpleXYSeries(SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Series1", 1, 2, 3, 4); xyPlot.addSeries(s, formatter); renderer.onRender(canvas, plotArea, s, formatter, renderStack); }
@Test public void testOriginShrinkMode() throws Exception { plot.addSeries(series1, new LineAndPointFormatter()); plot.centerOnDomainOrigin(5, null, BoundaryMode.SHRINNK); plot.calculateMinMaxVals(); assertEquals(0.0, plot.getCalculatedMinX()); assertEquals(10.0, plot.getCalculatedMaxX()); // update with more extreme values...nothing should change in shrink mode: series1.setModel(numList2, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); assertEquals(0.0, plot.getCalculatedMinX()); assertEquals(10.0, plot.getCalculatedMaxX()); }
@Test public void testOriginGrowMode() throws Exception { plot.addSeries(series1, new LineAndPointFormatter()); plot.centerOnDomainOrigin(5, null, BoundaryMode.GROW); plot.calculateMinMaxVals(); assertEquals(0.0, plot.getCalculatedMinX()); assertEquals(10.0, plot.getCalculatedMaxX()); // introduce a larger domain set. boundaries should change series1.setModel(numList2, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); assertEquals(-1.0, plot.getCalculatedMinX()); assertEquals(11.0, plot.getCalculatedMaxX()); // revert series model back to the previous set. boundaries should remain the same series1.setModel(numList1, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); assertEquals(-1.0, plot.getCalculatedMinX()); assertEquals(11.0, plot.getCalculatedMaxX()); }
@Test public void testSetRangeTopBottomMinMax() throws Exception { plot.addSeries(series1, new LineAndPointFormatter()); plot.calculateMinMaxVals(); // default to auto so check them assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); plot.setRangeTopMax(110); plot.setRangeBottomMin(-50); plot.calculateMinMaxVals(); // same values. assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); series1.setModel(numList2, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // on Limits assertEquals(-50, plot.getCalculatedMinY()); assertEquals(110, plot.getCalculatedMaxY()); plot.setRangeTopMax(null); plot.setRangeBottomMin(null); plot.calculateMinMaxVals(); // back to full assertEquals(-100, plot.getCalculatedMinY()); assertEquals(200, plot.getCalculatedMaxY()); // now the Min plot.setRangeTopMin(150); plot.setRangeBottomMax(-60); plot.calculateMinMaxVals(); // still to full assertEquals(-100, plot.getCalculatedMinY()); assertEquals(200, plot.getCalculatedMaxY()); // small list series1.setModel(numList1, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // on Limits assertEquals(-60, plot.getCalculatedMinY()); assertEquals(150, plot.getCalculatedMaxY()); // now off again plot.setRangeTopMin(null); plot.setRangeBottomMax(null); plot.calculateMinMaxVals(); // small values. assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); }
@Test public void testSetDomainRightMinMax() throws Exception { plot.addSeries(series1, new LineAndPointFormatter()); plot.calculateMinMaxVals(); // default to auto so check them assertEquals(0, plot.getCalculatedMinX()); assertEquals(9, plot.getCalculatedMaxX()); plot.setDomainRightMax(10); plot.calculateMinMaxVals(); // same values. assertEquals(0, plot.getCalculatedMinX()); assertEquals(9, plot.getCalculatedMaxX()); series1.setModel(numList2, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // on RightMax assertEquals(0, plot.getCalculatedMinX()); assertEquals(10, plot.getCalculatedMaxX()); plot.setDomainRightMax(null); plot.calculateMinMaxVals(); // back to full assertEquals(0, plot.getCalculatedMinX()); assertEquals(11, plot.getCalculatedMaxX()); // now the RightMin plot.setDomainRightMin(10); plot.calculateMinMaxVals(); // still to full assertEquals(0, plot.getCalculatedMinX()); assertEquals(11, plot.getCalculatedMaxX()); // small list series1.setModel(numList1, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // on RightMin assertEquals(0, plot.getCalculatedMinX()); assertEquals(10, plot.getCalculatedMaxX()); // now off again plot.setDomainRightMin(null); plot.calculateMinMaxVals(); // small values. assertEquals(0, plot.getCalculatedMinX()); assertEquals(9, plot.getCalculatedMaxX()); }
@Test public void testsetRangeBoundaries() throws Exception { plot.addSeries(series1, new LineAndPointFormatter()); plot.calculateMinMaxVals(); // default to auto so check them assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); plot.setRangeBoundaries(5, BoundaryMode.FIXED, 80, BoundaryMode.FIXED); plot.calculateMinMaxVals(); // fixed assertEquals(5, plot.getCalculatedMinY()); assertEquals(80, plot.getCalculatedMaxY()); // back to auto plot.setRangeBoundaries(2, BoundaryMode.AUTO, 8, BoundaryMode.AUTO); plot.calculateMinMaxVals(); // check again assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); // try grow plot.setRangeBoundaries(2, BoundaryMode.GROW, 8, BoundaryMode.GROW); plot.calculateMinMaxVals(); // check inital assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); // update with more extreme values... series1.setModel(numList2, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // after growing assertEquals(-100, plot.getCalculatedMinY()); assertEquals(200, plot.getCalculatedMaxY()); // back to previous series1.setModel(numList1, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // should not of changed. assertEquals(-100, plot.getCalculatedMinY()); assertEquals(200, plot.getCalculatedMaxY()); // back to big series1.setModel(numList2, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.setRangeBoundaries(2, BoundaryMode.SHRINNK, 8, BoundaryMode.SHRINNK); plot.calculateMinMaxVals(); // check inital assertEquals(-100, plot.getCalculatedMinY()); assertEquals(200, plot.getCalculatedMaxY()); // now small series1.setModel(numList1, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // after shrinking assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); // back to previous series1.setModel(numList2, SimpleXYSeries.ArrayFormat.Y_VALS_ONLY); plot.calculateMinMaxVals(); // should not of changed. assertEquals(0, plot.getCalculatedMinY()); assertEquals(100, plot.getCalculatedMaxY()); // back to auto plot.setRangeBoundaries(2, BoundaryMode.AUTO, 8, BoundaryMode.AUTO); plot.calculateMinMaxVals(); // should of changed. assertEquals(-100, plot.getCalculatedMinY()); assertEquals(200, plot.getCalculatedMaxY()); }