Published
Edited
Oct 30, 2019
1 fork
67 stars
Insert cell
Insert cell
files = [
FileAttachment("2014-acs5-B01003-state-01.json"),
FileAttachment("2014-acs5-B01003-state-04.json"),
FileAttachment("2014-acs5-B01003-state-45.json")
]
Insert cell
Insert cell
promises = files.map(file => file.json())
Insert cell
datasets = Promise.all(promises)
Insert cell
Insert cell
{
let total = 0;
const datasets = await Promise.all(files.map(file => file.json()));
for (const dataset of datasets) {
for (let i = 1; i < dataset.length; ++i) {
total += +dataset[i][0];
}
}
return total;
}
Insert cell
Insert cell
{
let total = 0;
for (const file of files) {
const dataset = await file.json();
for (let i = 1; i < dataset.length; ++i) {
total += +dataset[i][0];
yield total;
}
}
return total;
}
Insert cell
Insert cell
{
let total = 0;
for (const promise of files.map(file => file.json())) {
const dataset = await promise;
for (let i = 1; i < dataset.length; ++i) {
total += +dataset[i][0];
yield total;
}
}
return total;
}
Insert cell
Insert cell
{
let total = 0;
for await (const dataset of files.map(file => file.json())) {
for (let i = 1; i < dataset.length; ++i) {
total += +dataset[i][0];
yield total;
}
}
return total;
}
Insert cell
Insert cell
async function* foo() {
for (let i = 1; i <= 1000; ++i) {
await Promises.delay(100);
yield i;
}
}
Insert cell
Insert cell
foo()
Insert cell
Insert cell
{
const generator = foo();
const iterator = generator[Symbol.asyncIterator]();
while (true) {
const {done, value} = await iterator.next();
if (done) return;
yield value;
}
}
Insert cell
Insert cell
function* altFoo() {
for (let i = 0; i < 1000; ++i) {
yield Promises.delay(100, i);
}
}
Insert cell
altFoo()
Insert cell
Insert cell
function* fastFoo() {
for (let i = 0; i < 1000; ++i) {
yield i;
}
}
Insert cell
Insert cell
Insert cell
{
const w = Math.min(640, width);
const h = 320;
const r = 20;
const t = 1500;
const svg = d3.select(DOM.svg(w, h));
const circle = svg.append("circle").attr("r", r).attr("cx", w / 4).attr("cy", h / 4);
while (true) {
yield svg.node();
await circle.transition().duration(t).attr("cy", h * 3 / 4).end();
await circle.transition().duration(t).attr("cx", w * 3 / 4).end();
await circle.transition().duration(t).attr("cy", h * 1 / 4).end();
await circle.transition().duration(t).attr("cx", w * 1 / 4).end();
}
}
Insert cell
d3 = require("d3@5")
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