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

🔨 (grapher) remove entity-year highlight from stacked area charts #4127

Merged
merged 1 commit into from
Nov 11, 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
9 changes: 1 addition & 8 deletions packages/@ourworldindata/grapher/src/chart/ChartManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { TooltipManager } from "../tooltip/TooltipProps"
import { OwidTable, CoreColumn } from "@ourworldindata/core-table"

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

Expand Down Expand Up @@ -85,8 +80,6 @@ export interface ChartManager {
sortConfig?: SortConfig
showNoDataArea?: boolean

annotation?: Annotation

externalLegendFocusBin?: ColorScaleBin | undefined
disableIntroAnimation?: boolean

Expand Down
10 changes: 7 additions & 3 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import {
setWindowQueryStr,
getWindowUrl,
Url,
Annotation,
EntityYearHighlight,
ColumnSlug,
DimensionProperty,
SortBy,
Expand Down Expand Up @@ -282,7 +282,7 @@ export interface GrapherProgrammaticInterface extends GrapherInterface {
dataApiUrl?: string
env?: string
dataApiUrlForAdmin?: string
annotation?: Annotation
entityYearHighlight?: EntityYearHighlight
baseFontSize?: number
staticBounds?: Bounds
staticFormat?: GrapherStaticFormat
Expand Down Expand Up @@ -428,7 +428,11 @@ export class Grapher
@observable comparisonLines?: ComparisonLineConfig[] = undefined // todo: Persistables?
@observable relatedQuestions?: RelatedQuestionsConfig[] = undefined // todo: Persistables?

@observable.ref annotation?: Annotation = undefined
/**
* Used to highlight an entity at a particular time in a line chart.
* The sparkline in map tooltips makes use of this.
*/
@observable.ref entityYearHighlight?: EntityYearHighlight = undefined

@observable.ref hideFacetControl?: boolean = undefined

Expand Down
5 changes: 3 additions & 2 deletions packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ export class LineChart

@computed get activeX(): number | undefined {
return (
this.tooltipState.target?.x ?? this.props.manager.annotation?.year
this.tooltipState.target?.x ??
this.props.manager.entityYearHighlight?.year
)
}

Expand Down Expand Up @@ -750,7 +751,7 @@ export class LineChart
@computed get focusedSeriesNames(): string[] {
const { externalLegendFocusBin } = this.manager
const focusedSeriesNames = excludeUndefined([
this.props.manager.annotation?.entityName,
this.props.manager.entityYearHighlight?.entityName,
this.hoveredSeriesName,
])
if (externalLegendFocusBin) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { DualAxis } from "../axis/Axis"
import { ChartManager } from "../chart/ChartManager"
import { SeriesName, CoreValueType } from "@ourworldindata/types"
import {
SeriesName,
CoreValueType,
EntityYearHighlight,
} from "@ourworldindata/types"
import { ChartSeries } from "../chart/ChartInterface"
import { Color } from "@ourworldindata/utils"

Expand Down Expand Up @@ -40,6 +44,7 @@ export interface LinesProps {
}

export interface LineChartManager extends ChartManager {
entityYearHighlight?: EntityYearHighlight
lineStrokeWidth?: number
canSelectMultipleEntities?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class MapTooltip extends React.Component<MapTooltipProps> {
fontSize: 11,
disableIntroAnimation: true,
lineStrokeWidth: 2,
annotation: {
entityYearHighlight: {
entityName: this.entityName,
year: this.datum?.time,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,15 @@ export class StackedAreaChart

@computed get focusedSeriesNames(): string[] {
const { externalLegendFocusBin } = this.manager
const focusedSeriesNames = excludeUndefined([
this.props.manager.annotation?.entityName,
const externalFocusedSeriesNames = externalLegendFocusBin
? this.rawSeries
.map((s) => s.seriesName)
.filter((name) => externalLegendFocusBin.contains(name))
: []
return excludeUndefined([
this.hoverSeriesName,
...externalFocusedSeriesNames,
])
if (externalLegendFocusBin) {
focusedSeriesNames.push(
...this.rawSeries
.map((s) => s.seriesName)
.filter((name) => externalLegendFocusBin.contains(name))
)
}
return focusedSeriesNames
}

@computed get isFocusMode(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export enum ScaleType {
log = "log",
}

export interface Annotation {
export interface EntityYearHighlight {
entityName?: string
year?: number
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@ourworldindata/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export {
} from "./grapherTypes/GrapherConstants.js"

export {
type Annotation,
type EntityYearHighlight,
type Box,
type BasicChartInformation,
SortBy,
Expand Down
4 changes: 1 addition & 3 deletions site/multiembedder/MultiEmbedder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
SelectionArray,
} from "@ourworldindata/grapher"
import {
Annotation,
fetchText,
getWindowUrl,
isPresent,
Expand Down Expand Up @@ -124,7 +123,7 @@ class MultiEmbedder {
}

@action.bound
async renderInteractiveFigure(figure: Element, annotation?: Annotation) {
async renderInteractiveFigure(figure: Element) {
const isExplorer = figure.hasAttribute(
EXPLORER_EMBEDDED_FIGURE_SELECTOR
)
Expand Down Expand Up @@ -209,7 +208,6 @@ class MultiEmbedder {
this.selection.selectedEntityNames
),
},
annotation,
}
)
if (config.manager?.selection)
Expand Down