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

Skip to content

Support url on more Artists in svg #17338

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

Merged
merged 3 commits into from
May 27, 2020
Merged

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented May 6, 2020

PR Summary

Add Line2D, QuadMesh, and Ticks (from #9696.)

Fixes #9695.
Fixes #17336.

Don't know if this should be documented.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • [?] New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • [?] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@QuLogic
Copy link
Member Author

QuLogic commented May 6, 2020

Ah, draw_quad_mesh doesn't take urls keyword argument on (some) other backends; what do we do when we want to add an argument like that for a renderer method?

@anntzer
Copy link
Contributor

anntzer commented May 6, 2020

My guess is that the backcompatible approach would be to add a set_url on the GraphicsContextBase class and read it from there. Not sure whether we want to go that route, which is a bit inconsistent with what we have elswhere; I guess having some more setters on GraphicsContextBase is not too bad especially compared to adding more parameters to an already long signature.

@QuLogic
Copy link
Member Author

QuLogic commented May 6, 2020

There is already GraphicsContextBase.set_url, but that's for a single url on a singular artist. For QuadMesh, it's a collection that goes through iter_path_collection and so the urls need to be iterated at the same time.

@tacaswell
Copy link
Member

We could do a bit of inspection and only pass the urls if they are supported? We have been doing that in several other places when changing the signature of internal functions that may have been sub-classed.

Extending gc to take set_urls also seems ok?

@QuLogic QuLogic added this to the v3.3.0 milestone May 8, 2020
use_urls = 'urls' in sig.parameters
if use_urls:
renderer.draw_quad_mesh(
gc, transform.frozen(), self._meshWidth, self._meshHeight,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion to make the code more concise:

kw = dict(urls=self.get_urls()) if use_urls else {}
renderer.draw_quad_mesh(gc, transform_frozen(), self._meshWidth, self._meshHeight,
                    coordinates, offsets, transOffset, self.get_facecolor(),
                    self._antialiased, self.get_edgecolors(), **kw)

@efiring
Copy link
Member

efiring commented May 8, 2020

I'm not sure that trying to add urls to quadmesh this way is going to be useful. You would need to go through all the same dimension checks when setting the urls that you have to go through for the colors, to make sure that the urls match the quadrilaterals that are actually shown. It gets complicated. And is quadmesh the right tool for this? Quadmesh shines when working with big arrays, but urls are only going to make sense for very small arrays--say a dozen blocks of color. For that, pcolor works fine. So adding url support to pcolor might make sense (if it doesn't already exist), but for pcolormesh it's not worth the pain.

@anntzer
Copy link
Contributor

anntzer commented May 8, 2020

Introspection won't work for things that can reasonably be implemented in C, e.g. mplcairo's draw_quad_mesh. (I'm fine for doing introspection on things that are rather unlikely to be implemented in C, e.g. FuncFormatter functions.)

@QuLogic
Copy link
Member Author

QuLogic commented May 12, 2020

Well, someone did ask for it, so I'm not sure it's totally inconceivable. Also, the URL does not have to be an actual URL that points to an external website. It could be a query or fragment for the current page or something used by some JS later.

I understand we aren't too good about the dimensions, so I guess I'd wait for #16908 for what we really want to accept.

@tacaswell
Copy link
Member

On a bit more thought, do want want to merge the non-quadmesh changes and defer the API extension / inspection until 3.4?

coordinates, offsets, transOffset, self.get_facecolor(),
self._antialiased, self.get_edgecolors())
try:
sig = inspect.signature(renderer.draw_quad_mesh)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted above I really don't think this is the correct (extensible) approach. Hence blocking, but just as a marker of "this specific point needs more discussion".

@QuLogic
Copy link
Member Author

QuLogic commented May 26, 2020

Let's do the non-QuadMesh stuff now, and defer that one for later.

@QuLogic QuLogic requested a review from anntzer May 26, 2020 22:21
@QuLogic QuLogic mentioned this pull request May 26, 2020
6 tasks
khyox and others added 3 commits May 26, 2020 18:32
In the class Tick, the url attribute is not passed to any of the objects
that are to be drawn. Suggested solution is to override the set_url()
method in Tick to transfer the url attribute content to the tick labels,
that are to be drawn.
@tacaswell tacaswell merged commit 510482f into matplotlib:master May 27, 2020
@QuLogic QuLogic deleted the svg-url branch June 3, 2020 21:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

set_url without effect for instances of Line2D set_url() without effect in the plot for instances of Tick
5 participants