Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5678ac0

Browse files
committed
Combine withEffect PathEffect definitions.
1 parent 42e3f92 commit 5678ac0

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

lib/matplotlib/patheffects.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,26 @@ class Normal(AbstractPathEffect):
159159
The Normal PathEffect's sole purpose is to draw the original artist with
160160
no special path effect.
161161
"""
162-
pass
162+
163+
164+
def _make_with_effect(cls):
165+
"""
166+
Generate a PathEffect combining the effect of *cls* and a normal draw.
167+
"""
168+
169+
class withEffect(cls):
170+
def draw_path(self, renderer, gc, tpath, affine, rgbFace):
171+
super().draw_path(renderer, gc, tpath, affine, rgbFace)
172+
renderer.draw_path(gc, tpath, affine, rgbFace)
173+
174+
withEffect.__name__ = f"with{cls.__name__}"
175+
withEffect.__doc__ = f"""
176+
Adds a `.{cls.__name__}` and then draws the original Artist to avoid
177+
needing to call `.Normal`.
178+
"""
179+
# Docstring inheritance doesn't work for locally-defined subclasses.
180+
withEffect.draw_path.__doc__ = cls.draw_path.__doc__
181+
return withEffect
163182

164183

165184
class Stroke(AbstractPathEffect):
@@ -185,15 +204,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
185204
gc0.restore()
186205

187206

188-
class withStroke(Stroke):
189-
"""
190-
Adds a simple :class:`Stroke` and then draws the
191-
original Artist to avoid needing to call :class:`Normal`.
192-
193-
"""
194-
def draw_path(self, renderer, gc, tpath, affine, rgbFace):
195-
Stroke.draw_path(self, renderer, gc, tpath, affine, rgbFace)
196-
renderer.draw_path(gc, tpath, affine, rgbFace)
207+
withStroke = _make_with_effect(Stroke)
197208

198209

199210
class SimplePatchShadow(AbstractPathEffect):
@@ -262,15 +273,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
262273
gc0.restore()
263274

264275

265-
class withSimplePatchShadow(SimplePatchShadow):
266-
"""
267-
Adds a simple :class:`SimplePatchShadow` and then draws the
268-
original Artist to avoid needing to call :class:`Normal`.
269-
270-
"""
271-
def draw_path(self, renderer, gc, tpath, affine, rgbFace):
272-
SimplePatchShadow.draw_path(self, renderer, gc, tpath, affine, rgbFace)
273-
renderer.draw_path(gc, tpath, affine, rgbFace)
276+
withSimplePatchShadow = _make_with_effect(SimplePatchShadow)
274277

275278

276279
class SimpleLineShadow(AbstractPathEffect):

0 commit comments

Comments
 (0)