Protect against out of bounds array condition

This commit is contained in:
D. Berge
2025-07-28 10:10:05 +02:00
parent 31ac8d3c01
commit 89c565a0f5

View File

@@ -124,30 +124,38 @@ class SequenceDataLayer extends CompositeLayer {
};
SequenceDataLayer.layerName = "SequenceDataLayer";
SequenceDataLayer.tooltip = ({index, sourceLayer}) => {
if (index >= 0) {
const p = sourceLayer?.props?.data;
// console.log("P", p);
if (p.type == MSGTYPE.PREPLOT_RAWERROR_OPT) {
try {
if (index >= 0) {
const p = sourceLayer?.props?.data;
if (index >= p.length) {
console.log("Index out of bounds");
}
// console.log("P", p);
if (p.type == MSGTYPE.PREPLOT_RAWERROR_OPT) {
const seq = p.seq.toString().padStart(3, "0");
const pnt = p.sp0 + p.Δsp * index;
return `S${seq} ${pnt}`;
const seq = p.seq.toString().padStart(3, "0");
const pnt = p.sp0 + p.Δsp * index;
return `S${seq} ${pnt}`;
} else if (p.type == MSGTYPE.RAW_OPT || p.type == MSGTYPE.FINAL_OPT) {
} else if (p.type == MSGTYPE.RAW_OPT || p.type == MSGTYPE.FINAL_OPT) {
const seq = p.seq.toString().padStart(3, "0");
const pnt = p.sp0 + p.Δsp * index;
const kind = p.type == MSGTYPE.RAW_OPT ? "Raw" : "Final";
const Δi = p.Δij[index*2];
const Δj = p.Δij[index*2+1];
const tstamp = new Date(Number(p.ts0) + p.Δts[index]);
const seq = p.seq.toString().padStart(3, "0");
const pnt = p.sp0 + p.Δsp * index;
const kind = p.type == MSGTYPE.RAW_OPT ? "Raw" : "Final";
const Δi = p.Δij[index*2];
const Δj = p.Δij[index*2+1];
const tstamp = new Date(Number(p.ts0) + p.Δts[index]);
const html = `S${seq} ${pnt} (${kind})<br/>\n` +
`<small>${tstamp.toISOString()}</small><br/>\n` +
`Δi: ${Δi.toFixed(2)}<br/>\n` +
`Δj: ${Δj.toFixed(2)}</br/>`;
return {html};
const html = `S${seq} ${pnt} (${kind})<br/>\n` +
`<small>${tstamp.toISOString()}</small><br/>\n` +
`Δi: ${Δi.toFixed(2)}<br/>\n` +
`Δj: ${Δj.toFixed(2)}</br/>`;
return {html};
}
}
} catch (err) {
console.error(err.message);
console.log(index, sourceLayer);
}
};