Skip to content

Data and streaming

Streaming point replacement ​

The call

plot.replacePoints(handle: PointsHandle, points: PointSet): void

Replace the points behind handle, keeping the handle.

What a live cloud should call each time its data changes. Uploading again also works and is what most people reach for first, but it issues a new handle every time and leaves the old cloud resident: a page feeding an instrument would leak a cloud a frame.

This sends the whole cloud, which is the right call when most of it changed or when its length moves every time. A feed rewriting part of a cloud that stays the same size wants writePoints, which costs the part rather than the cloud.

calls/streaming-point-replacement
const cloud = plot.uploadPoints(shell(count));
plot.showPoints(cloud);
plot.frameScene();
return {
  readout: `${count.toLocaleString("en-GB")} points`,
  stream(at) {
    // A cloud whose every point moved: the radius breathes.
    plot.replacePoints(cloud, shell(count, 10 + Math.sin(at * 3)));
  },
};

Also called

3 in the code above, in the order it makes them

plot.uploadPoints(points: PointSet): PointsHandle

Upload a point cloud and return a handle naming it.

plot.showPoints(handle: PointsHandle): void

Draw the point cloud handle names.

plot.frameScene(): void

Point the camera at the middle of everything uploaded, far enough back to see it.

Call after uploading. A scene measured in grid cells or in millimetres is nowhere near where a camera starts, and without this the first thing a caller sees is an empty canvas.