Skip to content

Empty chaco plot crashes when clicked on #529

@sandhya-sago

Description

@sandhya-sago

Problem Description
Clicking on an empty chaco plot results in a crash. In our usage, an empty chaco plot is created first, and later data is added.
Reproduction Steps:

class LinePlot(HasTraits):
    plot = Instance(Plot)
    x = []
    y = []
    traits_view = View(
            Item('plot', editor=ComponentEditor(),
                 show_label=False),
            width=500, height=500,
            resizable=True,
            title="Chaco Plot")
    def _plot_default(self):
        # Create the data and the PlotData object
        # Create a Plot and associate it with the PlotData
        plot = Plot(ArrayPlotData(x=self.x, y=self.y))
        # Create a line plot in the Plot
        plot.plot(("x", "y"), type="line", color="blue")
        # Set the title and label the x-axis
        plot.title = "sin(x) * x^3"
        plot.x_axis.title = "x-axis label"
        plot.tools.append(PanTool(plot))
        plot.overlays.append(ZoomTool(plot, zoom_fator=1.1))
        # Assign it to our self.plot attribute
        return plot
demo = LinePlot()
demo.configure_traits()

Once the plot comes up, try clicking on it. It crashes with the following traceback (full path has been replaced with <>).

Traceback (most recent call last):
  File "<>/lib/python3.6/site-packages/enable/qt4/base_window.py", line 213, in paintEvent
    self.handler.paintEvent(event)
  File "<>/lib/python3.6/site-packages/enable/qt4/base_window.py", line 65, in paintEvent
    self._enable_window._paint(event)
  File "<>/lib/python3.6/site-packages/enable/abstract_window.py", line 471, in _paint
    self.component.draw(gc, view_bounds=(0, 0, size[0], size[1]))
  File "<>/lib/python3.6/site-packages/enable/component.py", line 427, in draw
    self._draw(gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/component.py", line 779, in _draw
    self._dispatch_draw(layer, gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/container.py", line 273, in _dispatch_draw
    component._dispatch_draw(layer, gc, new_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/container.py", line 258, in _dispatch_draw
    my_handler(gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/container.py", line 298, in _draw_container_underlay
    self._draw_underlay(gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/enable/component.py", line 887, in _draw_underlay
    underlay.overlay(self, gc, view_bounds, mode)
  File "<>/lib/python3.6/site-packages/chaco/grid.py", line 307, in overlay
    self._compute_ticks(other_component)
  File "<>/lib/python3.6/site-packages/chaco/grid.py", line 255, in _compute_ticks
    scale=scale)
  File "<>/lib/python3.6/site-packages/chaco/ticks.py", line 84, in get_ticks
    interval, use_endpoints=False), float64)
  File "<>/lib/python3.6/site-packages/chaco/ticks.py", line 216, in auto_ticks
    ticks = arange( start, end + (tick_interval / 2.0), tick_interval )
ValueError: arange: cannot compute length

Expected behavior:

No crash when an empty plot is clicked. After data is added, Zoom and Pan work.

OS, Python version: [Enter OS name and Python version]
Python 3.6, MacOS Catalina 10.15.6
chaco 4.8.0-4
enable 4.8.1-5

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions