pieChartRender = {
let graph = d3.select("#grf").node();
const pie = d3
.pie()
.sort(null)
.value(function (d) {
return d.occurences;
})
.padAngle(0);
const pie2 = d3
.pie()
.sort(null)
.value(function (d) {
return d.occurences;
})
.padAngle(0.0);
const margin = { top: 20, right: 200, bottom: 20, left: 200 };
const width = 300,
height = 300,
radius = 100;
const arc = d3
.arc()
.outerRadius(radius - 10)
.innerRadius(15);
const outArc = d3
.arc()
.outerRadius(radius + 60)
.innerRadius(0);
const arcTween = function (a) {
var i = d3.interpolate(this._current, a);
this._current = i(0);
return function (t) {
return arc(i(t));
};
};
d3.select(graph)
.selectAll(".graphArea")
.data(["svg"])
.enter()
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("class", "graphArea")
.attr(
"transform",
"translate(" +
(margin.left + width / 2) +
"," +
(margin.top + height / 2) +
")"
);
const teso = data.reduce(
(a, b) =>
b.done && b.done < 1
? [
...a,
{ ...b, occurences: b.occurences * b.done, color: "green" },
{ ...b, occurences: b.occurences * (1 - b.done), color: "none" }
]
: [...a, b],
[]
);
const pieChart = d3.select(graph).select(".graphArea");
let arcs = pieChart.selectAll(".arc").data(pie(data));
arcs
.enter()
.append("g")
.attr("class", "arc")
.each(function (d) {
d3.select(this)
.append("path")
.style("stroke", "white")
.style("fill", "none");
})
.merge(arcs)
.select("path")
.attr("d", arc)
.style("stroke", d3.color("green").brighter());
arcs.exit().remove();
arcs = pieChart.selectAll(".arcc").data(pie2(teso));
arcs
.enter()
.append("g")
.attr("class", "arcc")
.each(function (d) {
d3.select(this)
.append("path")
.attr("d", "")
.style("stroke", "none")
.style("fill", "none");
})
.merge(arcs)
.select("path")
.transition()
.duration(1000)
.attr("d", arc)
.attrTween("d", arcTween)
.style("fill", (d) => d.data.color);
arcs.exit().remove();
}