Skip to content

Implement per-frame animation durations for Figure and FigureWidget#5601

Open
FredericoMendes10 wants to merge 2 commits into
plotly:mainfrom
FredericoMendes10:feature-5362
Open

Implement per-frame animation durations for Figure and FigureWidget#5601
FredericoMendes10 wants to merge 2 commits into
plotly:mainfrom
FredericoMendes10:feature-5362

Conversation

@FredericoMendes10
Copy link
Copy Markdown

Link to issue

Closes #5362

Description of change

Adds set_frame_durations(durations) to Figure and animate_frames(frames_data, durations) to FigureWidget, allowing each animation frame to have its own duration in milliseconds. When per-frame durations are set, to_html generates a custom JavaScript playback loop instead of the global Plotly.animate(null) call.

Demo

https://youtu.be/qyjkXgh-Tf8

Testing strategy

Added tests/test_animation/test_set_frame_durations.py with 174 lines covering: scalar vs list durations, validation errors (wrong length, negative values, non-numeric), chaining behaviour, and HTML output containing the custom JS loop.

Additional information

Co-authored with Mário Vaz Silvestre (@MarioSilvestre2901).

Guidelines

Add set_frame_durations(durations) to Figure, which accepts a scalar
or a list of values (in milliseconds) and stores the duration on each
frame. Example:

    fig = go.Figure(frames=[go.Frame(name=0), go.Frame(name=1)])
    fig.set_frame_durations([200, 2000])

When to_html detects per-frame durations it generates a custom
JavaScript playback loop instead of the global Plotly.animate(null)
call, so each frame is displayed for its own duration.

Also add animate_frames(frames_data, durations) to FigureWidget for
the widget use-case, delegating to batch_animate per frame.

Closes plotly#5362

Co-authored-by: Mário Vaz Silvestre <mario.silvestre@tecnico.ulisboa.pt>
@camdecoster
Copy link
Copy Markdown
Contributor

Thanks for the PR! One of our team members will review it soon.

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.

Animations: let 'Play' button support different durations for different frames

3 participants