Public
Edited
Apr 13, 2023
Insert cell
Insert cell
Insert cell
Insert cell
import { model } from "@stuwilmur/mt"
Insert cell
Insert cell
model1 = model()
Insert cell
Insert cell
o1 = model1.data(weather)
Insert cell
Insert cell
Insert cell
o2 = model().group("weather").data(weather)
Insert cell
Insert cell
Insert cell
o3 = model()
.calc()
.called("wind (mph)")
.does((r) => r.wind * 2.23694)
.end()
.data(weather)
Insert cell
Insert cell
Insert cell
o4 = model()
.calc()
.called("wind (mph)")
.does((r) => r.wind * 2.23694)
.end()
.group("weather")
.data(weather)
Insert cell
Insert cell
Insert cell
o5 = model()
.sort()
.inc("name")
.end()
.calc()
.called("economical")
.does((d) => d["economy (mpg)"] > 20)
.end()
.calc()
.called("heavy")
.does((d) => d["weight (lb)"] > 2000)
.end()
.group("economical", "heavy")
.data(cars)
Insert cell
Insert cell
Insert cell
o6 = model()
.reduce()
.groupBy("cylinders")
.add()
.called("average mpg")
.does((x) => d3.mean(x, (d) => d["economy (mpg)"]))
.end()
.add()
.called("maximum power")
.does((x) => d3.max(x, (d) => d["power (hp)"]))
.end()
.end()
.sort()
.inc("cylinders")
.end()
.data(cars)
Insert cell
Insert cell
Insert cell
o7 = model().select("location", "date", "weather").data(weather)
Insert cell
Insert cell
Insert cell
model().const().called("Sales Tax").value(20).end()
Insert cell
Insert cell
model().const().value(20).called("Sales Tax").end()
Insert cell
Insert cell
Insert cell
m1 = model().calc().called('a').does(x=>x.a + x.b).end() // replaces column a with value of a + b
Insert cell
m2 = model().sort().inc('a').end() // sorts on increasing a
Insert cell
Insert cell
d1 = [{a:1, b:2},{a:2, b:-2}]
Insert cell
m2.data(m1.data(d1))
Insert cell
Insert cell
m1.add(m2).data(d1) // apply m1, then apply m2 to the result
Insert cell
m3 = m2.add(m1) // make a new model, which is m2 followed by m1
Insert cell
m3.data(d1)
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