diff --git a/src/main/java/org/jfree/chart/axis/LogAxis.java b/src/main/java/org/jfree/chart/axis/LogAxis.java index 57b545773..3dac5ca4f 100644 --- a/src/main/java/org/jfree/chart/axis/LogAxis.java +++ b/src/main/java/org/jfree/chart/axis/LogAxis.java @@ -302,8 +302,14 @@ public void setNumberFormatOverride(NumberFormat formatter) { * @see #calculateValue(double) * @see #getBase() */ - public double calculateLog(double value) { - return Math.log(value) / this.baseLog; + public double calculateLog(double value) + { + // CS427: Issue link: https://github.com/jfree/jfreechart/issues/215 + double returnVal = smallestValue; + if (value > 0.0) { + returnVal = Math.log(value) / this.baseLog; + } + return returnVal; } /** @@ -527,7 +533,7 @@ public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, @Override public List refreshTicks(Graphics2D g2, AxisState state, Rectangle2D dataArea, RectangleEdge edge) { - List result = new java.util.ArrayList(); + List result = new ArrayList(); if (RectangleEdge.isTopOrBottom(edge)) { result = refreshTicksHorizontal(g2, dataArea, edge); } @@ -571,7 +577,7 @@ protected List refreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, double start = index * unit; double end = calculateLog(getUpperBound()); double current = start; - boolean hasTicks = (this.tickUnit.getSize() > 0.0) + boolean hasTicks = this.tickUnit.getSize() > 0.0 && !Double.isInfinite(start); while (hasTicks && current <= end) { double v = calculateValueNoINF(current); @@ -629,7 +635,7 @@ protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, double start = index * unit; double end = calculateLog(getUpperBound()); double current = start; - boolean hasTicks = (this.tickUnit.getSize() > 0.0) + boolean hasTicks = this.tickUnit.getSize() > 0.0 && !Double.isInfinite(start); while (hasTicks && current <= end) { double v = calculateValueNoINF(current); diff --git a/src/test/java/org/jfree/chart/axis/LogAxisTest.java b/src/test/java/org/jfree/chart/axis/LogAxisTest.java index 7a2cdd589..d8b350160 100644 --- a/src/test/java/org/jfree/chart/axis/LogAxisTest.java +++ b/src/test/java/org/jfree/chart/axis/LogAxisTest.java @@ -274,4 +274,19 @@ public void testRefreshTicksWithZeroTickUnit() { Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, 200, 100); axis.refreshTicks(g2, state, area, RectangleEdge.TOP); } + + /** + * CS427: Issue link: https://github.com/jfree/jfreechart/issues/215 + * Test for fixing issue #215 + i.e., Setting the lower limit of a LogAxis to zero creates a blank chart + */ + @Test + public void testSetLowerBoundZero() { + LogAxis axis = new LogAxis("X"); + axis.setRange(0.0, 10.0); + axis.setLowerBound(0.0); + assertEquals(1e-100, axis.getLowerBound(), EPSILON); + assertEquals(10.0, axis.getUpperBound(), EPSILON); + assertEquals(1.0E-100, axis.getSmallestValue(), EPSILON); + } }