Skip to content

Commit

Permalink
Fix padded auto grow ranging
Browse files Browse the repository at this point in the history
With padding enabled auto grow ranging was broken (see #465, thanks to
@ennerf for reporting) because the padding was applied to the auto
range stored in the axis. Because of this the padding was added each
time the axis range was updated with grow ranging enabled.

This commit changes Abstract axis to directly use the result of
`autoRange()` instead of overwriting the autoRange property with it.

In XYChart the autoGrow code had to be changed to use the previous
computed range instead of the displayed range (which would include the
padding, leading to pileup).

fixes #465
  • Loading branch information
wirew0rm authored and RalphSteinhagen committed Sep 24, 2021
1 parent ee382ff commit ac46a36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions chartfx-chart/src/main/java/de/gsi/chart/XYChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ protected static void updateNumericAxis(final Axis axis, final List<DataSet> dat
return;
}
final boolean oldAutoState = axis.autoNotification().getAndSet(false);
final double oldMin = axis.getMin();
final double oldMax = axis.getMax();
final double oldMin = axis.getAutoRange().getMin();
final double oldMax = axis.getAutoRange().getMax();
final double oldLength = axis.getLength();

final boolean isHorizontal = axis.getSide().isHorizontal();
Expand Down Expand Up @@ -482,8 +482,8 @@ protected static void updateNumericAxis(final Axis axis, final List<DataSet> dat
}

if (axis.isAutoGrowRanging()) {
axis.getAutoRange().add(axis.getMin());
axis.getAutoRange().add(axis.getMax());
axis.getAutoRange().add(oldMin);
axis.getAutoRange().add(oldMax);
}

axis.getAutoRange().setAxisLength(axis.getLength() == 0 ? 1 : axis.getLength(), side);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,11 @@ public void invalidateCaches() {
@Override
public void invalidateRange(final List<Number> data) {
final boolean oldState = autoNotification().getAndSet(false);
getAutoRange().set(autoRange(getLength())); // derived axes may potentially pad and round limits
if (set(getAutoRange().getMin(), getAutoRange().getMax())) {
final AxisRange autoRange = autoRange(getLength()); // derived axes may potentially pad and round limits
if (set(autoRange.getMin(), autoRange.getMax())) {
getAutoRange().setAxisLength(getLength() == 0 ? 1 : getLength(), getSide());
setScale(getAutoRange().getScale());
//setScale(getAutoRange().getScale());
setScale(calculateNewScale(getLength(), autoRange.getMin(), autoRange.getMax()));
updateAxisLabelAndUnit();
// update cache in derived classes
updateCachedVariables();
Expand Down

0 comments on commit ac46a36

Please sign in to comment.