Skip to content

Commit

Permalink
Show all labels for 2025 status on the table
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluesmile82 committed Oct 3, 2024
1 parent 2efae1e commit 069dc53
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ import styles from './ndcs-enhancements-2025-map-styles.scss';

const TOOLTIP_ID = 'ndcs-2025-map-tooltip';

// Show submitted 2025 only once. Remove if we want to add more values
const uniqueLegendItems = legendBuckets => {
const uniqueItems = {};
Object.entries(legendBuckets).forEach(([key, item]) => {
if (!Object.values(uniqueItems).find(uItem => uItem.name === item.name)) {
uniqueItems[key] = item;
}
});
return uniqueItems;
};

const NDCSEnhancements2025Map = ({
loading,
indicator,
Expand Down Expand Up @@ -60,7 +49,7 @@ const NDCSEnhancements2025Map = ({
<MapLegend
className={cx(styles.legend, { [styles.isPNG]: isPNG })}
title={indicator.legend}
buckets={uniqueLegendItems(indicator.legendBuckets)}
buckets={indicator.legendBuckets}
mapColors={mapColors}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ export const getIndicatorsParsed = createSelector(
[getCategories, getIndicatorsData, getISOCountries],
(categories, indicators, isos) => {
if (!categories || !indicators || !indicators.length) return null;
// const categoryId = Object.keys(categories).find(id =>
// ENHANCEMENT_CATEGORIES.includes(categories[id].slug)
// );

return sortBy(
uniqBy(
Expand All @@ -75,7 +72,7 @@ export const getIndicatorsParsed = createSelector(
'value'
),
'label'
); // .filter(ind => ind.categoryIds?.indexOf(parseInt(categoryId, 10)) > -1);
);
}
);

Expand Down Expand Up @@ -210,28 +207,17 @@ export const reduceLegendBuckets = createSelector(
if (!indicator) return null;
const updatedIndicator = { ...indicator };

// Get legend buckets and only use the ones on the namesLegendOrder
updatedIndicator.legendBuckets = Object.entries(
updatedIndicator.legendBuckets
).reduce((acc, [key, value]) => {
const allowedNames = [
'Submitted 2025 NDC',
'No Information',
'Not Applicable'
];
if (value.name === 'No Information') {
acc[key] = { ...value, name: 'No 2025 NDC' };
} else if (!allowedNames.includes(value.name)) {
delete acc[key];
const submitted2025NDC = Object.entries(
updatedIndicator.legendBuckets
).find(([, v]) => v.name === 'Submitted 2025 NDC');
acc[key] = submitted2025NDC[1];
} else {
acc[key] = value;
}
return acc;
}, {});

updatedIndicator.locations = Object.entries(
updatedIndicator.locations
).reduce((acc, [key, value]) => {
Expand All @@ -253,6 +239,8 @@ export const sortIndicatorLegend = createSelector(
if (!indicator) return null;
const updatedIndicator = { ...indicator };
const namesLegendOrder = [
'Submitted 2025 NDC with 2030 and 2035 targets',
'Submitted 2025 NDC with 2030 target',
'Submitted 2025 NDC',
'No 2025 NDC',
'Not Applicable'
Expand Down Expand Up @@ -303,19 +291,10 @@ export const getPathsWithStyles = createSelector(
: locations[iso];

let style = COUNTRY_STYLES;
const submittedLabelId = Object.values(locations).find(
l => l.value === 'Submitted 2025 NDC'
)?.label_id;

const strokeWidth = zoom > 2 ? (1 / zoom) * 2 : 0.5;

if (countryData && countryData.label_id) {
// Correction for the enhanced 2025 NDCs. We only want to show the Submitted 2025 NDCs info
const reducedLabelId =
countryData.value === 'No Information'
? countryData.label_id
: submittedLabelId;
const legendIndex = legendBuckets[reducedLabelId].index;
const legendIndex = legendBuckets[countryData.label_id].index;
const color = getColorByIndex(legendBuckets, legendIndex, MAP_COLORS);
style = {
...COUNTRY_STYLES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,21 @@ export const tableRemoveIsoFromData = createSelector(
const updatedD = { ...d };
updatedD['2025 Statement'] = updatedD['2025 NDC Statement'];

// Use the color of the NDC status to color also the 2030 target status
const submissionValue =
d['2025 NDC Submission'] === 'Submitted 2025 NDC with 2030 target'
? 'Submitted 2025 NDC'
: d['2025 NDC Submission'];

const color =
(d['2025 NDC Submission'] &&
NDC_2025_LABEL_COLORS[
INVERTED_NDC_2025_LABEL_SLUGS[submissionValue]
INVERTED_NDC_2025_LABEL_SLUGS[d['2025 NDC Submission']]
]) ||
NDC_2025_LABEL_COLORS.NO_SUBMISSION;
updatedD['NDC Status'] = submissionValue && {
updatedD['NDC Status'] = d['2025 NDC Submission'] && {
color,
text:
d['2025 NDC Submission'] === 'No Information'
? 'No 2025 NDC'
: d['2025 NDC Submission'],
sortIndex: color === NDC_2025_LABEL_COLORS.SUBMITTED_2025 ? '1' : '0'
sortIndex: Object.values(NDC_2025_LABEL_SLUGS).indexOf(
d['2025 NDC Submission']
)
};

updatedD['Source Link'] = d.Source
Expand Down
15 changes: 11 additions & 4 deletions app/javascript/app/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ export const ENHANCEMENT_LABEL_SLUGS = {
};

export const NDC_2025_LABEL_SLUGS = {
SUBMITTED_2025_WITH_2030_AND_2035_TARGETS:
'Submitted 2025 NDC with 2030 and 2035 targets',
SUBMITTED_2025_WITH_2030_TARGET: 'Submitted 2025 NDC with 2030 target',
SUBMITTED_2025: 'Submitted 2025 NDC',
NO_INFO: 'No Information'
};
Expand All @@ -421,8 +424,8 @@ export const ENHANCEMENT_LABEL_COLORS = {

export const NDC_2025_LABEL_COLORS = {
SUBMITTED_2025: CHART_NAMED_COLORS.color2,
SUBMITTED_2025_WITH_ENHANCEMENTS: CHART_NAMED_COLORS.color2,
SUBMITTED_2025_WITH_ENHANCEMENTS_2035: CHART_NAMED_COLORS.color2,
SUBMITTED_2025_WITH_2030_AND_2035_TARGETS: CHART_NAMED_COLORS.color1,
SUBMITTED_2025_WITH_2030_TARGET: CHART_NAMED_COLORS.color3,
NO_SUBMISSION: '#999C9F'
};

Expand Down Expand Up @@ -552,8 +555,12 @@ export const NDC_2025_COLORS = {
};

export const LEGEND_STATUS_2025_VALUES_COLORS = {
'Submitted 2025 NDC': NDC_2025_COLORS.darkBlue,
'No information': NDC_2025_COLORS.darkGray,
'Submitted 2025 NDC with 2030 and 2035 targets':
NDC_2025_LABEL_COLORS.SUBMITTED_2025_WITH_2030_AND_2035_TARGETS,
'Submitted 2025 NDC with 2030 target':
NDC_2025_LABEL_COLORS.SUBMITTED_2025_WITH_2030_TARGET,
'Submitted 2025 NDC': NDC_2025_LABEL_COLORS.SUBMITTED_2025,
'No information': NDC_2025_LABEL_COLORS.NO_SUBMISSION,
'Not Applicable: Countries that are not a Party to the UNFCCC':
NDC_2025_COLORS.lightGray
};
Expand Down

0 comments on commit 069dc53

Please sign in to comment.