diff --git a/components/widgets/land-cover/fao-cover/index.js b/components/widgets/land-cover/fao-cover/index.js index aa4f4ecb8b..82dc0d0343 100644 --- a/components/widgets/land-cover/fao-cover/index.js +++ b/components/widgets/land-cover/fao-cover/index.js @@ -25,23 +25,36 @@ export default { }, settings: { unit: 'ha', + faoYear: 2020, }, + refetchKeys: ['faoYear'], sentences: { globalInitial: - 'According to the FAO, in {year}, {percent}% ({amountInHectares}) of the globe was covered by forest. Of this, {primaryPercent}%, was primary forest.', + 'According to the FAO, in {year}, {percent} ({amountInHectares}) of the globe was covered by forest. Of this, {primaryPercent}, was primary forest.', // globalInitial: // 'FAO data from 2015 shows that there are {extent} of forest {location}, with primary forest occupying {primaryPercent} of the world.', globalNoPrimary: 'FAO data from 2015 shows that there are {extent} of forest {location}, which occupies {primaryPercent} of the world.', initial: - 'According to the FAO, in {year}, {percent}% ({amountInHectares}) of {country} was covered by forest. Of this, {primaryPercent}%, was primary forest.', + 'According to the FAO, in {year}, {percent} ({amountInHectares}) of {country} was covered by forest. Of this, {primaryPercent}, was primary forest.', // initial: // 'FAO data from 2015 shows that {location} contains {extent} of forest, with primary forest occupying {primaryPercent} of the country.', noPrimary: 'FAO data from 2015 shows that {location} contains {extent} of forest, which occupies {primaryPercent} of the country.', }, - getData: (params) => - all([getFAOExtent({ ...params }), getRanking({ ...params })]).then( + getSettingsConfig: () => { + return [ + { + key: 'faoYear', + label: 'Period', + type: 'select', + clearable: false, + border: true, + }, + ]; + }, + getData: (params) => { + return all([getFAOExtent({ ...params }), getRanking({ ...params })]).then( spread((getFAOResponse, getRankingResponse) => { let data = {}; const fao = getFAOResponse.data.rows; @@ -64,7 +77,8 @@ export default { } return data; }) - ), + ); + }, getDataURL: ({ params }) => [getFAOExtent({ ...params, download: true })], getWidgetProps, }; diff --git a/components/widgets/land-cover/fao-cover/selectors.js b/components/widgets/land-cover/fao-cover/selectors.js index 45aa67509c..1ff159a6d3 100644 --- a/components/widgets/land-cover/fao-cover/selectors.js +++ b/components/widgets/land-cover/fao-cover/selectors.js @@ -8,6 +8,7 @@ const getLocationName = (state) => state.locationLabel; const getColors = (state) => state.colors; const getSentences = (state) => state.sentences; const getTitle = (state) => state.title; +const getSettings = (state) => state.settings; // get lists selected export const parseData = createSelector( @@ -60,19 +61,29 @@ export const parseData = createSelector( ); export const parseSentence = createSelector( - [getData, getLocationName, getSentences], - (data, locationName, sentences) => { + [getData, getLocationName, getSentences, getSettings], + (data, locationName, sentences, settings) => { if (isEmpty(data)) return null; const { initial, noPrimary, globalInitial, globalNoPrimary } = sentences; - const { area_ha, extent, forest_primary } = data; + const { area_ha, extent, forest_primary, planted_forest } = data; + const { faoYear } = settings; const primaryPercent = forest_primary > 0 ? (forest_primary / area_ha) * 100 : (extent / area_ha) * 100; + const percent = (planted_forest / area_ha) * 100; const params = { location: locationName === 'global' ? 'globally' : locationName, extent: formatNumber({ num: extent, unit: 'ha', spaceUnit: true }), primaryPercent: formatNumber({ num: primaryPercent, unit: '%' }), + year: faoYear, + percent: formatNumber({ num: percent, unit: '%' }), + amountInHectares: formatNumber({ + num: area_ha, + unit: 'ha', + spaceUnit: true, + }), + country: locationName, }; let sentence = forest_primary > 0 ? initial : noPrimary; if (locationName === 'global') { diff --git a/components/widgets/options.js b/components/widgets/options.js index 151af483b5..e835b6701e 100644 --- a/components/widgets/options.js +++ b/components/widgets/options.js @@ -18,6 +18,7 @@ import confidence from 'data/confidence.json'; import bioTypes from 'data/biodiversity-int.json'; import ifl from 'data/ifl.json'; import source from 'data/sources.json'; +import faoYear from 'data/fao-cover-years.json'; export default { forestType: forestType.filter((f) => !f.hidden), @@ -25,6 +26,7 @@ export default { threshold, decile, firesThreshold, + faoYear, unit, gasesIncluded, period, diff --git a/data/fao-cover-years.json b/data/fao-cover-years.json new file mode 100644 index 0000000000..1ef734f3f6 --- /dev/null +++ b/data/fao-cover-years.json @@ -0,0 +1,18 @@ +[ + { + "label": "2000", + "value": 2000 + }, + { + "label": "2010", + "value": 2010 + }, + { + "label": "2015", + "value": 2015 + }, + { + "label": "2020", + "value": 2020 + } +] diff --git a/services/forest-data.js b/services/forest-data.js index 1ddf20e533..971fe141d1 100644 --- a/services/forest-data.js +++ b/services/forest-data.js @@ -44,13 +44,13 @@ const getLocationQuery = (adm0, adm1, adm2) => adm2 ? ` AND adm2 = ${adm2}` : '' }`; -export const getFAOExtent = async ({ adm0, year = 2020, download }) => { +export const getFAOExtent = async ({ adm0, faoYear = 2020, download }) => { const target = download ? 'csv' : 'json'; const url = `/dataset/fao_forest_extent/v2020/query/${target}?sql=${NEW_SQL_QUERIES.faoExtent}` .replace('{location}', adm0 ? `iso = '${adm0}'` : '1 = 1') - .replace('{year}', year); + .replace('{year}', faoYear); if (download) { return {