DOC: Clarify SVG hyperlink behavior in gallery hyperlinks example#31497
Conversation
timhoffm
left a comment
There was a problem hiding this comment.
This is not the intended solution for #31452
Instead, we want to show the SVG images. There are to possible approaches
- the difficult one: make sphinx-gallery (optionally) support creating SVG output.
- the hacked one: render the SVG image locally and add it as a static image to the example.
|
@timhoffm Thanks for the clarification! I understand that the goal is to actually show the SVG output rather than just explain the behavior. I’ll work on implementing the second approach by rendering the SVG locally and adding it as a static image to the example. |
timhoffm
left a comment
There was a problem hiding this comment.
Missing svg files and inappropirate comment location/(maybe) content.
Please take more care in veryifing the result of your changes.
| # NOTE: | ||
| # Hyperlinks in SVG output may not appear interactive in the documentation | ||
| # because Sphinx renders SVGs as static images (<img> tags), | ||
| # so hyperlinks are not clickable | ||
| # The SVG images are shown below. | ||
| # To see working hyperlinks, open the generated SVG file directly in a browser. | ||
|
|
There was a problem hiding this comment.
This renders as a comment in the code, which is not appropriate. Instead it should be regular example text.
Also, I'm not clear whether the content is correct. If we show the svgs here, is it still needed to open the files separately in a browser?
timhoffm
left a comment
There was a problem hiding this comment.
Again, I urge you to validate your proposals locally before pushing to a public PR. - Or at the very least mark your PR as draft until you are sure it does the right thing.
Posting half-baked PRs causes unnecessary reviewer effort. In the interest of project health, we can only tolerate so much of this. Continued deficits in PR quality may lead to closure.
| # %% | ||
| # Display generated SVGs in docs | ||
| # | ||
| # .. image:: scatter.svg |
There was a problem hiding this comment.
The SVGs do not appear in the documentation. Likely because the generated .rst source file are in a different place than the .py. So the files cannot be found. See also https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#images
|
@timhoffm Thank you for pointing this out, and sorry for not validating the changes properly before pushing. I now understand the issue with SVGs not appearing due to incorrect paths. I'll fix this and verify the documentation locally before updating the PR. |
|
Hello @timhoffm
The outputs are now visible in the documentation. Please let me know if anything still needs improvement. |
|
Hello @timhoffm, I’ve updated the example based on your suggestion:
The elements are now clickable (cursor changes on hover), and clicking triggers navigation. However, the link opens within the embedded SVG (replacing the image). Could you please confirm if this behavior is acceptable, or would you prefer the links to open externally (e.g., in a new tab)? Happy to adjust accordingly. |
336724d to
1cf8052
Compare
direct html embedding seems like the way to go.
|
Opening externally would be better, if that is possible. Could you please rebase onto main? Doc builds are failing, but it's not due to the changes in this PR. I suspect that the merge of this branch with main somehow messes up the doc build environment config. |
1cf8052 to
8d2302d
Compare
|
@timhoffm Thanks! I’ve rebased the branch onto main. Regarding external opening: currently, the links are embedded in the SVG and clicking navigates within the SVG. Could you confirm if this is acceptable, or if you'd prefer a specific enforcing opening in a new tab? |
|
Thanks for rebasing. This looks good now. Opening externally is strongly preferred. I suspect the way to do this is adding a |
|
Thanks for the clarification! @timhoffm Understood, I'll keep this PR focused on the documentation update. I’ll open a separate PR for adding target="_blank" to SVG links. |
When embedding SVG in HTML, link `href`s can target different browsing contexts. This e.g. leads to links inside SVGs in matplotlib#31497 replacing the SVG image instead of opening a new browser window. The solution is to set `target="_blank"` for all links that implement `Artist.get_url()`. This is always intended as an external link, so universally adding `target="_blank"` is justified. Background info: https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/target https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/target#_blank
When embedding SVG in HTML, link `href`s can target different browsing contexts. This e.g. leads to links inside SVGs in matplotlib#31497 replacing the SVG image instead of opening a new browser window. The solution is to set `target="_blank"` for all links that implement `Artist.get_url()`. This is always intended as an external link, so universally adding `target="_blank"` is justified. Background info: https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/target https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/target#_blank
31265b8 to
0488e1f
Compare
|
Thanks @jayaprajapatii ! |
|
@meeseeksdev backport to v3.11.x |
…497-on-v3.11.x Backport PR #31497 on branch v3.11.x (DOC: Clarify SVG hyperlink behavior in gallery hyperlinks example)

Closes #31452
Summary
Show the generated SVG outputs in the hyperlinks example by embedding them directly in the documentation.
Problem
The example generated SVG files with hyperlinks, but they were not visible or interactive in the documentation, making the behavior unclear.
Solution
The example still generates SVG files as before.
The documentation now embeds these SVGs using HTML (
<object>), so that the hyperlinks inside the SVG remain interactive.Impact