Public
Edited
Dec 26, 2023
1 fork
Insert cell
Insert cell
<div id="grf" >zefe</div>
Insert cell
Insert cell
Insert cell
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));
// tot / data.length;

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));
// tot / data.length;

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();
}
Insert cell
dataP = [1, 6, 12]
Insert cell
t = FileAttachment("image.png").image()
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more