chart = {
const chart = new G2.Chart({
width,
height: 1000,
paddingLeft: 30
});
chart
.coordinate({ type: "transpose" })
.data(data)
.call((chart) =>
order === "time"
? chart
: chart.transform({
type: "connector",
callback: (data) =>
groupSort(
data,
([, values]) => d3.min(values, (d) => d.start),
(d) => d.region
)
})
);
chart
.interval()
.scale("x", {
guide: null
})
.scale("color", { range: d3.schemeSet2 })
.scale("y", {
guide: { formatter: (d) => Math.abs(d) + (d < 0 ? "BC" : "AC") }
})
.encode("x", "civilization")
.encode("y", ["start", "end"])
.encode("color", "region");
chart
.text()
.encode("x", "civilization")
.encode("y", (d) => (d.end > -1500 && d.start > -3000 ? d.start : d.end))
.encode("text", "civilization")
.style("textAnchor", "end")
.style("fontSize", 10)
.style("fill", "black")
.style("dy", 5)
.style("dx", -5);
return node(chart.render());
}