Published
Edited
Dec 26, 2018
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
cars = require("@observablehq/cars")
Insert cell
Insert cell
carsQuery = query(
[
// of all cars
// 1. look at each's "Name"
// 2. keep the ones that test true on the regexp: /\(sw\)/i short for station wagon
// 3. group the result as "stationWagons"
["Name", /\(sw\)/i, "stationWagons"],
// in "stationWagons"
// 1. look at each car's "Origin"
// 2. select the ones that are from the USA or Europe
// 3. group them as westernSWs"
["stationWagons", "Origin", o => o == "USA" || o == "Europe", "westernSWs"], // predicate function
// same with japanese specifically
["stationWagons", "Origin", "Japan", "JapaneseSWs"], // Origin == "Japan" equality
// of all cars
// 1. look at each's "Horsepower" and "Acceleration"
// 2. keep the strong and fast-ish ones
// 3. group the result as "strongAndFast"
[
({ Horsepower, Acceleration }) => Horsepower >= 200 && 10 >= Acceleration,
"strongAndFast"
]
],
cars
)
Insert cell
Insert cell
yearBuiltQuery = (fromYear, toYear) =>
query(
[
[
"ALL",
"Year",
y => (toYear ? y >= fromYear && y < toYear : y >= fromYear),
toYear ? `${fromYear}-${toYear}` : `${fromYear}'s`
]
]
// look no dataset!
)
Insert cell
yearBuiltQuery(1973, 1980)(cars)
Insert cell
Insert cell
selectorFn.rels()
Insert cell
Insert cell
query([[123]], []) // oh no!
Insert cell
Insert cell
// selectorFn.add("number", selector => ctx =>
// (ctx.myResult = { foo: 42, originalSelector: selector })
// )
Insert cell
Insert cell
// query([[123]], [])
Insert cell
Insert cell
Insert cell
Insert cell
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