Published
Edited
Nov 14, 2019
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
top = d3.csvParse(await FileAttachment("atores.csv").text(), (d, i, columns) => (d3.autoType(d), d.total = d3.sum(columns, c => d[c]), d)).sort((a, b) => b.total - a.total)
Insert cell
data = top.slice(0,10)
Insert cell
series = d3.stack().keys(top.columns.slice(1))(data)

Insert cell
y = d3.scaleBand()
.domain(data.map(d => d.nome_autor))
.range([margin.top, height - margin.bottom])
.padding(0.1)
Insert cell
x = d3.scaleLinear()
.domain([0, d3.max(series, d => d3.max(d, d => d[1]))])
.rangeRound([margin.left,width - margin.right])
Insert cell
color = d3.scaleOrdinal()
.domain(series.map(d => d.key))
.range(d3.quantize(t => d3.interpolateSpectral(t * 0.8 + 0.1), series.length).reverse())
.unknown("#ccc")
Insert cell
yAxis = g => g
.attr("transform", `translate(0,${width - margin.right})`)
.call(d3.axisBottom(y).tickSizeOuter(0))
.call(g => g.selectAll(".domain").remove())
Insert cell
xAxis = g => g
.attr("transform", `translate(${margin.top},0)`)
.call(d3.axisLeft(x).ticks(null, "s"))
.call(g => g.selectAll(".domain").remove())
Insert cell
height = 600
Insert cell
width = 1000
Insert cell
margin = ({top: 10, right: 10, bottom: 20, left: 40})
Insert cell
names = g => g
.append("text")
.attr("y", 30)
.attr("x", 0)
.text(d => d.nome_autor)
Insert cell
d3 = require("d3@5")
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