Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions packages/scales/src/compute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ const getDatumAxisPosition = <D extends SerieDatum = SerieDatum>(
return scale(datum.data[axis]) ?? null
}

const chunkArray = (array: number[], chunkSize: number) =>
Array.from({ length: Math.ceil(array.length / chunkSize) }, (_, index) =>
array.slice(index * chunkSize, (index + 1) * chunkSize)
)

/**
* Compute x/y d3 scales from an array of data series, and scale specifications.
*
Expand Down Expand Up @@ -235,7 +240,11 @@ export const generateSeriesAxis = <Axis extends ScaleAxis, Value extends ScaleVa
v => v
)

return { all, min: Math.min(...all), max: Math.max(...all) }
return {
all,
min: Math.min(...chunkArray(all, 10000).map(chunk => Math.min(...chunk))),
max: Math.max(...chunkArray(all, 10000).map(chunk => Math.max(...chunk))),
}
}
case 'time': {
const all = uniqBy(values as Date[], v => v.getTime())
Expand Down Expand Up @@ -293,8 +302,8 @@ export const stackAxis = <S = never, D extends SerieDatum = SerieDatum>(
})
})

xy[axis].minStacked = Math.min(...all)
xy[axis].maxStacked = Math.max(...all)
xy[axis].minStacked = Math.min(...chunkArray(all, 10000).map(chunk => Math.min(...chunk)))
xy[axis].maxStacked = Math.max(...chunkArray(all, 10000).map(chunk => Math.max(...chunk)))
}

const stackX = <S = never, D extends SerieDatum = SerieDatum>(
Expand Down