Skip to content

Commit

Permalink
🔨 refactor hover states
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 6, 2024
1 parent 8fec598 commit b0bb266
Show file tree
Hide file tree
Showing 18 changed files with 571 additions and 589 deletions.
1 change: 0 additions & 1 deletion packages/@ourworldindata/grapher/src/chart/ChartManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export interface ChartManager {
sortConfig?: SortConfig
showNoDataArea?: boolean // No data area in Marimekko charts

externalLegendHoverBin?: ColorScaleBin | undefined
disableIntroAnimation?: boolean

missingDataStrategy?: MissingDataStrategy
Expand Down
13 changes: 13 additions & 0 deletions packages/@ourworldindata/grapher/src/chart/ChartUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
GrapherChartType,
GRAPHER_CHART_TYPES,
GRAPHER_TAB_QUERY_PARAMS,
InteractionState,
} from "@ourworldindata/types"
import { LineChartSeries } from "../lineCharts/LineChartConstants"
import { SelectionArray } from "../selection/SelectionArray"
Expand Down Expand Up @@ -188,3 +189,15 @@ export function findValidChartTypeCombination(
}
return undefined
}

/** Useful for sorting series by their interaction state */
export function byInteractionState(series: {
hover?: InteractionState
}): number {
// background series first,
// then series in their default state,
// then active series
if (series.hover === InteractionState.background) return 1
else if (series.hover === InteractionState.active) return 3
else return 2
}
12 changes: 0 additions & 12 deletions packages/@ourworldindata/grapher/src/facetChart/FacetChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ export class FacetChart
const manager = {
...series.manager,
useValueBasedColorScheme,
externalLegendHoverBin: this.legendHoverBin,
xAxisConfig: {
// For now, sharing an x axis means hiding the tick labels of inner facets.
// This means that none of the x axes are actually hidden (we just don't plot their tick labels).
Expand Down Expand Up @@ -763,17 +762,6 @@ export class FacetChart
return sortedBins
}

@observable.ref private legendHoverBin: ColorScaleBin | undefined =
undefined

@action.bound onLegendMouseOver(bin: ColorScaleBin): void {
this.legendHoverBin = bin
}

@action.bound onLegendMouseLeave(): void {
this.legendHoverBin = undefined
}

// end of legend props

@computed private get legend(): HorizontalColorLegend {
Expand Down
Loading

0 comments on commit b0bb266

Please sign in to comment.