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 10, 2024
1 parent 67bc52b commit f3bab8f
Show file tree
Hide file tree
Showing 17 changed files with 635 additions and 597 deletions.
2 changes: 1 addition & 1 deletion packages/@ourworldindata/grapher/src/chart/ChartManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { OwidTable, CoreColumn } from "@ourworldindata/core-table"

import { SelectionArray } from "../selection/SelectionArray"
import { ColumnSlug, SortConfig, TimeBound } from "@ourworldindata/utils"
import { ColorScaleBin } from "../color/ColorScaleBin"
import { ColorScale } from "../color/ColorScale"
import { ColorScaleBin } from "../color/ColorScaleBin"

// The possible options common across our chart types. Not all of these apply to every chart type, so there is room to create a better type hierarchy.

Expand Down
30 changes: 30 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,8 @@ import {
GrapherChartType,
GRAPHER_CHART_TYPES,
GRAPHER_TAB_QUERY_PARAMS,
InteractionState,
SeriesName,
} from "@ourworldindata/types"
import { LineChartSeries } from "../lineCharts/LineChartConstants"
import { SelectionArray } from "../selection/SelectionArray"
Expand All @@ -17,6 +19,8 @@ import {
GRAPHER_SETTINGS_CLASS,
validChartTypeCombinations,
} from "../core/GrapherConstants"
import { ChartSeries } from "./ChartInterface"
import { ColorScaleBin } from "../color/ColorScaleBin"

export const autoDetectYColumnSlugs = (manager: ChartManager): string[] => {
if (manager.yColumnSlugs && manager.yColumnSlugs.length)
Expand Down Expand Up @@ -188,3 +192,29 @@ 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
switch (series.hover) {
case InteractionState.background:
return 1
case InteractionState.none:
return 2
case InteractionState.active:
return 3
}
}

export function findSeriesNamesContainedInBin(
series: readonly ChartSeries[],
bin: ColorScaleBin
): SeriesName[] {
return series
.map(({ seriesName }) => seriesName)
.filter((seriesName) => bin.contains(seriesName))
}
Loading

0 comments on commit f3bab8f

Please sign in to comment.