Skip to content

Commit

Permalink
Merge e3d9388 into 3e52ecb
Browse files Browse the repository at this point in the history
  • Loading branch information
corranwebster committed Dec 12, 2014
2 parents 3e52ecb + e3d9388 commit ed252ac
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
13 changes: 12 additions & 1 deletion chaco/tools/better_zoom.py
Expand Up @@ -2,7 +2,7 @@

from chaco.grid_mapper import GridMapper
from enable.api import BaseTool, KeySpec
from traits.api import Enum, Float, Instance, Bool, HasTraits, List
from traits.api import Enum, Float, Instance, Bool, List, Tuple

from tool_history_mixin import ToolHistoryMixin
from tool_states import ZoomState, PanState, GroupedToolState, ToolState
Expand Down Expand Up @@ -56,6 +56,9 @@ class BetterZoom(BaseTool, ToolHistoryMixin):
# The amount to zoom in by. The zoom out will be inversely proportional
zoom_factor = Float(2.0)

#: the position to zoom on (usually the mouse location)
position = Tuple(Float, Float)

# The zoom factor on each axis
_index_factor = Float(1.0)
_value_factor = Float(1.0)
Expand Down Expand Up @@ -358,3 +361,11 @@ def _reset_state_pressed(self):
for state in self._history[::-1]:
state.revert(self)
self._history = []

#--------------------------------------------------------------------------
# Traits defaults
#--------------------------------------------------------------------------

def _position_default(self):
# center of the component is a sensible default
return self._center_screen()
37 changes: 37 additions & 0 deletions chaco/tools/tests/better_zoom_test_case.py
@@ -0,0 +1,37 @@
import unittest

import numpy

from chaco.api import create_line_plot
from chaco.tools.api import BetterZoom
from enable.testing import EnableTestAssistant
from traits.testing.api import UnittestTools

class TestBetterZoomTool(EnableTestAssistant, UnittestTools, unittest.TestCase):
""" Tests for the TraversePolyLine enable tool """

def setUp(self):
values = numpy.arange(10)
self.plot = create_line_plot((values, values))
self.plot.bounds = [100, 100]
self.plot._window = self.create_mock_window()
self.tool = BetterZoom(component=self.plot)
self.plot.active_tool = self.tool
self.plot.do_layout()

def tearDown(self):
del self.tool
del self.plot

def test_default_position(self):
tool = self.tool

# this doesn't throw an exception
self.send_key(tool, '+')

self.assertEqual(tool.position, (50, 50))

# expected behaviour for a normal zoom in operation
self.assertNotEqual(tool._index_factor, 1.0)
self.assertNotEqual(tool._value_factor, 1.0)
self.assertEqual(len(tool._history), 2)

0 comments on commit ed252ac

Please sign in to comment.