vidmake v0.2.1
Download

Journal/data · charts · tutorialEntry 07 / 10

Animated charts from data

A bar chart, a line chart with a marker riding its tip, and a donut, each built from a few layers with repeat, expressions and attach, with the data passed in as props.

▸ blog-data-donut1280×720 · 30 fps · 0:04.0Rendered by vidmake

Some of the best uses of programmatic video are a weekly metrics recap, a launch-day chart for social, or a dashboard that turns into a 10-second clip. They are also where hand-built video tools are weakest, because the numbers change every week and nobody wants to re-time 40 keyframes by hand.

vidmake doesn't have chart layers, and we don't think it needs them. A chart is a handful of shapes positioned by data, and since 0.2 a project can express that directly: repeat stamps out one layer per data point, expressions read the data with pick(i, [...]), and attach lets a marker ride a line as it draws. This post builds three charts that way. Each is one file, and the data lives in props so a script can swap it without touching the layers.

#Bars from two arrays

00:00.0 · f 000
A bar chart from two prop arrays: one repeated group per day with a bar, a counting value and a labelDownload

The whole chart is one repeated group. The composition declares the data as props:

json
"props": { "values": [412, 538, 497, 621, 884, 356, 298],           "labels": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], "peak": 4 }

and the group repeats once per day, laid out in a row:

json
{ "id": "day", "type": "group", "width": 120, "height": 520, "x": "50%", "y": 400,  "repeat": { "count": 7, "layout": "row", "spacing": 146, "delay": "0.07s" }, "children": [ ... ] }

Every child of a repeated group sees the copy's i, so each child can read its own data point:

  • the bar's height is pick(i, {{values}}) * 0.36 * easeOutCubic(clamp(t / 0.9, 0, 1)), its data value scaled to pixels and eased in over 0.9 seconds. "anchor": "bottom" makes it grow up from the baseline.
  • the value label uses the same product for its y, so it rides the top of its bar, and prints round(...) of the same eased value so the number counts while the bar grows.
  • the day label prints pick(i, {{labels}}).
  • the color is i == {{peak}} ? '#c92a26' : '#161412', a ternary that returns one of two colors.

The {{values}} inside an expression is ordinary props templating: before anything is compiled, the prop's JSON text is spliced into the string, so the expression becomes pick(i, [412, 538, ...]). String arrays work the same way, since expressions accept double-quoted strings. That means new data needs no edit to the file. The same project with different props:

vidmake still blog-data-bars.json -t 3s -p values=[120,240,360,480,600,720,840] -p peak=6
$ vidmake still blog-data-bars.json -t 3s -p values=[120,240,360,480,600,720,840] -p peak=6

From a pipeline, write the data to a file and pass --props-file week43.json. The scale factor (0.36 px per unit) is the one thing that doesn't adapt by itself. Put it in props too, or compute it upstream as the chart height divided by the maximum value.

Children of a repeated group keep their own ids, so inspect lists a bar, value and label under each day.<i> copy, with every bounding box in canvas pixels. That's enough to check that the numbers landed where they should, and that no value label collides with the title:

vidmake inspect blog-data-bars.json -t 3s
$ vidmake inspect blog-data-bars.json -t 3s
Frame 90 (3.00s) of `bars` (1280x720), 33 visible layer(s), drawn bottom→top:

ID                       TYPE            X        Y       W       H    ROT  SCALE  OPAC  BBOX [x0,y0,x1,y1]          NOTES
title                    text        120.0     92.0   443.7    72.0    0.0   1.00  1.00  [120,56,564,128]            "Renders per day"
grid.0                   rect        640.0    300.0  1040.0     1.0    0.0   1.00  1.00  [120,300,1160,300]          
grid.1                   rect        640.0    400.0  1040.0     1.0    0.0   1.00  1.00  [120,400,1160,400]          
grid.2                   rect        640.0    500.0  1040.0     1.0    0.0   1.00  1.00  [120,500,1160,500]          
grid.3                   rect        640.0    600.0  1040.0     1.0    0.0   1.00  1.00  [120,600,1160,600]          
day.0                    group       202.0    400.0   120.0   520.0    0.0   1.00  1.00  [142,140,262,660]           
  bar                    rect         60.0    460.0    64.0   148.3    0.0   1.00  1.00  [170,452,234,600]           
  value                  text         60.0    291.7    32.4    21.6    0.0   1.00  1.00  [186,421,218,442]           "412"
  label                  text         60.0    494.0    28.6    16.8    0.0   1.00  1.00  [188,626,216,642]           "MON"
day.1                    group       348.0    400.0   120.0   520.0    0.0   1.00  1.00  [288,140,408,660]           
  bar                    rect         60.0    460.0    64.0   193.7    0.0   1.00  1.00  [316,406,380,600]           
  value                  text         60.0    246.3    32.4    21.6    0.0   1.00  1.00  [332,376,364,397]           "538"
  label                  text         60.0    494.0    28.6    16.8    0.0   1.00  1.00  [334,626,362,642]           "TUE"
day.2                    group       494.0    400.0   120.0   520.0    0.0   1.00  1.00  [434,140,554,660]           
  bar                    rect         60.0    460.0    64.0   178.9    0.0   1.00  1.00  [462,421,526,600]           
  value                  text         60.0    261.1    32.4    21.6    0.0   1.00  1.00  [478,390,510,412]           "497"
  label                  text         60.0    494.0    28.6    16.8    0.0   1.00  1.00  [480,626,508,642]           "WED"
day.3                    group       640.0    400.0   120.0   520.0    0.0   1.00  1.00  [580,140,700,660]           
  bar                    rect         60.0    460.0    64.0   223.6    0.0   1.00  1.00  [608,376,672,600]           
  value                  text         60.0    216.4    32.4    21.6    0.0   1.00  1.00  [624,346,656,367]           "621"
  label                  text         60.0    494.0    28.6    16.8    0.0   1.00  1.00  [626,626,654,642]           "THU"
day.4                    group       786.0    400.0   120.0   520.0    0.0   1.00  1.00  [726,140,846,660]           
  bar                    rect         60.0    460.0    64.0   318.2    0.0   1.00  1.00  [754,282,818,600]           
  value                  text         60.0    121.8    32.4    21.6    0.0   1.00  1.00  [770,251,802,273]           "884"
  label                  text         60.0    494.0    28.6    16.8    0.0   1.00  1.00  [772,626,800,642]           "FRI"
day.5                    group       932.0    400.0   120.0   520.0    0.0   1.00  1.00  [872,140,992,660]           
  bar                    rect         60.0    460.0    64.0   128.2    0.0   1.00  1.00  [900,472,964,600]           
  value                  text         60.0    311.8    32.4    21.6    0.0   1.00  1.00  [916,441,948,463]           "356"
  label                  text         60.0    494.0    28.6    16.8    0.0   1.00  1.00  [918,626,946,642]           "SAT"
day.6                    group      1078.0    400.0   120.0   520.0    0.0   1.00  1.00  [1018,140,1138,660]         
  bar                    rect         60.0    460.0    64.0   107.3    0.0   1.00  1.00  [1046,493,1110,600]         
  value                  text         60.0    332.7    32.4    21.6    0.0   1.00  1.00  [1062,462,1094,484]         "298"
  label                  text         60.0    494.0    28.6    16.8    0.0   1.00  1.00  [1064,626,1092,642]         "SUN"

#A line that draws, and a marker that rides it

00:00.0 · f 000
A line chart that draws itself, a glowing marker riding its drawn tip, and a label that pops in when it landsDownload

The trend is a line layer with twelve points and an animated drawEnd, which trims the stroke from 0 (nothing) to 1 (the whole line):

json
"drawEnd": { "from": 0, "to": 1, "start": "0.3s", "duration": "2.4s", "ease": "easeInOutCubic" }

The marker is a 16 px ellipse with one line of positioning: "attach": "trend". An attached layer sits on the drawn tip of a sibling path or line every frame. Its glow gives it a soft halo. Here is the dot following the tip:

vidmake trace blog-data-line.json -l dot --every 15 --from 0.3s --to 2.7s
$ vidmake trace blog-data-line.json -l dot --every 15 --from 0.3s --to 2.7s
 FRAME    TIME        X        Y       W       H    ROT  SCALE  OPAC  NOTES
     9   0.30s    160.0    438.0    16.0    16.0    0.0   1.00  1.00  
    24   0.80s    195.6    430.2    16.0    16.0    0.0   1.00  1.00  
    39   1.30s    445.0    392.0    16.0    16.0    0.0   1.00  1.00  
    54   1.80s    922.4    295.2    16.0    16.0    0.0   1.00  1.00  
    69   2.30s   1102.8    225.3    16.0    16.0    0.0   1.00  1.00

Two things we learned building this one:

A counting label at the tip is harder than it looks. drawEnd is a fraction of the line's length. For a gently rising line like this one, that is close to the fraction of the x-axis: at 1.3 seconds the eased progress is 0.29 and the dot is 30% of the way across. Steep segments, though, use up more length per month than flat ones. Our first version had a value label riding the tip, counting from 18k to 66k with the same easing as the line. Halfway through it read 42k while the dot sat between June and July, where the data says about 33k: an eased count from the first value to the last ignores every value in between. If the label has to be live, compute its value from the data at the tip yourself. Here, the label pops in once the line has landed, attached to the same tip, showing the final value.

Use path for filled areas. The soft gradient under the line is a path whose d is the same points plus the two bottom corners. A line layer is stroke-first: without a stroke, its fill becomes the stroke color, so a closed line with only a fill draws an outline rather than an area.

The month labels are a repeated text layer with pick(i, ['J', 'F', ...]), spaced 960 / 11 apart so each sits under its data point, and the gridlines are a repeated 1 px rect in a column.

#A donut from one arc

00:00.0 · f 000
A donut chart from one repeated arc: cumulative start angles, one continuous sweep, and a legend from the same arraysDownload

Four slices, one layer. An arc draws a stroke from startAngle to endAngle (degrees, 0 at twelve o'clock, clockwise). Each copy's start angle comes from a cumulative array, and its end grows with a single shared sweep:

json
"startAngle": "=pick(i, {{start}}) * 3.6 + 1","endAngle": "=max(pick(i, {{start}}) * 3.6 + 1, min((pick(i, {{start}}) + pick(i, {{pct}})) * 3.6 - 1, 360 * easeInOutCubic(clamp(t / 1.8, 0, 1))))"

That endAngle reads better from the inside out. 360 * easeInOutCubic(...) is a sweep angle that goes once around the circle in 1.8 seconds. Each slice clips the sweep to its own range with min (don't pass my end) and max (don't go below my start), so the slices fill in turn, as if one pen drew the whole ring. The + 1 and - 1 leave a 2° gap between slices, and "lineCap": "butt" keeps the ends square.

The props hold both the percentages and their running totals ("start": [0, 42, 70, 88]). Expressions can't sum an array, so we compute the cumulative values when we write the props, which any script producing the data can do in one line.

The legend is the same pattern as the bar chart: a group repeated in a column, each copy with a swatch, a name and a percentage picked from the same arrays, entering with fadeLeft 0.15 seconds apart. The number in the middle counts up with round(42 * easeOutCubic(...)).

#Counters that stay honest

Every chart here has a number that counts. A few rules keep them correct:

  • Count with the same easing as the shape it labels, so the number and the bar agree on every frame.
  • Avoid overshooting eases such as easeOutBack and springs on numbers. A bar that overshoots looks lively; a number that overshoots is briefly wrong. trace prints the text at each sample, so you can check: vidmake trace project.json -l value --every 2.
  • Format with fmt() and round(), for example fmt(round(x)) for 12,480, or fmt(x, '.', 2) for European separators. ${x:1} prints one decimal.

#From data to MP4, unattended

Put together, a weekly chart video is a template project plus a props file:

bash
vidmake validate chart.json --props-file week43.jsonvidmake still chart.json --props-file week43.json -t 3s -o check.pngvidmake render chart.json --props-file week43.json -o out/week43.mp4 --json

validate still runs the layout lint with the new data, so a label that a longer series pushed off the canvas shows up as a warning. The still is a cheap image to look at, or to attach to a pull request, before the render.

See repeat, attach, expressions and props for the details.

View .md Ask Claude Ask ChatGPT

Keep reading

showcasemotion

Four reels, thirty seconds each

A Swiss poster, a piece of generative op-art, a data poem and a risograph collage. Each is a single vidmake JSON file, written, checked and rendered by an agent, using nothing but the four stock assets.

Read

releasemotion

What's new in vidmake 0.5

Markers name the beats of a video, decoration draws underlines, strike-throughs and highlights from the glyphs, design tokens and named easings bring a brand's system into a project, and WOFF2 fonts, synthetic italics, skewX, themed SVG icons, repeat origins and wipe edges close the gaps an agent hit making a 20-second ad.

Read

releaseaudio

What's new in vidmake 0.2.1

vidmake analyze shows the beats and loudness curves that audio-reactive expressions will see, rich-text spans take fontWeight, italic and font, drawMode: "total" draws many strokes with one pen, and source builds report the right version.

Read