~ubuntu-branches/ubuntu/trusty/python-chaco/trusty

« back to all changes in this revision

Viewing changes to chaco/lasso_overlay.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-07-08 20:38:02 UTC
  • mfrom: (7.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110708203802-5t32e0ldv441yh90
Tags: 4.0.0-1
* New upstream release
* debian/control:
  - Depend on python-traitsui (Closes: #633604)
  - Bump Standards-Version to 3.9.2
* Update debian/watch file
* Remove debian/patches/* -- no longer needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
""" Defines the LassoOverlay class.
 
2
"""
 
3
 
 
4
from __future__ import with_statement
 
5
 
 
6
from numpy import concatenate, newaxis
 
7
 
 
8
# Enthought library imports
 
9
from enable.api import ColorTrait, LineStyle
 
10
from traits.api import Float, Instance
 
11
 
 
12
# Local imports
 
13
from abstract_overlay import AbstractOverlay
 
14
 
 
15
class LassoOverlay(AbstractOverlay):
 
16
    """ Draws a lasso selection region on top of a plot.
 
17
 
 
18
    LassoOverlay gets its data from a LassoSelection.
 
19
    """
 
20
 
 
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
 
33
 
 
34
    # The background color (overrides AbstractOverlay).
 
35
    bgcolor = 'clear'
 
36
 
 
37
    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
 
38
        """ Draws this component overlaid on another component.
 
39
 
 
40
        Implements AbstractOverlay.
 
41
        """
 
42
        with gc:
 
43
            c = other_component
 
44
            gc.clip_to_rect(c.x, c.y, c.width, c.height)
 
45
            self._draw_component(gc, view_bounds, mode)
 
46
        return
 
47
 
 
48
    def _updated_changed_for_lasso_selection(self):
 
49
        self.component.invalidate_draw()
 
50
        self.component.request_redraw()
 
51
 
 
52
    def _draw_component(self, gc, view_bounds=None, mode='normal'):
 
53
        """ Draws the component.
 
54
 
 
55
        This method is preserved for backwards compatibility with _old_draw().
 
56
        Overrides PlotComponent.
 
57
        """
 
58
        with gc:
 
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)
 
63
                if len(points) == 0:
 
64
                    return
 
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)
 
71
                gc.lines(points)
 
72
                gc.draw_path()