Skip to content

world.dataHistory(name) ​

Returns the recent values of data[name] and the time at which each one arrived.

dataHistory(name: string): Promise<Array<{ value: unknown; time: number }>> | Array<{ value: unknown; time: number }>
js
const points = await world.dataHistory('score');

Parameters ​

ParameterWhat it is
nameA name of data such as 'score'.

Returns ​

An array sorted from the oldest value to the newest. Each item is an object with two fields:

FieldWhat it is
valueThe value in the same form as in data (a number, an array, a data URI, ...).
timeThe arrival time in Unix milliseconds.

For a name absent from data the array is empty.

In the webapp the call returns a Promise that resolves to the array. With a fake world it returns the array directly. Always await the call so that the same code runs in both cases.

Usage ​

Draw a chart of a number ​

js
const points = await world.dataHistory('temperature');
const first = points[0]?.time ?? 0;
for (const { value, time } of points) {
  plot((time - first) / 1000, value); // seconds since the first value
}

Keep the chart going ​

dataHistory reads the history only once. Render it first and then append each new value that onData delivers:

js
const points = await world.dataHistory('temperature');
drawChart(points);
world.onData('temperature', (value) => {
  points.push({ value, time: Date.now() });
  drawChart(points);
});

Caveats ​

  • A copy taken at the time of the call. The array does not grow. Call dataHistory again or follow the new values with onData.
  • Recent values only. The array holds at most the last 200 values of that name received by the webapp since the person entered the world.
  • It sends nothing on behalf of the person. It only reads values already received by the webapp.

Troubleshooting ​

CodeWhyWhat to do
'failed'The webapp could not run the call (rare).Render from data alone without the history.
ProblemWhyWhat to do
points.map is not a functionIn the webapp the call returns a Promise.await the call.
The array is empty.The name is not in data or the world has sent no value yet.Check the name in Object.keys(world.get().data).

See also ​

The UNaIVERSE GUI kit, released under the Apache License 2.0. Copyright 2024-2026 UNaIVERSE S.r.l.