Fix TypeScript errors in toPolyline function

Accept undefined arrays and use non-null assertions for
array indexing after length check.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Yvv
2026-02-21 15:28:00 +01:00
parent b30e54a8f7
commit 39b2d7c9fd

View File

@@ -529,16 +529,17 @@ const gridPrices2 = computed(() => {
return arr
})
function toPolyline(vols: number[], vals: number[], cyFn: (v: number) => number) {
if (!vols?.length) return ''
// Downsample for performance (every 4th point)
return vols
.filter((_: number, i: number) => i % 4 === 0 || i === vols.length - 1)
.map((_: number, i: number) => {
const idx = i * 4 >= vols.length ? vols.length - 1 : i * 4
return `${cx2(vols[idx])},${cyFn(vals[idx])}`
})
.join(' ')
function toPolyline(vols: number[] | undefined, vals: number[] | undefined, cyFn: (v: number) => number): string {
if (!vols?.length || !vals?.length) return ''
const pts: string[] = []
for (let i = 0; i < vols.length; i += 4) {
pts.push(`${cx2(vols[i]!)},${cyFn(vals[i]!)}`)
}
const last = vols.length - 1
if (last % 4 !== 0) {
pts.push(`${cx2(vols[last]!)},${cyFn(vals[last]!)}`)
}
return pts.join(' ')
}
const baselineBillRP = computed(() => toPolyline(curveData.value?.baseline_volumes, curveData.value?.baseline_bills_rp, cy2bill))