Skip to content

Commit

Permalink
Fix XYPlot axis major tick mark hangup
Browse files Browse the repository at this point in the history
Create XYPlot.
Set width to 1530 pixels.
Set X axis range to min=3.0, max=3.0
There will be a warning about the invalid axis range, it gets adjusted
to some small range, but then the major tick mark computation gets
stuck, keeps adding tick marks for the same position until it runs out
of memory.

This update detects a stuck linear axis tick mark computation and moved
on.
  • Loading branch information
kasemir committed Jul 25, 2024
1 parent 7a0bca9 commit 22cf1e1
Showing 1 changed file with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014-2017 Oak Ridge National Laboratory.
* Copyright (c) 2014-2024 Oak Ridge National Laboratory.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -90,7 +90,7 @@ public void compute(Double low, Double high, final Graphics2D gc, final int scre
double newHigh = adjustedRange.getValue();

if (newLow != low || newHigh != high) {
logger.log(Level.WARNING, "Invalid value range for a linear scale {0,number,#.###############E0} ... {1,number,#.###############E0}. Adjusting the range to {2,number,#.###############E0} ... {3,number,#.###############E0}.",
logger.log(Level.WARNING, " for a linear scale {0,number,#.###############E0} ... {1,number,#.###############E0}. Adjusting the range to {2,number,#.###############E0} ... {3,number,#.###############E0}.",
new Object[] {low, high, newLow, newHigh });
high = newHigh;
low = newLow;
Expand Down Expand Up @@ -163,35 +163,45 @@ public void compute(Double low, Double high, final Graphics2D gc, final int scre
{
double start = Math.ceil(low / distance) * distance;

// Set prev to one before the start
// and loop until high + distance
// to get minor marks before and after the major tick mark range
double prev = start - distance;
for (double value = start; value < high + distance; value += distance)
{
// Compute major tick marks
if (value >= low && value <= high)
major_ticks.add(new MajorTick<>(value, format(value)));

// Fill major tick marks with minor ticks
for (int i=1; i<minor; ++i)
{
final double min_val = prev + ((value - prev)*i)/minor;
if (min_val <= low || min_val >= high)
continue;
minor_ticks.add(new MinorTick<>(min_val));
}
prev = value;
}
// Set prev to one before the start
// and loop until high + distance
// to get minor marks before and after the major tick mark range
double prev = start - distance;
for (double value = start; value < high + distance; value += distance)
{
if (prev == value)
{
logger.log(Level.WARNING, "Major ticks for axis " + start + " ... " + high + " do not advance from " + value);
break;
}
// Compute major tick marks
if (value >= low && value <= high)
major_ticks.add(new MajorTick<>(value, format(value)));

// Fill major tick marks with minor ticks
for (int i=1; i<minor; ++i)
{
final double min_val = prev + ((value - prev)*i)/minor;
if (min_val <= low || min_val >= high)
continue;
minor_ticks.add(new MinorTick<>(min_val));
}
prev = value;
}
}
else
{
distance = -distance;
double start = Math.floor(low / distance) * distance;
distance = -distance;
double start = Math.floor(low / distance) * distance;

double prev = start - distance;
for (double value = start; value > high + distance; value += distance)
{
if (prev == value)
{
logger.log(Level.WARNING, "Major ticks for axis " + start + " ... " + high + " do not advance from " + value);
break;
}
// Compute major tick marks
if (value <= low && value >= high)
major_ticks.add(new MajorTick<>(value, format(value)));
Expand Down

0 comments on commit 22cf1e1

Please sign in to comment.