Home Reference Source

Function

Static Public Summary
public

addGoal(params: Object): Object

Add a goal to the store.

public

addGoals(options: Object): Object[]

Add all goals to the store.

public

addIndicator(indicator: Object): Object

Add an indicator to the store

public

Add the spillover assessment to the store

public

Add a LNOB to the store.

public

Add all lnobs to the store.

public

addObservation(observation: Object): Object

Add an observation to the store

public

Add the overall assessment to the store

public

addRegion(region: Object): Object

Add a region to the store

public

Add the spillover assessment to the store

public

addTimeseries(timeseries: Object): Object

Add timeseries to the store.

public

Convert score to rating color.

public

Convert a sheet in an Excel file into JSON format.

public

Find an assessment by its ID.

public

Find an assessment by its slug.

public

findAssessmentForRegionById(region: Object, assessmentId: string): Object

Find a specific assessment by ID and include the observation for the given region.

public

Find a specific goal by assessment ID and include the observation for the given region.

public

Find an indicator by its ID.

public

Find an indicator by its slug.

public

Find a specific indicator by ID and include the observation for the given region.

public

findIndicatorForRegionBySlug(region: Object, indicatorSlug: string): Object

Find a specific indicator by slug and include the observation for the given region.

public

Get the leave-no-one-behind assessment.

public

Get the leave-no-one-behind assessment, including the observation for the given region.

public

Find the observation for the given region and assessment.

public

Get the overall SDG Index assessment.

public

Get the overall SDG Index assessment, including the observation for the given region.

public

Find a region by its ID.

public

Find a region by its slug.

public

Find a specific region by ID and include the observation for the given assessment.

public

Get the spillover index assessment.

public

Get the spillover index assessment, including the observation for the given region.

public

Find the timeseries for a specific region and assessment.

public

Find the timeseries for a specific region and indicator.

public

Get all assessments from the store.

public

getColor(sdgNumber: number): String

Get the color for an SDG with the given number.

public

getFirstYear(timeseries: Object): number

Get the first year where the timeseries has a non-null value.

public

Get all goal assessments from the store.

public

Get all goal assessments from the store, each including the respective observation for the given region.

public

Extract the unit from an indicator label.

public

Get all indicators from the store.

public

Get all indicators for the given goal from the store.

public

Get all indicators for the given lnob dimension from the store.

public

Get all indicators from the store, each including the respective observation for the given region.

public

Get all indicators for the given goal from the store, each including the respective observation for the given region.

public

Get all indicators for the given lnob dimension from the store, each including the respective observation for the given region.

public

getLabel(sdgNumber: number): String

Get the label/title for an SDG with the given number.

public

Remove the unit from the indicator label.

public

getLastYear(timeseries: Object): number

Get the last year where the timeseries has a non-null value.

public

Get the label & description for a LNOB dimension with the given number.

public

Get all LNOB assessments from the store.

public

Get all lnob assessments from the store, each including the respective observation for the given region.

public

getRank(observation: Object): number

Get the numeric rank for the given observation.

public

getRankAsText(observation: Object, fallback: string): String

Get the text rank for a given observation.

public

getRating(observation: Object): String

Get the rating for a given observation (green, yellow, orange, etc...).

public

Get all regions from the store.

public

Get all regions from the store of a given type.

public

Get all regions from the store, each including the respective observation for the given assessment.

public

Get all regions from the store, each including the respective timeseries values for the given assessment.

public

getScore(observation: Object)

Get the numeric score for the given observation.

public

getScoreAsText(observation: Object, precision: number, fallback: string): String

Get the text score for a given observation, with the given level of decimal precision.

public

getSdg(sdgNumber: number): Object

Get the label and the color for an SDG with the given number.

public

getTimeseriesValue(timeseries: Object, year: Number): number

Get timeseries value for the given year.

public

getTrend(observation: Object): string

Get the trend (e.g., "↑", "➚", etc...) for the given observation.

public

Get all trend indicators from the store.

public

getValue(observation: Object): number

Get the numeric, raw value for the given observation.

public

getValueAsText(observation: Object, precision: number, fallback: string): String

Get the text raw value for a given observation, with the given level of decimal precision.

public

getYear(observation: Object): number

Get the numeric year for the given observation.

public

getYearAsText(observation: Object, fallback: string): String

Get the text year for a given observation.

public

hasTimeseries(timeseries: Object): bool

Check if the given object has timeseries values.

public

isCountry(region: Object): bool

Check if the given region is a country.

public

Check if all datasets have already been loaded into the store.

public

isGlobalOnly(assessment: Object): bool

Check whether the given assessment is a global-only indicator (used only to assess non-OECD countries).

public

isGoal(assessment: Object): bool

Check if the given assessment is a goal.

public

isImputed(observation: Object): bool

Check if the given observation is imputed.

public

isIndicator(assessment: Object): bool

Check if the given assessment is an indicator.

public

isLnobAssessment(assessment: Object): bool

Check if the given assessment is the leave-no-one-behind performance.

public

isLnobDimension(assessment: Object): bool

Check if the given assessment is a LNOB dimension.

public

isOecd(region: Object): bool

Check whether the given region is a member of the OECD.

public

isOecdOnly(assessment: Object): bool

Check whether the given assessment is an OECD-only indicator (used only to assess OECD countries).

public

isOverallAssessment(assessment: Object): bool

Check if the given assessment is the overall SDG Index performance.

public

isRelevantIndicatorForRegion(assessment: Object, region: Object): bool

Check whether the given assessment is a relevant indicator for the region.

public

isSpilloverAssessment(assessment: Object): bool

Check if the given assessment is the overall spillover index performance.

public

isTrendIndicator(assessment: Object): bool

Check if the given assessment is a trend indicator.

public

loadData(options: Object): Promise

Loads data (assessments, regions, observations, ...) into store.

public

roundNumber(number: string | number, precision: number): number

Round a number to a given level of precision.

public

Use any @sdgindex/data functions in a React component.

public

Write the store to a series of human-readable and minified JSON files.

Static Private Summary
private

addAssessment(assessment: Object): Object

Add an assessment to the store.

private

decodeObject(array: Array, encoding: Array): Object

Decode the given array back into an object structure, based on the provided encoding.

private

Determine object encoding by counting the number of times each property/key appears in the objects.

private

encodeObject(object: Object, encoding: Array): Array

Convert the given object into array, which requires less space and is faster to load.

private

ensureDataIds(param: *)

Ensure dataId prop is present on the object, otherwise load dataId from store The dataId prop is added permanently to the object, so that we don't have to reload it again and again.

private

Load a single dataset into the store.

Static Public

public addGoal(params: Object): Object source

import {addGoal} from '@sdgindex/data/parse'

Add a goal to the store.

Params:

NameTypeAttributeDescription
params Object
params.number number

the goals to add, e.g., 1 for SDG 1, 2 for SDG 2.

params.label string
  • optional

can be used to overwrite the default label

params.description string
  • optional

can be used to overwrite the default description

Return:

Object

the goal that was added to the store

public addGoals(options: Object): Object[] source

import {addGoals} from '@sdgindex/data/parse'

Add all goals to the store. Optionally, skip certain goals by passing the except argument.

Params:

NameTypeAttributeDescription
options Object
  • optional
options.except number[]
  • optional

the goals to skip, e.g., 1 for SDG 1, 2 for SDG 2.

Return:

Object[]

an array of the goals that were added to the store

public addIndicator(indicator: Object): Object source

import {addIndicator} from '@sdgindex/data/parse'

Add an indicator to the store

Params:

NameTypeAttributeDescription
indicator Object
indicator.id string

The unique ID for the indicator

indicator.goalNumber number

The goal to which the indicator belongs, e.g., 1 for SDG 1, 2 for SDG 2.

indicator.labelWithUnit string
  • optional

The label for the indicater, including the unit. Used to automatically generate the slug, label, and unit. Alternatively, slug, label, and unit properties can be set manually.

indicator.slug string
  • optional

The slug for the indicator, usually automatically generated from labelWithUnit.

indicator.label string
  • optional

The label for the indicator, usually automatically generated from labelWithUnit.

indicator.unit string
  • optional

The unit for the indicator, usually automatically generated from labelWithUnit.

indicator.params ...Object
  • optional

any other params to add to the indicator, such as description or source

Return:

Object

the indicator that was added to the store

public addLnobAssessment(params: Object): Object source

import {addLnobAssessment} from '@sdgindex/data/parse'

Add the spillover assessment to the store

Params:

NameTypeAttributeDescription
params Object
  • optional

any custom parameters to add to the assessment or default properties to overwrite

Return:

Object

the spillover assessment that was added to the store

public addLnobDimension(params: Object): Object source

import {addLnobDimension} from '@sdgindex/data/parse'

Add a LNOB to the store.

Params:

NameTypeAttributeDescription
params Object
params.number number

the LNOBs to add, e.g., 1 for LNOB 1, 2 for LNOB 2.

params.label string
  • optional

can be used to overwrite the default label

params.description string
  • optional

can be used to overwrite the default description

Return:

Object

the LNOB that was added to the store

public addLnobDimensions(options: Object): Object[] source

import {addLnobDimensions} from '@sdgindex/data/parse'

Add all lnobs to the store. Optionally, skip certain lnobs by passing the except argument.

Params:

NameTypeAttributeDescription
options Object
  • optional
options.except number[]
  • optional

the lnobs to skip, e.g., 1 for LNOB 1, 2 for LNOB 2.

Return:

Object[]

an array of the lnobs that were added to the store

public addObservation(observation: Object): Object source

import {addObservation} from '@sdgindex/data/parse'

Add an observation to the store

Params:

NameTypeAttributeDescription
observation Object
observation.region Object

the region to which the observation belongs

observation.assessment Object

the assessment to which the observation belongs

observation.score number
  • optional

the score of the region on the assessment

observation.rank number
  • optional

the rank of the region on the assessment

observation.rating string
  • optional

the rating of the region on the assessment, e.g., green, yellow, orange, red, or gray

observation.trend string
  • optional
  • nullable: true

the trend of the region on the assessment, e.g., , , , , or null

observation.value number
  • optional

the raw value of the region on the assessment (applicable to indicators only)

observation.year number
  • optional

the raw value of the region on the assessment (applicable to indicators only)

observation.isImputed boolean
  • optional
  • default: false

whether the observation is imputed (true or false)

observation.params ...Object
  • optional

any other properties to store on the observation

Return:

Object

the observation that was added to the store

public addOverallAssessment(params: Object): Object source

import {addOverallAssessment} from '@sdgindex/data/parse'

Add the overall assessment to the store

Params:

NameTypeAttributeDescription
params Object
  • optional

any custom parameters to add to the assessment or default properties to overwrite

Return:

Object

the overall assessment that was added to the store

public addRegion(region: Object): Object source

import {addRegion} from '@sdgindex/data/parse'

Add a region to the store

Params:

NameTypeAttributeDescription
region Object
region.id string

the unique ID for the region

region.name string

The name of the region. Used to automatically generate the region slug.

region.type string

the type of the region, e.g., country or city

region.slug string
  • optional

provide a slug to overwrite the auto-generated slug

region.params ...Object
  • optional

any other params to add to the region, such as population or GDP

Return:

Object

the region that was added to the store

public addSpilloverAssessment(params: Object): Object source

import {addSpilloverAssessment} from '@sdgindex/data/parse'

Add the spillover assessment to the store

Params:

NameTypeAttributeDescription
params Object
  • optional

any custom parameters to add to the assessment or default properties to overwrite

Return:

Object

the spillover assessment that was added to the store

public addTimeseries(timeseries: Object): Object source

import {addTimeseries} from '@sdgindex/data/parse'

Add timeseries to the store. If the values of all data points are null, the series is not added.

Params:

NameTypeAttributeDescription
timeseries Object
timeseries.region Object

the region to which the timeseries belongs

timeseries.assessment Object

the assessment to which the timeseries belongs

timeseries.dataPoints Object[]

an array of data points

timeseries.dataPoints[].year number

the year of the data point

timeseries.dataPoints[].value number

the value of the data point

Return:

Object

the timeseries object that was added to the store

public convertScoreToColor(colorScore: number): string source

import {convertScoreToColor} from '@sdgindex/data/parse'

Convert score to rating color. Color scores are sometimes used in the US SDG Index.

  • colorScore below 1 => red
  • colorScore below 2 => orange
  • colorScore below 3 => yellow
  • colorScore over or equal 3 => green
  • colorScore null | undefined => gray

Params:

NameTypeAttributeDescription
colorScore number

The numeric color score

Return:

string

Return the color as string

public excelToJson(param: Object): Array source

import {excelToJson} from '@sdgindex/data/parse'

Convert a sheet in an Excel file into JSON format. See: https://www.npmjs.com/package/xlsx

Params:

NameTypeAttributeDescription
param Object
param.file string

the path to the Excel file to convert

param.sheet string
  • optional

the name of the sheet to convert. If not provided, the first sheet in the Excel file will be used.

Return:

Array

the converted sheet as an array of objects. See: https://www.npmjs.com/package/xlsx#json

public findAssessmentById(id: String): Object source

import {findAssessmentById} from '@sdgindex/data'

Find an assessment by its ID.

Params:

NameTypeAttributeDescription
id String

The UNIQUE id associated with the assessment

Return:

Object

return an object of the assessment {id:..., name:..., ...}

public findAssessmentBySlug(slug: String): Object source

import {findAssessmentBySlug} from '@sdgindex/data'

Find an assessment by its slug.

Params:

NameTypeAttributeDescription
slug String

The UNIQUE slug associated with the assessment

Return:

Object

return an object of the assessment {id:..., name:..., ...}

public findAssessmentForRegionById(region: Object, assessmentId: string): Object source

import {findAssessmentForRegionById} from '@sdgindex/data'

Find a specific assessment by ID and include the observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observation

assessmentId string

The ID for which to find the assessment

Return:

Object

return the assessment, including the observation for the given region

public findGoalForRegionById(region: Object, goalId: string): Object source

import {findGoalForRegionById} from '@sdgindex/data'

Find a specific goal by assessment ID and include the observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observation

goalId string

The ID for which to find the goal

Return:

Object

return the goal, including the observation for the given region

public findIndicatorById(id: String): Object source

import {findIndicatorById} from '@sdgindex/data'

Find an indicator by its ID.

Params:

NameTypeAttributeDescription
id String

Return:

Object

return the indicator

public findIndicatorBySlug(slug: String): Object source

import {findIndicatorBySlug} from '@sdgindex/data'

Find an indicator by its slug.

Params:

NameTypeAttributeDescription
slug String

Return:

Object

return the indicator

public findIndicatorForRegionById(region: Object, indicatorId: string): Object source

import {findIndicatorForRegionById} from '@sdgindex/data'

Find a specific indicator by ID and include the observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observation

indicatorId string

The ID for which to find the indicator

Return:

Object

return the indicator, including the observation for the given region

public findIndicatorForRegionBySlug(region: Object, indicatorSlug: string): Object source

import {findIndicatorForRegionBySlug} from '@sdgindex/data'

Find a specific indicator by slug and include the observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observation

indicatorSlug string

The slug for which to find the indicator

Return:

Object

return the indicator, including the observation for the given region

public findLnobAssessment(): Object source

import {findLnobAssessment} from '@sdgindex/data'

Get the leave-no-one-behind assessment.

Return:

Object

public findLnobAssessmentForRegion(region: Object): Object source

import {findLnobAssessmentForRegion} from '@sdgindex/data'

Get the leave-no-one-behind assessment, including the observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

Return:

Object

return the LNOB assessment, including the observation for the given region

public findObservationByRegionAndAssessment(region: Object, assessment: Object): Object source

import {findObservationByRegionAndAssessment} from '@sdgindex/data'

Find the observation for the given region and assessment.

Params:

NameTypeAttributeDescription
region Object
assessment Object

Return:

Object (nullable: true)

return the observation

public findOverallAssessment(): Object source

import {findOverallAssessment} from '@sdgindex/data'

Get the overall SDG Index assessment.

Return:

Object

public findOverallAssessmentForRegion(region: Object): Object source

import {findOverallAssessmentForRegion} from '@sdgindex/data'

Get the overall SDG Index assessment, including the observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

Return:

Object

return the overall assessment, including the observation for the given region

public findRegionById(id: String): Object source

import {findRegionById} from '@sdgindex/data'

Find a region by its ID.

Params:

NameTypeAttributeDescription
id String

Return:

Object

return the region

public findRegionBySlug(slug: String): Object source

import {findRegionBySlug} from '@sdgindex/data'

Find a region by its slug.

Params:

NameTypeAttributeDescription
slug String

Return:

Object

return the region

public findRegionWithAssessmentById(assessment: Object, regionId: string): Object source

import {findRegionWithAssessmentById} from '@sdgindex/data'

Find a specific region by ID and include the observation for the given assessment.

Params:

NameTypeAttributeDescription
assessment Object

the assessment for which to load the observation

regionId string

The ID for which to find the region

Return:

Object

return the region, including the observation for the given assessment

public findSpilloverAssessment(): Object source

import {findSpilloverAssessment} from '@sdgindex/data'

Get the spillover index assessment.

Return:

Object

public findSpilloverAssessmentForRegion(region: Object): Object source

import {findSpilloverAssessmentForRegion} from '@sdgindex/data'

Get the spillover index assessment, including the observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

Return:

Object

return the overallspillover index assessment, including the observation for the given region

public findTimeseriesByRegionAndAssessment(region: Object, assessment: Object): Array source

import {findTimeseriesByRegionAndAssessment} from '@sdgindex/data'

Find the timeseries for a specific region and assessment.

Params:

NameTypeAttributeDescription
region Object
assessment Object

Return:

Array (nullable: true)

return the timeseries (or null, if none exist)

public findTimeseriesByRegionAndIndicator(region: Object, indicator: Object): Array source

import {findTimeseriesByRegionAndIndicator} from '@sdgindex/data'

Find the timeseries for a specific region and indicator.

Params:

NameTypeAttributeDescription
region Object
indicator Object

Return:

Array (nullable: true)

return the timeseries (or null, if none exist)

public getAssessments(): Array source

import {getAssessments} from '@sdgindex/data'

Get all assessments from the store.

Return:

Array

return an array of assessments

public getColor(sdgNumber: number): String source

import {getColor} from '@sdgindex/data/sdgs'

Get the color for an SDG with the given number.

Params:

NameTypeAttributeDescription
sdgNumber number

The number of the SDG (1 - 17)

Return:

String

Return goal color (HEX code)

public getFirstYear(timeseries: Object): number source

import {getFirstYear} from '@sdgindex/data/timeseries'

Get the first year where the timeseries has a non-null value.

Params:

NameTypeAttributeDescription
timeseries Object

Return:

number (nullable: true)

public getGoals(): Array source

import {getGoals} from '@sdgindex/data'

Get all goal assessments from the store.

Return:

Array

return an array of goals

public getGoalsForRegion(region: Object): Array source

import {getGoalsForRegion} from '@sdgindex/data'

Get all goal assessments from the store, each including the respective observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

Return:

Array

return an array of goals, each including the respective observation for the given region

public getIndicatorUnit(label: string): string | null source

import {getIndicatorUnit} from '@sdgindex/data/parse'

Extract the unit from an indicator label. Assumes that the unit is wrapped in parentheses. For example: "CO₂ emissions (kg/capita)"

Params:

NameTypeAttributeDescription
label string

the label with unit

Return:

string | null

the unit (or null, if no unit)

public getIndicators(): Array source

import {getIndicators} from '@sdgindex/data'

Get all indicators from the store.

Return:

Array

return an array of indicators

public getIndicatorsByGoal(goal: Object): Array source

import {getIndicatorsByGoal} from '@sdgindex/data'

Get all indicators for the given goal from the store.

Params:

NameTypeAttributeDescription
goal Object

The goal for which to load the indicators

Return:

Array

return an array of indicators

public getIndicatorsByLnobDimension(dimension: Object): Array source

import {getIndicatorsByLnobDimension} from '@sdgindex/data'

Get all indicators for the given lnob dimension from the store.

Params:

NameTypeAttributeDescription
dimension Object

The lnob dimension for which to load the indicators

Return:

Array

return an array of indicators

public getIndicatorsForRegion(region: Object): Array source

import {getIndicatorsForRegion} from '@sdgindex/data'

Get all indicators from the store, each including the respective observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

Return:

Array

return an array of indicators, each including the respective observation for the given region

public getIndicatorsForRegionByGoal(region: Object, goal: Object): Array source

import {getIndicatorsForRegionByGoal} from '@sdgindex/data'

Get all indicators for the given goal from the store, each including the respective observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

goal Object

The goal for which to load the indicators

Return:

Array

return an array of indicators, each including the respective observation for the given region

public getIndicatorsForRegionByLnobDimension(region: Object, dimension: Object): Array source

import {getIndicatorsForRegionByLnobDimension} from '@sdgindex/data'

Get all indicators for the given lnob dimension from the store, each including the respective observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

dimension Object

The lnob dimension for which to load the indicators

Return:

Array

return an array of indicators, each including the respective observation for the given region

public getLabel(sdgNumber: number): String source

import {getLabel} from '@sdgindex/data/sdgs'

Get the label/title for an SDG with the given number.

Params:

NameTypeAttributeDescription
sdgNumber number

The number of the SDG (1 - 17)

Return:

String

Return goal label/title

public getLabelWithoutUnit(label: string): string source

import {getLabelWithoutUnit} from '@sdgindex/data/parse'

Remove the unit from the indicator label. Assumes that the unit is wrapped in parentheses. For example: "CO₂ emissions (kg/capita)"

Params:

NameTypeAttributeDescription
label string

the label with unit

Return:

string

the label without the unit

public getLastYear(timeseries: Object): number source

import {getLastYear} from '@sdgindex/data/timeseries'

Get the last year where the timeseries has a non-null value.

Params:

NameTypeAttributeDescription
timeseries Object

Return:

number (nullable: true)

public getLnobDimension(dimNumber: number): Object source

import {getLnobDimension} from '@sdgindex/data/sdgs'

Get the label & description for a LNOB dimension with the given number.

Params:

NameTypeAttributeDescription
dimNumber number

The number of the LNOB (1 - 4)

Return:

Object

Return LNOB label & description

public getLnobDimensions(): Array source

import {getLnobDimensions} from '@sdgindex/data'

Get all LNOB assessments from the store.

Return:

Array

return an array of LNOB dimensions

public getLnobDimensionsForRegion(region: Object): Array source

import {getLnobDimensionsForRegion} from '@sdgindex/data'

Get all lnob assessments from the store, each including the respective observation for the given region.

Params:

NameTypeAttributeDescription
region Object

The region for which to load the observations

Return:

Array

return an array of lnob, each including the respective observation for the given region

public getRank(observation: Object): number source

import {getRank} from '@sdgindex/data/observations'

Get the numeric rank for the given observation.

Params:

NameTypeAttributeDescription
observation Object

Return:

number

public getRankAsText(observation: Object, fallback: string): String source

import {getRankAsText} from '@sdgindex/data/observations'

Get the text rank for a given observation. If rank is null, the fallback text is returned.

Params:

NameTypeAttributeDescription
observation Object
fallback string
  • optional
  • default: Not ranked

the string to return if rank is undefined or null

Return:

String

public getRating(observation: Object): String source

import {getRating} from '@sdgindex/data/observations'

Get the rating for a given observation (green, yellow, orange, etc...).

Params:

NameTypeAttributeDescription
observation Object

Return:

String

public getRegions(): Array source

import {getRegions} from '@sdgindex/data'

Get all regions from the store.

Return:

Array

return an array of regions

public getRegionsByType(type: String): Array source

import {getRegionsByType} from '@sdgindex/data'

Get all regions from the store of a given type.

Params:

NameTypeAttributeDescription
type String

The type of regions to return

Return:

Array

return an array of regions

public getRegionsWithAssessment(assessment: Object): Array source

import {getRegionsWithAssessment} from '@sdgindex/data'

Get all regions from the store, each including the respective observation for the given assessment.

Params:

NameTypeAttributeDescription
assessment Object

the assessment for which to load the observation

Return:

Array

return an array of regions, each including the observation for the given assessment

public getRegionsWithTimeseries(assessment: Object): Array source

import {getRegionsWithTimeseries} from '@sdgindex/data'

Get all regions from the store, each including the respective timeseries values for the given assessment.

Params:

NameTypeAttributeDescription
assessment Object

the assessment for which to load the timeseries

Return:

Array

return an array of regions, each including the timeseries values for the given assessment

public getScore(observation: Object) source

import {getScore} from '@sdgindex/data/observations'

Get the numeric score for the given observation.

Params:

NameTypeAttributeDescription
observation Object

public getScoreAsText(observation: Object, precision: number, fallback: string): String source

import {getScoreAsText} from '@sdgindex/data/observations'

Get the text score for a given observation, with the given level of decimal precision. If the score is null, the fallback text is returned.

Params:

NameTypeAttributeDescription
observation Object
precision number
  • optional
  • default: 2

number of desired decimal digits

fallback string
  • optional
  • default: Not scored

the string to return if score is undefined or null

Return:

String

public getSdg(sdgNumber: number): Object source

import {getSdg} from '@sdgindex/data/sdgs'

Get the label and the color for an SDG with the given number.

Params:

NameTypeAttributeDescription
sdgNumber number

The number of the SDG (1 - 17)

Return:

Object

Return SDG label and color

public getTimeseriesValue(timeseries: Object, year: Number): number source

import {getTimeseriesValue} from '@sdgindex/data/timeseries'

Get timeseries value for the given year.

Params:

NameTypeAttributeDescription
timeseries Object
year Number

Return:

number (nullable: true)

public getTrend(observation: Object): string source

import {getTrend} from '@sdgindex/data/observations'

Get the trend (e.g., "↑", "➚", etc...) for the given observation.

Params:

NameTypeAttributeDescription
observation Object

Return:

string (nullable: true)

public getTrendIndicators(): Array source

import {getTrendIndicators} from '@sdgindex/data'

Get all trend indicators from the store.

Return:

Array

return an array of trend indicators

public getValue(observation: Object): number source

import {getValue} from '@sdgindex/data/observations'

Get the numeric, raw value for the given observation.

Params:

NameTypeAttributeDescription
observation Object

Return:

number

public getValueAsText(observation: Object, precision: number, fallback: string): String source

import {getValueAsText} from '@sdgindex/data/observations'

Get the text raw value for a given observation, with the given level of decimal precision. If the raw value is null, the fallback text is returned.

Params:

NameTypeAttributeDescription
observation Object
precision number
  • optional
  • default: 2

number of desired decimal digits

fallback string
  • optional
  • default: Value unavailable

the string to return if the raw value is undefined or null

Return:

String

public getYear(observation: Object): number source

import {getYear} from '@sdgindex/data/observations'

Get the numeric year for the given observation.

Params:

NameTypeAttributeDescription
observation Object

Return:

number

public getYearAsText(observation: Object, fallback: string): String source

import {getYearAsText} from '@sdgindex/data/observations'

Get the text year for a given observation. If year is null, the fallback text is returned.

Params:

NameTypeAttributeDescription
observation Object
fallback string
  • optional
  • default: Year unavailable

the string to return if year is undefined or null

Return:

String

public hasTimeseries(timeseries: Object): bool source

import {hasTimeseries} from '@sdgindex/data/timeseries'

Check if the given object has timeseries values.

Params:

NameTypeAttributeDescription
timeseries Object

Return:

bool

Return true if the object has timeseries

public isCountry(region: Object): bool source

import {isCountry} from '@sdgindex/data/regions'

Check if the given region is a country.

Params:

NameTypeAttributeDescription
region Object

Return:

bool

return true if the given region is a country

public isDataLoaded(options: Object): boolean source

import {isDataLoaded} from '@sdgindex/data'

Check if all datasets have already been loaded into the store.

Params:

NameTypeAttributeDescription
options Object
  • optional
options.timeseries boolean
  • optional
  • default: false

whether to also check if timeseries data have been loaded

Return:

boolean

true if all datasets have already been loaded

public isGlobalOnly(assessment: Object): bool source

import {isGlobalOnly} from '@sdgindex/data/assessments'

Check whether the given assessment is a global-only indicator (used only to assess non-OECD countries).

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if the assessment is a global-only indicator

public isGoal(assessment: Object): bool source

import {isGoal} from '@sdgindex/data/assessments'

Check if the given assessment is a goal.

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if assessment type is "goal"

public isImputed(observation: Object): bool source

import {isImputed} from '@sdgindex/data/observations'

Check if the given observation is imputed.

Params:

NameTypeAttributeDescription
observation Object

Return:

bool

Return true if observation is imputed

public isIndicator(assessment: Object): bool source

import {isIndicator} from '@sdgindex/data/assessments'

Check if the given assessment is an indicator.

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if assessment type is "indicator"

public isLnobAssessment(assessment: Object): bool source

import {isLnobAssessment} from '@sdgindex/data/assessments'

Check if the given assessment is the leave-no-one-behind performance.

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if assessment is the LNOB performance

public isLnobDimension(assessment: Object): bool source

import {isLnobDimension} from '@sdgindex/data/assessments'

Check if the given assessment is a LNOB dimension.

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if assessment type is "lnob"

public isOecd(region: Object): bool source

import {isOecd} from '@sdgindex/data/regions'

Check whether the given region is a member of the OECD.

Params:

NameTypeAttributeDescription
region Object

Return:

bool

return true if the region is a member of the OECD

public isOecdOnly(assessment: Object): bool source

import {isOecdOnly} from '@sdgindex/data/assessments'

Check whether the given assessment is an OECD-only indicator (used only to assess OECD countries).

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if the assessment is an OECD-only indicator

public isOverallAssessment(assessment: Object): bool source

import {isOverallAssessment} from '@sdgindex/data/assessments'

Check if the given assessment is the overall SDG Index performance.

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if assessment is the overall SDG Index performance

public isRelevantIndicatorForRegion(assessment: Object, region: Object): bool source

import {isRelevantIndicatorForRegion} from '@sdgindex/data/assessments'

Check whether the given assessment is a relevant indicator for the region.

Params:

NameTypeAttributeDescription
assessment Object
region Object

Return:

bool

Return true if the assessment is a relevant indicator for the region

public isSpilloverAssessment(assessment: Object): bool source

import {isSpilloverAssessment} from '@sdgindex/data/assessments'

Check if the given assessment is the overall spillover index performance.

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

return true if the assessment is the overall spillover index performance

public isTrendIndicator(assessment: Object): bool source

import {isTrendIndicator} from '@sdgindex/data/assessments'

Check if the given assessment is a trend indicator.

Params:

NameTypeAttributeDescription
assessment Object

Return:

bool

Return true if the assessment is a trend indicator

public loadData(options: Object): Promise source

import {loadData} from '@sdgindex/data'

Loads data (assessments, regions, observations, ...) into store.

Params:

NameTypeAttributeDescription
options Object
  • optional
options.timeseries boolean
  • optional
  • default: false

whether to load timeseries data

Return:

Promise

a promise that resolves when the datasets have been loaded

public roundNumber(number: string | number, precision: number): number source

import {roundNumber} from '@sdgindex/data/parse'

Round a number to a given level of precision.

Params:

NameTypeAttributeDescription
number string | number

the number to round (can be a string)

precision number

the level of precision to which to round (0 = whole number, 1 = one decimal, etc...)

Return:

number

the rounded number

public useDataStore(options: Object): DataStoreStatus source

import {useDataStore} from '@sdgindex/data'

Use any @sdgindex/data functions in a React component. The data store will be loaded, if not already done so. Optionally, timeseries can be loaded, too. The hook uses useState internally, so the component will be re-rendered when the data has been fully loaded.

Params:

NameTypeAttributeDescription
options Object
  • optional
options.timeseries boolean
  • optional
  • default: false

whether to load timeseries

Return:

DataStoreStatus

Example:

const MyComponent = () => {
  const { isLoaded } = useDataStore();

  if(!isLoaded) return null;

  return <div>my content</div>;
};

public writeStoreToJson() source

import {writeStoreToJson} from '@sdgindex/data/parse'

Write the store to a series of human-readable and minified JSON files. These can then be loaded/imported in the data visualization. One JSON file is created for each type of data (assessments, regions, observations, and timeseries).

Static Private

private addAssessment(assessment: Object): Object source

import {addAssessment} from '@sdgindex/data/parse'

Add an assessment to the store.

Params:

NameTypeAttributeDescription
assessment Object

Return:

Object

assessment (identical to parameter)

private decodeObject(array: Array, encoding: Array): Object source

Decode the given array back into an object structure, based on the provided encoding.

Params:

NameTypeAttributeDescription
array Array

the array to decode

encoding Array

a list of properties determining the order in which the object's values were encoded in the array, e.g., ["value", "year", "rank"]

Return:

Object

private determineObjectEncoding(objects: Array): Array source

import {determineObjectEncoding} from '@sdgindex/data/src/utilities/determineObjectEncoding.js'

Determine object encoding by counting the number of times each property/key appears in the objects. The encoding is then set to start with the property that appears most frequently and to end with the property that appears least frequently.

Params:

NameTypeAttributeDescription
objects Array

the array of objects for which to determine the best encoding

Return:

Array

the encoding, e.g., ["value", "score", "year"]

private encodeObject(object: Object, encoding: Array): Array source

Convert the given object into array, which requires less space and is faster to load. The object properties are converted into an array according to the encoding. The encoding should be an array of properties.

Params:

NameTypeAttributeDescription
object Object

the object to encode

encoding Array

a list of properties determining the order in which the object's values should appear in the encoded array, e.g., ["value", "year", "rank"]

Return:

Array

private ensureDataIds(param: *) source

import {ensureDataIds} from '@sdgindex/data'

Ensure dataId prop is present on the object, otherwise load dataId from store The dataId prop is added permanently to the object, so that we don't have to reload it again and again.

Params:

NameTypeAttributeDescription
param *
param.region Object

The region for which to add dataId

param.assessment Object

The assessment for which to add dataId

private loadDataset(dataset: Object): Promise source

import {loadDataset} from '@sdgindex/data'

Load a single dataset into the store.

Params:

NameTypeAttributeDescription
dataset Object

The dataset to load

Return:

Promise

a promise that resolves when the dataset has been loaded