Published
Edited
Sep 13, 2018
2 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof map = embed({
width: width,
height: width * .6,
layer: layers,
config: {
view: {stroke: 'transparent'}
}
})
Insert cell
map.renderer('svg').run()
Insert cell
// todo: color by sides
layers = [{
data: {
url: topoJsonUrl,
format: {
type: 'topojson',
feature: 'chicago-community-areas'
},
},
projection: {
type: 'mercator',
},
mark: 'geoshape',
encoding: {
stroke: {value: '#333'},
fill: {value: '#ccc'},
tooltip: [
{field: 'properties.community', type: 'nominal', title: 'Community'},
],
},
}]
Insert cell
sideColors = d3[`scheme${'Pastel1'}`]
Insert cell
hoverStyle = html`
<style>
.vega-embed .mark-shape path:hover {
fill-opacity: 0.5;
fill: #000 !important;
}
</style>
`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
geoData = d3.json(geoJsonUrl)
Insert cell
communityData = d3.csv(dataUrl)
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
features = addCommunityInfo(geoData, communities)
Insert cell
function addCommunityInfo(geoData, communities) {
geoData.features.map(feature => {
// replace community name with community info
const communityName = feature.properties.community.toLowerCase();
feature.properties.community = communities[communityName];
});
return geoData.features;
}
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