Published
Edited
Jun 25, 2021
1 star
Insert cell
Insert cell
md`A final version of this notebook can be viewed on my blog [here](https://www.robinlinacre.com/flights/).`
Insert cell
Insert cell
Insert cell
Insert cell
tonnes_co2 = kwh_to_kg_co2(eu.flying.flying_miles_to_kwh(total_miles)) / 1000
Insert cell
kwh_to_kg_co2 = function(kwh) {
return kwh * eu.convert.per("kg_co2_jet_fuel/kwh");
}
Insert cell
total_miles = d3.sum(routes, d => d["distance"])
Insert cell
average_miles = d3.mean(routes, d => d["distance"])
Insert cell
eu = require("@robinl/energy_usage@0.0.34")
Insert cell
start_end_date = d3.extent(routes, d => d["date"])
Insert cell
fmt_num = d3.format(",.0f")
Insert cell
fmt_num_round = d3.format(",.2r")
Insert cell
function diff_years(dt2, dt1) {
var diff = (dt2.getTime() - dt1.getTime()) / 1000;
diff /= 60 * 60 * 24;
return Math.abs(Math.round(diff / 365.25));
}
Insert cell
format_date = d => d.toISOString().split('T')[0]
Insert cell
Insert cell
Insert cell
Insert cell
height = width
Insert cell
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
world = d3.json("https://unpkg.com/world-atlas@1/world/110m.json")
Insert cell
Insert cell
topojson = require("topojson-client@3")
Insert cell
d3 = require("d3@5")
Insert cell
routes_raw = d3.csv("https://gist.githubusercontent.com/RobinL/ba3acbf42349115ed266a98643eb5a80/raw/a603b1fec071383d6a3eb27cbcda789c54cb0014/my_flights.csv", d3.autoType)
Insert cell
routes = routes_raw.map(d => {
d["random"] = ((Math.random() - 0.5) * d["distance"]) / 1000;
return d;
})
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