Skip to content

Commit 247c626

Browse files
committed
optimize fast autorange further by splitting log into its own loop
1 parent cf48426 commit 247c626

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Diff for: src/plots/cartesian/autorange.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,19 @@ function expand(ax, data, options) {
258258
vmin = Infinity;
259259
vmax = -Infinity;
260260

261-
for(i = 0; i < data.length; i++) {
262-
v = data[i];
263-
if(Math.abs(v) < FP_SAFE) {
261+
if(isLog) {
262+
for(i = 0; i < len; i++) {
263+
v = data[i];
264264
// data is not linearized yet so we still have to filter out negative logs
265-
if(v < vmin && (!isLog || v > 0)) vmin = v;
266-
if(v > vmax) vmax = v;
265+
if(v < vmin && v > 0) vmin = v;
266+
if(v > vmax && v < FP_SAFE) vmax = v;
267+
}
268+
}
269+
else {
270+
for(i = 0; i < len; i++) {
271+
v = data[i];
272+
if(v < vmin && v > -FP_SAFE) vmin = v;
273+
if(v > vmax && v < FP_SAFE) vmax = v;
267274
}
268275
}
269276

@@ -340,8 +347,9 @@ function expand(ax, data, options) {
340347
// For efficiency covering monotonic or near-monotonic data,
341348
// check a few points at both ends first and then sweep
342349
// through the middle
343-
for(i = 0; i < 6; i++) addItem(i);
344-
for(i = len - 1; i > 5; i--) addItem(i);
350+
var iMax = Math.min(6, len);
351+
for(i = 0; i < iMax; i++) addItem(i);
352+
for(i = len - 1; i >= iMax; i--) addItem(i);
345353
}
346354

347355
// In order to stop overflow errors, don't consider points

0 commit comments

Comments
 (0)