Skip to content

Commit

Permalink
🔨 (stacked area) small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Nov 11, 2024
1 parent 39438cf commit 736e5f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,12 @@ export class StackedAreaChart
@computed get facetLegendHoveredSeriesName(): SeriesName | undefined {
const { externalLegendHoverBin } = this.manager
if (!externalLegendHoverBin) return undefined
const hoveredSeriesNames = this.rawSeries
.map((s) => s.seriesName)
.filter((name) => externalLegendHoverBin.contains(name))
// stacked area charts can't plot the same entity or column multiple times
return hoveredSeriesNames.length > 0 ? hoveredSeriesNames[0] : undefined
// stacked area charts can't plot the same entity or column multiple times,
// so we just find the first series that matches the hovered legend item
const hoveredSeries = this.rawSeries.find((series) =>
externalLegendHoverBin.contains(series.seriesName)
)
return hoveredSeries?.seriesName
}

@computed get focusedSeriesName(): SeriesName | undefined {
Expand Down
11 changes: 8 additions & 3 deletions packages/@ourworldindata/grapher/src/tooltip/TooltipContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,13 @@ export class TooltipTable extends React.Component<TooltipTableProps> {
annotation,
values,
notice,
swatch,
swatch = {},
} = row
const {
color: swatchColor = "transparent",
opacity: swatchOpacity = 1,
} = swatch

const [_m, seriesName, seriesParenthetical] =
name.trim().match(/^(.*?)(\([^()]*\))?$/) ?? []

Expand All @@ -226,8 +231,8 @@ export class TooltipTable extends React.Component<TooltipTableProps> {
<div
className="swatch"
style={{
backgroundColor: swatch?.color,
opacity: swatch?.opacity,
backgroundColor: swatchColor,
opacity: swatchOpacity,
}}
/>
</td>
Expand Down

0 comments on commit 736e5f6

Please sign in to comment.