New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify _bind_draw_path_function. #23571
Conversation
# FIXME: dpi_cor is for the dpi-dependency of the linewidth. There | ||
# could be room for improvement. Maybe _get_path_in_displaycoord could | ||
# take a renderer argument, but get_path should be adapted too. | ||
self._dpi_cor = renderer.points_to_pixels(1.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So its OK now for self._dpi_cor
to be changed permanently here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was already set permanently before?
It doesn't actually need to be a context manager, but can be a plain function, with an easier to explain behavior.
path = self.get_path() | ||
transform = self.get_transform() | ||
tpath = transform.transform_path_non_affine(path) | ||
affine = transform.get_affine() | ||
self._draw_paths_with_artist_properties( | ||
renderer, | ||
[(tpath, affine, | ||
# Work around a bug in the PDF and SVG renderers, which | ||
# do not draw the hatches if the facecolor is fully | ||
# transparent, but do if it is None. | ||
self._facecolor if self._facecolor[3] else None)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: What do you think of introducing
_DrawPathArgs = namedtuple('_DrawPathArgs', 'path, transform, rgb_face')
The main motivation is to name the tuple elements because the function signature
where we could look up their meaning is quite far away.
With this we could write:
path = self.get_path() | |
transform = self.get_transform() | |
tpath = transform.transform_path_non_affine(path) | |
affine = transform.get_affine() | |
self._draw_paths_with_artist_properties( | |
renderer, | |
[(tpath, affine, | |
# Work around a bug in the PDF and SVG renderers, which | |
# do not draw the hatches if the facecolor is fully | |
# transparent, but do if it is None. | |
self._facecolor if self._facecolor[3] else None)]) | |
transform = self.get_transform() | |
self._draw_paths_with_artist_properties( | |
renderer, | |
[_DrawPathArgs( | |
path=transform.transform_path_non_affine(self.get_path), | |
transform=transform.get_affine(), | |
# Work around a bug in the PDF and SVG renderers, which | |
# do not draw the hatches if the facecolor is fully | |
# transparent, but do if it is None. | |
rgb_face=self._facecolor if self._facecolor[3] else None), | |
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched to using a dict (and **kwargs
unpacking), which seems just as good here.
Actually #23571 (comment) doesn't really work because the parameter names are not part of the backend API; indeed, patheffects renderers use different parameter names. So really these arguments are currently positional and I reverted to the previous (tuple-based) approach. |
Ok, let's not overengineer this. You can self-merge when green. |
It doesn't actually need to be a context manager, but can be a plain
function, with an easier to explain behavior.
PR Summary
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).