Published
Edited
Nov 1, 2020
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
deaths = d3.csv("https://gist.githubusercontent.com/theojolliffe/85d0853cd04eeda8909dcdcd961238d7/raw/26f4ee978748235cae1ffa93af0f250a9b13d956/full_local_auth_care.csv", ({Total, Code}) => ({location: Code, rate : +Total}))
Insert cell
Insert cell
Insert cell
Insert cell
import {select} from "@jashkenas/inputs"
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
html`
<div id="sliderContainer">
<input id="timeslide" type="range" min="0" max="16" value="16" step="1"/><br>
<span id="range">2016</span>
</div>
`
Insert cell
{
let width = 960;
let height = 800;
// Create SVG
let svg = d3.select(DOM.svg(width, height));

let g = svg.append("g");
// Create empty object for holding dataset
const rateById = {};
// Create property for each ID, give it value from rate
deaths.forEach(d => (rateById[d.location] = +d.rate));
// Bind TopoJSON data
g.selectAll("path")
.data(topojson.feature(us, us.objects.Local_Authority_Districts__May_2020__Boundaries_UK_BFC).features) // Bind TopoJSON data elements
.enter().append("path")
.attr("class", "county")
.attr("d", path)
.style("fill", d => color(rateById[d.id])) // get rate value for property matching data ID
// pass rate value to color function, return color based on domain and range
const tooltip = svg.append("g");

svg
.selectAll(".county")
.on("touchmove mousemove", function(d) {
tooltip.call(
callout,
`${d.properties.lad20nm}`
);
tooltip.attr(
"transform",
`translate(${d3.mouse(this)[0]},${d3.mouse(this)[1]})`
);
d3.select(this)
.attr("stroke", "red")
.raise();
})
.on("touchend mouseleave", function() {
tooltip.call(callout, null);
d3.select(this)
.attr("stroke", null)
.lower();
});

return svg.node();
}
Insert cell
import { callout } from "@d3/line-chart-with-tooltip"
Insert cell
Insert cell
{
let width = 960;
let height = 600;
// Create SVG
let svg = d3.select(DOM.svg(width, height));

let g = svg.append("g");
// Create empty object for holding dataset
const rateById = {};
// Create property for each ID, give it value from rate
unemployment.forEach(d => (rateById[d.county] = +d.rate));
// Bind TopoJSON data
g.selectAll("path")
.data(topojson.feature(us, us.objects.counties).features) // Bind TopoJSON data elements
.enter().append("path")
.attr("d", path)
.style("fill", d => color(rateById[d.id]));

g.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("d", path);

return svg.node();
}
Insert cell
Insert cell
Insert cell
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