Public
Edited
Oct 24, 2022
Insert cell
Insert cell
brushArea = d3.areaRadial()
.angle(d => x(d))
.innerRadius(innerRadius)
.outerRadius(outerRadius);
Insert cell
drag = {
function dragstarted(e) {
console.log(e);
d3.select(chart).selectAll("#brush-area").remove();
const theta = Math.PI - Math.atan2(...d3.pointer(e));
set(viewof Theta, theta);
set(viewof brushStart, x.invert(theta));
}

function dragged(e) {
// console.log(d3.pointer(e));
const theta = Math.PI - Math.atan2(...d3.pointer(e));
set(viewof Theta, theta);
set(viewof brushStop, x.invert(theta));
d3.select(chart).selectAll("#brush-area")
.data([Array(100).fill(1).map( (d, i) => i * (x.invert(theta) - brushStart) / 100 + brushStart)])
.join("path")
.attr("d", d => brushArea(d))
.attr("fill", "grey")
.attr("stroke", "black")
.attr("opacity", 0.5)
.attr("id", "brush-area");
}

function dragended(e) {
console.log(e);
const theta = Math.PI - Math.atan2(...d3.pointer(e));
set(viewof Theta, theta);
set(viewof brushStop, x.invert(theta));
d3.select(chart).selectAll("#brush-area")
.data([Array(100).fill(1).map( (d, i) => i * (x.invert(theta) - brushStart) / 100 + brushStart)])
.join("path")
.attr("d", d => brushArea(d))
.attr("fill", "grey")
.attr("stroke", "black")
.attr("opacity", 0.5)
.attr("id", "brush-area");
}

return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
{
let svg = d3.select(chart);
svg.call(drag);
}

Insert cell
viewof Theta = Inputs.range([0,6.5], { label: "theta" })
Insert cell
chart
Insert cell
Insert cell
Insert cell
Insert cell
import {chart, x, innerRadius, outerRadius} from "@d3/radial-area-chart"
Insert cell
// d3 = require("d3@7")
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