Published
Edited
Nov 6, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
candidaturas = d3.csvParse(await FileAttachment("candidaturas-2020.csv").text(), d3.autoType);
Insert cell
Insert cell
Insert cell
dataMap = new Map(candidaturas.map(d => [codigos.get(d.sigla_ue), d]));
Insert cell
Insert cell
Insert cell
dataMap.get(1301654).nao_brancos
Insert cell
Insert cell
Insert cell
fillScalePop = {
const values = [... dataMap.values()].map(d => d.nao_brancos);
return d3.scaleSequential(d3.extent(values), d3.interpolateCividis).nice();
}
Insert cell
Insert cell
mapaBR = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.selectAll("path")
.data(topojson.feature(br, br.objects.Munic).features)
.join("path")
.attr("stroke", "none")
.attr("fill", d => dataMap.has(d.id) ? fillScalePop(dataMap.get(d.id).nao_brancos) : "#ddd")
.attr("d", pathBR)
.append("title")
.text(d => tooltipCP(d))
// legenda
svg.append("g")
.attr("transform", "translate(410,20)")
.append(() => legend({color: fillScalePop,
title: "Proporção dos candidatos que não são brancos.",
width: 250,
tickFormat: ",%"}));

return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
dadosPontosPB = {
const gjFeatureMap = new Map(topojson.feature(pb, pb.objects.Munic).features.map(d => [d.id, d]));
const dados = candidaturas.filter(d => d.sigla_uf === "PB").map(({codigo_ibge, nao_brancos, candidaturas, nome_municipio, capital}) => {
const feature = gjFeatureMap.get(codigo_ibge);
return{
codigo_ibge,
nao_brancos,
candidaturas,
nome_municipio,
capital,
posicao : feature && pathGenPB.centroid(feature) // <-- Repare aqui
};
})
return dados.filter(d => d.posicao);
}
Insert cell
radiusScale = d3.scaleSqrt([1, d3.max(dadosPontosPB, d => d.candidaturas)], [0, 20])
Insert cell
fillPointsScale = d3.scaleSequential([0, 1], d3.interpolatePuOr).nice()
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
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