From e4b1c9c6306862847e2a9cfa91fcb3e42163c8d3 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Wed, 11 Oct 2023 11:45:30 -0600 Subject: [PATCH] fix: do not allow impliedBandScale domain to exceed range --- src/utils/buildAxis.linear.ts | 40 ++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/utils/buildAxis.linear.ts b/src/utils/buildAxis.linear.ts index 278d84c9..c651ddb7 100644 --- a/src/utils/buildAxis.linear.ts +++ b/src/utils/buildAxis.linear.ts @@ -647,34 +647,40 @@ function buildPrimaryBandScale( range: [number, number] ) { // Find the two closest points along axis + // Do not allow the band to be smaller than single pixel of the output range let impliedBandWidth: number = Math.max(...range) + const bandRange: number = Math.max(...range) - for (let i = 0; i < series.length; i++) { - const serie = series[i] + ;(() => { + for (let i = 0; i < series.length; i++) { + const serie = series[i] - for (let j = 0; j < serie.datums.length; j++) { - const d1 = serie.datums[j] - const one = scale(d1.primaryValue ?? NaN) + for (let j = 0; j < serie.datums.length; j++) { + const d1 = serie.datums[j] + const one = scale(d1.primaryValue ?? NaN) - for (let k = 0; k < serie.datums.length; k++) { - const d2 = serie.datums[k] - const two = scale(d2.primaryValue ?? NaN) + for (let k = 0; k < serie.datums.length; k++) { + const d2 = serie.datums[k] + const two = scale(d2.primaryValue ?? NaN) - if (one === two) { - continue - } + if (one === two) { + continue + } + + const diff = Math.abs(Math.max(one, two) - Math.min(one, two)) - const diff = Math.abs(Math.max(one, two) - Math.min(one, two)) + if (diff < impliedBandWidth) { + impliedBandWidth = Math.max(diff, bandRange) - if (diff < impliedBandWidth) { - impliedBandWidth = diff + if (impliedBandWidth === bandRange) { + return + } + } } } } - } - - const bandRange = Math.max(...range) + })() const bandDomain = d3Range(bandRange / impliedBandWidth)