{
const chart = new G2.Chart();
const data = (
await fetch(url("data/population.json")).then((res) => res.json())
).filter((d) => d.year === 2000);
const flex = chart.flex().ratio([1, 0.15, 1]);
const symmetry = (node, sex, color, left = false) =>
node
.view()
.call((node) => (left ? node.paddingRight(0) : node.paddingLeft(0)))
.coordinate({ type: "transpose" })
.interval()
.scale("x", { guide: null, range: [1, 0] })
.scale("y", {
range: left ? [0, 1] : [1, 0],
guide: { formatter: d3.format("~s") },
field: ""
})
.data(data.filter((d) => d.sex === sex))
.encode("x", "age")
.encode("y", "people")
.encode("color", color);
flex.call(symmetry, 2, "#675193", true);
flex
.view()
.coordinate({ type: "transpose" })
.text()
.data(data.filter((d) => d.sex === 2))
.scale("y", { type: "identity" })
.scale("x", { guide: null, type: "band" })
.encode("x", "age")
.encode("y", 0.5)
.encode("text", "age")
.style("textAlign", "center")
.style("fill", "black")
.style("dy", "0.25em");
flex.call(symmetry, 1, "#ca8861");
return chart.render().node();
}