Skip to content

Commit da12e6f

Browse files
🎉 (region dods) add support for income groups
1 parent 4c8bbe7 commit da12e6f

File tree

15 files changed

+151
-62
lines changed

15 files changed

+151
-62
lines changed

baker/algolia/utils/shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as _ from "lodash-es"
22
import {
33
countries,
44
countriesByName,
5-
incomeGroupsByName,
5+
incomeGroupsByCode,
66
DbPlainFeaturedMetricWithParentTagName,
77
FeaturedMetricIncomeGroup,
88
removeTrailingParenthetical,
@@ -157,7 +157,7 @@ function getCorrespondingIncomeGroup(
157157
>
158158
) {
159159
const owidIncomeGroupName = incomeGroupMap[incomeGroupName]
160-
const countriesByIncomeGroup = incomeGroupsByName()
160+
const countriesByIncomeGroup = incomeGroupsByCode()
161161
return countriesByIncomeGroup[owidIncomeGroupName]
162162
}
163163

baker/algolia/utils/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ChartRecord,
77
ExplorerType,
88
} from "@ourworldindata/types"
9-
import { OwidIncomeGroupName } from "@ourworldindata/utils"
9+
import { OwidIncomeGroupCode } from "@ourworldindata/utils"
1010

1111
export interface DatasetChartRecordDimensions {
1212
datasetNamespaces: string[]
@@ -183,7 +183,7 @@ export const REAL_FM_INCOME_GROUPS: Exclude<
183183
*/
184184
export const incomeGroupMap: Record<
185185
Exclude<FeaturedMetricIncomeGroup, FeaturedMetricIncomeGroup.Default>,
186-
OwidIncomeGroupName
186+
OwidIncomeGroupCode
187187
> = {
188188
[FeaturedMetricIncomeGroup.Low]: "OWID_LIC",
189189
[FeaturedMetricIncomeGroup.LowerMiddle]: "OWID_LMC",

packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class DiscreteBarChart
143143
maxLabelWidth: 0.66 * this.bounds.width,
144144
fontSettings: this.entityLabelStyle,
145145
annotationFontSettings: this.entityAnnotationStyle,
146-
showRegionProviderTooltip: !this.manager.isStatic,
146+
showRegionTooltip: !this.manager.isStatic,
147147
})
148148
}
149149

packages/@ourworldindata/grapher/src/barCharts/DiscreteBarChartHelpers.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ export function enrichSeriesWithLabels<
194194
fontWeight: 300,
195195
lineHeight: 1,
196196
},
197-
showRegionProviderTooltip = false,
197+
showRegionTooltip = false,
198198
}: {
199199
series: readonly TSeries[]
200200
availableHeightPerSeries: number
201201
minLabelWidth: number
202202
maxLabelWidth: number
203203
fontSettings: FontSettings
204204
annotationFontSettings?: FontSettings
205-
showRegionProviderTooltip?: boolean
205+
showRegionTooltip?: boolean
206206
}): (TSeries & { label: SeriesLabelState; annotationTextWrap?: TextWrap })[] {
207207
// Wrap labels and annotations to fit within the available space
208208
const wrappedLabels = series.map((series) => {
@@ -278,7 +278,7 @@ export function enrichSeriesWithLabels<
278278
...series,
279279
label: SeriesLabelState.fromTextWrap(
280280
wrappedLabels[index].labelWrap,
281-
{ showRegionProviderTooltip, textAnchor: "end" }
281+
{ showRegionTooltip, textAnchor: "end" }
282282
),
283283
annotationTextWrap: wrappedLabels[index].annotationWrap,
284284
}))
@@ -339,7 +339,7 @@ export function enrichSeriesWithLabels<
339339
return series.map((series, index) => ({
340340
...series,
341341
label: SeriesLabelState.fromTextWrap(truncatedLabels[index], {
342-
showRegionProviderTooltip,
342+
showRegionTooltip,
343343
textAnchor: "end",
344344
}),
345345
annotationTextWrap: truncatedAnnotations[index],

packages/@ourworldindata/grapher/src/color/CustomSchemes.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,13 @@ CustomColorSchemes.push({
317317
colorSets: [CategoricalColorsPaletteA, CategoricalColorsPaletteC],
318318
})
319319

320+
export const IncomeGroupColors = {
321+
HighIncome: "#0d8553",
322+
UpperMiddleIncome: "#a1cb81",
323+
LowerMiddleIncome: "#df9fdb",
324+
LowIncome: "#974e94",
325+
} as const
326+
320327
export const ContinentColors = {
321328
Africa: OwidDistinctColors.Mauve,
322329
Antarctica: OwidDistinctColors.DarkCopper,
@@ -387,6 +394,12 @@ export const ContinentColors = {
387394
"Sub-Saharan Africa (Pew)": OwidDistinctColors.DarkMauve,
388395
"Latin America-Caribbean (Pew)": OwidDistinctColors.Maroon,
389396
"Middle East-North Africa (Pew)": OwidDistinctColors.Camel,
397+
398+
// Income groups
399+
"High-income countries": IncomeGroupColors.HighIncome,
400+
"Upper-middle-income countries": IncomeGroupColors.UpperMiddleIncome,
401+
"Lower-middle-income countries": IncomeGroupColors.LowerMiddleIncome,
402+
"Low-income countries": IncomeGroupColors.LowIncome,
390403
} as const
391404

392405
// Used for looking up color names from hex values

packages/@ourworldindata/grapher/src/controls/MapZoomDropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
GlobeRegionName,
1212
mappableCountries,
1313
MapRegionName,
14-
checkIsOwidIncomeGroupName,
14+
checkIsOwidIncomeGroupCode,
1515
getUserCountryInformation,
1616
regions,
1717
} from "@ourworldindata/utils"
@@ -205,7 +205,7 @@ export class MapZoomDropdown extends React.Component<{
205205

206206
const countryRegionsWithoutIncomeGroups = localCountryInfo.regions
207207
? localCountryInfo.regions.filter(
208-
(region) => !checkIsOwidIncomeGroupName(region)
208+
(region) => !checkIsOwidIncomeGroupCode(region)
209209
)
210210
: []
211211

packages/@ourworldindata/grapher/src/entitySelector/EntitySelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
getUserNavigatorLanguagesNonEnglish,
2525
getRegionAlternativeNames,
2626
convertDaysSinceEpochToDate,
27-
checkIsOwidIncomeGroupName,
27+
checkIsOwidIncomeGroupCode,
2828
checkHasMembers,
2929
Region,
3030
getRegionByName,
@@ -353,7 +353,7 @@ export class EntitySelector extends React.Component<EntitySelectorProps> {
353353

354354
const countryRegionsWithoutIncomeGroups = localCountryInfo.regions
355355
? localCountryInfo.regions.filter(
356-
(region) => !checkIsOwidIncomeGroupName(region)
356+
(region) => !checkIsOwidIncomeGroupCode(region)
357357
)
358358
: []
359359

packages/@ourworldindata/grapher/src/facet/FacetChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ export class FacetChart
887887
maxWidth: Infinity, // Facet labels never wrap
888888
fontWeight: 700,
889889
fontSize: this.facetFontSize,
890-
showRegionProviderTooltip: !this.manager.isStatic,
890+
showRegionTooltip: !this.manager.isStatic,
891891
}
892892
}
893893

packages/@ourworldindata/grapher/src/lineLegend/LineLegend.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export class LineLegend extends React.Component<LineLegendProps> {
401401
formattedValue: series.formattedValue,
402402
placeFormattedValueInNewLine:
403403
series.placeFormattedValueInNewLine,
404-
showRegionProviderTooltip: !this.props.isStatic,
404+
showRegionTooltip: !this.props.isStatic,
405405
})
406406

407407
const annotationTextWrap = this.makeAnnotationTextWrap(series)

packages/@ourworldindata/grapher/src/seriesLabel/SeriesLabel.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import {
1212
PositionedIconFragment,
1313
TextRole,
1414
SpanLine,
15+
TooltipKey,
1516
} from "./SeriesLabelState.js"
1617
import { Bounds, isTouchDevice } from "@ourworldindata/utils"
17-
import { AnyRegionDataProvider } from "../core/RegionGroups.js"
1818

1919
const defaultColors: Record<TextRole, string> = {
2020
name: GRAPHER_DARK_TEXT,
2121
value: GRAPHER_DARK_TEXT,
22-
suffix: GRAPHER_LIGHT_TEXT,
22+
regionProviderSuffix: GRAPHER_LIGHT_TEXT,
23+
incomeGroupIcon: GRAPHER_LIGHT_TEXT,
2324
}
2425

2526
export interface SeriesLabelProps {
@@ -95,11 +96,11 @@ export function SeriesLabel({
9596
/>
9697
{iconFragments.map((fragment) => (
9798
<IconFragment
98-
key={fragment.providerKey}
99+
key={fragment.tooltipKey}
99100
x={renderX}
100101
y={renderY}
101102
fragment={fragment}
102-
fill={colors.suffix}
103+
fill={colors.regionProviderSuffix}
103104
onMouseEnter={onMouseEnter}
104105
onMouseLeave={onMouseLeave}
105106
onInfoTooltipShow={onInfoTooltipShow}
@@ -334,9 +335,7 @@ function IconFragment({
334335
theme="grapher-explanation"
335336
placement="top"
336337
content={
337-
<RegionProviderTooltipContent
338-
providerKey={fragment.providerKey}
339-
/>
338+
<RegionTooltipContent tooltipKey={fragment.tooltipKey} />
340339
}
341340
onShow={onInfoTooltipShow}
342341
>
@@ -352,10 +351,10 @@ function IconFragment({
352351
)
353352
}
354353

355-
function RegionProviderTooltipContent({
356-
providerKey,
354+
function RegionTooltipContent({
355+
tooltipKey,
357356
}: {
358-
providerKey: AnyRegionDataProvider
357+
tooltipKey: TooltipKey
359358
}): React.ReactElement {
360-
return <div>{providerKey}</div>
359+
return <div>{tooltipKey}</div>
361360
}

0 commit comments

Comments
 (0)