Public
Edited
Apr 10, 2023
5 forks
9 stars
Insert cell
Insert cell
viewof selectedPointIndices = createScatterplotView({ points, invalidation })
Insert cell
/*
* Simple helper to create a dynamic viewof scatterplot based on:
* - https://observablehq.com/@radames/hello-regl-scatterplot
* - https://observablehq.com/@fil/hello-regl-scatterplot
*/
function createScatterplotView({
width = 600,
height = 340,
pointSize = 2,
points = [[0, 0]],
invalidation
} = {}) {
const canvas = document.createElement("canvas");
const scatterplot = createScatterplot({
canvas,
pointSize,
width,
height,
lassoOnLongPress: true,
backgroundColor: "white"
});

scatterplot.subscribe("select", ({ points }) => {
canvas.value = points;
canvas.dispatchEvent(new Event("input"));
});

scatterplot.set({ colorBy: "valueA", pointColor: colors }); // color by the third value
scatterplot.draw(points);

invalidation?.then(() => scatterplot.destroy());

return canvas;
}
Insert cell
Insert cell
Insert cell
Insert cell
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