I have set the range of my y-axis to a fixed range
plot.y_axis.mapper.range.set(low_setting=ylim[0], high_setting=ylim[1])
Then, when the user uses the zoom tool, and clicks the reset zoom key, e.g. ESC, the y-axis is reset to tightbounds. But my application has no idea that this has happened and is not able to set the axis limits correctly again. I am using the BetterSelectingZoom tool.
I see that in the _reset_range_settings method of BetterSelectingZoom, the range high and low setting is reset to BetterSelectingZoom._orig_low_setting, which is set to 'auto', but this overrides the setting I have set in the range. The _orig_low_setting is retrieved from the range when created, and not updated later when the zooming is actually done. So if you change the limits of your plot after the zoom tool creation, you will experience this issue. It seems like _reset_range_settings is called after the revert on the SelectZoomState, thus overriding the prev attribute in the zoom state. Is this a bug?
To make it work, I can set the _orig_low_setting attribute in the zoom tool, or override the BetterSelectingZoom _reset_range_settings method, but I feel bad messing around with private Traits
Code sample:
plot = Plot(self._plot_data, padding=10, border_visible=True)
...
plot.bgcolor = 'white'
vertical_grid = PlotGrid(component=plot,
mapper=plot.index_mapper,
orientation='vertical',
line_color="gray",
line_style='dot',
use_draw_order=True)
horizontal_grid = PlotGrid(component=plot,
mapper=plot.value_mapper,
orientation='horizontal',
line_color="gray",
line_style='dot',
use_draw_order=True)
vertical_axis = PlotAxis(orientation='left',
mapper=plot.value_mapper,
use_draw_order=True, tick_label_font=font)
horizontal_axis = PlotAxis(orientation='bottom',
mapper=plot.index_mapper,
use_draw_order=True, tick_label_font=font)
horizontal_axis.tick_generator = XTickGenerator()
vertical_axis.tick_generator = YTickGenerator()
plot.underlays.append(vertical_grid)
plot.underlays.append(horizontal_grid)
# Have to add axes to overlays because
# we are backbuffering the main plot,
# and only overlays get to render in addition to the backbuffer.
plot.overlays.append(vertical_axis)
plot.overlays.append(horizontal_axis)
# Enable Pan and Zoom
pan = PanTool(plot, restrict_to_data=True,
constrain=False, constrain_direction="x",
constrain_key=None)
zoom = BetterSelectingZoom(component=plot,
tool_mode="box", restrict_domain=True,
always_on=True, drag_button="right",
x_min_zoom_factor=1, y_min_zoom_factor=1)
plot.tools.append(pan)
plot.overlays.append(zoom)
To fix the issue I did this
class NoRangeResetZoom(BetterSelectingZoom):
def _reset_range_settings(self):
pass
And
zoom = NoRangeResetZoom(component=plot,
tool_mode="box", restrict_domain=True,
always_on=True, drag_button="right",
x_min_zoom_factor=1, y_min_zoom_factor=1)
plot.overlays.append(zoom)