Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[svg] Add rcParam["svg.id"] to add a top-level id attribute to <svg>#28536

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 3 commits intomatplotlib:mainfromwillemsk:feature/svg-top-level-id
Jul 12, 2024

Conversation

willemsk
Copy link
Contributor

PR summary

Exported SVGs now contain a fixedid="svg1" attribute in the top level<svg> tag.

<svgxmlns:xlink="http://www.w3.org/1999/xlink"width="50pt"height="50pt"viewBox="0 0 50 50"xmlns="http://www.w3.org/2000/svg"version="1.1"id="svg1">

This is useful if you would like to link the entire matplotlib SVG file within another SVG file with the<use> tag.

<usewidth="50"height="50"xlink:href="mpl.svg#svg1"id="use1"x="0"y="0"/>

Where the#svg1 indicator will now refer to the top level<svg> tag, and will hence result in the inclusion of the entire file.

Closes issue#28535

PR checklist

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@tacaswelltacaswell added this to thev3.10.0 milestoneJul 11, 2024
@tacaswell
Copy link
Member

Thank you for this work. I agree that this is useful and worth doing, but have some questions about the implementation.

I am a bit concerned about using a hard-coded value, would in be better to allow this to be threaded throughfig.savefig(...) with a default of'svg1'? Would a less generic string (likematplotlib ormpl) be better as a default?

@timhoffm
Copy link
Member

timhoffm commentedJul 11, 2024
edited
Loading

I share the concern of a hard-coded value.

Configuration can be

  • either viasavefig() - T.b.d. how to fit this in the signature. A top-levelid parameter is a bit awkward, because it would only be used for the SVG renderer. Alternatives would be a genericrederer_params dict, or (a bit hacky) put it inmetadata and let the SVG renderer pop it from there.
  • or if threading throughsafefig is too much song and dance API-wise, just create an rcParam. This would be a little more cumbersome to use but simpler to implement. - Ok if setting id is really rare.

I also believe, the default should be no attribute, as it is now. Setting the attribute should be opt-in.

@willemsk
Copy link
ContributorAuthor

Fair enough, I went the hardcoded route because there was indeed no straightforward path to pass it throughplt.savefig().
I think myuse-case is fairly niche, and it shouldbecome irrelevant when SVG2.0 is adopted (which may be never though).

If you agree on an approach I'd be happy to draft an implementation!

@timhoffm
Copy link
Member

timhoffm commentedJul 11, 2024
edited
Loading

If the application is fairly niche, I'd go with an rcParamsvg.id (default: None); seehere:

image

@tacaswell
Copy link
Member

I also support going the rcparam route with default behavior beingNone as Tim proposes.

If not None, the `svg.id` rcParam value will be used for settingthe `id` attribute of the top `<svg>` tag.
@willemsk
Copy link
ContributorAuthor

I've added an implementation using rcparams.

``svg.id`` rcParam
~~~~~~~~~~~~~~~~~~
The value of this new rcParam controls whether the top-level ``<svg>`` tag
contains an ``id`` attribute and what its value is. When set to ``None`` (the
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
contains an``id`` attribute and what its value is. When set to ``None`` (the
contains an:rc:`svg.id` attribute and what its value is. When set to ``None`` (the

to use our custom role.

Copy link
Member

Choose a reason for hiding this comment

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

No. Here,id is the attibute ins<svg>.

Copy link
Member

Choose a reason for hiding this comment

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

I took the liberty of rephrasing to make it more concise.

Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

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

conditional on the docs change to use the rc role goes in

@timhoffmtimhoffm changed the title[svg] Add 'id="svg1"' attribute top svg tag[svg] Add rcParam["svg.id"] to add a top-level id attribute to <svg>Jul 12, 2024
@timhoffmtimhoffm merged commitc56027b intomatplotlib:mainJul 12, 2024
42 of 43 checks passed
@timhoffm
Copy link
Member

Thanks@willemsk and congratulations on your first contribution to Matplotlib! We'd welcome to see you back.

willemsk reacted with heart emoji

@willemskwillemsk deleted the feature/svg-top-level-id branchJuly 12, 2024 18:20
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timhoffmtimhoffmtimhoffm approved these changes

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@tacaswelltacaswelltacaswell approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.10.0
Development

Successfully merging this pull request may close these issues.

3 participants
@willemsk@tacaswell@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp