Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #59 from enthought/lasso-updates

Updates to the lasso tool to make it work with the scatter inspector overlay
  • Loading branch information...
commit 05f7cfc15a68fb6adb2c69f58fa91d4ad8a5c62c 2 parents 550d736 + 6533870
nmichaud authored
View
15 chaco/lasso_overlay.py
@@ -7,7 +7,7 @@
# Enthought library imports
from enable.api import ColorTrait, LineStyle
-from traits.api import Float, Instance
+from traits.api import Float, Instance, Bool
# Local imports
from abstract_overlay import AbstractOverlay
@@ -34,11 +34,17 @@ class LassoOverlay(AbstractOverlay):
# The background color (overrides AbstractOverlay).
bgcolor = 'clear'
+ # Whether to draw the lasso
+ # depends on the state of the lasso tool
+ _draw_selection = Bool(False)
+
def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
""" Draws this component overlaid on another component.
Implements AbstractOverlay.
"""
+ if not self._draw_selection:
+ return
with gc:
c = other_component
gc.clip_to_rect(c.x, c.y, c.width, c.height)
@@ -49,6 +55,11 @@ def _updated_changed_for_lasso_selection(self):
self.component.invalidate_draw()
self.component.request_redraw()
+ def _event_state_fired_for_lasso_selection(self, val):
+ self._draw_selection = val == 'selecting'
+ self.component.invalidate_draw()
+ self.component.request_redraw()
+
def _draw_component(self, gc, view_bounds=None, mode='normal'):
""" Draws the component.
@@ -63,7 +74,7 @@ def _draw_component(self, gc, view_bounds=None, mode='normal'):
if len(points) == 0:
return
points = concatenate((points, points[0, newaxis]), axis=0)
- gc.set_line_width(self.border_width)
+ gc.set_line_width(self.selection_border_width)
gc.set_line_dash(self.selection_border_dash_)
gc.set_fill_color(self.selection_fill_color_)
gc.set_stroke_color(self.selection_border_color_)
View
4 chaco/scatter_inspector_overlay.py
@@ -53,8 +53,8 @@ def overlay(self, component, gc, view_bounds=None, mode="normal"):
for inspect_type in (self.hover_metadata_name, self.selection_metadata_name):
if inspect_type in plot.index.metadata:
- if hasattr(plot,"value") and not inspect_type in plot.value.metadata:
- continue
+ #if hasattr(plot,"value") and not inspect_type in plot.value.metadata:
+ # continue
index = plot.index.metadata.get(inspect_type, None)
if index is not None and len(index) > 0:
View
15 chaco/tools/lasso_selection.py
@@ -121,10 +121,10 @@ def normal_left_down(self, event):
"""
# We may want to generalize this for the n-dimensional case...
- self._active_selection = empty((0,2))
+ self._active_selection = empty((0,2), dtype=numpy.bool)
if self.selection_datasource is not None:
- self.selection_datasource.metadata['selection'] = zeros(len(self.selection_datasource.get_data()))
+ self.selection_datasource.metadata['selection'] = zeros(len(self.selection_datasource.get_data()), dtype=numpy.bool)
self.selection_mode = "include"
self.event_state = 'selecting'
self.selecting_mouse_move(event)
@@ -149,7 +149,7 @@ def selecting_left_up(self, event):
self._update_selection()
self._previous_selections.append(self._active_selection)
- self._active_selection = empty((0,2))
+ self._active_selection = empty((0,2), dtype=numpy.bool)
return
def selecting_mouse_move(self, event):
@@ -175,7 +175,8 @@ def selecting_mouse_leave(self, event):
Ends the selection operation.
"""
- self.selecting_left_up(event)
+ print event
+ #self.selecting_left_up(event)
return
def normal_key_pressed(self, event):
@@ -199,13 +200,13 @@ def normal_key_pressed(self, event):
#----------------------------------------------------------------------
def _dataspace_points_default(self):
- return empty((0,2))
+ return empty((0,2), dtype=numpy.bool)
def _reset(self):
""" Resets the selection
"""
self.event_state='normal'
- self._active_selection = empty((0,2))
+ self._active_selection = empty((0,2), dtype=numpy.bool)
self._previous_selections = []
self._update_selection()
@@ -231,7 +232,7 @@ def _update_selection(self):
if self.selection_datasource is None:
return
- selected_mask = zeros(self.selection_datasource._data.shape, dtype=numpy.int32)
+ selected_mask = zeros(self.selection_datasource._data.shape, dtype=numpy.bool)
data = self._get_data()
# Compose the selection mask from the cached selections first, then
Please sign in to comment.
Something went wrong with that request. Please try again.