Skip to content

Commit

Permalink
Prevent axis related plot crash when plot is resized too small (#848)
Browse files Browse the repository at this point in the history
* dont raise if datalow > datahigh

* additional NaN checking in auto_ticks

* add some logging about the bad range coming from the mappper

* better warning message
  • Loading branch information
aaronayres35 authored and corranwebster committed Jan 24, 2023
1 parent aeb50bf commit 55d6906
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 11 additions & 6 deletions chaco/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

""" Defines the PlotAxis class, and associated validator and UI.
"""
import logging

# Major library import
from numpy import (
array,
Expand Down Expand Up @@ -58,6 +60,8 @@
from .label import Label
from .log_mapper import LogMapper

logger = logging.getLogger(__name__)


def DEFAULT_TICK_FORMATTER(val):
return ("%f" % val).rstrip("0").rstrip(".")
Expand Down Expand Up @@ -500,20 +504,21 @@ def _compute_tick_positions(self, gc, overlay_component=None):
screenlow, screenhigh = screenhigh, screenlow

if (
(datalow == datahigh)
(datalow >= datahigh)
or (screenlow == screenhigh)
or (datalow in [inf, -inf])
or (datahigh in [inf, -inf])
):
if datalow > datahigh:
logger.warning(
"{self.mapper} has an invalid data range with "
"low={datalow} > high={datahigh}; unable to compute axis "
"ticks."
)
self._reset_cache()
self._cache_valid = True
return

if datalow > datahigh:
raise RuntimeError(
"DataRange low is greater than high; unable to compute axis ticks."
)

if not self.tick_generator:
return

Expand Down
2 changes: 2 additions & 0 deletions chaco/ticks.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ def auto_ticks(

if upper > end:
end += tick_interval
if isnan([start, end]).any():
return []
ticks = arange(start, end + (tick_interval / 2.0), tick_interval)

if len(ticks) < 2:
Expand Down

0 comments on commit 55d6906

Please sign in to comment.