{
const left = (d) => new Date(d.startDate) > new Date("2018/01/01");
const chart = new G2.Chart({
paddingLeft: 60,
paddingRight: 60,
width: 1000,
height: 600
});
chart.data(VersionHistory);
chart.coordinate({ transform: [{ type: "transpose" }] });
chart
.interval()
.transform({ type: "sortX", by: "y" })
.axis("y", [
{
tickCount: 5,
grid: null,
title: null
},
{
position: "top",
title: null
}
])
.axis("x", false)
.axis("y", {
title: "Date",
titlePosition: "end",
titleDx: 16,
titleDy: 7,
line: true,
arrow: true,
lineArrowOffset: 10
})
.encode("x", (d) => `${d.lib} v${d.version}`)
.encode("y", (d) => [new Date(d.startDate), new Date(d.endDate)])
.encode("color", "type")
.scale("y", { nice: false })
.scale("color")
.label({
text: (d) => `${d.lib} v${d.version}`,
position: (d) => (left(d) ? "left" : "right"),
textAlign: (d) => (left(d) ? "end" : "start"),
dx: (d) => (left(d) ? -5 : 5),
fontSize: 10
})
.tooltip([
{ name: "start", field: "startDate" },
{ name: "end", field: "endDate" }
]);
await chart.render();
return chart.getContainer();
}