~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to enthought/chaco/quiverplot.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-06 19:03:54 UTC
  • mfrom: (7.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110406190354-rwd55l2ezjecfo41
Tags: 3.4.0-2
d/rules: fix pyshared directory path (Closes: #621116)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
 
2
from __future__ import with_statement
 
3
 
2
4
from numpy import array, compress, matrix, newaxis, sqrt, zeros
3
5
 
4
6
# Enthought library imports
67
69
 
68
70
    
69
71
    def _render(self, gc, points, icon_mode=False):
70
 
        gc.save_state()
71
 
        gc.clip_to_rect(self.x, self.y, self.width, self.height)
72
 
 
73
 
        gc.set_stroke_color(self.line_color_)
74
 
        gc.set_line_width(self.line_width)
75
 
        
76
 
        # Draw the body of the arrow
77
 
        starts = points
78
 
        ends = points + self._cached_vector_data
79
 
        gc.begin_path()
80
 
        gc.line_set(starts, ends)
81
 
        gc.stroke_path()
82
 
 
83
 
        if self.arrow_size > 0:
84
 
            vec = self._cached_vector_data
85
 
            unit_vec = vec / sqrt(vec[:,0] ** 2 + vec[:,1] ** 2)[:, newaxis]
86
 
            a = 0.707106781   # sqrt(2)/2
87
 
 
88
 
            # Draw the left arrowhead (for an arrow pointing straight up)
89
 
            arrow_ends = ends - array(unit_vec * matrix([[a, a], [-a, a]])) * self.arrow_size
90
 
            gc.begin_path()
91
 
            gc.line_set(ends, arrow_ends)
92
 
            gc.stroke_path()
93
 
 
94
 
            # Draw the left arrowhead (for an arrow pointing straight up)
95
 
            arrow_ends = ends - array(unit_vec * matrix([[a, -a], [a, a]])) * self.arrow_size
96
 
            gc.begin_path()
97
 
            gc.line_set(ends, arrow_ends)
98
 
            gc.stroke_path()
99
 
 
100
 
        gc.restore_state()
 
72
        with gc:
 
73
            gc.clip_to_rect(self.x, self.y, self.width, self.height)
 
74
 
 
75
            gc.set_stroke_color(self.line_color_)
 
76
            gc.set_line_width(self.line_width)
 
77
            
 
78
            # Draw the body of the arrow
 
79
            starts = points
 
80
            ends = points + self._cached_vector_data
 
81
            gc.begin_path()
 
82
            gc.line_set(starts, ends)
 
83
            gc.stroke_path()
 
84
 
 
85
            if self.arrow_size > 0:
 
86
                vec = self._cached_vector_data
 
87
                unit_vec = vec / sqrt(vec[:,0] ** 2 + vec[:,1] ** 2)[:, newaxis]
 
88
                a = 0.707106781   # sqrt(2)/2
 
89
 
 
90
                # Draw the left arrowhead (for an arrow pointing straight up)
 
91
                arrow_ends = ends - array(unit_vec * matrix([[a, a], [-a, a]])) * self.arrow_size
 
92
                gc.begin_path()
 
93
                gc.line_set(ends, arrow_ends)
 
94
                gc.stroke_path()
 
95
 
 
96
                # Draw the left arrowhead (for an arrow pointing straight up)
 
97
                arrow_ends = ends - array(unit_vec * matrix([[a, -a], [a, a]])) * self.arrow_size
 
98
                gc.begin_path()
 
99
                gc.line_set(ends, arrow_ends)
 
100
                gc.stroke_path()