Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution to issue #215 #245

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/main/java/org/jfree/chart/axis/LogAxis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/jfree/chart/axis/LogAxisTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}