Skip to content

Commit

Permalink
Merge pull request #3553 from Vizzuality/fix/another-dynamic-sentence…
Browse files Browse the repository at this point in the history
…-branch

Header and dynamic sentence fixes
  • Loading branch information
edbrett committed Aug 17, 2018
2 parents b3ccbc3 + 58de002 commit bb30df3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ const mapStateToProps = (
const size = config.size;
const isDeviceTouch = isTouch() || window.innerWidth < SCREEN_L;
const widgetMetaKey =
widget === 'treeCover' && whitelist && whitelist.indexOf('plantations')
widget === 'treeCover' && whitelist && whitelist.indexOf('plantations') > -1
? 'widget_natural_vs_planted'
: config.metaKey;
const parsedTitle =
let parsedTitle =
title && currentLabel !== 'global'
? title.withLocation.replace('{location}', currentLabel)
: title.global;
if (
title.withPlantations &&
whitelist &&
whitelist.indexOf('plantations') > -1
) { parsedTitle = title.withPlantations.replace('{location}', currentLabel); }

return {
location,
size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class WidgetSettings extends PureComponent {
? settings.clearable
: true
}
noSelectedValue="All types"
noSelectedValue="All tree cover"
/>
)}
{!isEmpty(landCategories) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ export const getSentence = createSelector(
const totalBiomass = data
.map(d => d.biomass)
.reduce((sum, d) => (d ? sum + d : sum));
const emissionType = unit === 'biomassCarbon' ? 'carbon' : 'CO2';
const emissionType = unit === 'biomassCarbon' ? 'carbon' : 'CO\u2082';
const totalEmissions =
unit === 'biomassCarbon'
? biomassToC(totalBiomass)
: biomassToCO2(totalBiomass);
? biomassToC(totalBiomass) * 1e-6
: biomassToCO2(totalBiomass) * 1e-6;
let indicatorText = '';
if (indicator && indicator.value === 'mining') {
indicatorText = ` ${indicator.label.toLowerCase()} regions`;
Expand All @@ -84,7 +84,10 @@ export const getSentence = createSelector(

const params = {
type: emissionType,
value: `${format('.3s')(totalEmissions)}t`,
value:
unit === 'biomassCarbon'
? `${format('.3r')(totalEmissions)}Tg`
: `${format('.3r')(totalEmissions)}Mt`,
location: currentLabel,
startYear,
endYear,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export const initialState = {
globalWithIndicator:
'From {startYear} to {endYear}, {loss} of tree cover was lost {location}, within {indicator} equivalent to a {localPercent} decrease since {extentYear}',
initial:
'From {startYear} to {endYear}, {location} lost {loss} of tree cover, equivalent to a {localPercent} decrease since {extentYear} and {globalPercent} of global total.',
'From {startYear} to {endYear}, {location} lost {loss} of tree cover, equivalent to a {localPercent} decrease since {extentYear} and {globalPercent} of the global total.',
withIndicator:
'From {startYear} to {endYear}, {location} lost {loss} of tree cover in {indicator}, equivalent to a {localPercent} decrease since {extentYear} and {globalPercent} of global total.',
'From {startYear} to {endYear}, {location} lost {loss} of tree cover in {indicator}, equivalent to a {localPercent} decrease since {extentYear} and {globalPercent} of the global total.',
noLoss: 'There was no tree cover loss identified in {location}.'
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
settings: {
forestType: 'primary_forest',
threshold: 30,
extentYear: 2010,
extentYear: 2000,
layers: ['forest2000']
},
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export default {
sentences: {
initial:
'As of {extentYear}, {location} had {extent} of tree cover, equivalent to {landPercentage} of its land area and {globalPercentage} of the global total.',
withInd:
landCatOnly:
'As of {extentYear}, {location} had {extent} of tree cover in {indicator}, equivalent to {landPercentage} of its land area and {globalPercentage} of the global total.',
forestTypeOnly:
withInd:
'As of {extentYear}, {location} had {extent} of {indicator}, equivalent to {landPercentage} of its land area and {globalPercentage} of the global total.'
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const getSentence = createSelector(
sentences
) => {
if (!data || !data.length || !currentLocation) return null;
const { initial, withInd, forestTypeOnly } = sentences;
const { initial, withInd, landCatOnly } = sentences;
const locationData =
currentLocation && data.find(l => l.id === currentLocation.value);
const extent = locationData && locationData.extent;
Expand All @@ -119,7 +119,7 @@ export const getSentence = createSelector(
};

let sentence = indicator ? withInd : initial;
if (forestType && !landCategory) sentence = forestTypeOnly;
if (!forestType && landCategory) sentence = landCatOnly;

return {
sentence,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export default {
title: {
global: 'Global tree cover',
withLocation: 'Tree cover in {location}'
withLocation: 'Tree cover in {location}',
withPlantations: 'Forest cover in {location}'
},
config: {
size: 'small',
categories: ['summary', 'land-cover'],
admins: ['global', 'country', 'region', 'subRegion'],
selectors: ['landCategories', 'thresholds', 'extentYears'],
selectors: ['forestTypes', 'landCategories', 'thresholds', 'extentYears'],
type: 'extent',
metaKey: 'widget_tree_cover',
layers: ['forest2000', 'forest2010'],
Expand All @@ -20,9 +21,10 @@ export default {
'As of {year}, {percentage} of {location} land cover was tree cover.',
globalWithIndicator:
'As of {year}, {percentage} of {location} land cover within {indicator} was tree cover.',
initial: 'As of {year}, {percentage} of {location} was tree cover.',
initial:
'As of {year}, {percentage} of {location} was natural forest cover.',
withIndicator:
"As of {year}, {percentage} of {location}<b>'s</b> tree cover was in {indicator}."
"As of {year}, {percentage} of {location}<b>'s</b> natural forest was in {indicator}."
}
},
settings: {
Expand Down

0 comments on commit bb30df3

Please sign in to comment.