Hi Eric,
>
> Sorry about the broken links. I've attached a diff made against trunk
> from a few days ago.
Thanks!
>
> The discussion about what to do with my patch fizzled. I created a
> decorator that made mixed-mode switching a one-line change per artist
> type. I also added get/set_rasterized and an _rasterized attribute to
> the Artist base class. I've used it on and off for a few months now
> with no noted bugs.
>
> If we don't like the decorator, we can just make a helper function
> that is called at the beginning of every artist.draw() method. It's
> not a very complicated modification.
>
>
Would there be a case that draw methods of some Artists do not need to
be decorated?
If not, I guess some metaclass black magic might be not harmful. What
do you think? I'm attaching modified version of your patch which
utilize metaclass for decoration.
I personally want that rasterization is also supported in the ps
backend. I guess the missing support of alpha composition would be a
problem. But, in most of the my use case, I want rasterization for
artist with z lower than some specified value (i.e., background images
using pcolormesh), so it is not a problem for me.
Regards,
-JJ
>>
>> Are you planning to commit your patch to the trunk? I'll be glad to
>> help you if there are any issues.
>
>
> I'd love to get the patch in trunk, if only so that more people can
> try it out and find things to improve (or re-implement).
>
> Thanks,
> Eric
>
Index: lib/matplotlib/artist.py
===================================================================
--- lib/matplotlib/artist.py (revision 7065)
+++ lib/matplotlib/artist.py (working copy)
@@ -22,12 +22,49 @@
# http://groups.google.com/groups?hl=en&lr=&threadm=mailman.5090.1098044946.5135.python-list%40python.org&rnum=1&prev=/groups%3Fq%3D__doc__%2Bauthor%253Ajdhunter%2540ace.bsd.uchicago.edu%26hl%3Den%26btnG%3DGoogle%2BSearch
+
+
+def hook_before_after_draw(draw):
+ """
+ Decorator for Artist.draw method. Provides routines
+ that run before and after the draw call. The before and after functions
+ are useful for changing artist-dependant renderer attributes or making
+ other setup function calls, such as starting and flushing a mixed-mode
+ renderer.
+ """
+
+ def draw_wrapper(artist, renderer):
+ if artist.get_rasterized():
+ renderer.start_rasterizing()
+ draw(artist, renderer)
+ renderer.stop_rasterizing()
+ else:
+ draw(artist, renderer)
+
+ # "safe wrapping" to exactly replicate anything we haven't overridden above
+ draw_wrapper.__name__ = draw.__name__
+ draw_wrapper.__dict__ = draw.__dict__
+ draw_wrapper.__doc__ = draw.__doc__
+ return draw_wrapper
+
+
+class RasterizedArtistType(type):
+ def __new__(meta, name, bases, dct):
+ if "draw" in dct:
+ _draw = dct["draw"]
+ #dct["_draw_original"] = _draw
+ dct["draw"] = hook_before_after_draw(_draw)
+ return type.__new__(meta, name, bases, dct)
+
+
class Artist(object):
"""
Abstract base class for someone who renders into a
:class:`FigureCanvas`.
"""
+ __metaclass__ = RasterizedArtistType
+
aname = 'Artist'
zorder = 0
def __init__(self):
@@ -45,6 +82,7 @@
self._label = ''
self._picker = None
self._contains = None
+ self._rasterized = None
self.eventson = False # fire events only if eventson
self._oid = 0 # an observer id
@@ -511,6 +549,19 @@
gc.set_clip_rectangle(None)
gc.set_clip_path(None)
+ def get_rasterized(self):
+ return self._rasterized
+
+ def set_rasterized(self, rasterized):
+ """
+ Force rasterized (bitmap) drawing in vector backend output.
+
+ Defaults to None, which implies the backend's default behavior
+
+ ACCEPTS: [True | False | None]
+ """
+ self._rasterized = rasterized
+
def draw(self, renderer, *args, **kwargs):
'Derived classes drawing method'
if not self.get_visible(): return
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel