Published
Edited
Aug 23, 2018
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = width
Insert cell
color = d3.scaleOrdinal().range(d3.schemeCategory10)
Insert cell
format = d3.format(",d")
Insert cell
Insert cell
Insert cell
communityData = d3.csv(communitiesInfoUrl)
Insert cell
sides = {
// group communities by side
const sides = {}
communityData.slice(1) // skip 1st null row
.map(community => {
if (!sides[community.Side]) {
sides[community.Side] = [];
}
sides[community.Side].push(community);
});
return sides;
}
Insert cell
communities = {
// create communities info map
const communities = {}
communityData.slice(1) // skip 1st null row
.map(community => communities[community.CommunityName.toLowerCase()] = community);
return communities;
}
Insert cell
function groupBySide(sides, homicides) {
const communityData = groupByCommunity(homicides);
return {
name: 'flare',
children: Object.keys(sides).map(sideName => {
return {
name: sideName,
children: sides[sideName].map(community => {
return {
name: community.CommunityName,
size: communityData[community.CommunityArea].length
};
})
};
})
};
}
Insert cell
function groupByCommunity (data) {
const communityData = {};
data.map(d => {
const communityId = d['Community Area'];
if (!communityData[communityId]) {
communityData[communityId] = [];
}
communityData[communityId].push(d);
});
return communityData;
}
Insert cell
d3 = require("https://d3js.org/d3.v5.min.js")
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