Skip to content

Commit

Permalink
fix(bar): bleed-out for includeZero set to false (#1780)
Browse files Browse the repository at this point in the history
grouped-bar chart would bleed-out on includeZero set to false.
  • Loading branch information
markchou0225 committed Mar 9, 2024
1 parent 87cb1b3 commit 4c14db0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/components/graphs/bar-grouped.ts
Expand Up @@ -134,7 +134,8 @@ export class GroupedBar extends Bar {
const x0 = startX
const x1 = startX + barWidth
const rangeAxis = this.services.cartesianScales.getRangeAxisPosition({ datum: d })
const y0 = this.services.cartesianScales.getValueThroughAxisPosition(rangeAxis, 0)
const lowerBound = this.services.cartesianScales.getDomainLowerBound(rangeAxis)
const y0 = this.services.cartesianScales.getValueThroughAxisPosition(rangeAxis, lowerBound)
const y1 = this.services.cartesianScales.getRangeValue(d)

// don't show if part of bar is out of zoom domain - test zoom on bar pos, not group
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/services/scales-cartesian.ts
Expand Up @@ -636,6 +636,27 @@ export class CartesianScales extends Service {
return scale
}

getDomainLowerBound(position: any): number {
let domainRange: number[]
let lowerBound = 0

// get domain ranges based on orientations
if (this.getOrientation() === CartesianOrientations.VERTICAL) {
domainRange = this.getMainYScale().domain() as number[]
} else {
domainRange = this.getMainXScale().domain() as number[]
}

if (getProperty(this.model.getOptions(), 'axes', position, 'includeZero') === false) {
// get domain lowerBound if all are positive values
if (domainRange[0] > 0 && domainRange[1] > 0) {
lowerBound = domainRange[0]
}
}

return lowerBound
}

getHighestDomainThreshold(): null | {
threshold: ThresholdOptions
scaleValue: number
Expand Down

0 comments on commit 4c14db0

Please sign in to comment.