diff --git a/packages/@ourworldindata/grapher/src/core/Grapher.tsx b/packages/@ourworldindata/grapher/src/core/Grapher.tsx
index ca835175558..dff3caed7c4 100644
--- a/packages/@ourworldindata/grapher/src/core/Grapher.tsx
+++ b/packages/@ourworldindata/grapher/src/core/Grapher.tsx
@@ -1446,24 +1446,48 @@ export class Grapher
])
}
- @computed get columnsWithSources(): CoreColumn[] {
+ @computed get columnsWithSourcesExtensive(): CoreColumn[] {
const { yColumnSlugs, xColumnSlug, sizeColumnSlug, colorColumnSlug } =
this
+ const columnSlugs = excludeUndefined([
+ ...yColumnSlugs,
+ xColumnSlug,
+ sizeColumnSlug,
+ colorColumnSlug,
+ ])
+
+ return this.inputTable
+ .getColumns(uniq(columnSlugs))
+ .filter(
+ (column) => !!column.source.name || !isEmpty(column.def.origins)
+ )
+ }
+
+ getColumnSlugsForCondensedSources(): string[] {
+ const { xColumnSlug, sizeColumnSlug, colorColumnSlug, isMarimekko } =
+ this
+ const columnSlugs: string[] = []
+
// "Countries Continent"
const isContinentsVariableId = (id: string): boolean => id === "123"
+ // exclude "Countries Continent" if it's used as the color dimension in a scatter plot, slope chart etc.
+ if (
+ colorColumnSlug !== undefined &&
+ !isContinentsVariableId(colorColumnSlug)
+ )
+ columnSlugs.push(colorColumnSlug)
+
const isPopulationVariableId = (id: string): boolean =>
id === "525709" || // "Population (historical + projections), Gapminder, HYDE & UN"
id === "525711" || // "Population (historical estimates), Gapminder, HYDE & UN"
id === "597929" || // "Population (various sources, 2023.1)"
id === "597930" // "Population (various sources, 2023.1)"
- const columnSlugs = [...yColumnSlugs]
-
if (xColumnSlug !== undefined) {
// exclude population variable if it's used as the x dimension in a marimekko
- if (!isPopulationVariableId(xColumnSlug) || !this.isMarimekko)
+ if (!isMarimekko || !isPopulationVariableId(xColumnSlug))
columnSlugs.push(xColumnSlug)
}
@@ -1473,13 +1497,14 @@ export class Grapher
!isPopulationVariableId(sizeColumnSlug)
)
columnSlugs.push(sizeColumnSlug)
+ return columnSlugs
+ }
- // exclude "Countries Continent" if it's used as the color dimension in a scatter plot, slope chart etc.
- if (
- colorColumnSlug !== undefined &&
- !isContinentsVariableId(colorColumnSlug)
- )
- columnSlugs.push(colorColumnSlug)
+ @computed get columnsWithSourcesCondensed(): CoreColumn[] {
+ const { yColumnSlugs } = this
+
+ const columnSlugs = [...yColumnSlugs]
+ columnSlugs.push(...this.getColumnSlugsForCondensedSources())
return this.inputTable
.getColumns(uniq(columnSlugs))
@@ -1489,22 +1514,24 @@ export class Grapher
}
@computed private get defaultSourcesLine(): string {
- const attributions = this.columnsWithSources.flatMap((column) => {
- // if the variable metadata specifies an attribution on the
- // variable level then this is preferred over assembling it from
- // the source and origins
- if (
- column.def.attribution !== undefined &&
- column.def.attribution !== ""
- )
- return [column.def.attribution]
- else {
- const originFragments = getOriginAttributionFragments(
- column.def.origins
+ const attributions = this.columnsWithSourcesCondensed.flatMap(
+ (column) => {
+ // if the variable metadata specifies an attribution on the
+ // variable level then this is preferred over assembling it from
+ // the source and origins
+ if (
+ column.def.attribution !== undefined &&
+ column.def.attribution !== ""
)
- return [column.source.name, ...originFragments]
+ return [column.def.attribution]
+ else {
+ const originFragments = getOriginAttributionFragments(
+ column.def.origins
+ )
+ return [column.source.name, ...originFragments]
+ }
}
- })
+ )
const uniqueAttributions = uniq(compact(attributions))
diff --git a/packages/@ourworldindata/grapher/src/modal/SourcesModal.stories.tsx b/packages/@ourworldindata/grapher/src/modal/SourcesModal.stories.tsx
index ffdd7e1124e..77265545a49 100644
--- a/packages/@ourworldindata/grapher/src/modal/SourcesModal.stories.tsx
+++ b/packages/@ourworldindata/grapher/src/modal/SourcesModal.stories.tsx
@@ -9,9 +9,11 @@ export default {
export const WithSources = (): JSX.Element => (
)
export const NoSources = (): JSX.Element => (
-
+
)
diff --git a/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx b/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx
index 2033f6ec7a4..95b771330d6 100644
--- a/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx
+++ b/packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx
@@ -16,7 +16,7 @@ import { Modal } from "./Modal"
export interface SourcesModalManager {
adminBaseUrl?: string
- columnsWithSources: CoreColumn[]
+ columnsWithSourcesExtensive: CoreColumn[]
showAdminControls?: boolean
isSourcesModalOpen?: boolean
tabBounds?: Bounds
@@ -268,7 +268,7 @@ export class SourcesModal extends React.Component<{
}
render(): JSX.Element {
- const cols = this.manager.columnsWithSources
+ const cols = this.manager.columnsWithSourcesExtensive
return (