diff --git a/adminSiteClient/ChartList.tsx b/adminSiteClient/ChartList.tsx
index dccdf863c14..c3ed89386cc 100644
--- a/adminSiteClient/ChartList.tsx
+++ b/adminSiteClient/ChartList.tsx
@@ -4,9 +4,10 @@ import { runInAction, observable } from "mobx"
import { bind } from "decko"
import { AdminAppContext, AdminAppContextType } from "./AdminAppContext.js"
import {
- ChartTypeName,
+ GrapherChartType,
GrapherInterface,
- GrapherTabOption,
+ GRAPHER_CHART_TYPES,
+ GRAPHER_TAB_OPTIONS,
} from "@ourworldindata/types"
import { startCase, DbChartTagJoin } from "@ourworldindata/utils"
import { References, getFullReferencesCount } from "./ChartEditor.js"
@@ -24,7 +25,7 @@ export interface ChartListItem {
tab: GrapherInterface["tab"]
hasMapTab: GrapherInterface["hasMapTab"]
- type?: ChartTypeName
+ type?: GrapherChartType
hasChartTab: boolean
lastEditedAt: string
@@ -152,11 +153,11 @@ export function showChartType(chart: ChartListItem): string {
if (!chartType) return "Map"
- const displayType = ChartTypeName[chartType]
- ? startCase(ChartTypeName[chartType])
+ const displayType = GRAPHER_CHART_TYPES[chartType]
+ ? startCase(GRAPHER_CHART_TYPES[chartType])
: "Unknown"
- if (chart.tab === GrapherTabOption.map) {
+ if (chart.tab === GRAPHER_TAB_OPTIONS.map) {
if (chart.hasChartTab) return `Map + ${displayType}`
else return "Map"
} else {
diff --git a/adminSiteClient/ColorSchemeDropdown.tsx b/adminSiteClient/ColorSchemeDropdown.tsx
index bb10e8ca5dc..b4f0b0df570 100644
--- a/adminSiteClient/ColorSchemeDropdown.tsx
+++ b/adminSiteClient/ColorSchemeDropdown.tsx
@@ -1,7 +1,7 @@
import React from "react"
import { computed, action } from "mobx"
import Select from "react-select"
-import { ChartTypeName } from "@ourworldindata/types"
+import { GrapherChartOrMapType } from "@ourworldindata/types"
import {
ColorScheme,
getColorSchemeForChartType,
@@ -21,7 +21,7 @@ interface ColorSchemeDropdownProps {
value?: string
gradientColorCount: number
invertedColorScheme: boolean
- chartType: ChartTypeName
+ chartType: GrapherChartOrMapType
onChange: (selected: ColorSchemeOption) => void
onBlur?: () => void
}
diff --git a/adminSiteClient/EditorBasicTab.tsx b/adminSiteClient/EditorBasicTab.tsx
index d484ef7842a..04f05a9cead 100644
--- a/adminSiteClient/EditorBasicTab.tsx
+++ b/adminSiteClient/EditorBasicTab.tsx
@@ -9,9 +9,10 @@ import {
} from "mobx"
import { observer } from "mobx-react"
import {
- ChartTypeName,
EntitySelectionMode,
StackMode,
+ ALL_GRAPHER_CHART_TYPES,
+ GrapherChartType,
} from "@ourworldindata/types"
import {
DimensionSlot,
@@ -362,7 +363,9 @@ export class EditorBasicTab<
const { grapher } = this.props.editor
grapher.chartTypes =
- value === this.chartTypeOptionNone ? [] : [value as ChartTypeName]
+ value === this.chartTypeOptionNone
+ ? []
+ : [value as GrapherChartType]
if (grapher.isMarimekko) {
grapher.hideRelativeToggle = false
@@ -403,11 +406,7 @@ export class EditorBasicTab<
value: string
label: string
}[] {
- const allChartTypes = Object.keys(ChartTypeName).filter(
- (chartType) => chartType !== ChartTypeName.WorldMap
- )
-
- const chartTypeOptions = allChartTypes.map((key) => ({
+ const chartTypeOptions = ALL_GRAPHER_CHART_TYPES.map((key) => ({
value: key,
label: startCase(key),
}))
diff --git a/adminSiteClient/EditorColorScaleSection.tsx b/adminSiteClient/EditorColorScaleSection.tsx
index b04e6ea07b6..fe6753d1276 100644
--- a/adminSiteClient/EditorColorScaleSection.tsx
+++ b/adminSiteClient/EditorColorScaleSection.tsx
@@ -7,7 +7,7 @@ import { faPlus, faMinus } from "@fortawesome/free-solid-svg-icons"
import {
ColorSchemeName,
BinningStrategy,
- ChartTypeName,
+ GrapherChartOrMapType,
Color,
} from "@ourworldindata/types"
import {
@@ -43,7 +43,7 @@ interface EditorColorScaleSectionFeatures {
@observer
export class EditorColorScaleSection extends React.Component<{
scale: ColorScale
- chartType: ChartTypeName
+ chartType: GrapherChartOrMapType
features: EditorColorScaleSectionFeatures
showLineChartColors: boolean
onChange?: () => void
@@ -132,7 +132,7 @@ class ColorLegendSection extends React.Component<{
@observer
class ColorsSection extends React.Component<{
scale: ColorScale
- chartType: ChartTypeName
+ chartType: GrapherChartOrMapType
showLineChartColors: boolean
onChange?: () => void
}> {
diff --git a/adminSiteClient/EditorCustomizeTab.tsx b/adminSiteClient/EditorCustomizeTab.tsx
index 2949b38a5d0..7f92dd1fb09 100644
--- a/adminSiteClient/EditorCustomizeTab.tsx
+++ b/adminSiteClient/EditorCustomizeTab.tsx
@@ -6,7 +6,7 @@ import {
ColorSchemeName,
FacetAxisDomain,
FacetStrategy,
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
} from "@ourworldindata/types"
import { Grapher } from "@ourworldindata/grapher"
import {
@@ -161,7 +161,7 @@ export class ColorSchemeSelector extends React.Component<{
onBlur={this.onBlur}
chartType={
this.props.grapher.chartType ??
- ChartTypeName.LineChart
+ GRAPHER_CHART_TYPES.LineChart
}
invertedColorScheme={!!grapher.invertColorScheme}
additionalOptions={[
@@ -755,7 +755,9 @@ export class EditorCustomizeTab<
{grapher.chartInstanceExceptMap.colorScale && (
>"$.hasMapTab" = "true"`)
- tab = tab || GrapherTabOption.map
+ tab = tab || GRAPHER_TAB_OPTIONS.map
} else {
query = query.andWhereRaw(`cc.chartType = :type`, {
type: params.type,
})
- tab = tab || GrapherTabOption.chart
+ tab = tab || GRAPHER_TAB_OPTIONS.chart
}
}
@@ -163,26 +165,26 @@ async function propsFromQueryParams(
query = query.andWhereRaw(
`cc.full->>'$.yAxis.canChangeScaleType' = "true" OR cc.full->>'$.xAxis.canChangeScaleType' = "true"`
)
- tab = GrapherTabOption.chart
+ tab = GRAPHER_TAB_OPTIONS.chart
}
if (params.comparisonLines) {
query = query.andWhereRaw(
`cc.full->'$.comparisonLines[0].yEquals' != ''`
)
- tab = GrapherTabOption.chart
+ tab = GRAPHER_TAB_OPTIONS.chart
}
if (params.stackMode) {
query = query.andWhereRaw(`cc.full->'$.stackMode' = :stackMode`, {
stackMode: params.stackMode,
})
- tab = GrapherTabOption.chart
+ tab = GRAPHER_TAB_OPTIONS.chart
}
if (params.relativeToggle) {
query = query.andWhereRaw(`cc.full->>'$.hideRelativeToggle' = "false"`)
- tab = GrapherTabOption.chart
+ tab = GRAPHER_TAB_OPTIONS.chart
}
if (params.categoricalLegend) {
@@ -192,7 +194,7 @@ async function propsFromQueryParams(
query = query.andWhereRaw(
`json_length(cc.full->'$.map.colorScale.customCategoryColors') > 1`
)
- tab = GrapherTabOption.map
+ tab = GRAPHER_TAB_OPTIONS.map
}
if (params.mixedTimeTypes) {
@@ -232,9 +234,9 @@ async function propsFromQueryParams(
query = query.andWhereRaw(`charts.id IN (${params.ids})`)
}
- if (tab === GrapherTabOption.map) {
+ if (tab === GRAPHER_TAB_OPTIONS.map) {
query = query.andWhereRaw(`cc.full->>"$.hasMapTab" = "true"`)
- } else if (tab === GrapherTabOption.chart) {
+ } else if (tab === GRAPHER_TAB_OPTIONS.chart) {
query = query.andWhereRaw(`cc.chartType IS NOT NULL`)
}
diff --git a/baker/updateChartEntities.ts b/baker/updateChartEntities.ts
index 10264e28155..49e582a71d8 100644
--- a/baker/updateChartEntities.ts
+++ b/baker/updateChartEntities.ts
@@ -9,7 +9,7 @@ import {
ChartsXEntitiesTableName,
DbPlainChart,
GrapherInterface,
- GrapherTabOption,
+ GRAPHER_TAB_OPTIONS,
MultipleOwidVariableDataDimensionsMap,
OwidVariableDataMetadataDimensions,
DbRawChartConfig,
@@ -97,7 +97,7 @@ const obtainAvailableEntitiesForGrapherConfig = async (
// If the grapher has a chart tab, then the available entities there are the "most interesting" ones to us
if (grapher.hasChartTab) {
- grapher.tab = GrapherTabOption.chart
+ grapher.tab = GRAPHER_TAB_OPTIONS.chart
// If the grapher allows for changing or multi-selecting entities, then let's index all entities the
// user can choose from. Otherwise, we'll just use the default-selected entities.
@@ -112,7 +112,7 @@ const obtainAvailableEntitiesForGrapherConfig = async (
return grapher.tableForSelection.availableEntityNames as string[]
else return grapher.selectedEntityNames ?? []
} else if (grapher.hasMapTab) {
- grapher.tab = GrapherTabOption.map
+ grapher.tab = GRAPHER_TAB_OPTIONS.map
// On a map tab, tableAfterAuthorTimelineAndActiveChartTransform contains all
// mappable entities for which data is available
return grapher.tableAfterAuthorTimelineAndActiveChartTransform
diff --git a/db/migration/1661264304751-MigrateSelectedData.ts b/db/migration/1661264304751-MigrateSelectedData.ts
index 5c8e73382ce..c7ae5880ac4 100644
--- a/db/migration/1661264304751-MigrateSelectedData.ts
+++ b/db/migration/1661264304751-MigrateSelectedData.ts
@@ -3,7 +3,7 @@ import { MigrationInterface, QueryRunner } from "typeorm"
import { entityNameById } from "./data/entityNameById.js"
-import { ChartTypeName } from "@ourworldindata/types"
+import { GRAPHER_CHART_TYPES, GrapherChartType } from "@ourworldindata/types"
type GrapherInterface = Record
@@ -85,11 +85,11 @@ export class MigrateSelectedData1661264304751 implements MigrationInterface {
}
})
- const migrateDimensionsTypes: ChartTypeName[] = [
- ChartTypeName.Marimekko,
- ChartTypeName.StackedArea,
- ChartTypeName.StackedBar,
- ChartTypeName.StackedDiscreteBar,
+ const migrateDimensionsTypes: GrapherChartType[] = [
+ GRAPHER_CHART_TYPES.Marimekko,
+ GRAPHER_CHART_TYPES.StackedArea,
+ GRAPHER_CHART_TYPES.StackedBar,
+ GRAPHER_CHART_TYPES.StackedDiscreteBar,
]
// Migrate order of dimensions.
diff --git a/db/model/Chart.ts b/db/model/Chart.ts
index e665f6301c0..7a74b18698d 100644
--- a/db/model/Chart.ts
+++ b/db/model/Chart.ts
@@ -13,7 +13,6 @@ import {
} from "@ourworldindata/utils"
import {
GrapherInterface,
- ChartTypeName,
RelatedChart,
DbPlainPostLink,
DbPlainChart,
@@ -22,6 +21,7 @@ import {
DbPlainTag,
DbRawChartConfig,
DbEnrichedChartConfig,
+ GrapherChartType,
} from "@ourworldindata/types"
import { OpenAI } from "openai"
import {
@@ -556,7 +556,7 @@ export async function getChartVariableData(
export const getMostViewedGrapherIdsByChartType = async (
knex: db.KnexReadonlyTransaction,
- chartType: ChartTypeName,
+ chartType: GrapherChartType,
count = 10
): Promise => {
const ids = await db.knexRaw<{ id: number }>(
diff --git a/db/model/Gdoc/GdocBase.ts b/db/model/Gdoc/GdocBase.ts
index 4dfacfe69f0..f0c5e036a38 100644
--- a/db/model/Gdoc/GdocBase.ts
+++ b/db/model/Gdoc/GdocBase.ts
@@ -19,7 +19,7 @@ import {
OwidGdocMinimalPostInterface,
urlToSlug,
grabMetadataForGdocLinkedIndicator,
- GrapherTabOption,
+ GRAPHER_TAB_OPTIONS,
DbInsertPostGdocLink,
DbPlainTag,
formatDate,
@@ -934,7 +934,7 @@ export async function makeGrapherLinkedChart(
const resolvedSlug = config.slug ?? ""
const resolvedTitle = config.title ?? ""
const resolvedUrl = `${BAKED_GRAPHER_URL}/${resolvedSlug}`
- const tab = config.tab ?? GrapherTabOption.chart
+ const tab = config.tab ?? GRAPHER_TAB_OPTIONS.chart
const datapageIndicator = await getVariableOfDatapageIfApplicable(config)
return {
configType: ChartConfigType.Grapher,
diff --git a/db/model/Variable.ts b/db/model/Variable.ts
index dacd7ed1ebd..ddd6665bc5f 100644
--- a/db/model/Variable.ts
+++ b/db/model/Variable.ts
@@ -22,7 +22,7 @@ import {
OwidVariableMixedData,
OwidVariableWithSourceAndDimension,
OwidVariableId,
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
DimensionProperty,
GrapherInterface,
DbRawVariable,
@@ -878,7 +878,7 @@ export async function getVariableOfDatapageIfApplicable(
// showing a data page.
if (
yVariableIds.length === 1 &&
- (grapher.chartTypes?.[0] !== ChartTypeName.ScatterPlot ||
+ (grapher.chartTypes?.[0] !== GRAPHER_CHART_TYPES.ScatterPlot ||
xVariableIds.length === 0)
) {
const variableId = yVariableIds[0]
diff --git a/devTools/graphersToGit/tasks.ts b/devTools/graphersToGit/tasks.ts
index c5a95e87711..cc555c3ad30 100755
--- a/devTools/graphersToGit/tasks.ts
+++ b/devTools/graphersToGit/tasks.ts
@@ -2,7 +2,7 @@
import { CoreTable } from "@ourworldindata/core-table"
import {
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
ColorScaleConfig,
Grapher,
GrapherProgrammaticInterface,
@@ -173,7 +173,7 @@ const dumpComplexSelections = async () => {
: 0
return {
grapherId: config.id,
- type: config.type ?? ChartTypeName.LineChart,
+ type: config.type ?? GRAPHER_CHART_TYPES.LineChart,
url: `https://ourworldindata.org/grapher/${config.slug}`,
dimensionVariableCount,
selectionVariableCount,
diff --git a/devTools/svgTester/chart-configurations.ts b/devTools/svgTester/chart-configurations.ts
index 03a82a5f1c7..f7de4b99909 100644
--- a/devTools/svgTester/chart-configurations.ts
+++ b/devTools/svgTester/chart-configurations.ts
@@ -1,10 +1,11 @@
import _ from "lodash"
import {
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
StackMode,
ScaleType,
FacetStrategy,
GrapherQueryParams,
+ GrapherChartType,
} from "@ourworldindata/types"
import { cartesian } from "@ourworldindata/utils"
@@ -32,8 +33,8 @@ const scaleTypeOptions = Object.values(ScaleType)
const facetOptions = Object.values(FacetStrategy)
const booleanOptions = Object.values(Boolean)
-const VIEW_MATRIX_BY_CHART_TYPE: Record = {
- [ChartTypeName.LineChart]: {
+const VIEW_MATRIX_BY_CHART_TYPE: Record = {
+ [GRAPHER_CHART_TYPES.LineChart]: {
tab: ["chart"],
time: timeOptionsAll,
stackMode: stackModeOptions,
@@ -41,7 +42,7 @@ const VIEW_MATRIX_BY_CHART_TYPE: Record = {
facet: facetOptions,
uniformYAxis: booleanOptions,
},
- [ChartTypeName.ScatterPlot]: {
+ [GRAPHER_CHART_TYPES.ScatterPlot]: {
tab: ["chart"],
time: timeOptionsAll,
stackMode: stackModeOptions,
@@ -50,61 +51,60 @@ const VIEW_MATRIX_BY_CHART_TYPE: Record = {
endpointsOnly: booleanOptions,
// zoomToSelection ignored for now
},
- [ChartTypeName.DiscreteBar]: {
+ [GRAPHER_CHART_TYPES.DiscreteBar]: {
tab: ["chart"],
time: timePoints,
facet: facetOptions,
// uniformYAxis doesn't apply
},
- [ChartTypeName.StackedDiscreteBar]: {
+ [GRAPHER_CHART_TYPES.StackedDiscreteBar]: {
tab: ["chart"],
time: timePoints,
stackMode: stackModeOptions,
facet: facetOptions,
// uniformYAxis doesn't apply
},
- [ChartTypeName.Marimekko]: {
+ [GRAPHER_CHART_TYPES.Marimekko]: {
tab: ["chart"],
time: timePoints,
stackMode: stackModeOptions,
showNoDataArea: booleanOptions,
},
- [ChartTypeName.SlopeChart]: {
+ [GRAPHER_CHART_TYPES.SlopeChart]: {
tab: ["chart"],
time: timeSpan,
yScale: scaleTypeOptions,
},
- [ChartTypeName.StackedArea]: {
+ [GRAPHER_CHART_TYPES.StackedArea]: {
tab: ["chart"],
time: timeSpan,
stackMode: stackModeOptions,
facet: facetOptions,
uniformYAxis: booleanOptions,
},
- [ChartTypeName.StackedBar]: {
+ [GRAPHER_CHART_TYPES.StackedBar]: {
tab: ["chart"],
time: timeSpan,
stackMode: stackModeOptions,
facet: facetOptions,
uniformYAxis: booleanOptions,
},
- [ChartTypeName.WorldMap]: {},
}
// the above view matrix is used to generate all possible combinations of query params
// but some combinations don't make sense. this matrix is used to exclude those combinations.
// for example, if a chart is not faceted, the uniformYAxis param doesn't apply
const EXCLUDE_VIEWS_BY_CHART_TYPE: Record<
- ChartTypeName,
+ GrapherChartType,
Record[]
> = {
- [ChartTypeName.LineChart]: [
+ [GRAPHER_CHART_TYPES.LineChart]: [
// sharing an axis only makes sense if a chart is faceted
{ facet: FacetStrategy.none, uniformYAxis: Boolean.true },
// log scale for percentage values doesn't make sense
{ stackMode: StackMode.relative, yScale: ScaleType.log },
],
- [ChartTypeName.ScatterPlot]: [
+ [GRAPHER_CHART_TYPES.ScatterPlot]: [
// relative mode only makes sense if a time span is selected
{ time: TimePoint.earliest, stackMode: StackMode.relative },
{ time: TimePoint.latest, stackMode: StackMode.relative },
@@ -117,19 +117,18 @@ const EXCLUDE_VIEWS_BY_CHART_TYPE: Record<
{ stackMode: StackMode.relative, yScale: ScaleType.log },
{ stackMode: StackMode.relative, xScale: ScaleType.log },
],
- [ChartTypeName.DiscreteBar]: [],
- [ChartTypeName.StackedDiscreteBar]: [],
- [ChartTypeName.Marimekko]: [],
- [ChartTypeName.SlopeChart]: [],
- [ChartTypeName.StackedArea]: [
+ [GRAPHER_CHART_TYPES.DiscreteBar]: [],
+ [GRAPHER_CHART_TYPES.StackedDiscreteBar]: [],
+ [GRAPHER_CHART_TYPES.Marimekko]: [],
+ [GRAPHER_CHART_TYPES.SlopeChart]: [],
+ [GRAPHER_CHART_TYPES.StackedArea]: [
// sharing an axis only makes sense if a chart is faceted
{ facet: FacetStrategy.none, uniformYAxis: Boolean.true },
],
- [ChartTypeName.StackedBar]: [
+ [GRAPHER_CHART_TYPES.StackedBar]: [
// sharing an axis only makes sense if a chart is faceted
{ facet: FacetStrategy.none, uniformYAxis: Boolean.true },
],
- [ChartTypeName.WorldMap]: [],
}
export const queryStringsByChartType = Object.fromEntries(
@@ -137,7 +136,7 @@ export const queryStringsByChartType = Object.fromEntries(
const combinations = explode(viewMatrix)
const viewsToExclude =
- EXCLUDE_VIEWS_BY_CHART_TYPE[chartType as ChartTypeName]
+ EXCLUDE_VIEWS_BY_CHART_TYPE[chartType as GrapherChartType]
const validCombinations = combinations.filter((view) =>
viewsToExclude.every(
(viewToExclude) => !_.isMatch(view, viewToExclude)
@@ -147,7 +146,7 @@ export const queryStringsByChartType = Object.fromEntries(
const queryStrings = validCombinations.map(toQueryStr)
return [chartType, queryStrings]
})
-) as Record
+) as Record
function toQueryStr(params: Record): string {
return new URLSearchParams(params).toString()
diff --git a/devTools/svgTester/dump-chart-ids.ts b/devTools/svgTester/dump-chart-ids.ts
index e824f5898f9..16055805e54 100644
--- a/devTools/svgTester/dump-chart-ids.ts
+++ b/devTools/svgTester/dump-chart-ids.ts
@@ -5,7 +5,7 @@ import parseArgs from "minimist"
import { TransactionCloseMode, knexReadonlyTransaction } from "../../db/db.js"
import { getMostViewedGrapherIdsByChartType } from "../../db/model/Chart.js"
-import { CHART_TYPES } from "./utils.js"
+import { ALL_GRAPHER_CHART_TYPES } from "@ourworldindata/types"
const DEFAULT_OUT_FILE = "../owid-grapher-svgs/most-viewed-charts.txt"
const CHART_COUNT_PER_TYPE = 25
@@ -15,7 +15,7 @@ async function main(parsedArgs: parseArgs.ParsedArgs) {
const outFile = parsedArgs["o"] ?? DEFAULT_OUT_FILE
const chartIds = await knexReadonlyTransaction(async (trx) => {
- const promises = CHART_TYPES.flatMap((chartType) =>
+ const promises = ALL_GRAPHER_CHART_TYPES.flatMap((chartType) =>
getMostViewedGrapherIdsByChartType(
trx,
chartType,
diff --git a/devTools/svgTester/utils.ts b/devTools/svgTester/utils.ts
index 724a41a0492..746e94a7bb6 100644
--- a/devTools/svgTester/utils.ts
+++ b/devTools/svgTester/utils.ts
@@ -1,7 +1,8 @@
import {
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
+ GrapherChartType,
GrapherTabName,
- GrapherTabOption,
+ ALL_GRAPHER_CHART_TYPES,
} from "@ourworldindata/types"
import {
MultipleOwidVariableDataDimensionsMap,
@@ -26,11 +27,6 @@ import { getHeapStatistics } from "v8"
import { queryStringsByChartType } from "./chart-configurations.js"
import * as d3 from "d3"
-// ignore WorldMaps
-export const CHART_TYPES = Object.values(ChartTypeName).filter(
- (chartType) => chartType !== ChartTypeName.WorldMap
-)
-
// the owid-grapher-svgs repo is usually cloned as a sibling to the owid-grapher repo
export const DEFAULT_CONFIGS_DIR = "../owid-grapher-svgs/configs"
export const DEFAULT_REFERENCE_DIR = "../owid-grapher-svgs/svg"
@@ -44,7 +40,7 @@ export const finished = util.promisify(stream.finished) // (A)
export interface ChartWithQueryStr {
id: number
slug: string
- type: ChartTypeName
+ type: GrapherChartType
queryStr?: string
}
@@ -182,7 +178,7 @@ export async function selectChartIdsToProcess(
options: {
chartIdsFile?: string
grapherIds?: number[]
- chartTypes?: ChartTypeName[]
+ chartTypes?: GrapherChartType[]
randomCount?: number
}
): Promise {
@@ -210,7 +206,7 @@ export async function findChartViewsToGenerate(
const slug = grapherConfig.slug ?? chartId.toString()
const chartType =
- grapherConfig.chartTypes?.[0] ?? ChartTypeName.LineChart
+ grapherConfig.chartTypes?.[0] ?? GRAPHER_CHART_TYPES.LineChart
const queryStrings = options.shouldTestAllViews
? queryStringsByChartType[chartType]
@@ -240,7 +236,7 @@ export async function findValidChartIds(
}: {
chartIdsFile?: string
grapherIds?: number[]
- chartTypes?: ChartTypeName[]
+ chartTypes?: GrapherChartType[]
}
): Promise {
const validChartIds: number[] = []
@@ -289,7 +285,8 @@ export async function findValidChartIds(
inDir,
})
const chartType =
- grapherConfig.chartTypes?.[0] ?? ChartTypeName.LineChart
+ grapherConfig.chartTypes?.[0] ??
+ GRAPHER_CHART_TYPES.LineChart
if (chartTypes.includes(chartType)) {
validChartIds.push(grapherId)
}
@@ -300,17 +297,17 @@ export async function findValidChartIds(
return validChartIds
}
-export function validateChartTypes(chartTypes: string[]): ChartTypeName[] {
+export function validateChartTypes(chartTypes: string[]): GrapherChartType[] {
const validChartTypes = chartTypes.filter(
- (chartType): chartType is ChartTypeName =>
- CHART_TYPES.includes(chartType as any)
+ (chartType): chartType is GrapherChartType =>
+ ALL_GRAPHER_CHART_TYPES.includes(chartType as any)
)
const invalidChartTypes = chartTypes.filter(
- (chartType) => !CHART_TYPES.includes(chartType as any)
+ (chartType) => !ALL_GRAPHER_CHART_TYPES.includes(chartType as any)
)
if (invalidChartTypes.length) {
console.warn(
- `Invalid chart types given: ${invalidChartTypes}. Valid chart types are: ${CHART_TYPES}`
+ `Invalid chart types given: ${invalidChartTypes}. Valid chart types are: ${ALL_GRAPHER_CHART_TYPES}`
)
}
return _.uniq(validChartTypes)
diff --git a/packages/@ourworldindata/explorer/src/Explorer.jsdom.test.tsx b/packages/@ourworldindata/explorer/src/Explorer.jsdom.test.tsx
index 644852c0684..e35fcf581c0 100755
--- a/packages/@ourworldindata/explorer/src/Explorer.jsdom.test.tsx
+++ b/packages/@ourworldindata/explorer/src/Explorer.jsdom.test.tsx
@@ -8,7 +8,7 @@ import {
import Enzyme from "enzyme"
import Adapter from "@wojtekmaj/enzyme-adapter-react-17"
-import { GrapherTabOption } from "@ourworldindata/types"
+import { GRAPHER_TAB_OPTIONS } from "@ourworldindata/types"
Enzyme.configure({ adapter: new Adapter() })
@@ -30,20 +30,20 @@ describe(Explorer, () => {
explorer.onChangeChoice("Gas")("All GHGs (CO₂eq)")
- if (explorer.grapher) explorer.grapher.tab = GrapherTabOption.table
+ if (explorer.grapher) explorer.grapher.tab = GRAPHER_TAB_OPTIONS.table
else throw Error("where's the grapher?")
expect(explorer.queryParams.tab).toEqual("table")
explorer.onChangeChoice("Gas")("CO₂")
expect(explorer.queryParams.tab).toEqual("table")
- explorer.grapher.tab = GrapherTabOption.chart
+ explorer.grapher.tab = GRAPHER_TAB_OPTIONS.chart
})
it("switches to first tab if current tab does not exist in new view", () => {
const explorer = element.instance() as Explorer
expect(explorer.queryParams.tab).toBeUndefined()
- if (explorer.grapher) explorer.grapher.tab = GrapherTabOption.map
+ if (explorer.grapher) explorer.grapher.tab = GRAPHER_TAB_OPTIONS.map
else throw Error("where's the grapher?")
expect(explorer.queryParams.tab).toEqual("map")
diff --git a/packages/@ourworldindata/explorer/src/Explorer.sample.tsx b/packages/@ourworldindata/explorer/src/Explorer.sample.tsx
index a15b805a6f5..53cb8bff93e 100644
--- a/packages/@ourworldindata/explorer/src/Explorer.sample.tsx
+++ b/packages/@ourworldindata/explorer/src/Explorer.sample.tsx
@@ -1,6 +1,6 @@
import React from "react"
import { DimensionProperty } from "@ourworldindata/utils"
-import { GrapherTabOption } from "@ourworldindata/types"
+import { GRAPHER_TAB_OPTIONS } from "@ourworldindata/types"
import { GrapherProgrammaticInterface } from "@ourworldindata/grapher"
import { Explorer, ExplorerProps } from "./Explorer.js"
@@ -54,7 +54,7 @@ export const SampleExplorerOfGraphers = (props?: Partial) => {
property: DimensionProperty.y,
},
],
- tab: GrapherTabOption.chart,
+ tab: GRAPHER_TAB_OPTIONS.chart,
owidDataset: new Map([
[
142609,
diff --git a/packages/@ourworldindata/explorer/src/Explorer.tsx b/packages/@ourworldindata/explorer/src/Explorer.tsx
index 7cffdb8c34a..fcc38ed659e 100644
--- a/packages/@ourworldindata/explorer/src/Explorer.tsx
+++ b/packages/@ourworldindata/explorer/src/Explorer.tsx
@@ -8,8 +8,7 @@ import {
TableSlug,
GrapherInterface,
GrapherQueryParams,
- GrapherTabQueryParam,
- GrapherTabName,
+ GRAPHER_TAB_QUERY_PARAMS,
} from "@ourworldindata/types"
import {
OwidTable,
@@ -455,14 +454,14 @@ export class Explorer
} else if (this.grapher.validChartTypes.length > 0) {
// otherwise, switch to the first chart tab
newGrapherParams.tab = this.grapher.mapGrapherTabToQueryParam(
- this.grapher.validChartTypes[0] as unknown as GrapherTabName
+ this.grapher.validChartTypes[0]
)
} else if (this.grapher.hasMapTab) {
// or switch to the map, if there is one
- newGrapherParams.tab = GrapherTabQueryParam.WorldMap
+ newGrapherParams.tab = GRAPHER_TAB_QUERY_PARAMS.map
} else {
// if everything fails, switch to the table tab that is always available
- newGrapherParams.tab = GrapherTabQueryParam.Table
+ newGrapherParams.tab = GRAPHER_TAB_QUERY_PARAMS.table
}
this.grapher.populateFromQueryParams(newGrapherParams)
diff --git a/packages/@ourworldindata/explorer/src/ExplorerProgram.ts b/packages/@ourworldindata/explorer/src/ExplorerProgram.ts
index 748b4e333c0..033dc5746d4 100644
--- a/packages/@ourworldindata/explorer/src/ExplorerProgram.ts
+++ b/packages/@ourworldindata/explorer/src/ExplorerProgram.ts
@@ -8,7 +8,7 @@ import {
FacetAxisDomain,
GrapherInterface,
AxisMinMaxValueStr,
- ChartTypeName,
+ GrapherChartType,
} from "@ourworldindata/types"
import {
CoreTable,
@@ -65,7 +65,7 @@ interface ExplorerGrapherInterface extends GrapherInterface {
relatedQuestionText?: string
relatedQuestionUrl?: string
mapTargetTime?: number
- type?: ChartTypeName | "None"
+ type?: GrapherChartType | "None"
}
const ExplorerRootDef: CellDef = {
diff --git a/packages/@ourworldindata/explorer/src/GrapherGrammar.ts b/packages/@ourworldindata/explorer/src/GrapherGrammar.ts
index bbcb295f6a6..78d6a82344a 100644
--- a/packages/@ourworldindata/explorer/src/GrapherGrammar.ts
+++ b/packages/@ourworldindata/explorer/src/GrapherGrammar.ts
@@ -1,9 +1,9 @@
import {
- ChartTypeName,
+ ALL_GRAPHER_CHART_TYPES,
ColorSchemeName,
FacetAxisDomain,
FacetStrategy,
- GrapherTabOption,
+ GRAPHER_TAB_OPTIONS,
MissingDataStrategy,
StackMode,
} from "@ourworldindata/types"
@@ -65,7 +65,7 @@ export const GrapherGrammar: Grammar = {
keyword: "type",
description: `The type of chart to show such as LineChart or ScatterPlot. If set to None, then the chart tab is hidden.`,
terminalOptions: toTerminalOptions([
- ...Object.values(ChartTypeName),
+ ...ALL_GRAPHER_CHART_TYPES,
"None",
]),
toGrapherObject: (value) => ({
@@ -95,7 +95,7 @@ export const GrapherGrammar: Grammar = {
...EnumCellDef,
keyword: "tab",
description: "Which tab to show by default",
- terminalOptions: toTerminalOptions(Object.values(GrapherTabOption)),
+ terminalOptions: toTerminalOptions(Object.values(GRAPHER_TAB_OPTIONS)),
toGrapherObject: (value) => ({ tab: value }),
},
xSlug: {
diff --git a/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.stories.tsx b/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.stories.tsx
index 63157d73e38..830ed484691 100644
--- a/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.stories.tsx
+++ b/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.stories.tsx
@@ -1,8 +1,8 @@
import { SynthesizeGDPTable } from "@ourworldindata/core-table"
import {
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
FacetStrategy,
- GrapherTabOption,
+ GRAPHER_TAB_OPTIONS,
SeriesStrategy,
} from "@ourworldindata/types"
import { DEFAULT_BOUNDS } from "@ourworldindata/utils"
@@ -48,13 +48,13 @@ export const StaticLineChartForExport = (): React.ReactElement => {
}
export const MapChart = (): React.ReactElement => (
-
+
)
export const StackedArea = (): React.ReactElement => (
@@ -63,7 +63,7 @@ export const Scatter = (): React.ReactElement => (
diff --git a/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx b/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx
index 7e5b8482a13..2238dc78e8f 100644
--- a/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx
+++ b/packages/@ourworldindata/grapher/src/captionedChart/CaptionedChart.tsx
@@ -34,11 +34,14 @@ import { HeaderManager } from "../header/HeaderManager"
import { SelectionArray } from "../selection/SelectionArray"
import {
EntityName,
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
FacetStrategy,
RelatedQuestionsConfig,
Color,
GrapherTabName,
+ GRAPHER_MAP_TYPE,
+ GrapherChartOrMapType,
+ GrapherChartType,
} from "@ourworldindata/types"
import { DataTable, DataTableManager } from "../dataTable/DataTable"
import {
@@ -79,7 +82,7 @@ export interface CaptionedChartManager
activeTab?: GrapherTabName
isOnMapTab?: boolean
isOnTableTab?: boolean
- activeChartType?: ChartTypeName
+ activeChartType?: GrapherChartType
isLineChartThatTurnedIntoDiscreteBar?: boolean
showEntitySelectionToggle?: boolean
isExportingForSocialMedia?: boolean
@@ -189,29 +192,34 @@ export class CaptionedChart extends React.Component {
return !this.manager.isOnMapTab && hasStrategy
}
- @computed get activeChartType(): ChartTypeName | undefined {
+ @computed get activeChartOrMapType(): GrapherChartOrMapType | undefined {
const { manager } = this
if (manager.isOnTableTab) return undefined
- if (manager.isOnMapTab) return ChartTypeName.WorldMap
+ if (manager.isOnMapTab) return GRAPHER_MAP_TYPE
if (manager.isOnChartTab) {
return manager.isLineChartThatTurnedIntoDiscreteBar
- ? ChartTypeName.DiscreteBar
+ ? GRAPHER_CHART_TYPES.DiscreteBar
: manager.activeChartType
}
return undefined
}
renderChart(): React.ReactElement | void {
- const { manager, activeChartType, containerElement } = this
+ const {
+ manager,
+ boundsForChartArea: bounds,
+ activeChartOrMapType,
+ containerElement,
+ } = this
- if (!activeChartType) return
-
- const bounds = this.boundsForChartArea
- const ChartClass =
- ChartComponentClassMap.get(activeChartType) ?? DefaultChartClass
+ if (!activeChartOrMapType) return
// Todo: make FacetChart a chart type name?
- if (this.isFaceted)
+ const activeChartType =
+ activeChartOrMapType !== GRAPHER_MAP_TYPE
+ ? activeChartOrMapType
+ : undefined
+ if (this.isFaceted && activeChartType)
return (
{
/>
)
+ const ChartClass =
+ ChartComponentClassMap.get(activeChartOrMapType) ??
+ DefaultChartClass
+
return (
{
}
export const ChartComponentClassMap = new Map<
- ChartTypeName,
+ GrapherChartOrMapType,
ChartComponentClass
>([
- [ChartTypeName.DiscreteBar, DiscreteBarChart],
- [ChartTypeName.LineChart, LineChart],
- [ChartTypeName.SlopeChart, SlopeChart],
- [ChartTypeName.StackedArea, StackedAreaChart],
- [ChartTypeName.StackedBar, StackedBarChart],
- [ChartTypeName.StackedDiscreteBar, StackedDiscreteBarChart],
- [ChartTypeName.ScatterPlot, ScatterPlotChart],
- [ChartTypeName.Marimekko, MarimekkoChart],
- [ChartTypeName.WorldMap, MapChart],
+ [GRAPHER_CHART_TYPES.DiscreteBar, DiscreteBarChart],
+ [GRAPHER_CHART_TYPES.LineChart, LineChart],
+ [GRAPHER_CHART_TYPES.SlopeChart, SlopeChart],
+ [GRAPHER_CHART_TYPES.StackedArea, StackedAreaChart],
+ [GRAPHER_CHART_TYPES.StackedBar, StackedBarChart],
+ [GRAPHER_CHART_TYPES.StackedDiscreteBar, StackedDiscreteBarChart],
+ [GRAPHER_CHART_TYPES.ScatterPlot, ScatterPlotChart],
+ [GRAPHER_CHART_TYPES.Marimekko, MarimekkoChart],
+ [GRAPHER_MAP_TYPE, MapChart],
])
export const DefaultChartClass = LineChart as ChartComponentClass
+export const defaultChartType = GRAPHER_CHART_TYPES.LineChart
diff --git a/packages/@ourworldindata/grapher/src/chart/ChartTypeSwitcher.tsx b/packages/@ourworldindata/grapher/src/chart/ChartTypeSwitcher.tsx
index 8afc64f6754..0e1886d7a8b 100644
--- a/packages/@ourworldindata/grapher/src/chart/ChartTypeSwitcher.tsx
+++ b/packages/@ourworldindata/grapher/src/chart/ChartTypeSwitcher.tsx
@@ -1,9 +1,12 @@
import React from "react"
-import { ChartTypeName } from "@ourworldindata/types"
+import {
+ ALL_GRAPHER_CHART_TYPES,
+ GrapherChartType,
+} from "@ourworldindata/types"
// Just a utility for testing
export class ChartTypeSwitcher extends React.Component<{
- onChange: (chartType: ChartTypeName) => void
+ onChange: (chartType: GrapherChartType) => void
}> {
render(): React.ReactElement {
return (
@@ -12,7 +15,7 @@ export class ChartTypeSwitcher extends React.Component<{
this.props.onChange(event.target.value as any)
}
>
- {Object.values(ChartTypeName).map((value) => (
+ {ALL_GRAPHER_CHART_TYPES.map((value) => (
diff --git a/packages/@ourworldindata/grapher/src/chart/ChartUtils.tsx b/packages/@ourworldindata/grapher/src/chart/ChartUtils.tsx
index 4ba869a8132..375e9816c7a 100644
--- a/packages/@ourworldindata/grapher/src/chart/ChartUtils.tsx
+++ b/packages/@ourworldindata/grapher/src/chart/ChartUtils.tsx
@@ -4,7 +4,9 @@ import {
SeriesStrategy,
EntityName,
GrapherTabQueryParam,
- ChartTypeName,
+ GrapherChartType,
+ GRAPHER_CHART_TYPES,
+ GRAPHER_TAB_QUERY_PARAMS,
} from "@ourworldindata/types"
import { LineChartSeries } from "../lineCharts/LineChartConstants"
import { SelectionArray } from "../selection/SelectionArray"
@@ -128,51 +130,48 @@ export function isTargetOutsideElement(
export function mapQueryParamToChartTypeName(
chartTab: string
-): ChartTypeName | undefined {
+): GrapherChartType | undefined {
switch (chartTab) {
- case GrapherTabQueryParam.LineChart:
- return ChartTypeName.LineChart
- case GrapherTabQueryParam.SlopeChart:
- return ChartTypeName.SlopeChart
- case GrapherTabQueryParam.ScatterPlot:
- return ChartTypeName.ScatterPlot
- case GrapherTabQueryParam.StackedArea:
- return ChartTypeName.StackedArea
- case GrapherTabQueryParam.StackedBar:
- return ChartTypeName.StackedBar
- case GrapherTabQueryParam.DiscreteBar:
- return ChartTypeName.DiscreteBar
- case GrapherTabQueryParam.StackedDiscreteBar:
- return ChartTypeName.StackedDiscreteBar
- case GrapherTabQueryParam.Marimekko:
- return ChartTypeName.Marimekko
+ case GRAPHER_TAB_QUERY_PARAMS.line:
+ return GRAPHER_CHART_TYPES.LineChart
+ case GRAPHER_TAB_QUERY_PARAMS.slope:
+ return GRAPHER_CHART_TYPES.SlopeChart
+ case GRAPHER_TAB_QUERY_PARAMS.scatter:
+ return GRAPHER_CHART_TYPES.ScatterPlot
+ case GRAPHER_TAB_QUERY_PARAMS["stacked-area"]:
+ return GRAPHER_CHART_TYPES.StackedArea
+ case GRAPHER_TAB_QUERY_PARAMS["stacked-bar"]:
+ return GRAPHER_CHART_TYPES.StackedBar
+ case GRAPHER_TAB_QUERY_PARAMS["discrete-bar"]:
+ return GRAPHER_CHART_TYPES.DiscreteBar
+ case GRAPHER_TAB_QUERY_PARAMS["stacked-discrete-bar"]:
+ return GRAPHER_CHART_TYPES.StackedDiscreteBar
+ case GRAPHER_TAB_QUERY_PARAMS.marimekko:
+ return GRAPHER_CHART_TYPES.Marimekko
default:
return undefined
}
}
export function mapChartTypeNameToQueryParam(
- chartType: ChartTypeName
+ chartType: GrapherChartType
): GrapherTabQueryParam {
switch (chartType) {
- case ChartTypeName.LineChart:
- return GrapherTabQueryParam.LineChart
- case ChartTypeName.SlopeChart:
- return GrapherTabQueryParam.SlopeChart
- case ChartTypeName.ScatterPlot:
- return GrapherTabQueryParam.ScatterPlot
- case ChartTypeName.StackedArea:
- return GrapherTabQueryParam.StackedArea
- case ChartTypeName.StackedBar:
- return GrapherTabQueryParam.StackedBar
- case ChartTypeName.DiscreteBar:
- return GrapherTabQueryParam.DiscreteBar
- case ChartTypeName.StackedDiscreteBar:
- return GrapherTabQueryParam.StackedDiscreteBar
- case ChartTypeName.Marimekko:
- return GrapherTabQueryParam.Marimekko
- // TODO: remove once stricter typed
- default:
- return GrapherTabQueryParam.LineChart
+ case GRAPHER_CHART_TYPES.LineChart:
+ return GRAPHER_TAB_QUERY_PARAMS.line
+ case GRAPHER_CHART_TYPES.SlopeChart:
+ return GRAPHER_TAB_QUERY_PARAMS.slope
+ case GRAPHER_CHART_TYPES.ScatterPlot:
+ return GRAPHER_TAB_QUERY_PARAMS.scatter
+ case GRAPHER_CHART_TYPES.StackedArea:
+ return GRAPHER_TAB_QUERY_PARAMS["stacked-area"]
+ case GRAPHER_CHART_TYPES.StackedBar:
+ return GRAPHER_TAB_QUERY_PARAMS["stacked-bar"]
+ case GRAPHER_CHART_TYPES.DiscreteBar:
+ return GRAPHER_TAB_QUERY_PARAMS["discrete-bar"]
+ case GRAPHER_CHART_TYPES.StackedDiscreteBar:
+ return GRAPHER_TAB_QUERY_PARAMS["stacked-discrete-bar"]
+ case GRAPHER_CHART_TYPES.Marimekko:
+ return GRAPHER_TAB_QUERY_PARAMS.marimekko
}
}
diff --git a/packages/@ourworldindata/grapher/src/color/ColorSchemes.ts b/packages/@ourworldindata/grapher/src/color/ColorSchemes.ts
index ab213d91406..7e553aee094 100644
--- a/packages/@ourworldindata/grapher/src/color/ColorSchemes.ts
+++ b/packages/@ourworldindata/grapher/src/color/ColorSchemes.ts
@@ -3,28 +3,32 @@ import { ColorScheme } from "./ColorScheme"
import { match } from "ts-pattern"
import { partition } from "@ourworldindata/utils"
import {
- ChartTypeName,
+ GRAPHER_CHART_TYPES,
ColorSchemeInterface,
ColorSchemeName,
+ GRAPHER_MAP_TYPE,
+ GrapherChartOrMapType,
} from "@ourworldindata/types"
import { getColorBrewerScheme } from "./ColorBrewerSchemes.js"
-function getPreferredSchemesByType(type: ChartTypeName): ColorSchemeName[] {
- // This function could also be a Map but
+function getPreferredSchemesByType(
+ type: GrapherChartOrMapType
+): ColorSchemeName[] {
+ // This function could also be a Map but
// by doing it as a function usign ts-pattern.match we get compile
- // time safety that all enum cases in ChartTypeName are always handled here
+ // time safety that all enum cases in GrapherChartOrMapType are always handled here
return match(type)
- .with(ChartTypeName.DiscreteBar, () => [
+ .with(GRAPHER_CHART_TYPES.DiscreteBar, () => [
ColorSchemeName.SingleColorDenim,
ColorSchemeName.SingleColorDustyCoral,
ColorSchemeName.SingleColorPurple,
ColorSchemeName.SingleColorTeal,
ColorSchemeName.SingleColorDarkCopper,
])
- .with(ChartTypeName.LineChart, () => [
+ .with(GRAPHER_CHART_TYPES.LineChart, () => [
ColorSchemeName.OwidDistinctLines,
])
- .with(ChartTypeName.Marimekko, () => [
+ .with(GRAPHER_CHART_TYPES.Marimekko, () => [
ColorSchemeName.continents,
ColorSchemeName.SingleColorDenim,
ColorSchemeName.SingleColorDustyCoral,
@@ -37,15 +41,15 @@ function getPreferredSchemesByType(type: ChartTypeName): ColorSchemeName[] {
ColorSchemeName.OwidCategoricalD,
ColorSchemeName.OwidCategoricalE,
])
- .with(ChartTypeName.ScatterPlot, () => [
+ .with(GRAPHER_CHART_TYPES.ScatterPlot, () => [
ColorSchemeName.continents,
ColorSchemeName.OwidDistinctLines,
])
- .with(ChartTypeName.SlopeChart, () => [
+ .with(GRAPHER_CHART_TYPES.SlopeChart, () => [
ColorSchemeName.continents,
ColorSchemeName.OwidDistinctLines,
])
- .with(ChartTypeName.StackedArea, () => [
+ .with(GRAPHER_CHART_TYPES.StackedArea, () => [
ColorSchemeName["owid-distinct"],
ColorSchemeName.OwidCategoricalA,
ColorSchemeName.OwidCategoricalB,
@@ -58,7 +62,7 @@ function getPreferredSchemesByType(type: ChartTypeName): ColorSchemeName[] {
ColorSchemeName.SingleColorGradientDustyCoral,
ColorSchemeName.SingleColorGradientDarkCopper,
])
- .with(ChartTypeName.StackedBar, () => [
+ .with(GRAPHER_CHART_TYPES.StackedBar, () => [
ColorSchemeName["owid-distinct"],
ColorSchemeName.OwidCategoricalA,
ColorSchemeName.OwidCategoricalB,
@@ -71,7 +75,7 @@ function getPreferredSchemesByType(type: ChartTypeName): ColorSchemeName[] {
ColorSchemeName.SingleColorGradientDustyCoral,
ColorSchemeName.SingleColorGradientDarkCopper,
])
- .with(ChartTypeName.StackedDiscreteBar, () => [
+ .with(GRAPHER_CHART_TYPES.StackedDiscreteBar, () => [
ColorSchemeName["owid-distinct"],
ColorSchemeName.OwidCategoricalA,
ColorSchemeName.OwidCategoricalB,
@@ -84,7 +88,7 @@ function getPreferredSchemesByType(type: ChartTypeName): ColorSchemeName[] {
ColorSchemeName.SingleColorGradientDustyCoral,
ColorSchemeName.SingleColorGradientDarkCopper,
])
- .with(ChartTypeName.WorldMap, () => [
+ .with(GRAPHER_MAP_TYPE, () => [
ColorSchemeName.BinaryMapPaletteA,
ColorSchemeName.BinaryMapPaletteB,
ColorSchemeName.BinaryMapPaletteC,
@@ -129,7 +133,7 @@ const getAllColorSchemes = (): Map => {
)
}
-export function getColorSchemeForChartType(type: ChartTypeName): {
+export function getColorSchemeForChartType(type: GrapherChartOrMapType): {
[key in ColorSchemeName]: ColorScheme
} {
const preferred = new Set(getPreferredSchemesByType(type))
diff --git a/packages/@ourworldindata/grapher/src/controls/ChartIcons.tsx b/packages/@ourworldindata/grapher/src/controls/ChartIcons.tsx
index 605c2f7fd7f..00b89c46017 100644
--- a/packages/@ourworldindata/grapher/src/controls/ChartIcons.tsx
+++ b/packages/@ourworldindata/grapher/src/controls/ChartIcons.tsx
@@ -4,21 +4,22 @@ import {
faChartBar,
faChartLine,
faChartColumn,
- faEarthAmericas,
} from "@fortawesome/free-solid-svg-icons"
-import { ChartTypeName } from "@ourworldindata/types"
+import { GRAPHER_CHART_TYPES, GrapherChartType } from "@ourworldindata/types"
-export const chartIcons: Record = {
+export const chartIcons: Record = {
// line chart
- [ChartTypeName.LineChart]: ,
+ [GRAPHER_CHART_TYPES.LineChart]: ,
// bar charts
- [ChartTypeName.DiscreteBar]: ,
- [ChartTypeName.StackedBar]: ,
- [ChartTypeName.StackedDiscreteBar]: ,
+ [GRAPHER_CHART_TYPES.DiscreteBar]: ,
+ [GRAPHER_CHART_TYPES.StackedBar]: ,
+ [GRAPHER_CHART_TYPES.StackedDiscreteBar]: (
+
+ ),
// scatter
- [ChartTypeName.ScatterPlot]: (
+ [GRAPHER_CHART_TYPES.ScatterPlot]: (