chart = {
const zoom = d3.zoom()
.scaleExtent([0.0001, 32])
.on("zoom", zoomed);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const gGrid = svg.append("g");
const gDot = svg.append("g")
.attr("fill", "none")
.attr("stroke-linecap", "round");
gDot.selectAll("circle")
.data(data)
.join("a")
.datum(([w, x, y, z], i) => [w, x, y, z, i])
.attr("xlink:href", (d) => `https://store.steampowered.com/app/${d[0]}/`)
.append("circle")
.attr("cx", (d) => d[2])
.attr("cy", (d) => -d[3])
.attr("r", 20)
.attr("fill", "blue")
.on("mousedown", (event, d) => {})
.append("title")
.text((d, i) => `${d[1]} price: ${d[2]/100}$ owners: ${d[3]}k`);
const gx = svg.append("g");
const gy = svg.append("g");
svg.call(zoom).call(zoom.transform, d3.zoomIdentity);
function zoomed({transform}) {
const zx = transform.rescaleX(x).interpolate(d3.interpolateRound);
const zy = transform.rescaleY(y).interpolate(d3.interpolateRound);
gDot.attr("transform", transform).attr("stroke-width", 5 / transform.k);
gx.call(xAxis, zx);
gy.call(yAxis, zy);
gGrid.call(grid, zx, zy);
}
return Object.assign(svg.node(), {
reset() {
svg.transition()
.duration(750)
.call(zoom.transform, d3.zoomIdentity);
}
});
}