Published
Edited
Dec 25, 2019
Importers
3 stars
Insert cell
Insert cell
md`This is a range input ${bind(html`<input type=range style="width:80px;">`, viewof apples)}.

This is a number input ${bind(html`<input type=number style="width:80px;">`, viewof apples)}.`
Insert cell
Insert cell
bind(html`<input type=range>`, viewof apples)
Insert cell
Insert cell
viewof apples = new View(3)
Insert cell
Insert cell
new Array(apples + 1).join("🍎")
Insert cell
Insert cell
function bind(input, view) {
const value = ["range", "number"].includes(input.type) ? "valueAsNumber" : "value";
var update;
if (input.type == "file") {
update = () => { };
input.oninput = () => { view.value = input.files };
}
else if (input.type == "radiogroup") {
update = () => { input.setter(view.value) };
input.oninput = () => { view.value = input.getter() };
}
else if (input.type == "checkbox") {
update = () => input.checked = view.value;
input.oninput = () => view.value = input.checked;
}
else {
update = () => input[value] = view.value;
input.oninput = () => view.value = input[value];
}
view.addEventListener("input", update);
disposal(input).then(() => view.removeEventListener("input", update));
return update(), input;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`### Example:`
Insert cell
md `X: ${bindSelect({options:["a","b","c"]}, viewof x)}&nbsp;&nbsp;&nbsp;&nbsp;Y:${bindSliderNumber ({min:0,max:10,step:0.1}, viewof y)}

Z: ${bindCheckbox("z", viewof z)}

W: ${bindRadioGroup ({options:["a","b","c"]}, viewof w)}

S: ${bindCheckGroup ({options:["a","b","c"]}, viewof s)}

F: ${bindFile({multiple:true, accept:".png,.jpg", size:'20em'}, viewof f)}

C: ${bindColor({}, viewof c)}`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof c = new View("#ffaa00")
Insert cell
[x,y,z,w,s]
Insert cell
{
const div = html`<div>`;
div.append(html`<h3>Image:</h3>`);
for (var j = 0; j < f.length; j++) {
let file = f[j];
let img = html`<img height="125px" />`
img.src = await Files.url(f[j]);
div.append(img);
}
return div;
}
Insert cell
md`### Imports`
Insert cell
import {View} from "@mbostock/synchronized-views"
Insert cell
import {disposal} from "@mbostock/disposal"
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