CustomLogarithmicAxis extends LogarithmicAxis { List refreshTicks(RectangleEdge edge, int mode) { List ticks = new java.util.ArrayList(); double upperBoundVal = 0.0; double lowerBoundVal = 0.0; boolean NEGATIVE = false; if (getRange().getLowerBound() >= 0.0 && getRange().getUpperBound() >= 0.0) { upperBoundVal = getRange().getUpperBound(); lowerBoundVal = getRange().getLowerBound(); if (getRange().getLowerBound() == 0.0) { lowerBoundVal = SMALL_LOG_VALUE; } } else if (getRange().getLowerBound() < 0.0 && getRange().getUpperBound() < 0.0) { upperBoundVal = -1.0 * getRange().getLowerBound(); lowerBoundVal = -1.0 * getRange().getUpperBound(); NEGATIVE = true; } final int iEndCount = (int) Math.floor(Math.log10(upperBoundVal)); int iBegCount; if (lowerBoundVal == SMALL_LOG_VALUE) { iBegCount = iEndCount - 3; } else { iBegCount = (int) Math.floor(Math.log10(lowerBoundVal)); } String tickLabel; for (int i = iBegCount; i <= iEndCount; i++) { int jEndCount = 9; if (i == iEndCount) { if (iEndCount == 0) { jEndCount = (int) Math.abs(Math.floor(upperBoundVal)); } else { jEndCount = (int) (upperBoundVal / Math.pow(10.0, iEndCount)); } } for (int j = 0; j < jEndCount; j++) { final boolean displayTickLabel = (j == 0) || (iEndCount - iBegCount < 2); double tickVal = Math.pow(10, i) + (Math.pow(10, i) * j); if (NEGATIVE) { tickVal *= -1.0; } if (displayTickLabel) { tickLabel = NumberFormat.getNumberInstance().format(tickVal); } else { tickLabel = ""; } if (tickValInRange(lowerBoundVal, upperBoundVal, tickVal, NEGATIVE)) { switch (mode) { case VERTICAL: if (NEGATIVE) { addVerticalTicks(edge, ticks, -upperBoundVal, tickLabel, tickVal); } else { addVerticalTicks(edge, ticks, lowerBoundVal, tickLabel, tickVal); } break; case HORIZONTAL: if (NEGATIVE) { addHorizontalTicks(edge, ticks, -upperBoundVal, tickLabel, tickVal); } else { addHorizontalTicks(edge, ticks, lowerBoundVal, tickLabel, tickVal); } break; default: throw new IllegalStateException("Illegal axis orientation - cannot add ticks"); } } } } return ticks; } CustomLogarithmicAxis(String label);   }
@Test public void testRefreshTicks() throws Exception { CustomLogarithmicAxis testAxis = new CustomLogarithmicAxis("testAxis"); testAxis.setRange(0.3, 300.0); List ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL); assertNotNull(ticks); assertEquals(28, ticks.size()); assertEquals("", ((NumberTick) ticks.get(0)).getText()); assertEquals("", ((NumberTick) ticks.get(1)).getText()); assertEquals("1", ((NumberTick) ticks.get(7)).getText()); assertEquals("", ((NumberTick) ticks.get(9)).getText()); assertEquals("10", ((NumberTick) ticks.get(16)).getText()); assertEquals("", ((NumberTick) ticks.get(18)).getText()); assertEquals("100", ((NumberTick) ticks.get(25)).getText()); assertEquals("", ((NumberTick) ticks.get(26)).getText()); testAxis.setRange(0.3, 30.0); ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL); assertNotNull(ticks); assertEquals(19, ticks.size()); assertEquals("", ((NumberTick) ticks.get(0)).getText()); assertEquals("", ((NumberTick) ticks.get(1)).getText()); assertEquals("1", ((NumberTick) ticks.get(7)).getText()); assertEquals("", ((NumberTick) ticks.get(9)).getText()); assertEquals("10", ((NumberTick) ticks.get(16)).getText()); assertEquals("", ((NumberTick) ticks.get(18)).getText()); testAxis.setRange(0.3, 3.0); ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL); assertNotNull(ticks); assertEquals(10, ticks.size()); assertEquals(0.3, ((NumberTick) ticks.get(0)).getValue(), 1.E-6); assertEquals(0.4, ((NumberTick) ticks.get(1)).getValue(), 1.E-6); assertEquals(0.5, ((NumberTick) ticks.get(2)).getValue(), 1.E-6); assertEquals(0.6, ((NumberTick) ticks.get(3)).getValue(), 1.E-6); assertEquals(0.7, ((NumberTick) ticks.get(4)).getValue(), 1.E-6); assertEquals(0.8, ((NumberTick) ticks.get(5)).getValue(), 1.E-6); assertEquals(0.9, ((NumberTick) ticks.get(6)).getValue(), 1.E-6); assertEquals("1", ((NumberTick) ticks.get(7)).getText()); assertEquals("2", ((NumberTick) ticks.get(8)).getText()); assertEquals("3", ((NumberTick) ticks.get(9)).getText()); testAxis.setRange(0.3, 0.8); ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL); assertNotNull(ticks); assertEquals(6, ticks.size()); assertEquals(0.3, ((NumberTick) ticks.get(0)).getValue(), 1.E-6); assertEquals(0.4, ((NumberTick) ticks.get(1)).getValue(), 1.E-6); assertEquals(0.5, ((NumberTick) ticks.get(2)).getValue(), 1.E-6); assertEquals(0.6, ((NumberTick) ticks.get(3)).getValue(), 1.E-6); assertEquals(0.7, ((NumberTick) ticks.get(4)).getValue(), 1.E-6); assertEquals(0.8, ((NumberTick) ticks.get(5)).getValue(), 1.E-6); }
@Test public void testRefreshTicksForNegativeAxisRange() throws Exception { CustomLogarithmicAxis testAxis = new CustomLogarithmicAxis("testAxis"); testAxis.setRange(-300, -3); List ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL); assertNotNull(ticks); assertEquals(19, ticks.size()); assertEquals("", ((NumberTick) ticks.get(0)).getText()); assertEquals("", ((NumberTick) ticks.get(1)).getText()); assertEquals("-10", ((NumberTick) ticks.get(7)).getText()); assertEquals("", ((NumberTick) ticks.get(9)).getText()); assertEquals("-100", ((NumberTick) ticks.get(16)).getText()); assertEquals("", ((NumberTick) ticks.get(18)).getText()); }
@Test public void testRefreshTicksForInvalidAxisRange() throws Exception { CustomLogarithmicAxis testAxis = new CustomLogarithmicAxis("testAxis"); try { testAxis.setRange(30, 3); } catch (IllegalArgumentException expected) { assertEquals("Range(double, double): require lower (30.0) <= upper (3.0).", expected.getMessage()); } testAxis.setRange(-30, 30); List ticks = testAxis.refreshTicks(RectangleEdge.TOP, CustomLogarithmicAxis.HORIZONTAL); assertNotNull(ticks); assertEquals(0, ticks.size()); }
@Test public void testRefreshTicksVerticalAxisOrientation() throws Exception { CustomLogarithmicAxis testAxis = new CustomLogarithmicAxis("testAxis"); testAxis.setRange(-300, -3); List ticks = testAxis.refreshTicks(RectangleEdge.LEFT, CustomLogarithmicAxis.VERTICAL); assertNotNull(ticks); assertEquals(19, ticks.size()); assertEquals("", ((NumberTick) ticks.get(0)).getText()); assertEquals("", ((NumberTick) ticks.get(1)).getText()); assertEquals("-10", ((NumberTick) ticks.get(7)).getText()); assertEquals("", ((NumberTick) ticks.get(9)).getText()); assertEquals("-100", ((NumberTick) ticks.get(16)).getText()); assertEquals("", ((NumberTick) ticks.get(18)).getText()); }