Skip to content

Add dropdowns showing the code for cookbook figures - #4927

Closed
maxrjones wants to merge 4 commits into
masterfrom
cookbook-code-dropdowns
Closed

maxrjones wants to merge 4 commits into
masterfrom
cookbook-code-dropdowns

Conversation

@maxrjones

@maxrjones maxrjones commented Mar 8, 2021 •

Copy link
Copy Markdown
Member

Description of proposed changes

This PR adds dropdown panels (using sphinx-panels) that show the code used to generate the figures in the 'features' section of the cookbook. Relates to #4926, which shows a different sphinx extension for generating dropdown panels. Also relates to the documentation discussion initiated by @KristofKoch here.

Preview link: https://gmt-1r6r2gxux-gmt.vercel.app/cookbook/features.html#overview-and-the-gmt-conf-file

It shows a toggle button:

image

which can be clicked on to show the code:

image

Fixes #

Reminders

  • Make sure that your code follows our style. Use the other functions/files as a basis.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Describe changes to function behavior and arguments in a comment below the function declaration.
  • If adding new functionality, add a detailed description to the documentation and/or an example.

@maxrjones maxrjones changed the title Cookbook code dropdowns Add dropdowns showing the code for cookbook figures Mar 8, 2021
@KristofKoch

Copy link
Copy Markdown
Contributor

Great work @meghanrjones! I'm not sure about the prominence of the dropdowns. In my eyes they draw too much attention from the reader. I agree with @seisman in #4926 and would prefer the sphinx-togglebutton. Compare for yourself in this crude mock-up:

dropdown vs toggle

Additionally I would place the script beneath the plot as this would aid the flow of reading:

your version:

  • explaining text
  • script for a figure I haven't seen yet
  • illustrating figure
  • figure caption

proposed version:

  • explaining text
  • illustrating figure
  • figure caption
  • script for figure

What do you think?

@maxrjones

Copy link
Copy Markdown
Member Author

Great work @meghanrjones! I'm not sure about the prominence of the dropdowns. In my eyes they draw too much attention from the reader. I agree with @seisman in #4926 and would prefer the sphinx-togglebutton. Compare for yourself in this crude mock-up:

dropdown vs toggle

Additionally I would place the script beneath the plot as this would aid the flow of reading:

your version:

* explaining text

* script for a figure I haven't seen yet

* illustrating figure

* figure caption

proposed version:

* explaining text

* illustrating figure

* figure caption

* script for figure

What do you think?

I agree with placing the dropdown/toggle-button after the code. I also like the more subtle style of the togglebutton, but think that a more descriptive message for the button is essential (i.e., 'Click to show the source script' rather than 'Click to show'). I don't think this is included in the sphinx-togglebutton extension, but since the source code is so simple with a permissive license perhaps we could add the functionality or open an issue in sphinx-togglebutton. @seisman, do you know if changing the 'Click to show' text is already possible with that extension?

@seisman

seisman commented Mar 8, 2021

Copy link
Copy Markdown
Member

do you know if changing the 'Click to show' text is already possible with that extension?

Yes, the extension provides a configuration to change the hint text (see https://sphinx-togglebutton.readthedocs.io/en/latest/#configuration), but the text is the same for all toggle buttons.

I think we may want to use different texts for different cases. For example:

  • "Click to show the source script"
  • "Click to show an example"

It's possible to extend the directive to support a custom hint text, e.g.,

.. toggle:: Click to show an example
   
   IMAGE.

   SOURCE.

@maxrjones

Copy link
Copy Markdown
Member Author

do you know if changing the 'Click to show' text is already possible with that extension?

Yes, the extension provides a configuration to change the hint text (see https://sphinx-togglebutton.readthedocs.io/en/latest/#configuration), but the text is the same for all toggle buttons.

I think we may want to use different texts for different cases. For example:

* "Click to show the source script"

* "Click to show an example"

It's possible to extend the directive to support a custom hint text, e.g.,

.. toggle:: Click to show an example
   
   IMAGE.

   SOURCE.

Great, let's move forward with using the togglebutton for showing the scripts.

This branch was previously deployed

1 inactive deployment
Preview — 88d0cf24 Deployed Mar 8, 2021 by vercel[bot]
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