Bars to Points in the Terminal
Bars to points on the terminal renderer: a bar per gender at its mean weight, then a point per person, back and forth. The bars are keyed by gender and the points grouped by it, so each bar of cells splits into a piece per person, and the pieces move cell by cell to their points, a cell each.
js
const people = await d3.json("/data/people.json");
const renderer = cm.terminal({width: 640, height: 480, units: "pixels"});
const root = cm.flow({transition: {duration: 1000, direction: "alternate", iterations: 4}}).renderer(renderer);
function draw() {
root
.append(cm.keyframe)
.data(people)
.transform(cm.encode, {x: "gender", y: "weight", fill: "gender", key: "gender"})
.transform(cm.groupX, {y: "mean"})
.transform(cm.spreadX)
.transform(cm.plane)
.add(cm.rect);
root
.append(cm.keyframe)
.data(people)
.transform(cm.encode, {x: "height", y: "weight", fill: "gender", groupKey: "gender"})
.transform(cm.plane)
.add(cm.circle, {r: 3, fillOpacity: 0.7});
}
// Plays the keyframes, then plays them again a second after they end.
function play() {
draw();
root.render();
root.finished().then(() => setTimeout(play, 1000));
}
play();
document.body.append(renderer.node());