diff --git a/frontend/app/pages/commune/[slug]/index.vue b/frontend/app/pages/commune/[slug]/index.vue index 273211b..8644a67 100644 --- a/frontend/app/pages/commune/[slug]/index.vue +++ b/frontend/app/pages/commune/[slug]/index.vue @@ -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))