Public
Edited
Apr 16
Insert cell
Insert cell
Insert cell
viewof dataOfTag = Inputs.select(["Metroidvania", "Puzzle-Platformer"], {label: "Tags on Steam"})
Insert cell
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("circle")
.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")
//.join("path")
//.attr("d", d => `M${x(d[0])},${y(d[1])}h0`)
//.attr("stroke", d => z(d[2]))
.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);
}
});
}
Insert cell
reset, chart.reset()
Insert cell
steamspyMetroidvania = FileAttachment("steamspy-metroidvania.json").json()
Insert cell
steamspyPuzzleplatformer = FileAttachment("steamspy-puzzleplatformer.json").json()
Insert cell
dataPreprocess = (d) =>
Object.values(d).map((game) => {
return [
game.appid,
game.name,
parseInt(game.initialprice),
ownerParser(game.owners) // Unit: K
]
})
Insert cell
ownerParser = (ownerStr) => parseInt(ownerStr.replaceAll(/[\s,]/g, "").split("..")[0]) / 1000
Insert cell
data = dataPreprocess(dataMapping[dataOfTag])
Insert cell
dataMapping = {
return {
Metroidvania: steamspyMetroidvania,
"Puzzle-Platformer": steamspyPuzzleplatformer
}
}
Insert cell
x = d3.scaleLinear()
.domain([0, 3000])
.range([0, width])
Insert cell
y = d3.scaleLinear()
.domain([2000, 0])
.range([height, 0])
Insert cell
xAxis = (g, x) => g
.attr("transform", `translate(0,${height})`)
.call(d3.axisTop(x).ticks(12))
.call(g => g.select(".domain").attr("display", "none"))
Insert cell
yAxis = (g, y) => g
.call(d3.axisRight(y).ticks(12 * k))
.call(g => g.select(".domain").attr("display", "none"))
Insert cell
grid = (g, x, y) => g
.attr("stroke", "currentColor")
.attr("stroke-opacity", 0.1)
.call(g => g
.selectAll(".x")
.data(x.ticks(12))
.join(
enter => enter.append("line").attr("class", "x").attr("y2", height),
update => update,
exit => exit.remove()
)
.attr("x1", d => 0.5 + x(d))
.attr("x2", d => 0.5 + x(d)))
.call(g => g
.selectAll(".y")
.data(y.ticks(12 * k))
.join(
enter => enter.append("line").attr("class", "y").attr("x2", width),
update => update,
exit => exit.remove()
)
.attr("y1", d => 0.5 + y(d))
.attr("y2", d => 0.5 + y(d)));
Insert cell
k = height / width
Insert cell
height = 600
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more