prototype = {
const d = diameter;
const svg = d3.create("svg")
.style("width", d)
.style("height", d)
.style("background", "black")
.attr("viewBox", [-d/2, -d/2, d, d]);
var lines;
if (options2.color === "rank") {
lines = svg.selectAll(".line")
.data(ranks)
.join("path")
.attr("opacity", 0)
.attr("class", "line")
.attr("fill", "none")
.attr("stroke", (d, i) => color(sortedTerritories[i]))
.attr("d", d => line(d.series));
}
var g;
const isSeq = options2.color === "value";
if (isArc) {
g = svg.append("g")
.selectAll("g")
.data(sorted)
.join("g")
.selectAll("path")
.data((d, i) => d.values.map(v => ({index: i, territory: v.territory, value: v.value})))
.join("path")
.attr("fill", d => color(isSeq ? d.value : d.territory))
.attr("d", arc);
}
else {
const r = radius, x = 2 * r;
const gg = svg.append("g")
.selectAll("g")
.data(sorted)
.join("g")
.attr("transform", (d, i) => `rotate(${xl(i)})`);
if (options2.shape === "circle")
g = gg.selectAll("circle")
.data(d => d.values)
.join("circle")
.attr("fill", d => color(isSeq ? d.value : d.territory))
.attr("cx", (d, i) => sticky ? i * x + options2.innerRadius: y(i))
.attr("r", r);
else {
const w = 2 * r, hb = y.bandwidth() / 2;
g = gg.selectAll("rect")
.data(d => d.values)
.join("rect")
.attr("fill", d => color(isSeq ? d.value : d.territory))
.attr("x", (d, i) => (sticky ? i * w + options2.innerRadius: y(i)) - hb)
.attr("y", sticky ? -r : -hb)
.attr("width", w)
.attr("height", w);
}
}
g.attr("opacity", 1)
.on("mouseenter", (e, d) => {
g.transition().duration(500).attr("opacity", _ => _.territory === d.territory ? 1 : 0.5);
if (lines) lines.transition().duration(250).attr("opacity", _ => _.territory === d.territory ? 1 : 0);
})
.on("mouseleave", () => {
g.transition().duration(500).attr("opacity", 1);
if (lines) lines.transition().duration(250).attr("opacity", 0);
});
return svg.node();
}