Skip to content

Add gifs of usage to widget examples #19222

Open

Description

@ianhi

Problem

It can be hard to discern what a widget example does as for many of them there are no images that show up in the docs. For example the Lasso Selector Demo has no image and the Lasso Demo only has a static image.

Suggested Improvement

Manually generate GIFS of the usage and embed them onto the example pages. For example here is a GIF of me using the LassoSelector demo:
lasso-selector

I'm not sure if sphinx-gallery supports this though? maybe embeding and html <img> tag into the comment at the top would work?
Also instead of .gifs I it would be better to keep files small by using .apng and running them https://tinypng.com/

Activity

  1. story645 commented on Jan 3, 2021

    @story645
    Member

    Agree, and also #17479 has a discussion on the viability of doing something automated.

  2. timhoffm commented on Jan 4, 2021

    @timhoffm
    Member

    The animation is a useful addition to make the widget examples more easy to understand.

    This is not particular difficult but somewhat tedious because AFAICS it will need some manual steps and explicit configuration.

    Automated creation:

    While it may be possible to automatically generate a sceenshot from the user interface (as suggested in #17479), this animation here requires user interaction, which is more complicated. I assume it's not worth the effort to script user interaction for the examples.

    Manually generate GIFS

    I'm happy to see it if somebody takes the responsibility.

    What would have to be done:

    1. Generate a useful animated image (gif/apng).
    2. Embed that explicitly into the example using sphinx .. image:: directive.
    3. Create a downsampled version of that image for the tumbnail and configure sphinx-gallery to use this explicitly](https://sphinx-gallery.github.io/stable/configuration.html#providing-an-image-for-the-thumbnail-image)

    The whole process (in particular also the tooling used in 1.) should be described in the documentation guide so that we and others are able to reproduce it if necessary.

    Remark: It may be reasonable to get in touch with sphinx-gallery if the want to integrate something like a "standalone image", that combines 2. and 3. into a single command. I imagine that this could be useful for other cases that don't generate a in image (not necessarily animated) in the example code.

  3. QuLogic commented on Jan 5, 2021

    @QuLogic
    Member

    We do have a way of mocking events to widgets, so it might be possible to write some automated way to generate these. It would still require some work somewhere though to implement it all.

  4. timhoffm commented on Jan 5, 2021

    @timhoffm
    Member

    We do have a way of mocking events to widgets

    The downside is that you don't get the cursor. IMHO seeing the cursor movement significantly helps in understanding what's going on.

  5. ianhi commented on Jan 10, 2021

    @ianhi
    ContributorAuthor

    I agree that seeing the cursor is crucial for understanding, however manually recording the GIFs is also sad times because it would need to be redone anytime the styling changes. I think we can get the best of both worlds by doing:

    1. Mock the events and save these in a python file somewhere
      • I think this can be easily done by interacting by hand and just printing out the events and then throwing them into a python file.
    2. At docs build time run through the mock events + manually draw in a shape that looks like a mouse cursor
    3. Save that as an animation somewhere - can just be a FuncAnimation or something.
    4. Use a sphinx-gallery comment to embed the generated gif

    This also carries the extra advantage of not increasing the repo size as the only thing that is persistent is a text file of the mouseevents.

  6. timhoffm commented on Jan 11, 2021

    @timhoffm
    Member

    Um, this is doable but sounds like a medium size effort. I'm somewhat reluctant taking this on in core Matplotlib. 1-3 could be developed as a 3rd party package.

  7. jklymak commented on Jan 11, 2021

    @jklymak
    Member

    Agreed - this is a lot of machinery for something the user could just try themselves from the example.

    The low-tech way of doing this is to do them by hand, and then putting a comment in the widget code noting that they should be modified if there are major changes. That is pretty low maintenance and it is not like widgets are changing very often.

  8. ianhi commented on Jan 11, 2021

    @ianhi
    ContributorAuthor

    Um, this is doable but sounds like a medium size effort. I'm somewhat reluctant taking this on in core Matplotlib. 1-3 could be developed as a 3rd party package.

    I think it makes sense as a third party package. I would use this, and I think animatplotlib would also find it useful. To that end I couldn't get it out of my head so I did some maybe terrible things using exec and made this https://github.com/ianhi/mpl-playback

    Which I used to generate this gif:

  9. ianhi commented on Jan 11, 2021

    @ianhi
    ContributorAuthor

    But I hear the arguments about not adding extra machinery. If matplotlib ends up going the route of manually recording gifs I won't be made sad :)

  10. story645 commented on Jan 11, 2021

    @story645
    Member

    Is there also the option of making it a 3rd party package that is then a dependency in the doc builds?

  11. QuLogic commented on Jan 11, 2021

    @QuLogic
    Member
    • Mock the events and save these in a python file somewhere

      • I think this can be easily done by interacting by hand and just printing out the events and then throwing them into a python file.
    • At docs build time run through the mock events + manually draw in a shape that looks like a mouse cursor

    • Save that as an animation somewhere - can just be a FuncAnimation or something.

    • Use a sphinx-gallery comment to embed the generated gif

    This is essentially what I would do, with some small tweaks. Sphinx-gallery has a custom scraper API, so I would use that instead to create and inject the resulting GIF.

  12. ianhi commented on Jan 12, 2021

    @ianhi
    ContributorAuthor

    Thanks for the pointer @QuLogic, that does seem to be the correct approach. I don't think I handled the thumbnail stuff correctly yet, but here is a working gallery with GIFs:
    https://mpl-playback.readthedocs.io/en/latest/gallery/index.html

    edit: almost working it turns out. On readthedocs only the thumbnail renders, not inside the example. Which is different than locally 🤔 (edit2: now it all works 🎉)

  13. github-actions commented on Sep 25, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  14. added
    keepItems to be ignored by the “Stale” Github Action
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions