function diagram(piano) {
const selectedColor = "#f1ff5e";
const height = piano.filter(key => key.type=="white")[0].coord.y.max
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)
.attr("y", key => key.coord.y.min)
.attr("width", key => key.coord.x.max - key.coord.x.min)
.attr("height", key => key.coord.y.max - key.coord.y.min)
.attr("stroke", "#ccc")
.attr("fill", key => key.selected ? selectedColor : "#fff")
.attr("stroke-width", 1);
svg.selectAll("rect.black").data(piano.filter(key => key.type=="black"))
.enter()
.append("rect")
.attr("x", key => key.coord.x.min)
.attr("y", 0)
.attr("width", key => key.coord.x.max - key.coord.x.min)
.attr("height", key => key.coord.y.max - key.coord.y.min)
.attr("stroke", "#ccc")
.attr("fill", "#444")
.attr("stroke-width", 1);
svg.selectAll("rect.black").data(piano.filter(key => key.type=="black" && key.selected))
.enter()
.append("rect")
.attr("x", key => key.coord.x.min + 2)
.attr("y", 0)
.attr("width", key => key.coord.x.max - key.coord.x.min - 4)
.attr("height", key => key.coord.y.max - key.coord.y.min - 2)
.attr("fill", selectedColor)
return svg.node();
}