Published
Edited
Apr 11, 2020
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
html`<link rel="stylesheet" href="//rawgithub.com/Caged/d3-tip/master/examples/example-styles.css">
<style>
.rect:hover {
opacity: 0.7;
}
`

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`# Sunburst`
Insert cell
md`probably will actually quilt`
Insert cell
piechart = {
const arcs = pie(pieData);

const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height]);

svg.selectAll("path")
.data(arcs)
.join("path")
.attr("fill", function(d,i){ console.log(d.data); return d3.interpolateViridis(d.data.count/11);})
.attr("d", arc)
.append("title")
.text(d => 'hi');

svg.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 12)
.attr("text-anchor", "middle")
.selectAll("text")
.data(arcs)
.join("text")
.attr("transform", d => `translate(${arc.centroid(d)})`)
.call(text => text.append("tspan")
.attr("y", "-0.4em")
.attr("font-weight", "bold")
.text(d => d.data.name))
.call(text => text.filter(d => (d.endAngle - d.startAngle) > 0.25).append("tspan")
.attr("x", 0)
.attr("y", "0.7em")
.attr("fill-opacity", 0.7)
.text(d => d.data.value.toLocaleString()));

return svg.node();
}
Insert cell
pieData = {
const data = d3.csvParse(await FileAttachment("data.csv").text(), d3.autoType);
// i'm sooo lazy
const data2 = data.slice(821,1211)
return data2;
}
Insert cell
color = d3.scaleOrdinal()
.domain(pieData.map(d => d.name))
.range(d3.quantize(t => d3.interpolateSpectral(t * 0.8 + 0.1), pieData.length).reverse())
Insert cell
pieHeight = 800;
Insert cell
arc = {
const radius = Math.min(width, height) / 2;
return d3.arc().innerRadius(radius * 0.5).outerRadius(radius - 1);
}
Insert cell
pie = d3.pie()
.padAngle(0.00000005)
.sort(null)
.value(d => 1)
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