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

« back to all changes in this revision

Viewing changes to enthought/chaco/polar_line_renderer.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
""" Defines the PolarLineRenderer class.
2
2
"""
 
3
 
 
4
from __future__ import with_statement
 
5
 
3
6
# Major library imports
4
7
from numpy import array, cos, pi, sin, transpose
5
8
 
67
70
    def _render(self, gc, points):
68
71
        """ Actually draw the plot.
69
72
        """
70
 
        gc.save_state()
71
 
 
72
 
        gc.set_antialias(True)
73
 
        self._draw_default_axes(gc)
74
 
        self._draw_default_grid(gc)
75
 
        if len(points)>0:
76
 
            gc.clip_to_rect(self.x, self.y, self.width, self.height)
77
 
            gc.set_stroke_color(self.color_)
78
 
            gc.set_line_width(self.line_width)
79
 
            gc.set_line_dash(self.line_style_)
80
 
 
81
 
            gc.begin_path()
82
 
            gc.lines(points)
83
 
            gc.stroke_path()
84
 
 
85
 
        gc.restore_state()
 
73
        with gc:
 
74
            gc.set_antialias(True)
 
75
            self._draw_default_axes(gc)
 
76
            self._draw_default_grid(gc)
 
77
            if len(points)>0:
 
78
                gc.clip_to_rect(self.x, self.y, self.width, self.height)
 
79
                gc.set_stroke_color(self.color_)
 
80
                gc.set_line_width(self.line_width)
 
81
                gc.set_line_dash(self.line_style_)
 
82
 
 
83
                gc.begin_path()
 
84
                gc.lines(points)
 
85
                gc.stroke_path()
86
86
 
87
87
        return
88
88
 
150
150
    def _draw_default_axes(self, gc):
151
151
        if not self.origin_axis_visible:
152
152
            return
153
 
        gc.save_state()
154
 
        gc.set_stroke_color(self.origin_axis_color_)
155
 
        gc.set_line_width(self.origin_axis_width)
156
 
        gc.set_line_dash(self.grid_style_)
157
 
        x_data,y_data= transpose(self._cached_data_pts)
158
 
        x_center=self.x + self.width/2.0
159
 
        y_center=self.y + self.height/2.0
160
 
 
161
 
        for theta in range(12):
162
 
                r= min(self.width/2.0,self.height/2.0)
163
 
                x= r*cos(theta*pi/6) + x_center
164
 
                y= r*sin(theta*pi/6) + y_center
165
 
                data_pts= array([[x_center,y_center],[x,y]])
166
 
                start,end = data_pts
167
 
                gc.move_to(int(start[0]), int(start[1]))
168
 
                gc.line_to(int(end[0]), int(end[1]))
169
 
                gc.stroke_path()
170
 
        gc.restore_state()
 
153
 
 
154
        with gc:
 
155
            gc.set_stroke_color(self.origin_axis_color_)
 
156
            gc.set_line_width(self.origin_axis_width)
 
157
            gc.set_line_dash(self.grid_style_)
 
158
            x_data,y_data= transpose(self._cached_data_pts)
 
159
            x_center=self.x + self.width/2.0
 
160
            y_center=self.y + self.height/2.0
 
161
 
 
162
            for theta in range(12):
 
163
                    r= min(self.width/2.0,self.height/2.0)
 
164
                    x= r*cos(theta*pi/6) + x_center
 
165
                    y= r*sin(theta*pi/6) + y_center
 
166
                    data_pts= array([[x_center,y_center],[x,y]])
 
167
                    start,end = data_pts
 
168
                    gc.move_to(int(start[0]), int(start[1]))
 
169
                    gc.line_to(int(end[0]), int(end[1]))
 
170
                    gc.stroke_path()
171
171
        return
172
172
 
173
173
    def _draw_default_grid(self,gc):
174
174
        if not self.grid_visible:
175
175
            return
176
 
        gc.save_state()
177
 
        gc.set_stroke_color(self.origin_axis_color_)
178
 
        gc.set_line_width(self.origin_axis_width)
179
 
        gc.set_line_dash(self.grid_style_)
180
 
        x_data,y_data = transpose(self._cached_data_pts)
181
 
        x_center = self.x + self.width/2.0
182
 
        y_center = self.y + self.height/2.0
183
 
        rad = min(self.width/2.0, self.height/2.0)
184
 
        for r_part in range(5):
185
 
            r = rad*r_part/4
186
 
            gc.arc(x_center, y_center, r, 0, 2*pi)
187
 
            gc.stroke_path()
188
 
 
189
 
        gc.restore_state()
 
176
 
 
177
        with gc:
 
178
            gc.set_stroke_color(self.origin_axis_color_)
 
179
            gc.set_line_width(self.origin_axis_width)
 
180
            gc.set_line_dash(self.grid_style_)
 
181
            x_data,y_data = transpose(self._cached_data_pts)
 
182
            x_center = self.x + self.width/2.0
 
183
            y_center = self.y + self.height/2.0
 
184
            rad = min(self.width/2.0, self.height/2.0)
 
185
            for r_part in range(1,5):
 
186
                r = rad*r_part/4
 
187
                gc.arc(x_center, y_center, r, 0, 2*pi)
 
188
                gc.stroke_path()
 
189
 
190
190
        return
191
 
 
192
 
# EOF