-
Notifications
You must be signed in to change notification settings - Fork 93
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
Fixed Tree Cover Pies #3571
Fixed Tree Cover Pies #3571
Conversation
let plantations = 0; | ||
let data = {}; | ||
if (extent.length) { | ||
totalArea = adminExtent[0].total_area; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check admin response is defined here and below too otherwise it might crash the app.
const plantationsData = | ||
plantationsResponse.data && plantationsResponse.data.data; | ||
plantations = plantationsData.length | ||
? plantationsData[0].value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
plantationsResponse => { | ||
const plantationsData = | ||
plantationsResponse.data && plantationsResponse.data.data; | ||
plantations = plantationsData.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you check for length on a undefined your gonna have a bad time.
} | ||
]; | ||
if (!indicator && hasPlantations) { | ||
if (indicator) { | ||
parsedData.splice(1, 0, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to mutate the array?
color: colors.otherCover, | ||
percentage: otherCover / totalArea * 100 | ||
}); | ||
} else if (!indicator && hasPlantations) { | ||
parsedData.splice(1, 0, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need updating also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to have this fixed. You are creating a lot of situations where undefined could crash the app, particularly with arrays. Just make sure to check that [0] references are definitely array before doing so.
Overview
For any selected indicator (forest type / land category) the pies should show:
a) forest cover in that indicators polygon
b) forest NOT in that indicators polygon
c) Non-forest
e.g.
This fixes this and also introduces:
It also fixes other mathematical errors in calculating areas (see: mangroves)
Testing
Please test for indicator combination at iso/adm1/2 levels (Global not affected)