Skip to content

Commit 7e26b3c

Browse files
authored
Merge pull request #2732 from ControlSystemStudio/FixLinearTicks
CSSTUDIO-1133 Change condition when selecting distance between major ticks in `LinearTicks.selectNiceStep()`.
2 parents 12e032e + 4864949 commit 7e26b3c

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

app/rtplot/src/main/java/org/csstudio/javafx/rtplot/internal/LinearTicks.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,27 +254,25 @@ public static int determinePrecision(final double number)
254254
* A computed distance of 6.1 turns into 10.0, not 5.0.
255255
* @see #selectNiceStep(double)
256256
*/
257-
final private static double[] NICE_STEPS = { 10.0, 5.0, 2.0, 1.0 },
258-
NICE_THRESHOLDS = { 6.0, 3.0, 1.2, 0.0 };
257+
final private static double[] NICE_STEPS = { 1.0, 2.0, 5.0, 10.0 };
259258

260259
/** To a human viewer, tick distances of 5.0 are easier to see
261260
* than for example 7.
262261
*
263262
* <p>This method tries to adjust a computed tick distance
264263
* to one that is hopefully 'nicer'
265264
*
266-
* @param distance Original step distance
265+
* @param min_distance Original step distance
267266
* @return
268267
*/
269-
public static double selectNiceStep(final double distance)
268+
public static double selectNiceStep(final double min_distance)
270269
{
271-
final double log = Math.log10(distance);
270+
final double log = Math.log10(min_distance);
272271
final double order_of_magnitude = Math.pow(10, Math.floor(log));
273-
final double step = distance / order_of_magnitude;
274272
for (int i=0; i<NICE_STEPS.length; ++i)
275-
if (step >= NICE_THRESHOLDS[i])
273+
if (NICE_STEPS[i] * order_of_magnitude >= min_distance)
276274
return NICE_STEPS[i] * order_of_magnitude;
277-
return step * order_of_magnitude;
275+
return min_distance;
278276
}
279277

280278
/** Create decimal format

app/rtplot/src/main/java/org/csstudio/javafx/rtplot/internal/Ticks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public abstract class Ticks<XTYPE>
2525
protected volatile List<MinorTick<XTYPE>> minor_ticks = Collections.emptyList();
2626

2727
/** How many percent of the available space should be used for labels? */
28-
final public static int FILL_PERCENTAGE = 60;
28+
final public static int FILL_PERCENTAGE = 70;
2929

3030
/** Used to adjust a range to a meaningful range for the chosen scale.
3131
* @param low Desired low limit of the axis range.

app/rtplot/src/test/java/org/csstudio/javafx/rtplot/LogTicksTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void testLogTicks()
4646
System.out.println("Ticks for " + start + " .. " + end + ":");
4747
text = ticks2text(ticks);
4848
System.out.println(text);
49-
assertThat(text, equalTo("'1.1E3' '1.2E3' "));
49+
assertThat(text, equalTo("'1.05E3' '1.10E3' '1.15E3' '1.20E3' "));
5050

5151
}
5252
}

app/rtplot/src/test/java/org/csstudio/javafx/rtplot/TicksTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void testNiceDistance()
122122
assertThat(LinearTicks.selectNiceStep(5.0*order_of_magnitude), equalTo(5.0*order_of_magnitude));
123123
assertThat(LinearTicks.selectNiceStep(4.0*order_of_magnitude), equalTo(5.0*order_of_magnitude));
124124
assertThat(LinearTicks.selectNiceStep(3.0*order_of_magnitude), equalTo(5.0*order_of_magnitude));
125-
assertThat(LinearTicks.selectNiceStep(2.01*order_of_magnitude), equalTo(2.0*order_of_magnitude));
125+
assertThat(LinearTicks.selectNiceStep(1.99*order_of_magnitude), equalTo(2.0*order_of_magnitude));
126126
assertThat(LinearTicks.selectNiceStep(1.5*order_of_magnitude), equalTo(2.0*order_of_magnitude));
127127
}
128128
}

app/rtplot/src/test/java/org/csstudio/javafx/rtplot/internal/LinearTicksTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void testNiceDistance()
4242
assertThat(LinearTicks.selectNiceStep(5.0*order_of_magnitude), equalTo(5.0*order_of_magnitude));
4343
assertThat(LinearTicks.selectNiceStep(4.0*order_of_magnitude), equalTo(5.0*order_of_magnitude));
4444
assertThat(LinearTicks.selectNiceStep(3.0*order_of_magnitude), equalTo(5.0*order_of_magnitude));
45-
assertThat(LinearTicks.selectNiceStep(2.01*order_of_magnitude), equalTo(2.0*order_of_magnitude));
45+
assertThat(LinearTicks.selectNiceStep(1.99*order_of_magnitude), equalTo(2.0*order_of_magnitude));
4646
assertThat(LinearTicks.selectNiceStep(1.5*order_of_magnitude), equalTo(2.0*order_of_magnitude));
4747
}
4848
}

0 commit comments

Comments
 (0)