Published
Edited
Apr 30, 2019
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
topojson = require("topojson-client@3")
Insert cell
Insert cell
bostonjson = d3.json("https://gist.githubusercontent.com/cesandoval/09b2e39263c748fbcb84b927cecc7c46/raw/ab71d3638efd2545ec99c2651c6f2ddcea9d2a07/boston.json")
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
xScale = d3.scaleLinear()
.domain([0, d3.max(dataForGraph, d => d.value)])
.range([margin.left, width - margin.right]);
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
color = d3.scaleQuantize()
.domain([0, d3.max(csv311b, d => Math.log(d["tot_count \t\t\t"]))])
.range(d3.schemePurples[9]);
Insert cell
Insert cell
// Create GeoPath function that uses built-in D3 functionality to turn
// lat/lon coordinates into screen coordinates
path = d3.geoPath()
.projection( bosProjection );
Insert cell
Insert cell
Insert cell
height_map = 600
Insert cell
{
const neigh = {} //placeholder for data set
csv311b.forEach(d => (neigh[d.id] = Math.log(d["tot_count \t\t\t"])));
return neigh
}
Insert cell
{
let svg = d3.select(DOM.svg(width, height_map)); //make SVG
let g = svg.append("g");
let value = null;
const neigh = {} //placeholder for data set
csv311b.forEach(d => (neigh[d.id] = Math.log(d["tot_count \t\t\t"])));

const outline = svg.append("path")
.attr("fill", "none")
.attr("stroke", "red")
.attr("stroke-width", "3px")
.attr("stroke-linejoin", "round")
.attr("pointer-events", "none");
// Bind TopoJSON data to csv data
g.selectAll("path")
.data(topojson.feature(bostonjson, bostonjson.objects.boston_neigh).features) // bind TopoJSON data elements
.enter().append("path")
.attr("d", path)
.style("fill", d => color(neigh[d.properties.OBJECTID]))
.style("stroke", "white")
.on("click", d => {
const node = svg.node();
node.value = value = value === d.properties.OBJECTID ? null : d.properties.OBJECTID;
node.dispatchEvent(new CustomEvent("input"));
outline.attr("d", value ? path(d) : null);
});

svg.append("g")
.attr("transform", "translate(600,40)")
.call(legend);
return Object.assign(svg.node(), {value: null});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
formattedName = {
if (neighborhoodToDisplay == undefined) {
return "All Neighborhoods";
} else {
let row = z.filter(r => r.id == neighborhoodToDisplay, csv311)[0];
return row.Name;
}
}
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