Skip to content

Support odd-length dash patterns in Agg.#17444

Merged
QuLogic merged 1 commit intomatplotlib:masterfrom
anntzer:odddash
May 19, 2020
Merged

Support odd-length dash patterns in Agg.#17444
QuLogic merged 1 commit intomatplotlib:masterfrom
anntzer:odddash

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented May 18, 2020

PR Summary

All vector backends already support passing an odd-length dash pattern,
duplicating the on/off array (so that on the second repetition "on"
becomes "off" and vice-versa). This is also explicitly supported by
the svg spec for stroke-dasharray ("If an odd number of values is
provided, then the list of values is repeated to yield an even number of
values. Thus, 5,3,2 is equivalent to 5,3,2,5,3,2.") and less explicitly
by the pdf and ps specs, and by cairo. So the backend needing support
is Agg; iterating twice over the sequence is likely simplest.

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

Comment thread src/py_converters.cpp
return 0;
}
Py_ssize_t nentries = PySequence_Size(dashes_seq);
Py_ssize_t dash_pattern_length = (nentries % 2) ? 2 * nentries : nentries;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a comment what this is doing and why? It's hard to understand if one doesn't know the context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

All vector backends already support passing an odd-length dash pattern,
duplicating the on/off array (so that on the second repetition "on"
becomes "off" and vice-versa).  This is also explicitly supported by
the svg spec for `stroke-dasharray` ("If an odd number of values is
provided, then the list of values is repeated to yield an even number of
values. Thus, 5,3,2 is equivalent to 5,3,2,5,3,2.") and less explicitly
by the pdf and ps specs, and by cairo.  So the backend needing support
is Agg; iterating twice over the sequence is likely simplest.
@QuLogic QuLogic merged commit 16ae357 into matplotlib:master May 19, 2020
@QuLogic QuLogic added this to the v3.3.0 milestone May 19, 2020
@anntzer anntzer deleted the odddash branch May 19, 2020 22:02
brunobeltran added a commit to brunobeltran/matplotlib that referenced this pull request Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants