8000 Combine withEffect PathEffect definitions. · matplotlib/matplotlib@b85d64b · GitHub
[go: up one dir, main page]

Skip to content

Commit b85d64b

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

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

lib/matplotlib/patheffects.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,25 @@ 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+
180+
return withEffect
163181

164182

165183
class Stroke(AbstractPathEffect):
@@ -185,15 +203,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
185203
gc0.restore()
186204

187205

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)
206+
withStroke = _make_with_effect(Stroke)
197207

198208

199209
class SimplePatchShadow(AbstractPathEffect):
@@ -262,15 +272,7 @@ def draw_path(self, renderer, gc, tpath, affine, rgbFace):
262272
gc0.restore()
263273

264274

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)
275+
withSimplePatchShadow = _make_with_effect(SimplePatchShadow)
274276

275277

276278
class SimpleLineShadow(AbstractPathEffect):

0 commit comments

Comments
 (0)
0