Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/biodiversity glads aoi widget #3355

Merged
merged 15 commits into from
Apr 4, 2018
29 changes: 17 additions & 12 deletions app/javascript/pages/country/data/indicators.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
[
{
"label": "All of {location}",
"value": "gadm28",
"metaKey": ""
"value": "gadm28"
},
{
"label": "Biomes",
"value": "bra_biomes",
"metaKey": ""
"value": "bra_biomes"
},
{
"label": "Mining concessions",
Expand All @@ -19,6 +17,21 @@
"value": "wdpa",
"metaKey": "wdpa_protected_areas"
},
{
"label": "Key Biodiversity Areas",
"value": "kba",
"metaKey": "key_biodiversity_areas"
},
{
"label": "Tiger Conservation Landscapes",
"value": "tcl",
"metaKey": "tiger_conservation_landscapes"
},
{
"label": "Aliance for Zero Extinction",
"value": "aze",
"metaKey": "alliance_for_zero_extinction_sites"
},
{
"label": "Primary Forests",
"value": "primary_forest",
Expand All @@ -27,13 +40,11 @@
{
"label": "Mining concessions in Primary Forests",
"value": "primary_forest__mining",
"metaKey": "",
"group": "Intersections"
},
{
"label": "Protected Areas in Primary Forests",
"value": "primary_forest__wdpa",
"metaKey": "",
"group": "Intersections"
},
{
Expand All @@ -44,13 +55,11 @@
{
"label": "Protected Areas in Intact Forest Landscapes",
"value": "ifl_2013__wdpa",
"metaKey": "",
"group": "Intersections"
},
{
"label": "Mining concessions in Intact Forest Landscapes",
"value": "ifl_2013__mining",
"metaKey": "",
"group": "Intersections"
},
{
Expand All @@ -61,7 +70,6 @@
{
"label": "Indigenous Lands in Primary Forests",
"value": "primary_forest__landmark",
"metaKey": "",
"group": "Intersections"
},
{
Expand All @@ -72,19 +80,16 @@
{
"label": "Mining concessions in Plantation Areas",
"value": "plantations__mining",
"metaKey": "",
"group": "Intersections"
},
{
"label": "Protected areas in Plantations",
"value": "plantations__wdpa",
"metaKey": "",
"group": "Intersections"
},
{
"label": "Indigenous Lands in Plantations",
"value": "plantations__landmark",
"metaKey": "",
"group": "Intersections"
}
]
4 changes: 4 additions & 0 deletions app/javascript/pages/country/data/weeks.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[
{
"label": "4 weeks",
"value": 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this affects the glad-alerts widget. Is this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cheese 🤔 . Yes I should have put in the .env. And yes weeks selector needs updating. 🏎 💨

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

},
{
"label": "3 months",
"value": 13
Expand Down
77 changes: 71 additions & 6 deletions app/javascript/pages/country/data/widgets-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"title": "Tree cover gain",
"config": {
"size": "small",
"indicators": ["gadm28", "wdpa", "primary_forest", "plantations", "ifl_2013"],
"indicators": ["gadm28", "wdpa", "primary_forest", "plantations", "ifl_2013", "landmark", "mining"],
"units": ["ha", "%"],
"categories": ["summary", "forest-change"],
"admins": ["country", "region", "subRegion"],
Expand Down Expand Up @@ -251,7 +251,7 @@
"admins": ["country"],
"selectors": ["indicators", "thresholds", "extentYears", "units", "startYears", "endYears"],
"type": "loss",
"metaKey": "widget_tree_cover_loss",
"metaKey": "widget_tree_cover_loss_ranking",
"layers": ["loss"],
"sortOrder": {
"summary": 5,
Expand Down Expand Up @@ -282,7 +282,7 @@
"admins": ["country"],
"selectors": ["indicators", "thresholds", "extentYears", "units"],
"type": "extent",
"metaKey": "widget_tree_cover",
"metaKey": "widget_forest_cover_ranking",
"layers": ["forest2000", "forest2010"],
"sortOrder": {
"summary": 1,
Expand Down Expand Up @@ -340,7 +340,7 @@
"title": "Where did tree cover gain occur",
"config": {
"size": "small",
"indicators": ["gadm28", "ifl_2013", "mining", "wdpa","plantations","landmark", "primary_forest",
"indicators": ["gadm28", "ifl_2013", "mining", "wdpa", "plantations", "landmark", "primary_forest",
"ifl_2013", "ifl_2013__wdpa", "ifl_2013__mining", "ifl_2013__landmark",
"primary_forest", "primary_forest__mining", "primary_forest__wdpa", "primary_forest__landmark",
"plantations__mining", "plantations__wdpa", "plantations__landmark"],
Expand Down Expand Up @@ -389,10 +389,11 @@
"config": {
"size": "large",
"categories": ["summary", "forest-change"],
"weeks": [13, 26, 52],
"admins": ["country", "region", "subRegion"],
"type": "loss",
"selectors": ["weeks"],
"metaKey": "widget_deforestation_alert_location",
"metaKey": "widget_deforestation_graph",
"customLocationWhitelist": ["BRA", "COL", "ECU", "GUF", "GUY", "PER", "SUR", "BDI",
"CMR", "CAF", "GNQ", "GAB", "RWA", "UGA", "IDN", "MYS",
"PNG", "VEN", "TLS", "COD","COG"],
Expand All @@ -409,6 +410,70 @@
},
"enabled": true
},
"gladBiodiversity": {
"title": "Deforestation Alerts in Biodiversity Areas",
"config": {
"size": "small",
"indicators": [
"kba", "aze", "wdpa"
],
"units": ["ha", "%"],
"categories": ["conservation"],
"admins": ["country", "region"],
"selectors": ["indicators", "thresholds", "units", "extentYears", "weeks"],
"metaKey": "widget_deforestation_alert_location_biodiversity",
"locationCheck": true,
"type": "loss",
"layers": ["umd_as_it_happens"],
"sortOrder": {
"summary": 6,
"forest-change": 4
}
},
"settings": {
"indicator": "kba",
"threshold": 30,
"extentYear": 2000,
"unit": "ha",
"weeks": 4,
"pageSize": 5,
"page": 0,
"layers": ["umd_as_it_happens"]
},
"enabled": true
},
"gladRanked": {
"title": "Deforestation Alerts",
"config": {
"size": "small",
"indicators": ["gadm28", "ifl_2013", "wdpa",
"kba", "aze",
"tcl"],
"units": ["ha", "%"],
"categories": ["forest-change"],
"admins": ["country", "region"],
"selectors": ["indicators", "thresholds", "units", "extentYears", "weeks"],
"metaKey": "widget_deforestation_alert_location",
"locationCheck": true,
"type": "loss",
"layers": ["umd_as_it_happens"],
"sortOrder": {
"summary": 6,
"forest-change": 4
}
},
"settings": {
"indicator": "gadm28",
"threshold": 30,
"extentYear": 2000,
"unit": "ha",
"weeks": 4,
"pageSize": 5,
"page": 0,
"layers": ["umd_as_it_happens"]
},
"enabled": true
},
"rankedPlantations": {
"title": "Ranked plantation breakdown",
"config": {
Expand Down Expand Up @@ -449,7 +514,7 @@
"title": "Emissions from biomass loss",
"config": {
"size": "small",
"indicators": ["gadm28", "bra_biomes", "mining", "wdpa", "primary_forest", "ifl_2013"],
"indicators": ["gadm28", "bra_biomes", "mining", "wdpa", "primary_forest", "ifl_2013", "landmark"],
"categories": ["climate"],
"admins": ["country", "region", "subRegion"],
"selectors": ["indicators", "startYears", "endYears", "units"],
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/pages/country/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import * as widgetFAOCoverComponent from 'pages/country/widget/widgets/widget-fa
import * as widgetFAOReforestationComponent from 'pages/country/widget/widgets/widget-fao-reforestation';
import * as widgetFAODeforestationComponent from 'pages/country/widget/widgets/widget-fao-deforestation';
import * as widgetGladAlertsComponent from 'pages/country/widget/widgets/widget-glad-alerts';
import * as widgetGladBiodiversityComponent from 'pages/country/widget/widgets/widget-glad-biodiversity';
import * as widgetGladRankedComponent from 'pages/country/widget/widgets/widget-glad-ranked';
import * as widgetRankedPlantationsComponent from 'pages/country/widget/widgets/widget-ranked-plantations';
import * as widgetEmissionsComponent from 'pages/country/widget/widgets/widget-emissions';
import * as widgetEmissionsDeforestationComponent from 'pages/country/widget/widgets/widget-emissions-deforestation';
Expand Down Expand Up @@ -70,6 +72,8 @@ const componentsReducers = {
widgetFAOReforestation: handleActions(widgetFAOReforestationComponent),
widgetFAODeforestation: handleActions(widgetFAODeforestationComponent),
widgetGladAlerts: handleActions(widgetGladAlertsComponent),
widgetGladBiodiversity: handleActions(widgetGladBiodiversityComponent),
widgetGladRanked: handleActions(widgetGladRankedComponent),
widgetRankedPlantations: handleActions(widgetRankedPlantationsComponent),
widgetEmissions: handleActions(widgetEmissionsComponent),
widgetEmissionsDeforestation: handleActions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class WidgetSettings extends PureComponent {
render() {
const {
settings,
config,
loading,
locationNames,
onSettingsChange,
Expand Down Expand Up @@ -46,7 +47,7 @@ class WidgetSettings extends PureComponent {
disabled={loading}
optionsAction={setModalMeta}
optionsActionKey="metaKey"
clearable
clearable={config.indicators[0] === 'gadm28'}
noSelectedValue={`All of ${locationNames &&
locationNames.current.label}`}
/>
Expand Down Expand Up @@ -208,6 +209,7 @@ WidgetSettings.propTypes = {
periods: PropTypes.array,
years: PropTypes.array,
settings: PropTypes.object,
config: PropTypes.object,
startYears: PropTypes.array,
endYears: PropTypes.array,
loading: PropTypes.bool,
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/pages/country/widget/widget-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import * as FAOReforestationActions from 'pages/country/widget/widgets/widget-fa
import * as FAODeforestationActions from 'pages/country/widget/widgets/widget-fao-deforestation/widget-fao-deforestation-actions';
import * as FAOCoverActions from 'pages/country/widget/widgets/widget-fao-cover/widget-fao-cover-actions';
import * as gladAlertsActions from 'pages/country/widget/widgets/widget-glad-alerts/widget-glad-alerts-actions';
import * as gladBiodiversityActions from 'pages/country/widget/widgets/widget-glad-biodiversity/widget-glad-biodiversity-actions';
import * as gladRankedActions from 'pages/country/widget/widgets/widget-glad-ranked/widget-glad-ranked-actions';
import * as rankedPlantationsActions from 'pages/country/widget/widgets/widget-ranked-plantations/widget-ranked-plantations-actions';
import * as emissionsActions from 'pages/country/widget/widgets/widget-emissions/widget-emissions-actions';
import * as emissionsDeforestationActions from 'pages/country/widget/widgets/widget-emissions-deforestation/widget-emissions-deforestation-actions';
Expand All @@ -45,6 +47,8 @@ const widgetActions = {
...FAODeforestationActions.default,
...FAOCoverActions.default,
...gladAlertsActions.default,
...gladBiodiversityActions.default,
...gladRankedActions.default,
...rankedPlantationsActions.default,
...emissionsActions.default,
...emissionsDeforestationActions.default,
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/pages/country/widget/widget-component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import WidgetFaoCover from 'pages/country/widget/widgets/widget-fao-cover';
import WidgetFaoReforestation from 'pages/country/widget/widgets/widget-fao-reforestation';
import WidgetFaoDeforestation from 'pages/country/widget/widgets/widget-fao-deforestation';
import WidgetGladAlerts from 'pages/country/widget/widgets/widget-glad-alerts';
import WidgetGladBiodiversity from 'pages/country/widget/widgets/widget-glad-biodiversity';
import WidgetGladRanked from 'pages/country/widget/widgets/widget-glad-ranked';
import WidgetRankedPlantations from 'pages/country/widget/widgets/widget-ranked-plantations';
import WidgetEmissions from 'pages/country/widget/widgets/widget-emissions';
import WidgetEmissionsDeforestation from 'pages/country/widget/widgets/widget-emissions-deforestation';
Expand Down Expand Up @@ -53,6 +55,8 @@ const widgets = {
WidgetFaoReforestation,
WidgetFaoDeforestation,
WidgetGladAlerts,
WidgetGladBiodiversity,
WidgetGladRanked,
WidgetRankedPlantations,
WidgetEmissions,
WidgetEmissionsDeforestation,
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/pages/country/widget/widget-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export const getTypes = createSelector([], () => sortByKey(TYPES, 'label'));

export const getExtentYears = createSelector([], () => EXTENT_YEARS);

export const getWeeks = createSelector([], () => WEEKS);
export const getWeeks = createSelector([getConfig], config => {
if (!config || !config.weeks) return WEEKS;
return WEEKS.filter(w => config.weeks.indexOf(w.value) > -1);
});

export const getRangeYears = createSelector(
[getData, getConfig],
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/pages/country/widget/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const mapStateToProps = (state, ownProps) => {
});
break;
default:
options[selector] = selectorFunc();
options[selector] = selectorFunc({ config });
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createSelector } from 'reselect';
import isEmpty from 'lodash/isEmpty';
import uniqBy from 'lodash/uniqBy';
import sumBy from 'lodash/sumBy';
import { sortByKey, getColorPalette } from 'utils/data';
import { sortByKey } from 'utils/data';
import { format } from 'd3-format';

// get list data
Expand Down Expand Up @@ -33,19 +33,12 @@ export const getSortedData = createSelector(
value: settings.unit === 'ha' ? d.gain : percentage,
path: `/country/${location.country}/${
location.region ? `${location.region}/` : ''
}${d.id}`
}${d.id}`,
color: colors.main
});
}
});
const sortedData = sortByKey(uniqBy(dataMapped, 'label'), 'value', true);
const colorRange = getColorPalette(
colors.ramp,
sortedData.length < 10 ? sortedData.length : 10
);
return sortedData.map((o, i) => ({
...o,
color: o.gain ? colorRange[i] || colorRange[9] : colors.noGain
}));
return sortByKey(uniqBy(dataMapped, 'label'), 'value', true);
}
);

Expand Down Expand Up @@ -88,9 +81,9 @@ export const getSentence = createSelector(
let sentence = '';

if (indicator.value !== 'gadm28') {
sentence += `For <b>${
indicator.label
}</b> in <b>${currentLocation}</b>, `;
sentence += `For <b>${indicator.label}</b> in <b>${
currentLocation
}</b>, `;
} else {
sentence += `In <b>${currentLocation}</b>, `;
}
Expand All @@ -104,7 +97,9 @@ export const getSentence = createSelector(
const topGain = percentileGain / totalGain * 100;

if (percentileLength > 1) {
sentence += `the top <b>${percentileLength}</b> regions were responsible <b>`;
sentence += `the top <b>${
percentileLength
}</b> regions were responsible <b>`;
} else {
sentence += `<b>${topRegion.label}</b> was responsible <b>`;
}
Expand Down
Loading