1
""" Defines the LassoOverlay class.
4
from __future__ import with_statement
6
from numpy import concatenate, newaxis
8
# Enthought library imports
9
from enable.api import ColorTrait, LineStyle
10
from traits.api import Float, Instance
13
from abstract_overlay import AbstractOverlay
15
class LassoOverlay(AbstractOverlay):
16
""" Draws a lasso selection region on top of a plot.
18
LassoOverlay gets its data from a LassoSelection.
21
# The LassoSelection that provides the data for this overlay.
22
lasso_selection = Instance('chaco.tools.lasso_selection.LassoSelection')
23
# The fill color for the selection region.
24
selection_fill_color = ColorTrait('lightskyblue')
25
# The border color for the selection region.
26
selection_border_color = ColorTrait('dodgerblue')
27
# The transparency level for the selection fill color.
28
selection_alpha = Float(0.8)
29
# The width of the selection border.
30
selection_border_width = Float(2.0)
31
# The line style of the selection border.
32
selection_border_dash = LineStyle
34
# The background color (overrides AbstractOverlay).
37
def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
38
""" Draws this component overlaid on another component.
40
Implements AbstractOverlay.
44
gc.clip_to_rect(c.x, c.y, c.width, c.height)
45
self._draw_component(gc, view_bounds, mode)
48
def _updated_changed_for_lasso_selection(self):
49
self.component.invalidate_draw()
50
self.component.request_redraw()
52
def _draw_component(self, gc, view_bounds=None, mode='normal'):
53
""" Draws the component.
55
This method is preserved for backwards compatibility with _old_draw().
56
Overrides PlotComponent.
59
# We may need to make map_screen more flexible in the number of dimensions
60
# it accepts for ths to work well.
61
for selection in self.lasso_selection.disjoint_selections:
62
points = self.component.map_screen(selection)
65
points = concatenate((points, points[0, newaxis]), axis=0)
66
gc.set_line_width(self.border_width)
67
gc.set_line_dash(self.selection_border_dash_)
68
gc.set_fill_color(self.selection_fill_color_)
69
gc.set_stroke_color(self.selection_border_color_)
70
gc.set_alpha(self.selection_alpha)