Skip to content

Commit

Permalink
✨ (stacked bar) hide single-item legends
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed May 21, 2024
1 parent 896cb26 commit 9916c7a
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ export class StackedBarChart
.reverse() // Vertical legend orders things in the opposite direction we want
}

@computed get hideLegend(): boolean {
return this.manager.hideLegend || this.legendItems.length <= 1
}

@computed get maxLegendWidth(): number {
return this.sidebarMaxWidth
}
Expand All @@ -228,7 +232,7 @@ export class StackedBarChart
return 100
}
@computed get sidebarWidth(): number {
if (this.manager.hideLegend) return 0
if (this.hideLegend) return 0
const { sidebarMinWidth, sidebarMaxWidth, legendDimensions } = this
return Math.max(
Math.min(legendDimensions.width, sidebarMaxWidth),
Expand Down Expand Up @@ -537,9 +541,7 @@ export class StackedBarChart
})}
</g>

{!this.manager.hideLegend && (
<VerticalColorLegend manager={this} />
)}
{!this.hideLegend && <VerticalColorLegend manager={this} />}
{tooltip}
</g>
)
Expand Down

0 comments on commit 9916c7a

Please sign in to comment.