8000 SC 2005/03/09 · matplotlib/matplotlib@3f20c60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f20c60

Browse files
author
Steve Chaplin
committed
SC 2005/03/09
svn path=/trunk/matplotlib/; revision=1054
1 parent 9979a0b commit 3f20c60

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
New entries should be added at the top
22

3+
2005-03-09 backend_cairo.py: implemented draw_markers() - SC
4+
35
2005-03-09 cbook.py: only use enumerate() (the python version) if the builtin
46
version is not available.
57
Add new function 'izip' which is set to itertools.izip if available

lib/matplotlib/backends/backend_cairo.py

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -202,22 +202,27 @@ def draw_lines(self, gc, x, y, transform=None):
202202

203203

204204
def draw_markers(self, gc, path, x, y, transform):
205-
#def _draw_markers(self, gc, path, x, y, transform):
206205
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
207206

207+
ctx = gc.ctx
208+
208209
if transform.need_nonlinear():
209210
x,y = transform.nonlinear_only_numerix(x, y)
210-
x, y = transform.numerix_x_y(x, y) # todo - use cairo transform
211-
211 8000 +
x, y = transform.numerix_x_y(x, y)
212+
212213
# the a,b,c,d,tx,ty affine which transforms x and y
213214
#vec6 = transform.as_vec6_val() # not used (yet)
214215

215-
ctx = gc.ctx
216+
# todo - use cairo transform
217+
# matrix worked for dotted lines, but not markers in line_styles.py
218+
# it upsets/transforms generate_path() ?
219+
#matrix_old = ctx.matrix
220+
#matrix = cairo.Matrix (*vec6)
221+
#ctx.set_matrix (matrix)
216222

217-
def draw_path():
218-
# could trace path just once, then save/restore() ?
219-
# need to remember/store fill and fill_rgb
220-
fill = False
223+
def generate_path (path):
224+
"""trace path and return fill_rgb
225+
"""
221226
for p in path:
222227
code = p[0]
223228
if code == MOVETO:
@@ -226,31 +231,29 @@ def draw_path():
226231
ctx.line_to (p[1], -p[2])
227232
elif code == ENDPOLY:
228233
ctx.close_path()
229-
fill = p[1]
230-
if fill:
234+
if p[1]: # fill
231235
#rgba = p[2:]
232-
fill_rgb = p[2:5]
236+
return p[2:5] # don't really want to read the same fill_rgb every time we generate_path()
237+
return None
233238

234-
# draw marker
235-
if fill:
239+
for x,y in izip(x,y):
240+
ctx.save()
241+
ctx.new_path()
242+
ctx.translate(x, self.height - y)
243+
244+
fill_rgb = generate_path (path)
245+
if fill_rgb:
236246
ctx.save()
237247
ctx.set_rgb_color (*fill_rgb)
238248
# later - set alpha also?
239249
ctx.fill()
240-
ctx.restore()
250+
ctx.restore() # undo colour change and restore path
241251

242252
ctx.stroke()
243-
244-
for x,y in izip(x,y):
245-
# TODO
246-
# use Cairo transform
247-
# look to writing in a more efficient way - trace path once only - see above
248-
ctx.save()
249-
ctx.new_path()
250-
ctx.translate(x, self.height - y)
251-
draw_path()
252253
ctx.restore() # undo translate()
253254

255+
#ctx.set_matrix(matrix_old)
256+
254257

255258
def draw_point(self, gc, x, y):
256259
if DEBUG: print 'backend_cairo.RendererCairo.%s()' % _fn_name()
@@ -457,11 +460,13 @@ def set_capstyle(self, cs):
457460

458461

459462
def set_clip_rectangle(self, rectangle):
460-
# Cairo clipping is currently extremely slow
461-
# cairo/BUGS lists it as a known bug
463+
# Cairo < 0.4.0: clipping is currently extremely slow
464+
# Cairo 0.4.0 : pixel-aligned rectangular clip-regions are now faster
462465
self._cliprect = rectangle
463466

464467
x,y,w,h = rectangle
468+
# pixel-aligned clip-regions are faster
469+
x,y,w,h = round(x), round(y), round(w), round(h)
465470
ctx = self.ctx
466471
ctx.new_path()
467472
ctx.rectangle (x, self.renderer.height - h - y, w, h)
@@ -472,6 +477,9 @@ def set_clip_rectangle(self, rectangle):
472477
#ctx.stroke()
473478
#ctx.restore()
474479

480+
#ctx.init_clip() # not needed? used unsuccessfully to fix clip problem
481+
# when uncomment ctx.clip() it causes problems in line_styles.py
482+
# - multiple axes, only the first one has its background drawn
475483
#ctx.clip ()
476484

477485

0 commit comments

Comments
 (0)
0