Skip to content

Chart

Python motion graphics built from standard video2d entities. The package requires no renderer extension: preview, server export and native rendering consume the same primitive DOM.

Select Chart in project.json, then use:

from manifest import Video2d, Position, Font, FadeIn
from manifest.chart import LineChart, DrawIn

def build(seq, frame):
    chart = LineChart(frame, Position(100, 100),
        [(0, 12), (1, 28), (2, 20)], size=(800, 450),
        x_domain=(0, 2), y_domain=(0, 40), font=Font('Source Code Pro'))
    reveal = DrawIn(chart, time=2)
    seq.show(FadeIn(chart.axes))
    seq.show(FadeIn(chart.labels))
    seq.show(reveal)

def make_video():
    return Video2d(build)

Construct reveal helpers before earlier introduction animations to hide marks throughout those introductions. Every chart exposes normal entity properties; use ordinary Move, Fade, AbsoluteTransition, sequences and bundles.

  • LineChart, AreaChart, BarChart, and ScatterPlot accept numeric values (x defaults to index) or (x, y) points. add_series(data, name=..., color=...) adds another independently controllable series. Explicit domains are recommended for multiple series; domains remain fixed throughout data changes.
  • BarChart(orientation='horizontal') changes orientation. Multiple series group by default; stacked=True separates positive and negative accumulations.
  • AreaChart(stacked=True) stacks bands with matching x coordinates.
  • PieChart(values=[...]) and DonutChart(values=[...]) accept nonnegative values. radius, inner_radius, start_angle and colors configure geometry.
  • axes, labels, grid, and legend are independently animatable groups. Pass font to create tick labels and legend text. series exposes marks and lines. Series color, stroke_width, and marker_radius inherit into marks.
  • DrawIn, GrowBars, RevealPoints, and RevealSlices return sequence animations. TransitionData(chart, data, time=1, series=0) interpolates equal-size datasets; topology changes retain matching entities and fade only entering/leaving marks. Pass item_ids to retain identities through insertion, removal and reorder. Stacked areas require shared, unchanged x coordinates and item ordering. set_data(data, series=0) replaces Cartesian marks immediately at the current sequence position. Scatter plots also have add_point and add_points, with optional item IDs.

series_id assigns a stable string identity when constructing or adding a series. TransitionData(..., series='revenue', item_ids=['jan', 'feb'], bubble_sizes=[8, 16]) addresses that series and preserves the entity IDs of matching items. Bubble sizes are radii in drawing units; they scale with the series marker radius. Pie/donut constructors and data transitions also accept stable item_ids.

Animate geometry-dependent settings using the standard sequence helpers:

import manifest.chart as charts

seq.show(charts.TransitionLayout(chart,
    size=(1000, 500), x_domain=(0, 12), y_domain=(0, 1000), time=1))
seq.show(charts.TransitionPie(donut,
    radius=180, inner_radius=100, start_angle=45,
    sweep=270, slice_offsets=[0, 20, 0], time=1))

TransitionLayout synchronizes axes, grid, tick positions and formatted tick text, legend placement, marks and area polygons. Plot dimensions inherit into axes and marks even with a direct numeric property transition, but use this helper when changing domains or filled area geometry so dependent content stays synchronized.

TransitionPie animates radius, hole radius, start angle and total sweep (degrees), plus radial per-slice offsets in drawing units. Both helpers accept fps and interpolation; by default their sample rate follows the video. Tick formatting uses four significant digits during transitions. Positions, opacity, colors, stroke widths and marker radii remain ordinary animatable properties.

Area/pie data animations produce sampled hold keyframes (fps=60 by default; set this to the video's frame rate). Geometry helpers changing the same paths should run sequentially; concurrent writes to the same property follow the core sequence's normal rules. No network requests occur during rendering.

Run tests with the installed codeanimate environment:

python packages/Chart.package/tests/test_chart.py

examples/line_chart/main.py demonstrates the complete axes/labels/lines introduction. Tests verify compilation, inherited styles, chart variants, stable identities, bubble radii, layout and pie geometry, formatted tick updates, legend placement, temporal point insertion, invalid inputs, and random-order frame sampling. Pixel-level browser/native parity is covered by the hosts' primitive rendering checks, not asserted by these tests.

Managed projects and invalid data

Select Chart in project.json and use from manifest.chart import LineChart, DrawIn; the core library resolves the selected project packages automatically. Chart depends on Neutral and has no service or JavaScript renderer requirement.

Use finite numeric data. Cartesian domains must be finite and increasing; pie values must be nonnegative. Invalid data raises during construction/compilation, leaving the editor's previous successful preview visible. Keep stable item IDs when continuity matters across insertion/removal, and use explicit domains to compare multiple series on the same axes. Setting data changes the current sequence state; it does not revise earlier frames.

For a minimal first chart, omit the font argument and labels, create a LineChart, and show DrawIn(chart, time=1). Add axis/label introductions afterward, constructing DrawIn first so marks remain hidden until their reveal.

Version 1.0.0 · Package API 1 · Chart API reference