chartParallelDateHigh96 = {
const width = 900;
const height = 500;
const margin = { top: 40, right: 40, bottom: 40, left: 150 };
const platformOrder = [
"Xbox 360",
"PC",
"PlayStation 3",
"Switch",
"PlayStation 2",
"GameCube",
"Nintendo 64",
"PlayStation",
"Dreamcast",
"Wii",
"Xbox One",
"PlayStation 4",
"Xbox",
"Wii U",
"Xbox Series X",
"PlayStation 5"
];
const parseDate = d3.timeParse("%d-%b-%y");
const cleanHigh = data
.map(d => ({
Platform: d.Platform,
Metascore: +d.Metascore,
Year: parseDate(d.Date).getFullYear()
}))
.filter(d => d.Metascore >= 96);
const dimensions = ["Platform", "Metascore", "Year"];
const y = {
Platform: d3.scalePoint()
.domain(platformOrder.filter(p => cleanHigh.some(d => d.Platform === p)))
.range([height - margin.bottom, margin.top]),
Metascore: d3.scaleLinear()
.domain(d3.extent(cleanHigh, d => d.Metascore)).nice()
.range([height - margin.bottom, margin.top]),
Year: d3.scaleLinear()
.domain(d3.extent(cleanHigh, d => d.Year)).nice()
.range([height - margin.bottom, margin.top])
};
const x = d3.scalePoint()
.domain(dimensions)
.range([margin.left, width - margin.right]);
const line = d3.line()
.x(([dim, v]) => x(dim))
.y(([dim, v]) => y[dim](v));
const svg = d3.select(DOM.svg(width, height));
svg.append("g")
.selectAll("path")
.data(cleanHigh)
.join("path")
.attr("d", d => line(dimensions.map(dim => [dim, d[dim]])))
.attr("fill", "none")
.attr("stroke", "#eee");
svg.append("g")
.selectAll("path")
.data(cleanHigh)
.join("path")
.attr("d", d => line(dimensions.map(dim => [dim, d[dim]])))
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-opacity", 0.5)
.attr("stroke-width", 1);
dimensions.forEach(dim => {
const g = svg.append("g")
.attr("transform", `translate(${x(dim)},0)`);
if (dim === "Platform") {
g.call(d3.axisLeft(y.Platform));
} else {
g.call(
d3.axisLeft(y[dim])
.ticks(6)
.tickFormat(d3.format("d"))
);
}
g.append("text")
.attr("y", margin.top - 20)
.attr("text-anchor", "middle")
.attr("fill", "currentColor")
.text(dim);
});
return svg.node();
}