Skip to content

Commit

Permalink
Merge branch 'master' into enh/data-source-tests
Browse files Browse the repository at this point in the history
Conflicts:
	MANIFEST.in
  • Loading branch information
corranwebster committed Jan 6, 2015
2 parents 6ba47ec + b0346ec commit 1a998ed
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Enhancements

Fixes

* Fixed default position attribute in BetterZoom tool (PR#241)
* Workaround RuntimeWarnings from nanmin and nanmax in ImageData.get_bounds
(PR #242).


What's new in Chaco 4.5.0
-------------------------

Expand Down
11 changes: 11 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
include chaco/*.h
include chaco/tests/data/PngSuite/*.png
include chaco/tests/data/PngSuite/LICENSE.txt
include chaco/tools/toolbars/images*.png
include chaco/tools/toolbars/images*.svg
include chaco/tools/toolbars/images*.txt
include chaco/layers/data/*.svg
graft examples
recursive-exclude examples *.pyc
include README.rst
include CHANGES.txt
include LICENSE.txt
include image_LICENSE.txt
include dev_requirements.txt
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ http://github.enthought.com/chaco
:alt: Build status


.. image:: https://coveralls.io/repos/enthought/chaco/badge.png?branch=feature%2Fcoverall_badge
:target: https://coveralls.io/r/enthought/chaco?branch=feature%2Fcoverall_badge
.. image:: https://coveralls.io/repos/enthought/chaco/badge.png?branch=master
:target: https://coveralls.io/r/enthought/chaco?branch=master
:alt: Test coverage


Expand Down
16 changes: 13 additions & 3 deletions chaco/function_data_source.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
""" Defines the FunctionDataSource class to create an ArrayDataSource from a
callable.
"""

from numpy import array

Expand All @@ -11,7 +14,15 @@


class FunctionDataSource(ArrayDataSource):
""" A data source that lazily generates its data array from a callable.
The signature of the :attr:`func` attribute is `func(low, high)` where
`low` and `high` are attributes of the :attr:`data_range` attribute
(instance of a :class:`DataRange1D`).
This class does not listen to the array for value changes; if you need that
behavior, create a subclass that hooks up the appropriate listeners.
"""
# The function to call with the low and high values of the range.
# It should return an array of values.
func = Callable
Expand All @@ -34,13 +45,12 @@ def recalculate(self):
self._data = array([], dtype=float)

def set_data(self, *args, **kw):
raise RuntimeError("Cannot set numerical data on a FunctionDataSource")
raise RuntimeError("Cannot set numerical data on a {0}".format(
self.__class__))

def set_mask(self, mask):
# This would be REALLY FREAKING SLICK, but it's current unimplemented
raise NotImplementedError

def remove_mask(self):
raise NotImplementedError


45 changes: 31 additions & 14 deletions chaco/tools/better_zoom.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import numpy
# Copyright (c) 2005-2014, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.

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 @@ -43,19 +52,22 @@ class BetterZoom(BaseTool, ToolHistoryMixin):
# only applies in 'range' mode.
axis = Enum("both", "index", "value")

# The maximum ratio between the original data space bounds and the zoomed-in
# data space bounds. If No limit is desired, set to inf
# The maximum ratio between the original data space bounds and the
# zoomed-in data space bounds. If No limit is desired, set to inf
x_max_zoom_factor = Float(1e5)
y_max_zoom_factor = Float(1e5)

# The maximum ratio between the zoomed-out data space bounds and the original
# bounds. If No limit is desired, set to -inf
# The maximum ratio between the zoomed-out data space bounds and the
# original bounds. If No limit is desired, set to -inf
x_min_zoom_factor = Float(1e-5)
y_min_zoom_factor = Float(1e-5)

# 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 @@ -83,7 +95,7 @@ def _do_zoom(self, new_index_factor, new_value_factor):
y = y_map.map_data(location[1])
nexty = y + (cy - y)*(self._value_factor/new_value_factor)

pan_state = PanState((cx,cy), (nextx, nexty))
pan_state = PanState((cx, cy), (nextx, nexty))
zoom_state = ZoomState((self._index_factor, self._value_factor),
(new_index_factor, new_value_factor))

Expand Down Expand Up @@ -185,7 +197,6 @@ def zoom_out_x(self, factor=0):
return
self._do_zoom(new_index_factor, new_value_factor)


def zoom_in_y(self, factor=0):
if factor == 0:
factor = self.zoom_factor
Expand Down Expand Up @@ -287,13 +298,11 @@ def _zoom_limit_reached(self, factor, xy_axis):
"""

if xy_axis == 'x':
if factor <= self.x_max_zoom_factor and factor >= self.x_min_zoom_factor:
return False
return True
return not (self.x_min_zoom_factor <=
factor <= self.x_max_zoom_factor)
else:
if factor <= self.y_max_zoom_factor and factor >= self.y_min_zoom_factor:
return False
return True
return not (self.y_min_zoom_factor <=
factor <= self.y_max_zoom_factor)

def _zoom_in_mapper(self, mapper, factor):

Expand Down Expand Up @@ -358,3 +367,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()
50 changes: 50 additions & 0 deletions chaco/tools/tests/better_zoom_test_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2014, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only
# under the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
# Thanks for using Enthought open source!
#
# Author: Enthought, Inc.

""" Tests for the BetterZoom Chaco tool """

import unittest

import numpy

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


class TestBetterZoomTool(EnableTestAssistant, unittest.TestCase):
""" Tests for the BetterZoom Chaco 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)
6 changes: 3 additions & 3 deletions docs/source/user_manual/chaco_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ Here is a simple example of the "script-oriented" approach for creating
a static plot. This is probably familiar to anyone who has used Gnuplot,
MATLAB, or Matplotlib::

import numpy as np
from numpy import linspace, pi, sin
from chaco.shell import *

x = np.linspace(-2*pi, 2*pi, 100)
y = np.sin(x)
x = linspace(-2*pi, 2*pi, 100)
y = sin(x)

plot(x, y, "r-")
title("First plot")
Expand Down

0 comments on commit 1a998ed

Please sign in to comment.