Skip to content

Animated Export

A figure can be exported as an HTML fragment that reveals itself with GSAP when the page loads: the title and axes enter, the subtitle types itself in, then the data appears in stages.

Animation is opt-in and exists only in the exported HTML. view.figure is identical with or without it, and a static export contains no animation code.

view = strategy.build(dfs, tr, theme)

view.to_html()                  # static
view.to_html(animate=True)      # animated, default settings
view.to_html(animate=AnimationSpec(speed=1.5, replay_button=True))

Four frames of a staged bar reveal

See it move

Run uv run python -m demo.animated_export from a checkout of the repository. It writes demo/output/animated_charts.html with every supported chart and a Replay button on each.

For the stepped version, run uv run python -m demo.animated_showcase: a presentation with every chart type, option combinations and the four indicators. Press Space to step through it.

What each chart does

Chart Reveal
Bar, grouped bar Bars grow from their base (left for horizontal bars, bottom for vertical ones). Descending charts reveal smallest first.
Line, categorical line Each line draws itself left to right; filled areas wipe in beside it.
Pie, doughnut, sunburst Slices grow out of the shared centre.
Choropleth map Countries fade in.
Heat map A top-to-bottom wipe (Plotly draws a heat map as one image, so there are no cells to stage).
Box plots The data layers fade in.

In every case the title, axes and gridlines enter first, and value labels fade in after their shapes.

Staging with color rules

ColorRule(…, reveal_stage=n) sets when the entries a rule colors appear. Stage 0 goes first, rules sharing a stage appear together.

muted = ColorRule(ColorAssignerByCategory(anchor_colors=[grey]), reveal_stage=0)
highlight = ColorRule(
    ColorAssignerByCategory(anchor_colors=[gold]),
    ColorSelectByCategoryName(["Germany"]),
    reveal_stage=1,  # the punchline lands last
)

Without reveal_stage

Rules reveal in declaration order, after any entries no rule colored.

Stages are matched by color

The reveal finds each rendered shape by its color. If two rules with different stages produce the same color, the earliest stage wins. Give staged rules distinct colors.

AnimationSpec

Field Default Meaning
speed 1.0 Playback speed multiplier.
ease "power2.inOut" Any GSAP ease.
autoplay True Start when Plotly has drawn the figure.
replay_button False Add a Replay button below the figure.
type_subtitle True Type the subtitle in letter by letter instead of fading it.
gsap_src jsDelivr CDN A URL, or a path to a local gsap.min.js that is inlined into the page.
pause_after () Where to wait: "axes" and/or stage numbers. See Presenting step by step.
keys False Bind Space/arrows/Page keys to step through the reveal.

Pages with several figures

Plotly, GSAP and the reveal runtime only need to be on the page once:

for index, view in enumerate(views):
    html = view.to_html(
        animate=True,
        include_plotlyjs="cdn" if index == 0 else False,
        include_runtime=index == 0,
    )

Presenting step by step

By default the reveal plays straight through. With pause_after it waits at the points you choose, so you can show the axes, talk, show the common markers, talk, then show the highlighted ones.

spec = AnimationSpec(pause_after=["axes", 0])  # stop after the axes, and again after stage 0
view.to_html(animate=spec)

The reveal is cut into steps: one more than the number of pauses. ["axes", 0] gives three:

Step What is on screen Pause point
1 Title, subtitle and axes "axes"
2 …and the markers of reveal_stage=0 0
3 …and the markers of reveal_stage=1, labels included none: the end

Each pause point is "axes" or a reveal stage number. The end of the reveal is always the last step, so the last stage needs no pause. A chart whose rules declare no stages has a single stage, 0, which is the whole data layer.

A point the chart lacks is ignored

pause_after=[7] on a chart without a stage 7 places no pause and logs a warning in the browser console.

What advances it

Dispatch an event on the figure's container, or on document to drive every animated figure on the page:

chart.dispatchEvent(new CustomEvent("orama:next", { bubbles: true }));       // one chart
document.dispatchEvent(new CustomEvent("orama:next"));                       // all of them
document.dispatchEvent(new CustomEvent("orama:next", { detail: { id: "sales" } }));  // one, by id
document.dispatchEvent(new CustomEvent("orama:goto", { detail: { step: 0 } }));      // jump

The events are orama:next, orama:prev and orama:goto (with detail.step).

const handle = window.oramaAnimations["sales"];
handle.next();      // reveal the next step
handle.prev();      // go back one step
handle.goto(2);     // jump to a step (0 is the blank start, handle.steps the end)
handle.step;        // the step on screen
handle.steps;       // how many steps there are

AnimationSpec(keys=True) binds the keyboard, which is off by default:

Key Action
Space, Enter, →, ↓, Page Down next
←, ↑, Page Up previous
Home, End first (blank) and last step

Keys are ignored while typing in a field, and with Ctrl, Alt or ⌘ held.

A trigger during a step finishes it

If you advance while a step is still animating, that step completes instantly and the next trigger starts the following one, so a double press never skips a beat.

What it tells the page

The figure announces itself with events that bubble up from its container, and a state attribute for CSS:

Event When detail
orama:stage A step has finished (or you jumped to one) {id, step, steps}
orama:paused …and the reveal is waiting for a trigger {id, step, steps}
orama:done …and it was the last step {id, step, steps}

data-orama-animation-state is ready (step 0), playing, paused or done. The chart shows no hint of its own while it waits; use these to show yours.

Where it starts

autoplay=True (the default) plays up to the first pause as soon as the figure is drawn. With autoplay=False it starts blank and the first trigger starts it.

Indicators and sequences

KPI indicators animate too: the title fades in, the fill sweeps and the numbers count up from zero, ending on exactly the text of the static indicator. An indicator is a single step.

kpi_view.to_html(animate=True)

render_sequence chains figures and indicators into one page, one slide at a time. A trigger first advances the current slide's steps, then moves on to the next slide.

from orama.animation import AnimationSpec, render_sequence

page = render_sequence(
    [(chart, AnimationSpec(pause_after=["axes", 0])), kpi_view, another_chart],
    theme=theme,           # the page follows the theme's background and colors
    title="Q3 review",
)

Give a slide its own pauses with a (view, AnimationSpec) pair. The others use the spec argument.

exclusive=False keeps earlier slides on screen as the next ones appear, instead of replacing them.

Already have a page with several animated figures? Chain them in JavaScript:

const sequence = oramaReveal.sequence(["sales", "kpi", "map"], { keys: true, exclusive: true });
sequence.next();  sequence.prev();  sequence.goto(1);

Items not reached yet stay hidden. When the last item finishes its last step, orama:sequence-done is dispatched on document.

Going back

Back steps through a slide's steps, then to the previous slide in its final state. A slide that autoplays never rests blank, so going back from its first step leaves it.

Working offline

spec = AnimationSpec(gsap_src="static/gsap.min.js")  # inlined into the page
html = view.to_html(animate=spec, include_plotlyjs=True)  # Plotly inlined too (~4 MB)

GSAP is not bundled

orama does not redistribute GSAP; it loads it from a CDN, or inlines a copy you provide. GSAP has its own license.

Controlling playback from JavaScript

Every animated figure registers a handle in window.oramaAnimations, keyed by the container id (pass container_id= to choose it).

const handle = window.oramaAnimations["sales"];
handle.play();          // restart from the beginning (it still waits at its pause points)
handle.seek(1.5);       // jump to 1.5 s (the timeline pauses there)
handle.duration();      // total length in seconds
handle.next();          // stepped reveals: see "Presenting step by step"

The container also carries data-orama-animation-state: ready, playing, paused or done, handy for tests and for screen-recording tools. Set autoplay=False and call play() or next() yourself to start on your own cue.

Plotly internals

The reveal addresses the SVG that Plotly draws, through its CSS class names. A Plotly upgrade that renames them can break a chart's reveal (the figure still renders). All the selectors live in one table at the top of orama/animation/static/reveal.js, and the browser tests under tests/e2e/ catch regressions.