Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 refactor hover states / TAS-738 #4266

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 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,7 @@ import {
GRAPHER_SETTINGS_CLASS,
validChartTypeCombinations,
} from "../core/GrapherConstants"
import { ChartSeries } from "./ChartInterface"

export const autoDetectYColumnSlugs = (manager: ChartManager): string[] => {
if (manager.yColumnSlugs && manager.yColumnSlugs.length)
Expand Down Expand Up @@ -188,3 +191,24 @@ export function findValidChartTypeCombination(
}
return undefined
}

/** Useful for sorting series by their interaction state */
export function byInteractionState(series: {
hover: InteractionState
}): number {
// background series rank lowest
if (series.hover.background) return 1
// active series rank highest
if (series.hover.active) return 3
// series in their default state rank in the middle
return 2
}

export function getInteractionStateForSeries(
series: ChartSeries,
activeSeriesNames: SeriesName[]
): InteractionState {
const active = activeSeriesNames.includes(series.seriesName)
const background = activeSeriesNames.length > 0 && !active
return { active, background }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ export const GRAPHER_BACKGROUND_BEIGE = "#fbf9f3"
export const GRAPHER_DARK_TEXT = "#5b5b5b"
export const GRAPHER_LIGHT_TEXT = "#858585"

export const GRAPHER_OPACITY_MUTE = 0.3

export const GRAPHER_AXIS_LINE_WIDTH_DEFAULT = 1
export const GRAPHER_AXIS_LINE_WIDTH_THICK = 2

export const GRAPHER_AREA_OPACITY_DEFAULT = 0.8
export const GRAPHER_AREA_OPACITY_MUTE = 0.3
export const GRAPHER_AREA_OPACITY_MUTE = GRAPHER_OPACITY_MUTE
export const GRAPHER_AREA_OPACITY_FOCUS = 1

export const BASE_FONT_SIZE = 16
Expand Down
Loading
Loading