Public
Edited
Apr 10, 2023
5 forks
10 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

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