chart2 = {
const strokeWidth = 2;
const padding = strokeWidth + 3;
const numRows = myLanguagesByLevel.length;
const w = 640;
const h = 290;
const rowHeight = (h - padding * (numRows - 1) - strokeWidth) / numRows;
const leftMargin = 30;
const svg = d3.select(DOM.svg(w, h));
const rows = svg
.selectAll("g")
.data(myLanguagesByLevel)
.join("g")
.attr(
"transform",
(d, i) =>
`translate(${[
strokeWidth / 2 + leftMargin,
i * (rowHeight + padding) + strokeWidth / 2
]})`
)
.each(function ([level, languages]) {
const numCols = languages.length;
const colWidth =
(w - strokeWidth - padding * (numCols - 1) - leftMargin) / numCols;
const g = d3
.select(this)
.selectAll("g")
.data(languages)
.join("g")
.attr(
"transform",
(d, i) => `translate(${[i * (colWidth + padding), 0]})`
);
g.append("rect")
.attr("fill", "transparent")
.attr("opacity", .3)
.attr("stroke", "black")
.attr("height", rowHeight)
.attr("width", colWidth);
g.append("g")
.append((language) =>
WordCloud({
width: colWidth - padding,
height: rowHeight - padding,
padding: 1,
rotate: 0,
fontScale: 5,
fontFamily: "Monaco",
language,
spiral: "rectangular"
})
)
.attr("width", colWidth - strokeWidth)
.attr("height", rowHeight - strokeWidth);
});
rows.each(function ([level, languages]) {
d3.select(this)
.append("text")
.text(level)
.attr("font-family", "Impact")
.attr("font-size", 40)
.attr("opacity", .3)
.attr(
"transform",
(d, i) => `translate(${[-leftMargin, rowHeight/2]})`
)
.attr('dy', 15);
});
return svg.node();
}