diff --git a/chaco/tests/test_plot.py b/chaco/tests/test_plot.py index 431859d3c..fc7b74ccc 100644 --- a/chaco/tests/test_plot.py +++ b/chaco/tests/test_plot.py @@ -2,9 +2,16 @@ from numpy import alltrue, arange, array +from enable.api import ComponentEditor +from enable.testing import EnableTestAssistant +from traits.api import HasTraits, Instance +from traits.etsconfig.api import ETSConfig +from traitsui.api import Item, View + # Chaco imports from chaco.api import ArrayPlotData, Plot, DataRange1D, PlotGraphicsContext from chaco.default_colormaps import viridis +from chaco.tools.api import PanTool, ZoomTool class PlotTestCase(unittest.TestCase): @@ -91,3 +98,38 @@ def test_text_plot(self): gc.render_component(plot) actual = gc.bmp_array[:, :, :] self.assertFalse(alltrue(actual == 255)) + + +class EmptyLinePlot(HasTraits): + plot = Instance(Plot) + x = [] + y = [] + traits_view = View( + Item('plot', editor=ComponentEditor(), show_label=False), + width=500, + height=500, + resizable=True + ) + + def _plot_default(self): + plot = Plot(ArrayPlotData(x=self.x, y=self.y)) + plot.plot(("x", "y"), type="line", color="blue") + plot.tools.append(PanTool(plot)) + plot.overlays.append(ZoomTool(plot, zoom_factor=1.1)) + return plot + + +# regression test for enthought/chaco#529 +@unittest.skipIf(ETSConfig.toolkit == "null", "Skip on 'null' toolkit") +class TestEmptyPlot(unittest.TestCase, EnableTestAssistant): + + def test_dont_crash_on_click(self): + from traitsui.testing.api import UITester + tester = UITester() + empty_plot = EmptyLinePlot() + + with tester.create_ui(empty_plot): + self.press_move_release( + empty_plot.plot, + [(1, 1), (25, 25), (50, 50), (100, 100)], + ) diff --git a/chaco/ticks.py b/chaco/ticks.py index 7c1405263..99320a7b7 100644 --- a/chaco/ticks.py +++ b/chaco/ticks.py @@ -24,6 +24,7 @@ finfo, float64, floor, + isnan, linspace, log10, minimum, @@ -242,6 +243,10 @@ def auto_ticks( An array of tick mark locations. The first and last tick entries are the axis end points. """ + # if a NaN makes it here, we cant determine tick mark locations. Return + # empty list to prevent crash. Motivated by enthought/chaco#529 + if isnan([data_low, data_high, bound_low, bound_high]).any(): + return [] is_auto_low = bound_low == "auto" is_auto_high = bound_high == "auto"