From e435b72d1f375d5b76db830cd8f18bb5f9b45294 Mon Sep 17 00:00:00 2001 From: richardxs Date: Thu, 18 Nov 2021 11:24:46 -0600 Subject: [PATCH 1/4] Solution to issue #215 --- src/main/java/org/jfree/chart/axis/LogAxis.java | 9 +++++++-- .../java/org/jfree/chart/axis/LogAxisTest.java | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jfree/chart/axis/LogAxis.java b/src/main/java/org/jfree/chart/axis/LogAxis.java index 57b545773..c8a6d8ef0 100644 --- a/src/main/java/org/jfree/chart/axis/LogAxis.java +++ b/src/main/java/org/jfree/chart/axis/LogAxis.java @@ -302,8 +302,13 @@ 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) + { + double returnVal = smallestValue; + if (value > 0.0) { + returnVal = Math.log(value) / this.baseLog; + } + return returnVal; } /** diff --git a/src/test/java/org/jfree/chart/axis/LogAxisTest.java b/src/test/java/org/jfree/chart/axis/LogAxisTest.java index 7a2cdd589..0a22da1c2 100644 --- a/src/test/java/org/jfree/chart/axis/LogAxisTest.java +++ b/src/test/java/org/jfree/chart/axis/LogAxisTest.java @@ -274,4 +274,18 @@ public void testRefreshTicksWithZeroTickUnit() { Rectangle2D area = new Rectangle2D.Double(0.0, 0.0, 200, 100); axis.refreshTicks(g2, state, area, RectangleEdge.TOP); } + + /** + * 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); + } } From 663af5d4b785ededa5e311318d72a0bc04c9285c Mon Sep 17 00:00:00 2001 From: richardxs Date: Sun, 21 Nov 2021 14:48:57 -0600 Subject: [PATCH 2/4] Solution to issue #215 --- src/main/java/org/jfree/chart/axis/LogAxis.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jfree/chart/axis/LogAxis.java b/src/main/java/org/jfree/chart/axis/LogAxis.java index c8a6d8ef0..a0402982c 100644 --- a/src/main/java/org/jfree/chart/axis/LogAxis.java +++ b/src/main/java/org/jfree/chart/axis/LogAxis.java @@ -532,7 +532,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); } @@ -576,7 +576,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); @@ -634,7 +634,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); From cb1e909586e712904f6fef829e52eedc4c51145d Mon Sep 17 00:00:00 2001 From: richardxs Date: Tue, 7 Dec 2021 13:35:48 -0600 Subject: [PATCH 3/4] Update javadoc --- src/main/java/org/jfree/chart/axis/LogAxis.java | 1 + src/test/java/org/jfree/chart/axis/LogAxisTest.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/jfree/chart/axis/LogAxis.java b/src/main/java/org/jfree/chart/axis/LogAxis.java index a0402982c..19eeff894 100644 --- a/src/main/java/org/jfree/chart/axis/LogAxis.java +++ b/src/main/java/org/jfree/chart/axis/LogAxis.java @@ -304,6 +304,7 @@ public void setNumberFormatOverride(NumberFormat formatter) { */ public double calculateLog(double value) { + // CS427 double returnVal = smallestValue; if (value > 0.0) { returnVal = Math.log(value) / this.baseLog; diff --git a/src/test/java/org/jfree/chart/axis/LogAxisTest.java b/src/test/java/org/jfree/chart/axis/LogAxisTest.java index 0a22da1c2..b8e72f083 100644 --- a/src/test/java/org/jfree/chart/axis/LogAxisTest.java +++ b/src/test/java/org/jfree/chart/axis/LogAxisTest.java @@ -276,7 +276,7 @@ public void testRefreshTicksWithZeroTickUnit() { } /** - * Test for fixing issue #215 + * CS 427: Test for fixing issue #215 i.e., Setting the lower limit of a LogAxis to zero creates a blank chart */ @Test From 9474425174c5e17f59473a73ee9590ac3c73663b Mon Sep 17 00:00:00 2001 From: richardxs Date: Wed, 8 Dec 2021 00:33:40 -0600 Subject: [PATCH 4/4] Update javadoc --- src/main/java/org/jfree/chart/axis/LogAxis.java | 2 +- src/test/java/org/jfree/chart/axis/LogAxisTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jfree/chart/axis/LogAxis.java b/src/main/java/org/jfree/chart/axis/LogAxis.java index 19eeff894..3dac5ca4f 100644 --- a/src/main/java/org/jfree/chart/axis/LogAxis.java +++ b/src/main/java/org/jfree/chart/axis/LogAxis.java @@ -304,7 +304,7 @@ public void setNumberFormatOverride(NumberFormat formatter) { */ public double calculateLog(double value) { - // CS427 + // CS427: Issue link: https://github.com/jfree/jfreechart/issues/215 double returnVal = smallestValue; if (value > 0.0) { returnVal = Math.log(value) / this.baseLog; diff --git a/src/test/java/org/jfree/chart/axis/LogAxisTest.java b/src/test/java/org/jfree/chart/axis/LogAxisTest.java index b8e72f083..d8b350160 100644 --- a/src/test/java/org/jfree/chart/axis/LogAxisTest.java +++ b/src/test/java/org/jfree/chart/axis/LogAxisTest.java @@ -276,7 +276,8 @@ public void testRefreshTicksWithZeroTickUnit() { } /** - * CS 427: Test for fixing issue #215 + * 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