Public
Edited
Dec 18, 2022
1 fork
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chart = {
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", config.height + 20);

svg
.selectAll("path")
.data([
{
xfrom: 0,
xto: 1,
yfrom: 0,
yto: 1,
fill: colors[0],
stroke: colors[1]
},
{
xfrom: 0,
xto: 0.3,
yfrom: 0,
yto: 0.4,
fill: colors[6],
stroke: colors[7]
},
{
xfrom: 0.3,
xto: 0.6,
yfrom: 0.4,
yto: 0.8,
fill: colors[2],
stroke: colors[3]
},
{
xfrom: 0.7,
xto: 0.8,
yfrom: 0.2,
yto: 1,
fill: colors[4],
stroke: colors[5]
}
])
.join("path")
.attr("d", (d) => arc([d.xfrom, d.xto, d.yfrom, d.yto]))
.attr("fill", (d) => d.fill)
.attr("stroke", (d) => d.stroke)
.attr("stroke-width", 1)
.attr("transform", `translate(${width / 2}, ${config.outerRadius})`);

svg
.append("circle")
.attr("fill", "white")
.attr("stroke", "black")
.attr("r", 10)
.attr("cx", cx(1, 0))
.attr("cy", -cy(1, 0))
.attr("transform", `translate(${width / 2}, ${config.outerRadius})`);

return svg.node();
}
Insert cell
Insert cell
cx = (x, y) => {
return Math.cos(Math.PI / 2 - xScale(x)) * yScale(y);
}
Insert cell
cy = (x, y) => {
return Math.sin(Math.PI / 2 - xScale(x)) * yScale(y);
}
Insert cell
xScale = d3.scaleLinear().domain([0, 1]).range([-config.angle, config.angle])
Insert cell
yScale = d3
.scaleLinear()
.domain([0, 1])
.range([config.innerRadius, config.outerRadius])
Insert cell
Insert cell
Insert cell
config = {
let input = {
length: alength,
angle: awidth
};
input.outerRadius = Math.ceil(
width / (2 * Math.cos(Math.PI / 2 - input.angle))
);
input.innerRadius = Math.floor((1 - input.length) * input.outerRadius);
input.height =
input.outerRadius - Math.sin(Math.PI / 2 - input.angle) * input.innerRadius;

return input;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more