Skip to content

feat: add disease prevalence rates chart#1834

Merged
suhana13 merged 20 commits intodatacommonsorg:masterfrom
suhana13:disease-map
Jan 9, 2023
Merged

feat: add disease prevalence rates chart#1834
suhana13 merged 20 commits intodatacommonsorg:masterfrom
suhana13:disease-map

Conversation

@suhana13
Copy link
Copy Markdown
Contributor

In this PR, I'm re-using the maptile component from the graph explorer to plot the disease prevalence rates for the disease browser. Here is a screenshot for one of the diseases.

Screen Shot 2022-11-14 at 10 46 14 AM

Copy link
Copy Markdown
Collaborator

@beets beets left a comment

Choose a reason for hiding this comment

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

As you make updates to map tile, please ensure that the topic pages still work:
/topic/equity/country/USA

At a high level, also wondering if we need a denominator for these maps since we are calling them prevalence charts.

Thanks!

Comment thread static/js/biomedical/disease/page.tsx Outdated
Comment on lines +50 to +54
export const USA: NamedTypedPlace = {
dcid: "country/USA",
name: "United States of America",
types: ["Country"],
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please add this to constants.ts

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved!

Comment thread static/js/topic_page/map_tile.tsx Outdated
import { ChartTileContainer } from "./chart_tile";
import { CHART_HEIGHT } from "./constants";
import { ReplacementStrings } from "./string_utils";
export const MAP_ID = "map";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The topic page is designed for multiple map tiles to load, which is why the element ID is passed in as a prop, and not hardcoded to a single ID (HTML element IDs must be unique within a page).

Please pass this value in from the disease page component.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread static/js/topic_page/map_tile.tsx Outdated
}
return place.name + ": " + value;
};
document.getElementById(MAP_ID).innerHTML = "";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should not be required. Maybe this was added after the map Id's were hardcoded?

Comment thread static/js/topic_page/map_tile.tsx Outdated
document.getElementById(MAP_ID).innerHTML = "";
drawD3Map(
props.id,
MAP_ID,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please revert.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted!

Comment thread static/js/biomedical/disease/page.tsx Outdated
"Count_MedicalConditionIncident_Condition" + this.props.dcid;
const statVarDisease = {} as StatVarSpec;
statVarDisease.statVar = diseasePrevalenceStatVarValue;
statVarDisease.denom = "";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we are showing "prevalence", should this be Count_Person? That might also negate the changes in map_tile when there is no denominator defined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 - showing just the count of a disease might not be super meaningful because that count can be impacted by the population of a certain area

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Displaying percentages instead of counts! Thanks for the great suggestion!

Comment on lines +186 to +191
if (
!_.isEmpty(populationData.data) &&
denomStatVar in populationData.data
) {
population = populationData.data[denomStatVar];
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

perhaps, this should check if denomStatVar is defined in the first place. checking for "" in object works but is error prone.

also see comment above about always using a denominator for this..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Copy Markdown
Contributor

@chejennifer chejennifer left a comment

Choose a reason for hiding this comment

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

nice job getting the map to work!

Comment thread static/js/biomedical/disease/page.tsx Outdated

const diseasePrevalenceStatVarValue =
"Count_MedicalConditionIncident_Condition" + this.props.dcid;
const statVarDisease = {} as StatVarSpec;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

instead of defining an empty object and then setting the fields, you could just define the object with all the values like this:

const statVarSpec = {
statVar: diseasePrevalenceStatVarValue,
denom: "",
...
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread static/js/biomedical/disease/page.tsx Outdated
{ id: "drugSource", name: "Drug Source" },
];

const diseasePrevalenceStatVarValue =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: since this is the stat var dcid, maybe diseasePrevalenceStatVarDcid instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread static/js/shared/constants.ts Outdated
name: "Earth",
types: ["Planet"],
};
export const USA: NamedTypedPlace = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for consistency with the other NamedTypedPlace constants, let's name this "USA_NAMED_TYPED_PLACE"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed the name to USA_NAMED_TYPED_PLACE, for consistency!

Comment thread static/js/biomedical/disease/page.tsx Outdated
"Count_MedicalConditionIncident_Condition" + this.props.dcid;
const statVarDisease = {} as StatVarSpec;
statVarDisease.statVar = diseasePrevalenceStatVarValue;
statVarDisease.denom = "";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1 - showing just the count of a disease might not be super meaningful because that count can be impacted by the population of a certain area

beets added a commit that referenced this pull request Dec 2, 2022
also fixed topic page maps without denominator (from #1834, thanks
@suhana13)

given time pressure, i'd be happy to address comments in a followup pr
Copy link
Copy Markdown
Collaborator

@beets beets left a comment

Choose a reason for hiding this comment

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

one small nit left and feel free to submit after fixing it

Comment thread static/js/topic_page/map_tile.tsx Outdated
}
return place.name + ": " + value;
};
document.getElementById(props.id).innerHTML = "";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: this shouldn't be required anymore -- please remove.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@beets , the reason I added this was because before it, the map was getting duplicated multiple times (every time the state of the data got updated) but with the addition of this line, it's only being plotted once:)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see - let's do this within the disease page then (not in map_tile). It looks like we'll have to look at how the page is being redrawn with data refreshes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Copy Markdown
Contributor

@chejennifer chejennifer left a comment

Choose a reason for hiding this comment

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

thanks for the changes!

Comment thread static/js/topic_page/map_tile.tsx Outdated
100,
props.statVarSpec.unit
);
// shows upto 4 decimal points for very low values
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe we can use toPrecision & keep 2 significant digits for values whose absolute value is between 0-1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Copy Markdown
Contributor

@chejennifer chejennifer left a comment

Choose a reason for hiding this comment

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

thanks for the changes

Comment thread static/js/topic_page/map_tile.tsx Outdated
props.statVarSpec.unit
);
// shows upto 4 decimal points for very low values
if (chartData.dataValues[place.dcid] < 0.01) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's do this for all values where the absolute value (in case there are negatives) is between 0 and 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a great catch! Changed it to absolute value.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please also change the check so that this case is only for numbers between 0 and 1

Comment thread static/js/topic_page/map_tile.tsx Outdated
);
// shows upto 4 decimal points for very low values
if (chartData.dataValues[place.dcid] < 0.01) {
const val = Number(chartData.dataValues[place.dcid]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: don't need the Number() since dataValues values are already numbers
nit: let's be more specific in the naming about what value this variable is referring to because we already have another variable named value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done! Though I still had to do Number(chartDatavalue.toPrecision(2)) in line 286, as .Precision() returned a string and we want a number!

Copy link
Copy Markdown
Contributor

@chejennifer chejennifer left a comment

Choose a reason for hiding this comment

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

Thanks for all the changes, please fix this nit before merging

Math.abs(chartData.dataValues[place.dcid]) < 1 &&
Math.abs(chartData.dataValues[place.dcid]) > 0
) {
const chartDatavalue = chartData.dataValues[place.dcid];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: chartDataValue instead of chartDatavalue
nit: this variable can also be used in line 284, 285 & 295, so let's pull it out to before it's used by all those cases

@suhana13 suhana13 merged commit 432c5be into datacommonsorg:master Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants