Published
Edited
Jul 23, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`The current time is ${new Date(now).toLocaleTimeString()}.`
Insert cell
slow_tick = {
// can't use Observable's `now` here, need to create new Date objects for some reason..
const tick_ms = 3000
yield new Date().getTime();
while(true) yield Promises.delay(tick_ms, new Date().getTime());
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof chosen_input = html`<input type=${input_type}>`
Insert cell
Insert cell
Insert cell
Insert cell
hello_button = {
const button = html`<button>say hello`;
button.onclick = () => console.log('hello!');
return button;
}
Insert cell
Insert cell
Insert cell
viewof meter = html`
<meter min="0" max="100"
low="33" high="66" optimum="80"
value="${centillator}"
>`
Insert cell
meter
Insert cell
Insert cell
viewof progress = html`<progress max="100" value="${centillator}">`
Insert cell
progress
Insert cell
Insert cell
viewof ranged_value = html`<input type=range min=0 max=1 step=.01 value=.25>`
Insert cell
ranged_value
Insert cell
Insert cell
viewof selected_value = html`
<select>
<option value="">(select one)</option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>`
Insert cell
selected_value
Insert cell
Insert cell
viewof textarea_value = html`<textarea cols=25 rows=12 placeholder='jot anything!'>`
Insert cell
textarea_value
Insert cell
Insert cell
function* errorView() { // from: https://talk.observablehq.com/t/error-reporting/3771/6
let resolve, reject;
const p = new Promise((res, rej) => {
resolve = res, reject = rej;
}),
timer = Promises.delay(5000).then(() => {
throw Error('time\'s up!');
}),
yep = Object.assign(html`<button>Resolve`, {
onclick() { resolve('Done!') }
}),
nope = Object.assign(html`<button>Reject`, {
onclick() { reject(Error('Not gonna happen')) }
});
yield html`<div>Stand by, we're "loading" (5sec max). ${yep} ${nope}`;
yield Promise.race([p, timer]).then(data => html`<div>${data}`)
}
Insert cell
errorView()
Insert cell
Insert cell
Insert cell
Insert cell
{
const r = 5, lim = 128;
const context = DOM.context2d(lim, lim);
for (let radius = r; radius < lim; radius += r) {
context.beginPath();
context.arc(0, 0, radius, 0, 2 * Math.PI);
context.stroke();
}
return context.canvas;
}
Insert cell
Insert cell
Insert cell
dot`digraph { a -> b; a -> c; }`
Insert cell
Insert cell
html`${['d','b','9','7','5','3','1'].map((v,i) => {
const color = `#${v.repeat(3)}`;
return html`<div title="${color}" style="display:inline-block; width:50px; height:50px; background:${color};">`
})}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
svg`<svg width="100" height="100"><circle cx="50" cy="50" r="35" fill="#57f" />`
Insert cell
Insert cell
Insert cell
Insert cell
centillator = Math.round(Math.sin(now*.001) * 50 + 50)
Insert cell
Insert cell
Insert cell
dot = require("@observablehq/graphviz")
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