Skip to content

Commit

Permalink
🐛 mute all series if active series is not in facet
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 11, 2024
1 parent bb551ce commit 96d13d7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/@ourworldindata/grapher/src/chart/ChartUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,12 @@ export function byInteractionState(series: {

export function getInteractionStateForSeries(
series: ChartSeries,
activeSeriesNames: SeriesName[]
{
activeSeriesNames,
isInteractionModeActive,
}: { activeSeriesNames: SeriesName[]; isInteractionModeActive: boolean }
): InteractionState {
const active = activeSeriesNames.includes(series.seriesName)
const background = activeSeriesNames.length > 0 && !active
const background = isInteractionModeActive && !active
return { active, background }
}
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ export class LineChart

@computed get isHoverModeActive(): boolean {
return this.hoveredSeriesNames.length > 0
return (
this.hoveredSeriesNames.length > 0 ||
!!this.manager.externalLegendHoverBin
)
}

@computed private get hasEntityYearHighlight(): boolean {
Expand Down Expand Up @@ -1097,7 +1101,10 @@ export class LineChart
}

private hoverStateForSeries(series: LineChartSeries): InteractionState {
return getInteractionStateForSeries(series, this.hoveredSeriesNames)
return getInteractionStateForSeries(series, {
isInteractionModeActive: this.isHoverModeActive,
activeSeriesNames: this.hoveredSeriesNames,
})
}

@computed get renderSeries(): RenderLineChartSeries[] {
Expand Down
10 changes: 8 additions & 2 deletions packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ export class SlopeChart
}

@computed private get isHoverModeActive(): boolean {
return this.hoveredSeriesNames.length > 0
return (
this.hoveredSeriesNames.length > 0 ||
!!this.manager.externalLegendHoverBin
)
}

@computed private get yColumns(): CoreColumn[] {
Expand Down Expand Up @@ -448,7 +451,10 @@ export class SlopeChart
}

private hoverStateForSeries(series: SlopeChartSeries): InteractionState {
return getInteractionStateForSeries(series, this.hoveredSeriesNames)
return getInteractionStateForSeries(series, {
isInteractionModeActive: this.isHoverModeActive,
activeSeriesNames: this.hoveredSeriesNames,
})
}

@computed private get renderSeries(): RenderSlopeChartSeries[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,11 @@ export class StackedAreaChart extends AbstractStackedChart {
private hoverStateForSeries(
series: StackedSeries<number>
): InteractionState {
const focusedSeriesNames = excludeUndefined([this.hoveredSeriesName])
return getInteractionStateForSeries(series, focusedSeriesNames)
const hoveredSeriesNames = excludeUndefined([this.hoveredSeriesName])
return getInteractionStateForSeries(series, {
isInteractionModeActive: this.isHoverModeActive,
activeSeriesNames: hoveredSeriesNames,
})
}

@computed get lineLegendSeries(): LineLabelSeries[] {
Expand Down Expand Up @@ -439,6 +442,10 @@ export class StackedAreaChart extends AbstractStackedChart {
)
}

@computed get isHoverModeActive(): boolean {
return !!this.hoveredSeriesName || !!this.manager.externalLegendHoverBin
}

@computed get hoveredSeriesNames(): string[] {
return this.hoveredSeriesName ? [this.hoveredSeriesName] : []
}
Expand Down

0 comments on commit 96d13d7

Please sign in to comment.