pieChart = {
const width = 700;
const height = 600;
const radius = Math.min(width, height) / 2;
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.style("position", "relative");
const chartGroup = svg.append("g")
.attr("transform", `translate(${width / 2 + 40}, ${height / 2})`);
const color = d3.scaleOrdinal()
.domain(processedData.map(d => d.name))
.range(d3.schemeCategory10);
const pie = d3.pie().value(d => d.count);
const data_ready = pie(processedData);
const arc = d3.arc().innerRadius(0).outerRadius(radius - 10);
const tooltip = d3.create("div")
.style("position", "absolute")
.style("pointer-events", "none")
.style("opacity", 0)
.style("background", "white")
.style("border", "1px solid #ccc")
.style("border-radius", "4px")
.style("padding", "6px 10px")
.style("font-size", "12px")
.style("font-family", "Verdana, sans-serif")
.style("box-shadow", "0 2px 6px rgba(0,0,0,0.2)");
const wrapper = html`<div style="position: relative;">${svg.node()}${tooltip.node()}</div>`;
chartGroup.selectAll("path")
.data(data_ready)
.join("path")
.attr("d", arc)
.attr("fill", d => color(d.data.name))
.attr("stroke", "white")
.attr("stroke-width", 1)
.on("mouseenter", function(event, d) {
tooltip.style("opacity", 1)
.html(`<strong>${d.data.name}</strong><br>${d.data.count} game(s)`);
})
.on("mousemove", function(event) {
tooltip.style("left", `${event.offsetX + 10}px`)
.style("top", `${event.offsetY - 30}px`);
})
.on("mouseleave", function() {
tooltip.style("opacity", 0);
});
chartGroup.selectAll("text.internal-label")
.data(data_ready)
.join("text")
.attr("class", "internal-label")
.attr("transform", d => `translate(${arc.centroid(d)})`)
.style("text-anchor", "middle")
.attr("font-family", "Verdana")
.style("font-size", 10)
.text(d => d.data.name);
return wrapper;
}