Skip to content

Commit

Permalink
Merge pull request #188 from enthought/fix_datarange2d_bounds_reset
Browse files Browse the repository at this point in the history
DataRange2D can become inconsistent with underlying DataRange1D instances
  • Loading branch information
cfarrow committed Jun 10, 2014
2 parents 9d6c415 + 4343864 commit 930d51b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
33 changes: 10 additions & 23 deletions chaco/data_range_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ class supports only rectangular regions for now.
# Private traits
#------------------------------------------------------------------------

# The "_setting" attributes correspond to what the user has "set"; the
# "_value" attributes are the actual numerical values for the given
# setting.

# The user-specified low settings.
_low_setting = Trait(('auto', 'auto'), Any)
# The actual numerical values for the low setting.
_low_value = Trait((-inf, -inf), Tuple(CFloat, CFloat))
# The user-specified high settings.
_high_setting = Trait(('auto', 'auto'), Any)
# The actual numerical value for the high setting.
_high_value = Trait((inf, inf), Tuple(CFloat, CFloat))

# DataRange1D for the x-dimension.
_xrange = Instance(DataRange1D, args=())
# DataRange1D for the y-dimension.
Expand Down Expand Up @@ -126,30 +113,26 @@ def __init__(self, *args, **kwargs):
def reset(self):
""" Resets the bounds of this range.
"""
self._high_setting = ('auto', 'auto')
self._low_setting = ('auto', 'auto')
self._refresh_bounds()
self.high_setting = ('auto', 'auto')
self.low_setting = ('auto', 'auto')
self.refresh()

def refresh(self):
""" If any of the bounds is 'auto', this method refreshes the actual
low and high values from the set of the view filters' data sources.
"""
if 'auto' not in self._low_setting and \
'auto' not in self._high_setting:
if 'auto' not in self.low_setting and \
'auto' not in self.high_setting:
# If the user has hard-coded bounds, then refresh() doesn't do
# anything.
return
else:
self._refresh_bounds()

#------------------------------------------------------------------------
# Public methods
# Private methods
#------------------------------------------------------------------------

def _do_set_high_setting(self, val, fire_event=True):
self._xrange.high_setting = val[0]
self._yrange.high_setting = val[1]

def _refresh_bounds(self):
self._xrange.refresh()
self._yrange.refresh()
Expand Down Expand Up @@ -186,6 +169,10 @@ def _get_high_setting(self):
def _set_high_setting(self, val):
self._do_set_high_setting(val)

def _do_set_high_setting(self, val, fire_event=True):
self._xrange.high_setting = val[0]
self._yrange.high_setting = val[1]

def _get_x_range(self):
return self._xrange

Expand Down
19 changes: 19 additions & 0 deletions chaco/tests/datarange_2d_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,25 @@ def test_set_bounds(self):
assert_ary_(r.low, array([-100,-100]))
assert_ary_(r.high, array([100,100]))

def test_reset_bounds(self):
r = DataRange2D()

low = (13, 42)
high = (1337, 9001)

r.set_bounds(low, high)
self.assertEqual(r.low_setting, low)
self.assertEqual(r.high_setting, high)

r.reset()

self.assertEqual(r.low_setting, ('auto', 'auto'))
self.assertEqual(r.high_setting, ('auto', 'auto'))
self.assertEqual(r.x_range.low_setting, 'auto')
self.assertEqual(r.y_range.low_setting, 'auto')
self.assertEqual(r.x_range.high_setting, 'auto')
self.assertEqual(r.y_range.high_setting, 'auto')


def test_clip_data(self):
r = DataRange2D(low=[2.0,5.0], high=[10.0,8.0])
Expand Down

0 comments on commit 930d51b

Please sign in to comment.