Skip to content

Commit

Permalink
🔨 only render interactive elements if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Jan 3, 2025
1 parent 9f0c4ce commit 3441962
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
15 changes: 11 additions & 4 deletions packages/@ourworldindata/grapher/src/mapCharts/MapChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,21 @@ export class MapChart
}

renderMapLegend(): React.ReactElement {
const onMouseLeave = this.manager.isStatic
? undefined
: this.onLegendMouseLeave
const onMouseOver = this.manager.isStatic
? undefined
: this.onLegendMouseOver

return (
<>
{this.numericLegend && (
<HorizontalNumericColorLegendComponent
legend={this.numericLegend}
focusBin={this.numericFocusBracket}
onMouseLeave={this.onLegendMouseLeave}
onMouseOver={this.onLegendMouseOver}
onMouseLeave={onMouseLeave}
onMouseOver={onMouseOver}
/>
)}
{this.categoryLegend && (
Expand All @@ -649,8 +656,8 @@ export class MapChart
x={this.legendX}
y={this.categoryLegendY}
swatchStrokeColor={this.categoricalBinStroke}
onMouseLeave={this.onLegendMouseLeave}
onMouseOver={this.onLegendMouseOver}
onMouseLeave={onMouseLeave}
onMouseOver={onMouseOver}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,13 @@ export class MarimekkoChart

const footer = excludeUndefined([toleranceNotice, roundingNotice])

const onLegendMouseLeave = this.manager.isStatic
? undefined
: this.onLegendMouseLeave
const onLegendMouseOver = this.manager.isStatic
? undefined
: this.onLegendMouseOver

return (
<g
ref={this.base}
Expand Down Expand Up @@ -1061,8 +1068,8 @@ export class MarimekkoChart
x={this.legendX}
y={this.categoryLegendY}
opacity={this.legendOpacity}
onMouseLeave={this.onLegendMouseLeave}
onMouseOver={this.onLegendMouseOver}
onMouseLeave={onLegendMouseLeave}
onMouseOver={onLegendMouseOver}
/>
{this.renderBars()}
{target && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,13 +727,21 @@ export class StackedDiscreteBarChart

renderLegend(): React.ReactElement | void {
if (!this.showLegend) return

const onMouseLeave = this.manager.isStatic
? undefined
: this.onLegendMouseLeave
const onMouseOver = this.manager.isStatic
? undefined
: this.onLegendMouseOver

return (
<HorizontalCategoricalColorLegendComponent
legend={this.legend}
x={this.legendX}
y={this.categoryLegendY}
onMouseLeave={this.onLegendMouseLeave}
onMouseOver={this.onLegendMouseOver}
onMouseLeave={onMouseLeave}
onMouseOver={onMouseOver}
/>
)
}
Expand Down

0 comments on commit 3441962

Please sign in to comment.