From 96b8f4b9d6171c19ed4f1c5d8618531ef9634470 Mon Sep 17 00:00:00 2001 From: Dominik Moritz Date: Wed, 20 May 2020 09:50:34 -0700 Subject: [PATCH] Limit the number of iterations in scaleLinear.nice --- src/linear.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/linear.js b/src/linear.js index 73b3274..f9f91cb 100644 --- a/src/linear.js +++ b/src/linear.js @@ -26,14 +26,14 @@ export function linearish(scale) { let stop = d[i1]; let prestep; let step; + let maxIter = 10; if (stop < start) { step = start, start = stop, stop = step; step = i0, i0 = i1, i1 = step; } - // eslint-disable-next-line no-constant-condition - while (true) { + while (maxIter-- > 0) { const step = tickIncrement(start, stop, count); if (step === prestep) { d[i0] = start @@ -46,10 +46,12 @@ export function linearish(scale) { start = Math.ceil(start * step) / step; stop = Math.floor(stop * step) / step; } else { - return scale; + break; } prestep = step; } + + return scale; }; return scale;