{
const library = G2[lib]();
const groups = d3
.groups(Object.entries(library), ([key]) => key.split(".")[0])
.map(([name, nodes]) => ({
name,
value: nodes.length,
children: nodes.map(([d, f]) => ({
name: d.split(".")[1],
value: `${f}`.length
}))
}));
const root = { name: lib, children: groups };
const chart = new G2.Chart();
chart.options({
type: "forceGraph",
padding: 10,
width: 800,
height: 800,
data: { value: graph(root) },
legend: false,
layout: { joint: false },
scale: {
color: {
range: [
"#4e79a7",
"#f28e2c",
"#e15759",
"#76b7b2",
"#59a14f",
"#edc949",
"#af7aa1",
"#ff9da7",
"#9c755f",
"#bab0ab"
]
}
},
style: {
labelText: (d) => (d.data ? d.data.name.split(".").pop() : ""),
labelFill: "#000",
labelPosition: "top-left"
}
});
return chart.render().then((chart) => chart.getContainer());
}