Axis Ranging - How to listen to VisibleRange Changes
It is possible to subscribe to listening to the setVisibleRange(IRange visibleRange) changes using a VisibleRangeChangeListener:
final NumericAxis axis = new NumericAxis(getContext());
axis.setVisibleRangeChangeListener(new VisibleRangeChangeListener() {
@Override
public void onVisibleRangeChanged(IAxisCore axis, IRange oldRange, IRange newRange, boolean isAnimating) {
// TODO handle range changes here
}
});
Note
You can differentiate between changes that were part of an animation by checking the isAnimating parameter. For example, an animated zoom to extents operation will fire the callback many times with isAnimating = true
, then once at the end with isAnimating = false
.
The most typical use for this callback is to perform some kind of operation when the setVisibleRange(IRange visibleRange) changes, such as updating UI.
It is also possible to use this callback to restrict the VisibleRange in some way, e.g set a bounded or clipped range onto Axis.VisibleRange when the range changes outside of a desired area.
Note
We've already used this technique in Advanced VisibleRange Clipping