Skip to content

Commit

Permalink
Merge pull request #1506
Browse files Browse the repository at this point in the history
Fix numeric axis crash
  • Loading branch information
bfinzer authored Sep 23, 2024
2 parents 8871107 + 08c2d1d commit 344e556
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions v3/src/components/axis/helper-models/numeric-axis-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ export class NumericAxisHelper extends AxisHelper {
const numericScale = this.multiScale?.scaleType === "linear"
? this.multiScale.numericScale?.copy().range(this.newRange) as ScaleLinear<number, number>
: undefined
if (!isNumericAxisModel(this.axisModel) || !numericScale) return
if (!isNumericAxisModel(this.axisModel) || !numericScale || !this.subAxisElt) return

const subAxisSelection = select(this.subAxisElt),
numericAxisSelection = subAxisSelection.selectAll('.numeric-axis-tag')
// If we don't already have a numeric axis, we have to remove whatever is there
if (numericAxisSelection.size() === 0) {
subAxisSelection.selectAll('*').remove()
}
this.renderAxisLine()
// The axis line gets removed and rerendered each time.
// Tag it so the next time around we know we have a numeric axis.
subAxisSelection.select('.axis-line').classed('numeric-axis-tag', true)

const axisScale = this.axis(numericScale).tickSizeOuter(0).tickFormat(format('.9'))
const duration = this.isAnimating() ? transitionDuration : 0
Expand All @@ -64,7 +73,7 @@ export class NumericAxisHelper extends AxisHelper {
return Number.isInteger(d) ? d.toString() : ""
})
}
this.subAxisElt && select(this.subAxisElt)
subAxisSelection
.attr("transform", this.initialTransform)
.transition().duration(duration)
.call(axisScale).selectAll("line,path")
Expand Down

0 comments on commit 344e556

Please sign in to comment.