Skip to content

Commit

Permalink
refactor(grapher): add presentation property to CoreColumnDef
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Oct 17, 2023
1 parent b127a7b commit 50902bb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
8 changes: 3 additions & 5 deletions packages/@ourworldindata/core-table/src/CoreColumnDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ToleranceStrategy,
OwidOrigin,
OwidSource,
OwidVariablePresentation,
} from "@ourworldindata/utils"
import { CoreValueType, Color } from "./CoreTableConstants.js"

Expand Down Expand Up @@ -63,9 +64,6 @@ export interface CoreColumnDef extends ColumnColorScale {

// Column information used for display only
name?: string // The display name for the column
titlePublic?: string // The Metadata V2 display title for the variable
titleVariant?: string // The Metadata V2 title disambiguation fragment for the variant (e.g. "projected")
attributionShort?: string // The Metadata V2 title disambiguation fragment for the producer
description?: string
descriptionShort?: string
descriptionProcessing?: string
Expand All @@ -78,11 +76,11 @@ export interface CoreColumnDef extends ColumnColorScale {

// Source information used for display only
source?: OwidSource
attribution?: string
timespanFromMetadata?: string

// Origins
// Metadata v2
origins?: OwidOrigin[]
presentation?: Omit<OwidVariablePresentation, "topicTagsLinks">

// Dataset information
datasetId?: number
Expand Down
7 changes: 4 additions & 3 deletions packages/@ourworldindata/grapher/src/core/Grapher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1490,14 +1490,15 @@ export class Grapher

@computed private get defaultSourcesLine(): string {
const attributions = this.columnsWithSources.flatMap((column) => {
const { presentation = {} } = column.def
// 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 !== ""
presentation.attribution !== undefined &&
presentation.attribution !== ""
)
return [column.def.attribution]
return [presentation.attribution]
else {
const originFragments = getOriginAttributionFragments(
column.def.origins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,11 +563,9 @@ const columnDefFromOwidVariable = (
display,
timespan,
nonRedistributable,
presentation,
} = variable

const { attribution, titlePublic, titleVariant, attributionShort } =
variable.presentation || {}

// Without this the much used var 123 appears as "Countries Continent". We could rename in Grapher but not sure the effects of that.
const isContinent = variable.id === 123
const name = isContinent ? "Continent" : variable.name
Expand All @@ -591,10 +589,7 @@ const columnDefFromOwidVariable = (
source,
timespanFromMetadata: timespan,
origins,
attribution,
titlePublic,
titleVariant,
attributionShort,
presentation,
owidVariableId: variable.id,
type: isContinent
? ColumnTypeNames.Continent
Expand Down
8 changes: 5 additions & 3 deletions packages/@ourworldindata/grapher/src/modal/SourcesModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class SourcesModal extends React.Component<{
// made when the CoreColumn is filled from the Variable metadata
// in columnDefFromOwidVariable in packages/@ourworldindata/grapher/src/core/LegacyToOwidTable.ts
const { slug, source, def } = column
const { datasetId, coverage } = def as OwidColumnDef
const { datasetId, coverage, presentation } = def as OwidColumnDef

// there will not be a datasetId for explorers that define the FASTT in TSV
const editUrl =
Expand All @@ -83,8 +83,10 @@ export class SourcesModal extends React.Component<{
)}`

const title =
column.def.titlePublic && column.def.titlePublic !== ""
? column.def.titlePublic
presentation &&
presentation.titlePublic &&
presentation.titlePublic !== ""
? presentation.titlePublic
: column.name

const retrievedDate =
Expand Down

0 comments on commit 50902bb

Please sign in to comment.