chart = {
var data = presidents;
var width = 1200;
var height = 600;
var svg = d3
.select(DOM.svg(width, height))
.style("background", "rgb(250, 245, 240)");
svg
.append("text")
.attr("x", width / 2)
.attr("y", 30)
.attr("text-anchor", "middle")
.text("YouTubeにおけるYOASOBI「アイドル」 関連動画の視聴回数");
var images = svg
.selectAll("image")
.data(data)
.enter()
.append("image")
.attr("xlink:href", function (d) {
return d.thumbnail;
})
.attr("width", function (d) {
return Math.sqrt(d.views) * 2;
})
.attr("height", function (d) {
return Math.sqrt(d.views) * 2;
})
.attr("preserveAspectRatio", "xMidYMin slice")
.attr("x", function (d) {
return d.release_date;
})
.attr("y", height - 30);
images
.on("mouseover", function (event, d) {
d3.select(this).style("cursor", "pointer");
var tooltip = d3
.select(svg.node().parentNode)
.append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("background-color", "white")
.style("border", "solid")
.style("border-width", "1px")
.style("border-radius", "5px")
.style("padding", "5px")
.text(d.title);
tooltip
.style("left", event.pageX + 10 + "px")
.style("top", event.pageY - 28 + "px");
})
.on("mouseout", function () {
d3.select(this).style("cursor", "default");
d3.select(svg.node().parentNode).select("div").remove();
});
return svg.node();
}