Public
Edited
Apr 1
Importers
20 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
delayedDependentAsyncComputation = {
clicker; // create dependancy on clicker cellto resolve a value
return uid();
}
Insert cell
Insert cell
periodicFulfilled = {
while (runPeriodics) {
yield Promises.delay(1000, Math.random());
}
}
Insert cell
periodicThrow = {
periodicFulfilled; // depends on periodicFulfilled's clock
throw new Error(); // throw an error, errors are shown in red
}
Insert cell
uid = () => (Math.random() + 1).toString(36).substring(7)
Insert cell
Insert cell
Insert cell
excludes = descendants(
lookupVariable("events", thisModule),
lookupVariable("trackedVariables", thisModule),
...extra_excludes
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
events
Insert cell
viz = {
now;
const end = (endTime || performance.now()) - timeDelay * 1000;
const start = Math.max(end - windowSecs * 1000);
return Plot.plot({
width,
marginLeft: 300,
y: {
axis: null,
domain: [
...events.reduce((acc, e) => (acc.add(e.name), acc), new Set())
].sort()
},
x: {
domain: [start, end],
type: "time"
},
color: {
domain: ["pending", "fulfilled", "rejected", "idle"],
range: ["#BBF", "#0F0", "#F44", "#EEE"]
},
marks: [
Plot.ruleY(
events,
Plot.selectLast({
z: "name",
y: "name",
stroke: "#EEE",
strokeDasharray: [2, 3]
})
),
Plot.barX(
events,
Plot.selectLast({
x1: start,
x2: start - 60 * 60 * 1000,
y: "name",
z: "name",
text: "name",
textAnchor: "end",
dx: -10,
fill: (d) =>
d.type === "pending" ? "pending" : end - d.t < 500 ? d.type : "idle"
})
),
Plot.tickX(events, {
x: "t",
y: "name",
stroke: "type",
strokeWidth: 2
}),
// Plot.arrow(
// events.flatMap((e) =>
// e.variable._inputs.map((i) => ({
// input: i,
// variable: e.variable
// }))
// ),
// {
// x1: start,
// y1: (d) => d.input._name,
// x2: start,
// y2: (d) => d.variable._name,
// bend: true,
// stroke: "#ccc",
// headLength: 4,
// strokeWidth: 1
// }
// ),
Plot.text(
events,
Plot.selectLast({
x: start,
y: "name",
z: "name",
text: (d) => d.name, // + "\n " + d.variable._definition.toString().slice(0, 30),
textAnchor: "end",
dx: -10,
fill: "black"
})
)
]
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof clear = Inputs.button("clear", {
reduce: () => (mutable events = [])
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof timeDelay = Inputs.range([0, 30], {
value: 0,
step: 0.01,
label: "delay (secs)"
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
interceptVariables = {
trackedVariables.forEach((v) => interceptVariable(v, invalidation, excludes));
return Object.fromEntries(trackedVariables.map((v) => [v._name, v]));
}
Insert cell
function notify(name, type, value, variable) {
if (viewof pause.value) return;

const event = {
t: performance.now(),
name: name || variable._definition.toString().slice(0, 30),
value,
type,
variable
};
mutable events.push(event);
while (mutable events.length > 2000) mutable events.shift();

mutable events = mutable events;
if (viewof breakpoint.value) {
debugger;
}
}
Insert cell
names = ({})
Insert cell
function interceptVariable(v, invalidation, excludes, firstSeen = false) {
if (excludes.has(v)) return;
if (!v.ndd) {
v.ndd = true;
observe(v, {
pending: (...args) => notify(v._name, "pending", args[0], v),
rejected: (...args) => notify(v._name, "rejected", args[0], v),
fulfilled: (...args) => notify(v._name, "fulfilled", args[0], v)
});
}
}
Insert cell
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