function diagram(piano) {
const middleC = 60;
const selectedColor = "#f1ff5e";
const border = 2;
const height = piano.filter(key => key.type=="white")[0].coord.y.max + 2 * border
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
svg.selectAll("rect.white").data(piano.filter(key => key.type=="white"))
.enter()
.append("rect")
.attr("x", key => key.coord.x.min + border)
.attr("y", key => key.coord.y.min + border)
.attr("width", key => key.coord.x.max - key.coord.x.min)
.attr("height", key => key.coord.y.max - key.coord.y.min)
.attr("stroke", "#444")
.attr("fill", key => key.selected ? selectedColor : "#fff")
.attr("stroke-width", border);
svg.selectAll("rect.white").data(piano.filter(key => key.num === middleC))
.enter()
.append("circle")
.attr("cx", key => key.coord.x.min + border + (key.coord.x.max - key.coord.x.min) / 2)
.attr("cy", key => key.coord.y.max - 8)
.attr("r", 3)
.attr("fill", "#999")
svg.selectAll("rect.black").data(piano.filter(key => key.type=="black"))
.enter()
.append("rect")
.attr("x", key => key.coord.x.min + border)
.attr("y", 0 + border)
.attr("width", key => key.coord.x.max - key.coord.x.min)
.attr("height", key => key.coord.y.max - key.coord.y.min)
.attr("stroke", "#444")
.attr("fill", key => key.selected ? selectedColor : "#444")
.attr("stroke-width", border);
return svg.node();
}