Last active
February 24, 2019 07:19
-
-
Save jvkersch/76d050b8cf8623ab47d537bc6a640e1f to your computer and use it in GitHub Desktop.
Different behaviors in overlay vs underlay when it comes to updating. Create a 1D selection by right-dragging on the plot, and try dragging the selection back and forth. This works as expected when the selection is drawn using an overlay, but not when it is drawn as an underlay.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| from chaco.api import ArrayPlotData, Plot, VPlotContainer | |
| from chaco.tools.api import RangeSelection, RangeSelectionOverlay | |
| from enable.api import Component, ComponentEditor | |
| from traits.api import Enum, HasTraits, Instance | |
| from traitsui.api import UItem, View | |
| class A(HasTraits): | |
| plot = Instance(Component) | |
| which = Enum(["overlays", "underlays"]) | |
| view = View( | |
| UItem("which"), | |
| UItem("plot", editor=ComponentEditor()), | |
| ) | |
| def _create_plots(self): | |
| container = VPlotContainer(use_backbuffer=True) | |
| plot_data = ArrayPlotData( | |
| index=np.arange(1000), data=np.arange(1000), | |
| ) | |
| plot = Plot(plot_data) | |
| renderer = plot.plot(("index", "data"))[0] | |
| getattr(renderer, self.which).append( | |
| RangeSelectionOverlay(component=renderer) | |
| ) | |
| tool = RangeSelection(component=renderer) | |
| renderer.tools.append(tool) | |
| container.add(plot) | |
| return container | |
| def _which_changed(self): | |
| self.plot = self._create_plots() | |
| def _plot_default(self): | |
| return self._create_plots() | |
| if __name__ == '__main__': | |
| A().configure_traits() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment