Skip to content
This repository
Browse code

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
15 chaco/lasso_overlay.py
@@ -7,7 +7,7 @@
7 7
8 8 # Enthought library imports
9 9 from enable.api import ColorTrait, LineStyle
10   -from traits.api import Float, Instance
  10 +from traits.api import Float, Instance, Bool
11 11
12 12 # Local imports
13 13 from abstract_overlay import AbstractOverlay
@@ -34,11 +34,17 @@ class LassoOverlay(AbstractOverlay):
34 34 # The background color (overrides AbstractOverlay).
35 35 bgcolor = 'clear'
36 36
  37 + # Whether to draw the lasso
  38 + # depends on the state of the lasso tool
  39 + _draw_selection = Bool(False)
  40 +
37 41 def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
38 42 """ Draws this component overlaid on another component.
39 43
40 44 Implements AbstractOverlay.
41 45 """
  46 + if not self._draw_selection:
  47 + return
42 48 with gc:
43 49 c = other_component
44 50 gc.clip_to_rect(c.x, c.y, c.width, c.height)
@@ -49,6 +55,11 @@ def _updated_changed_for_lasso_selection(self):
49 55 self.component.invalidate_draw()
50 56 self.component.request_redraw()
51 57
  58 + def _event_state_fired_for_lasso_selection(self, val):
  59 + self._draw_selection = val == 'selecting'
  60 + self.component.invalidate_draw()
  61 + self.component.request_redraw()
  62 +
52 63 def _draw_component(self, gc, view_bounds=None, mode='normal'):
53 64 """ Draws the component.
54 65
@@ -63,7 +74,7 @@ def _draw_component(self, gc, view_bounds=None, mode='normal'):
63 74 if len(points) == 0:
64 75 return
65 76 points = concatenate((points, points[0, newaxis]), axis=0)
66   - gc.set_line_width(self.border_width)
  77 + gc.set_line_width(self.selection_border_width)
67 78 gc.set_line_dash(self.selection_border_dash_)
68 79 gc.set_fill_color(self.selection_fill_color_)
69 80 gc.set_stroke_color(self.selection_border_color_)
4 chaco/scatter_inspector_overlay.py
@@ -53,8 +53,8 @@ def overlay(self, component, gc, view_bounds=None, mode="normal"):
53 53
54 54 for inspect_type in (self.hover_metadata_name, self.selection_metadata_name):
55 55 if inspect_type in plot.index.metadata:
56   - if hasattr(plot,"value") and not inspect_type in plot.value.metadata:
57   - continue
  56 + #if hasattr(plot,"value") and not inspect_type in plot.value.metadata:
  57 + # continue
58 58 index = plot.index.metadata.get(inspect_type, None)
59 59
60 60 if index is not None and len(index) > 0:
15 chaco/tools/lasso_selection.py
@@ -121,10 +121,10 @@ def normal_left_down(self, event):
121 121 """
122 122 # We may want to generalize this for the n-dimensional case...
123 123
124   - self._active_selection = empty((0,2))
  124 + self._active_selection = empty((0,2), dtype=numpy.bool)
125 125
126 126 if self.selection_datasource is not None:
127   - self.selection_datasource.metadata['selection'] = zeros(len(self.selection_datasource.get_data()))
  127 + self.selection_datasource.metadata['selection'] = zeros(len(self.selection_datasource.get_data()), dtype=numpy.bool)
128 128 self.selection_mode = "include"
129 129 self.event_state = 'selecting'
130 130 self.selecting_mouse_move(event)
@@ -149,7 +149,7 @@ def selecting_left_up(self, event):
149 149 self._update_selection()
150 150
151 151 self._previous_selections.append(self._active_selection)
152   - self._active_selection = empty((0,2))
  152 + self._active_selection = empty((0,2), dtype=numpy.bool)
153 153 return
154 154
155 155 def selecting_mouse_move(self, event):
@@ -175,7 +175,8 @@ def selecting_mouse_leave(self, event):
175 175
176 176 Ends the selection operation.
177 177 """
178   - self.selecting_left_up(event)
  178 + print event
  179 + #self.selecting_left_up(event)
179 180 return
180 181
181 182 def normal_key_pressed(self, event):
@@ -199,13 +200,13 @@ def normal_key_pressed(self, event):
199 200 #----------------------------------------------------------------------
200 201
201 202 def _dataspace_points_default(self):
202   - return empty((0,2))
  203 + return empty((0,2), dtype=numpy.bool)
203 204
204 205 def _reset(self):
205 206 """ Resets the selection
206 207 """
207 208 self.event_state='normal'
208   - self._active_selection = empty((0,2))
  209 + self._active_selection = empty((0,2), dtype=numpy.bool)
209 210 self._previous_selections = []
210 211 self._update_selection()
211 212
@@ -231,7 +232,7 @@ def _update_selection(self):
231 232 if self.selection_datasource is None:
232 233 return
233 234
234   - selected_mask = zeros(self.selection_datasource._data.shape, dtype=numpy.int32)
  235 + selected_mask = zeros(self.selection_datasource._data.shape, dtype=numpy.bool)
235 236 data = self._get_data()
236 237
237 238 # Compose the selection mask from the cached selections first, then

0 comments on commit 05f7cfc

Please sign in to comment.
Something went wrong with that request. Please try again.