Skip to content

Animations for STV Elections#249

Merged
peterrrock2 merged 96 commits into3.4.0from
3.3.0-stv-animation
Feb 28, 2026
Merged

Animations for STV Elections#249
peterrrock2 merged 96 commits into3.4.0from
3.3.0-stv-animation

Conversation

@prismika
Copy link
Copy Markdown
Collaborator

Pursuant to issue #222. This PR adds support for animating STV elections using Manim. Given a votekit STV election called election, the user can render an animation using, for example,

animation = STVAnimation(election, title=f"Animation of STV Election")
animation.render(preview=True)

Here is an example of a rendered scene.

ElectionScene2.mp4

This PR is a draft. I have yet to write robust testing for the animation pipeline (such as snapshot testing). I also have yet to implement a few requested features:

  • Letting users specify which candidates are on screen, batching offscreen eliminations into a single animation event.
  • Letting users specify nicknames for candidates to appear onscreen.
  • "Light mode"

Before implementing these I wanted some feedback on my code so far.

Thanks!

@prismika prismika requested review from cdonnay and peterrrock2 July 25, 2025 16:08
Copy link
Copy Markdown
Collaborator

@cdonnay cdonnay left a comment

Choose a reason for hiding this comment

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

Hi @prismika. Switching computers here so just submitting a partial review for now, will pick it back up in an hour or so.

Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Copy link
Copy Markdown
Collaborator

@cdonnay cdonnay left a comment

Choose a reason for hiding this comment

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

Alright review complete!

  1. This looks great already! I think you should feel confident moving onto your other todos.
  2. I'd encourage a little more modularization. You can see the code for PreferenceProfile as an example of super tiny private methods that build into the bigger methods. Peter is a big fan of keeping functions short.

Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py
Comment thread src/votekit/animations.py
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
@cdonnay
Copy link
Copy Markdown
Collaborator

cdonnay commented Jul 25, 2025

Since I am not a manim guy, I'm going to skip looking at that code for now since the animation clearly works. But the same overall review comments would apply; aim for super tiny private methods that build into bigger ones (up to reason). @peterrrock2 will check out your manim code when he gets a chance.

Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py
Comment thread src/votekit/animations.py Outdated
Comment thread .github/workflows/test.yml Outdated
Copy link
Copy Markdown
Collaborator

@peterrrock2 peterrrock2 left a comment

Choose a reason for hiding this comment

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

This is looking great!

Small nit: I am trying to unify the doc string style across the repository. Can you modify the doc strings to look more like:

def  foo( arg1: str | None, arg2: int = 3) -> str:
    """
    Brief description (max 100 chars including indents)

    More details (max 100 chars per line, but as many lines as you would like)

    Example: 
        <Stuff goes here. This section is optional>

    Args:
        arg1 (str | None): description
        arg2 (int, optional): description. Defaults to 3.

    Returns:
        str: The string "baz"
    """
   ...

This is a mild modification of the Google-style doc string and adheres to the PEP 257 recommendation but with the line width modified to 100 chars rather than 80 (better for 16:9 screens IMO)

Comment thread src/votekit/animations.py
Comment thread src/votekit/animations.py
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
Comment thread src/votekit/animations.py Outdated
@peterrrock2 peterrrock2 merged commit 4b767f7 into 3.4.0 Feb 28, 2026
5 of 8 checks passed
@peterrrock2 peterrrock2 deleted the 3.3.0-stv-animation branch February 28, 2026 20:45
@peterrrock2 peterrrock2 mentioned this pull request Apr 9, 2026
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