Skip to content

Commit

Permalink
data-pages-fix-rendering-issues
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Oct 17, 2023
1 parent 2c333cf commit 6537b57
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
75 changes: 51 additions & 24 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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))
Expand All @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export default {

export const WithSources = (): JSX.Element => (
<SourcesModal
manager={{ columnsWithSources: SynthesizeGDPTable().columnsAsArray }}
manager={{
columnsWithSourcesExtensive: SynthesizeGDPTable().columnsAsArray,
}}
/>
)
export const NoSources = (): JSX.Element => (
<SourcesModal manager={{ columnsWithSources: [] }} />
<SourcesModal manager={{ columnsWithSourcesExtensive: [] }} />
)
4 changes: 2 additions & 2 deletions packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Modal } from "./Modal"

export interface SourcesModalManager {
adminBaseUrl?: string
columnsWithSources: CoreColumn[]
columnsWithSourcesExtensive: CoreColumn[]
showAdminControls?: boolean
isSourcesModalOpen?: boolean
tabBounds?: Bounds
Expand Down Expand Up @@ -268,7 +268,7 @@ export class SourcesModal extends React.Component<{
}

render(): JSX.Element {
const cols = this.manager.columnsWithSources
const cols = this.manager.columnsWithSourcesExtensive
return (
<Modal
title="Sources"
Expand Down

0 comments on commit 6537b57

Please sign in to comment.