Published
Edited
Sep 13, 2018
2 forks
Also listed in…
Vega
Random Bits
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

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