feat: add disease prevalence rates chart#1834
feat: add disease prevalence rates chart#1834suhana13 merged 20 commits intodatacommonsorg:masterfrom
Conversation
beets
left a comment
There was a problem hiding this comment.
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!
| export const USA: NamedTypedPlace = { | ||
| dcid: "country/USA", | ||
| name: "United States of America", | ||
| types: ["Country"], | ||
| }; |
There was a problem hiding this comment.
please add this to constants.ts
| import { ChartTileContainer } from "./chart_tile"; | ||
| import { CHART_HEIGHT } from "./constants"; | ||
| import { ReplacementStrings } from "./string_utils"; | ||
| export const MAP_ID = "map"; |
There was a problem hiding this comment.
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.
| } | ||
| return place.name + ": " + value; | ||
| }; | ||
| document.getElementById(MAP_ID).innerHTML = ""; |
There was a problem hiding this comment.
This should not be required. Maybe this was added after the map Id's were hardcoded?
| document.getElementById(MAP_ID).innerHTML = ""; | ||
| drawD3Map( | ||
| props.id, | ||
| MAP_ID, |
| "Count_MedicalConditionIncident_Condition" + this.props.dcid; | ||
| const statVarDisease = {} as StatVarSpec; | ||
| statVarDisease.statVar = diseasePrevalenceStatVarValue; | ||
| statVarDisease.denom = ""; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
+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
There was a problem hiding this comment.
Displaying percentages instead of counts! Thanks for the great suggestion!
| if ( | ||
| !_.isEmpty(populationData.data) && | ||
| denomStatVar in populationData.data | ||
| ) { | ||
| population = populationData.data[denomStatVar]; | ||
| } |
There was a problem hiding this comment.
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..
chejennifer
left a comment
There was a problem hiding this comment.
nice job getting the map to work!
|
|
||
| const diseasePrevalenceStatVarValue = | ||
| "Count_MedicalConditionIncident_Condition" + this.props.dcid; | ||
| const statVarDisease = {} as StatVarSpec; |
There was a problem hiding this comment.
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: "",
...
}
| { id: "drugSource", name: "Drug Source" }, | ||
| ]; | ||
|
|
||
| const diseasePrevalenceStatVarValue = |
There was a problem hiding this comment.
nit: since this is the stat var dcid, maybe diseasePrevalenceStatVarDcid instead
| name: "Earth", | ||
| types: ["Planet"], | ||
| }; | ||
| export const USA: NamedTypedPlace = { |
There was a problem hiding this comment.
for consistency with the other NamedTypedPlace constants, let's name this "USA_NAMED_TYPED_PLACE"
There was a problem hiding this comment.
Changed the name to USA_NAMED_TYPED_PLACE, for consistency!
| "Count_MedicalConditionIncident_Condition" + this.props.dcid; | ||
| const statVarDisease = {} as StatVarSpec; | ||
| statVarDisease.statVar = diseasePrevalenceStatVarValue; | ||
| statVarDisease.denom = ""; |
There was a problem hiding this comment.
+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
left a comment
There was a problem hiding this comment.
one small nit left and feel free to submit after fixing it
| } | ||
| return place.name + ": " + value; | ||
| }; | ||
| document.getElementById(props.id).innerHTML = ""; |
There was a problem hiding this comment.
nit: this shouldn't be required anymore -- please remove.
There was a problem hiding this comment.
@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:)
There was a problem hiding this comment.
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.
chejennifer
left a comment
There was a problem hiding this comment.
thanks for the changes!
| 100, | ||
| props.statVarSpec.unit | ||
| ); | ||
| // shows upto 4 decimal points for very low values |
There was a problem hiding this comment.
maybe we can use toPrecision & keep 2 significant digits for values whose absolute value is between 0-1.
| props.statVarSpec.unit | ||
| ); | ||
| // shows upto 4 decimal points for very low values | ||
| if (chartData.dataValues[place.dcid] < 0.01) { |
There was a problem hiding this comment.
let's do this for all values where the absolute value (in case there are negatives) is between 0 and 1
There was a problem hiding this comment.
That's a great catch! Changed it to absolute value.
There was a problem hiding this comment.
please also change the check so that this case is only for numbers between 0 and 1
| ); | ||
| // shows upto 4 decimal points for very low values | ||
| if (chartData.dataValues[place.dcid] < 0.01) { | ||
| const val = Number(chartData.dataValues[place.dcid]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Done! Though I still had to do Number(chartDatavalue.toPrecision(2)) in line 286, as .Precision() returned a string and we want a number!
chejennifer
left a comment
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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
In this PR, I'm re-using the
maptilecomponent from the graph explorer to plot the disease prevalence rates for the disease browser. Here is a screenshot for one of the diseases.