Skip to content

Commit

Permalink
Merge pull request #3093 from ControlSystemStudio/plot_axis_ticks
Browse files Browse the repository at this point in the history
Fix XYPlot axis major tick mark hangup
  • Loading branch information
kasemir authored Jul 25, 2024
2 parents 7a0bca9 + e22ee1a commit 02ca91a
Showing 1 changed file with 33 additions and 23 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 @@ -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 02ca91a

Please sign in to comment.