Skip to content

Commit

Permalink
fix: do not allow impliedBandScale domain to exceed range
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Oct 11, 2023
1 parent 7f329e7 commit e4b1c9c
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/utils/buildAxis.linear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -647,34 +647,40 @@ function buildPrimaryBandScale<TDatum>(
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)

Expand Down

0 comments on commit e4b1c9c

Please sign in to comment.