Skip to content

Commit

Permalink
Revert "✨ (map) left-align multi-line categorical legends (#4324)"
Browse files Browse the repository at this point in the history
This reverts commit f4a8e4c.
  • Loading branch information
sophiamersmann authored Jan 13, 2025
1 parent c39e7b3 commit bdf1b8f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,6 @@ export class HorizontalCategoricalColorLegend extends HorizontalColorLegend {
return max(this.marks.map((mark) => mark.y + mark.rectSize)) ?? 0
}

@computed get numLines(): number {
return this.markLines.length
}

renderLabels(): React.ReactElement {
const { manager, marks } = this
const { focusColors, hoverColors = [] } = manager
Expand Down
10 changes: 5 additions & 5 deletions packages/@ourworldindata/grapher/src/mapCharts/MapChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,13 @@ export class MapChart
}

@computed get legendMaxWidth(): number {
return this.bounds.width
// it seems nice to have just a little bit of
// extra padding left and right
return this.bounds.width * 0.95
}

@computed get legendX(): number {
return this.bounds.x
return this.bounds.x + (this.bounds.width - this.legendMaxWidth) / 2
}

@computed get legendHeight(): number {
Expand Down Expand Up @@ -555,9 +557,7 @@ export class MapChart
}

@computed get legendAlign(): HorizontalAlign {
if (this.numericLegend) return HorizontalAlign.center
const { numLines = 0 } = this.categoryLegend ?? {}
return numLines > 1 ? HorizontalAlign.left : HorizontalAlign.center
return HorizontalAlign.center
}

@computed get numericLegendY(): number {
Expand Down

0 comments on commit bdf1b8f

Please sign in to comment.