In trying to add my custom data to a heatmap using the new Forge Datavisualization API, but I'm having issues trying to use an async function to link the data to the heatmap.
I want to call an async fetch function inside the getSensorValue callback. If I just return a Math.random() it works:
function getSensorValue(surfaceShadingPoint, sensorType) {
return Math.random();
}
But whenever I try to add any awaitable function it won't render any surface shading:
[...]
function normalizeValue(value, min, max) {
return (value - min) / (max - min);
}
async function getSensorValue(surfaceShadingPoint, sensorType) {
let data = await asynchronousFunction();
data = data[data.length-1]
let temperature = (data[0].temperature);
return normalizeValue(temperature,19,37);
}
[...]
setInterval(async function () {
const floorName = 'A1_Level 1';
dataVizExt.renderSurfaceShading(floorName, sensorType, await getSensorValue);
}, 1000);
And I've also tried using Promises like this with no success... :
function getSensorValue(surfaceShadingPoint, sensorType) {
return (promise = new Promise((resolve, reject) => {
resolve(asynchronousFunction());
}));
}
function normalizeValue(value, min, max) {
return (value - min) / (max - min);
}
setInterval(function () {
const floorName = 'A1_Level 1';
dataVizExt.renderSurfaceShading(floorName, sensorType, () =>
getSensorValue().then((res) => {
let data = res;
data = data[data.length - 1];
let temperature = data.temperature;
return normalizeValue(temperature,22,40);
})
);
}, 1000);
Do I have any misconception on the API or am I messing up my JS async logic?