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

Skip to content

DOC: Sort gallery subsections by explicit list then by filename #11257

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

Conversation

ImportanceOfBeingErnest
Copy link
Member

@ImportanceOfBeingErnest ImportanceOfBeingErnest commented May 15, 2018

PR Summary

This is an alternative to #11214.
In #11214 I proposed to order the subsections by filename instead of codelength (which is a useless measure). While sorting by filename is clearly better, there are still some undesired effects, mostly within the tutorials section where you would rather like to have a custom order implemented to e.g. have the User Guide be the first item in the "introductory" section.

This PR creates a custom "Order-Class" for both, the sections in the gallery / tutorial, as well as the subsections.
This allows to set an explicit order for items if desired and falls back to sorting by path-/filename if some list does not contain the item.

In this way we can have the gallery mostly look nice due to filename ordering, but where necessary/desired impose some custom order.

If you consider this a viable option, feel free to suggest further custom ordering for sections where you feel it is needed.

PR Checklist

  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant

@ImportanceOfBeingErnest ImportanceOfBeingErnest changed the title Sort gallery subsections by explicit list then by filename DOC: Sort gallery subsections by explicit list then by filename May 15, 2018
@jklymak
Copy link
Member

jklymak commented May 15, 2018

This looks great to me, unless there are some weird eide effects.

I'd add a note both in the conf.py (though its a bit self-documenting) and the developer's guide to writing documentation about this so no one forgets where this gets done.

@jklymak jklymak added this to the v2.2-doc milestone May 15, 2018
@ImportanceOfBeingErnest
Copy link
Member Author

I added a note in conf.py and the dev guide to writing the docs.

The doc built from the tests is available here.
I did not observe any "weird side effects".

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Great improvement!

self.ordered_list = list_all

def __call__(self, item):
if item in self.ordered_list:
Copy link
Member

Choose a reason for hiding this comment

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

"""Return a string determining the sort order."""

if item in self.ordered_list:
return "{:04d}".format(self.ordered_list.index(item))
else:
return "zzz" + item
Copy link
Member

Choose a reason for hiding this comment

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

return "zzz" + item  # ensure not explicitly listed items come last.

# Examples/tutorials that do not appear in a list will be appended.

# Tutorials:
list_introductory = ["usage", "pyplot", "sample_plots", "images", "lifecycle",
Copy link
Member

Choose a reason for hiding this comment

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

Constructing all the small lists seems a bit cumbersome and is harder to read because of the variing list positions. I would just do:

explicit_subsection_order = [item + ".py" for item in [
    #  **Tutorials**
    #  introductory
    "usage", "pyplot", "sample_plots", "images", "lifecycle", "customizing",
    #  intermediate
    "artists", "legend_guide", "color_cycle", "gridspec",
    "constrainedlayout_guide", "tight_layout_guide",
    #  advanced
    #  text
    "text_intro", "text_props",
    #  colors
    "colors",

    #  **Examples**
    #  color
    "color_demo",
    #  pies
    "pie_features", "pie_demo2",
]]

Copy link
Member

@phobson phobson left a comment

Choose a reason for hiding this comment

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

Looks good. The sphinx galleries look great.
I'll leave this for someone like @timhoffm who's more up to speed with the current state of the docs

@timhoffm timhoffm merged commit c098519 into matplotlib:master May 16, 2018
@lumberbot-app
Copy link

lumberbot-app bot commented May 16, 2018

There seem to be a conflict, please backport manually

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.

5 participants