Unlisted
Edited
Jan 31, 2024
Insert cell
Insert cell
Insert cell
hover
Insert cell
Insert cell
click
Insert cell
viewof hover = Plot.plot({
marks: [Plot.dot(cars, { x: "power (hp)", y: "economy (mpg)", tip: true })]
})
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
click = Generators.observe((notify) => {
let lastValue = null;
const listener = (e) => {
// If e.detail is true, then this was a click (sticky) event.
// If e.detail is false, then (this feels untidy) deselect if the value is null.
if (e.sticky || (viewof hover.value === null && lastValue !== null)) {
lastValue = viewof hover.value;
notify(lastValue);
}
};
viewof hover.addEventListener("input", listener);
notify(lastValue);
return () => viewof hover.removeEventListener("input", listener);
})
Insert cell
// is = (value) => {
// return (
// utils.isObject(value) &&
// utils.hasOwn(value, implSymbol) &&
// value[implSymbol] instanceof Impl.implementation
// );
// }
Insert cell
Plot = require(await FileAttachment("plot@10.umd.js").url())
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