Copilot commented on code in PR #21601:
URL: https://github.com/apache/echarts/pull/21601#discussion_r3176958606
##########
src/processor/dataSample.ts:
##########
@@ -86,14 +102,18 @@ export default function dataSample(seriesType: string):
StageHandler {
const coordSys = seriesModel.coordinateSystem;
const count = data.count();
// Only cartesian2d support down sampling. Disable it when there
is few data.
- if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
+ if (count > 10 && coordSys.type === 'cartesian2d' && sampling &&
sampling !== 'none') {
const baseAxis = coordSys.getBaseAxis();
const valueAxis = coordSys.getOtherAxis(baseAxis);
const extent = baseAxis.getExtent();
const dpr = api.getDevicePixelRatio();
// Coordinste system has been resized
const size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
- const rate = Math.round(count / size);
+ if (count <= size) {
+ return;
+ }
+ const dataCount = countDataInAxisExtent(data, baseAxis,
data.mapDimension(baseAxis.dim));
+ const rate = Math.round(dataCount / size);
Review Comment:
`size` can be 0 when the base axis extent collapses (e.g., chart container
temporarily has 0 width/height). In that case we still iterate the entire
dataset in `countDataInAxisExtent`, which can become very expensive on large
series even though sampling will be skipped due to `rate` being non-finite. Add
an early return like `if (size <= 0) { return; }` before calling
`countDataInAxisExtent` to avoid the O(n) scan in this scenario.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]