Public
Edited
Nov 23
Insert cell
Insert cell
Insert cell
Insert cell
viewof hz = Inputs.range([1, 10], { label: "Hz", step: 1, value: 4 })
Insert cell
interval = 1000 / hz
Insert cell
Inputs.button("Start", { reduce: start })
Insert cell
Inputs.button("Stop", { reduce: stop })
Insert cell
Insert cell
mutable l = []
Insert cell
function callback() {
mutable l = [mutable t, mutable dt];
}
Insert cell
Insert cell
mutable t = Date.now()
Insert cell
mutable dt = 0
Insert cell
mutable _timeoutId = null
Insert cell
mutable _expectedNextTickTimestamp = mutable t + interval
Insert cell
Insert cell
function start() {
mutable t = Date.now();
mutable _expectedNextTickTimestamp = Date.now() + interval;

mutable _timeoutId = setTimeout(step, interval);
}
Insert cell
function step() {
mutable t = Date.now();
mutable dt = mutable t - mutable _expectedNextTickTimestamp;

if (mutable dt > interval) {
// something really bad happened. Maybe the browser (tab) was inactive?
// possibly special handling to avoid futile "catch up" run
}

callback();

// Start next iteration, take drift into account
mutable _expectedNextTickTimestamp += interval;
mutable _timeoutId = setTimeout(step, Math.max(0, interval - mutable dt));
}
Insert cell
function stop() {
if (mutable _timeoutId) {
clearTimeout(mutable _timeoutId);
mutable _expectedNextTickTimestamp = null
mutable _timeoutId = null;
}
}
Insert cell
Insert cell
Insert cell
window.innerHeight
Insert cell
mutable __listening = false
Insert cell
screenHeight = {
if (!mutable __listening) {
mutable __listening = true

window.addEventListener('resize', (event) => {
mutable __innerHeight = window.innerHeight
})
}

return __innerHeight
}
Insert cell
mutable __innerHeight = window.innerHeight
Insert cell
Insert cell
import { toCss, cssTag } from '@jerryjappinen/templates'
Insert cell
toCss({ foo: 'bar' })
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