diff --git a/components/widgets/forest-change/tree-cover-gain-outside-plantations/index.js b/components/widgets/forest-change/tree-cover-gain-outside-plantations/index.js index 40464e6459..293d68203c 100644 --- a/components/widgets/forest-change/tree-cover-gain-outside-plantations/index.js +++ b/components/widgets/forest-change/tree-cover-gain-outside-plantations/index.js @@ -16,6 +16,8 @@ import { EuropeFAOCountries } from 'utils/fao-countries'; import getWidgetProps from './selectors'; +const MIN_YEAR = 2000; + export default { widget: 'treeCoverGainOutsidePlantations', title: { @@ -46,12 +48,13 @@ export default { { key: 'baselineYear', label: 'Baseline Year', - type: 'select', - placeholder: '2000', + type: 'baseline-select', + startKey: 'startYear', + placeholder: MIN_YEAR, clearable: true, }, ], - refetchKeys: ['forestType', 'landCategory', 'baselineYear'], + refetchKeys: ['forestType', 'landCategory', 'startYear'], chartType: 'pieChart', colors: 'gainWithinOutsidePlantations', metaKey: 'widget_tree_cover_gain_outside_plantations', @@ -90,7 +93,8 @@ export default { }, settings: { threshold: 0, - baselineYear: 2000, + startYear: MIN_YEAR, + endYear: 2020, // reference to display the correct data on the map }, getData: (params) => { return getTreeCoverGainByPlantationType(params).then((response) => { diff --git a/components/widgets/forest-change/tree-cover-gain-outside-plantations/selectors.js b/components/widgets/forest-change/tree-cover-gain-outside-plantations/selectors.js index 4ab515e44c..fa289b6e83 100644 --- a/components/widgets/forest-change/tree-cover-gain-outside-plantations/selectors.js +++ b/components/widgets/forest-change/tree-cover-gain-outside-plantations/selectors.js @@ -41,12 +41,15 @@ export const parseSentence = createSelector( } })(); + const { baselineYear: dateFromDashboard, startYear: dateFromMapLayer } = + settings; + const params = { location: locationName, indicator: indicator && indicator.label, startYear: settings.startYear, endYear: settings.endYear, - baselineYear: settings?.baselineYear || 2000, + baselineYear: dateFromMapLayer || dateFromDashboard || 2000, gainPercent: formatNumber({ num: (100 * data?.areaOutsidePlantations) / data?.totalArea, unit: '%', diff --git a/components/widgets/forest-change/tree-cover-gain-simple/index.js b/components/widgets/forest-change/tree-cover-gain-simple/index.js index 317f95da13..12ceb291cc 100644 --- a/components/widgets/forest-change/tree-cover-gain-simple/index.js +++ b/components/widgets/forest-change/tree-cover-gain-simple/index.js @@ -14,6 +14,8 @@ import { import getWidgetProps from './selectors'; +const MIN_YEAR = 2000; + export default { widget: 'treeCoverGainSimple', title: 'Tree cover gain in {location}', @@ -24,7 +26,7 @@ export default { metaKey: 'umd_tree_cover_gain_from_height', dataType: 'gain', pendingKeys: ['threshold'], - refetchKeys: ['threshold', 'baselineYear'], + refetchKeys: ['threshold', 'startYear'], datasets: [ { dataset: POLITICAL_BOUNDARIES_DATASET, @@ -45,7 +47,8 @@ export default { settings: { threshold: 0, extentYear: 2000, - baselineYear: 2000, + startYear: MIN_YEAR, + endYear: 2020, // reference to display the correct data on the map }, chartType: 'listLegend', colors: 'gain', @@ -55,8 +58,9 @@ export default { { key: 'baselineYear', label: 'Baseline Year', - type: 'select', - placeholder: '2000', + type: 'baseline-select', + startKey: 'startYear', + placeholder: MIN_YEAR, clearable: true, }, ], diff --git a/components/widgets/forest-change/tree-cover-gain-simple/selectors.js b/components/widgets/forest-change/tree-cover-gain-simple/selectors.js index 491290e1f0..ad841a570e 100644 --- a/components/widgets/forest-change/tree-cover-gain-simple/selectors.js +++ b/components/widgets/forest-change/tree-cover-gain-simple/selectors.js @@ -14,12 +14,14 @@ export const parseSentence = createSelector( (gain, extent, sentence, location, settings) => { if (!gain && !extent) return null; const gainPerc = (gain && extent && (gain / extent) * 100) || 0; + const { baselineYear: dateFromDashboard, startYear: dateFromMapLayer } = + settings; const params = { gain: formatNumber({ num: gain, unit: 'ha', spaceUnit: true }), gainPercent: formatNumber({ num: gainPerc, unit: '%' }), location, - baselineYear: (settings?.baselineYear) || 2000, + baselineYear: dateFromMapLayer || dateFromDashboard || 2000, }; return { diff --git a/components/widgets/forest-change/tree-cover-gain/index.js b/components/widgets/forest-change/tree-cover-gain/index.js index 3e5d93f97d..6d06465504 100644 --- a/components/widgets/forest-change/tree-cover-gain/index.js +++ b/components/widgets/forest-change/tree-cover-gain/index.js @@ -47,18 +47,11 @@ export default { label: 'Baseline Year', type: 'baseline-select', startKey: 'startYear', - endKey: 2020, placeholder: MIN_YEAR, clearable: true, }, ], - refetchKeys: [ - 'forestType', - 'landCategory', - 'threshold', - 'baselineYear', - 'startYear', - ], + refetchKeys: ['forestType', 'landCategory', 'threshold', 'startYear'], chartType: 'rankedList', colors: 'gain', metaKey: 'umd_tree_cover_gain_from_height', @@ -97,7 +90,7 @@ export default { settings: { threshold: 0, startYear: MIN_YEAR, - endYear: 2020, + endYear: 2020, // reference to display the correct data on the map unit: 'ha', pageSize: 5, page: 0, diff --git a/components/widgets/forest-change/tree-gain-located/index.js b/components/widgets/forest-change/tree-gain-located/index.js index 25f876d38c..332a23d17a 100644 --- a/components/widgets/forest-change/tree-gain-located/index.js +++ b/components/widgets/forest-change/tree-gain-located/index.js @@ -13,6 +13,8 @@ import { import getWidgetProps from './selectors'; +const MIN_YEAR = 2000; + export default { widget: 'treeGainLocated', title: 'Location of tree cover gain in {location}', @@ -40,12 +42,13 @@ export default { { key: 'baselineYear', label: 'Baseline Year', - type: 'select', - placeholder: '2000', + type: 'baseline-select', + startKey: 'startYear', + placeholder: MIN_YEAR, clearable: true, }, ], - refetchKeys: ['forestType', 'landCategory', 'baselineYear'], + refetchKeys: ['forestType', 'landCategory', 'startYear'], chartType: 'rankedList', colors: 'gain', datasets: [ @@ -82,7 +85,8 @@ export default { page: 0, extentYear: 2000, ifl: 2000, - baselineYear: 2000, + startYear: MIN_YEAR, + endYear: 2020, // reference to display the correct data on the map }, getData: (params) => all([getExtentGrouped(params), getGainGrouped(params)]).then( diff --git a/components/widgets/forest-change/tree-gain-located/selectors.js b/components/widgets/forest-change/tree-gain-located/selectors.js index 8ea4c3ac2a..55f3ef8f43 100644 --- a/components/widgets/forest-change/tree-gain-located/selectors.js +++ b/components/widgets/forest-change/tree-gain-located/selectors.js @@ -57,12 +57,16 @@ export const parseSentence = createSelector( ], (data, sortedData, settings, indicator, locationName, sentences) => { if (!data || !locationName) return null; + const { initial, withIndicator, initialPercent, withIndicatorPercent } = sentences; const totalGain = sumBy(data, 'gain') || 0; const topRegion = (sortedData && sortedData.length && sortedData[0]) || {}; const avgGainPercentage = sumBy(data, 'percentage') || 0 / data.length; const avgGain = (sumBy(data, 'gain') || 0) / data.length; + const { baselineYear: dateFromDashboard, startYear: dateFromMapLayer } = + settings; + let percentileGain = 0; let percentileLength = 0; @@ -86,7 +90,7 @@ export const parseSentence = createSelector( const aveFormat = avgGain < 1 ? '.3r' : '.3s'; const params = { - baselineYear: (settings?.baselineYear) || 2000, + baselineYear: dateFromMapLayer || dateFromDashboard || 2000, indicator: indicator && indicator.label, location: locationName, topGain: formatNumber({ diff --git a/services/analysis-cached.js b/services/analysis-cached.js index e5d035b602..f5ac3608a5 100644 --- a/services/analysis-cached.js +++ b/services/analysis-cached.js @@ -890,7 +890,7 @@ export const getLossFiresGrouped = (params) => { }; export const getTreeCoverGainByPlantationType = (params) => { - const { forestType, landCategory, ifl, download, baselineYear } = params; + const { forestType, landCategory, ifl, download, startYear } = params; const requestUrl = getRequestUrl({ ...params, @@ -904,7 +904,7 @@ export const getTreeCoverGainByPlantationType = (params) => { const url = encodeURI( `${requestUrl}${sqlQuery}` - .replace('{baselineYear}', baselineYear || 2000) + .replace('{baselineYear}', startYear || 2000) .replace('{WHERE}', getWHEREQuery({ ...params })) ); @@ -1207,8 +1207,7 @@ export const getExtentGrouped = (params) => { // summed gain for single location export const getGain = (params) => { - const { forestType, landCategory, ifl, download, baselineYear } = - params || {}; + const { forestType, landCategory, ifl, download, startYear } = params || {}; const requestUrl = getRequestUrl({ ...params, @@ -1227,7 +1226,7 @@ export const getGain = (params) => { getLocationSelect({ ...params, cast: false }) ) .replace(/{location}/g, getLocationSelect({ ...params })) - .replace('{baselineYear}', baselineYear || 2000) + .replace('{baselineYear}', startYear || 2000) .replace('{WHERE}', getWHEREQuery({ ...params, dataset: 'annual' })) );