Skip to content

Instantly share code, notes, and snippets.

@MattTriano
Last active May 4, 2018 15:12
Show Gist options
  • Save MattTriano/154e9c142504d61985e2b65287e389be to your computer and use it in GitHub Desktop.
Save MattTriano/154e9c142504d61985e2b65287e389be to your computer and use it in GitHub Desktop.

This visualization shows cause-of-mortality data from the World Health Organization's mortality database and the death counts were normalized by population estimates from World Bank's population estimates. Death rates units are in deaths per 100,000 population.

This map was developed by Matt Triano and Amy Ching for our part of our group's CSC595 final project.

Data Sources

Reference Examples

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Causes of Mortality</title>
<link href="mort_map.css" rel="stylesheet" type="text/css">
<link href="http://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="container">
<div class='row'>
<h3 id='vis_title' class='six columns'>Causes of Mortality </h3>
<h3 class='three columns'></h3>
<h3 id="year_label" class='three columns'>2000<!-- </span> --> </h3>
</div>
<!-- <div class='row'>
<h6 class='six columns'>Mortality Cause Selector:</h6>
<h6 class='three columns'>Scale Color By:</h6>
<h6 class='three columns'>Year Selector</h6>
</div> -->
<div class='row'>
<select id="select_key" class='six columns'>
<option value="All_Causes" selected="selected">All Causes</option>
<option value="Communicable_maternal_perinatal_and_nutritional_conditions">&emsp;Communicable, maternal, perinatal and nutritional conditions</option>
<option value="Infectious_and_parasitic_diseases">&emsp;&emsp;Infectious and parasitic diseases</option>
<option value="Tuberculosis">&emsp;&emsp;&emsp;Tuberculosis</option>
<option value="STDs_excluding_HIV">&emsp;&emsp;&emsp;STDs excluding HIV</option>
<option value="Syphilis">&emsp;&emsp;&emsp;&emsp;Syphilis</option>
<option value="Chlamydia">&emsp;&emsp;&emsp;&emsp;Chlamydia</option>
<option value="Gonorrhoea">&emsp;&emsp;&emsp;&emsp;Gonorrhoea</option>
<option value="Trichomoniasis">&emsp;&emsp;&emsp;&emsp;Trichomoniasis</option>
<option value="Genital_herpes">&emsp;&emsp;&emsp;&emsp;Genital herpes</option>
<option value="Other_STDs">&emsp;&emsp;&emsp;&emsp;Other STDs</option>
<option value="HIV/AIDS">&emsp;&emsp;&emsp;HIV/AIDS</option>
<option value="Diarrhoeal_diseases">&emsp;&emsp;&emsp;Diarrhoeal diseases</option>
<option value="Childhood-cluster_diseases">&emsp;&emsp;&emsp;Childhood-cluster diseases</option>
<option value="Whooping_cough">&emsp;&emsp;&emsp;&emsp;Whooping cough</option>
<option value="Diphtheria">&emsp;&emsp;&emsp;&emsp;Diphtheria</option>
<option value="Measles">&emsp;&emsp;&emsp;&emsp;Measles</option>
<option value="Tetanus">&emsp;&emsp;&emsp;&emsp;Tetanus</option>
<option value="Meningitis">&emsp;&emsp;&emsp;Meningitis</option>
<option value="Encephalitis">&emsp;&emsp;&emsp;Encephalitis</option>
<option value="Hepatitis">&emsp;&emsp;&emsp;Hepatitis</option>
<option value="Acute_hepatitis_A">&emsp;&emsp;&emsp;&emsp;Acute hepatitis A</option>
<option value="Acute_hepatitis_B">&emsp;&emsp;&emsp;&emsp;Acute hepatitis B</option>
<option value="Acute_hepatitis_C">&emsp;&emsp;&emsp;&emsp;Acute hepatitis C</option>
<option value="Acute_hepatitis_E">&emsp;&emsp;&emsp;&emsp;Acute hepatitis E</option>
<option value="Cirrhosis_due_to_hepatitis_B">&emsp;&emsp;&emsp;&emsp;Cirrhosis due to hepatitis B</option>
<option value="Cirrhosis_due_to_hepatitis_C">&emsp;&emsp;&emsp;&emsp;Cirrhosis due to hepatitis C</option>
<option value="Liver_cancer_secondary_to_hepatitis_B">&emsp;&emsp;&emsp;&emsp;Liver cancer secondary to hepatitis B</option>
<option value="Liver_cancer_secondary_to_hepatitis_C">&emsp;&emsp;&emsp;&emsp;Liver cancer secondary to hepatitis C</option>
<option value="Parasitic_and_vector_diseases">&emsp;&emsp;&emsp;Parasitic and vector diseases</option>
<option value="Malaria">&emsp;&emsp;&emsp;&emsp;Malaria</option>
<option value="African_trypanosomiasis">&emsp;&emsp;&emsp;&emsp;African trypanosomiasis</option>
<option value="Chagas_disease">&emsp;&emsp;&emsp;&emsp;Chagas disease</option>
<option value="Schistosomiasis">&emsp;&emsp;&emsp;&emsp;Schistosomiasis</option>
<option value="Leishmaniasis">&emsp;&emsp;&emsp;&emsp;Leishmaniasis</option>
<option value="Lymphatic_filariasis">&emsp;&emsp;&emsp;&emsp;Lymphatic filariasis</option>
<option value="Onchocerciasis">&emsp;&emsp;&emsp;&emsp;Onchocerciasis</option>
<option value="Cysticercosis">&emsp;&emsp;&emsp;&emsp;Cysticercosis</option>
<option value="Echinococcosis">&emsp;&emsp;&emsp;&emsp;Echinococcosis</option>
<option value="Dengue">&emsp;&emsp;&emsp;&emsp;Dengue</option>
<option value="Trachoma">&emsp;&emsp;&emsp;&emsp;Trachoma</option>
<option value="Yellow_fever">&emsp;&emsp;&emsp;&emsp;Yellow fever</option>
<option value="Rabies">&emsp;&emsp;&emsp;&emsp;Rabies</option>
<option value="Intestinal_nematode_infections">&emsp;&emsp;&emsp;Intestinal nematode infections</option>
<option value="Ascariasis">&emsp;&emsp;&emsp;&emsp;Ascariasis</option>
<option value="Trichuriasis">&emsp;&emsp;&emsp;&emsp;Trichuriasis</option>
<option value="Hookworm_disease">&emsp;&emsp;&emsp;&emsp;Hookworm disease</option>
<option value="Food-bourne_trematodes">&emsp;&emsp;&emsp;&emsp;Food-bourne trematodes</option>
<option value="Leprosy">&emsp;&emsp;&emsp;Leprosy</option>
<option value="Other_infectious_diseases">&emsp;&emsp;&emsp;Other infectious diseases</option>
<option value="Respiratory_infections_">&emsp;&emsp;Respiratory infections </option>
<option value="Lower_respiratory_infections">&emsp;&emsp;&emsp;Lower respiratory infections</option>
<option value="Upper_respiratory_infections">&emsp;&emsp;&emsp;Upper respiratory infections</option>
<option value="Otitis_media">&emsp;&emsp;&emsp;Otitis media</option>
<option value="Maternal_conditions">&emsp;&emsp;Maternal conditions</option>
<option value="Neonatal_conditions">&emsp;&emsp;Neonatal conditions</option>
<option value="Preterm_birth_complications">&emsp;&emsp;&emsp;Preterm birth complications</option>
<option value="Birth_asphyxia_and_birth_trauma">&emsp;&emsp;&emsp;Birth asphyxia and birth trauma</option>
<option value="Neonatal_sepsis_and_infections">&emsp;&emsp;&emsp;Neonatal sepsis and infections</option>
<option value="Other_neonatal_conditions">&emsp;&emsp;&emsp;Other neonatal conditions</option>
<option value="Nutritional_deficiencies">&emsp;&emsp;Nutritional deficiencies</option>
<option value="Protein-energy_malnutrition">&emsp;&emsp;&emsp;Protein-energy malnutrition</option>
<option value="Iodine_deficiency">&emsp;&emsp;&emsp;Iodine deficiency</option>
<option value="Vitamin_A_deficiency">&emsp;&emsp;&emsp;Vitamin A deficiency</option>
<option value="Iron-deficiency_anaemia">&emsp;&emsp;&emsp;Iron-deficiency anaemia</option>
<option value="Other_nutritional_deficiencies">&emsp;&emsp;&emsp;Other nutritional deficiencies</option>
<option value="Noncommunicable_diseases">&emsp;Noncommunicable diseases</option>
<option value="Malignant_neoplasms">&emsp;&emsp;Malignant neoplasms</option>
<option value="Mouth_and_oropharynx_cancers">&emsp;&emsp;&emsp;Mouth and oropharynx cancers</option>
<option value="Lip_and_oral_cavity">&emsp;&emsp;&emsp;&emsp;Lip and oral cavity</option>
<option value="Nasopharynx">&emsp;&emsp;&emsp;&emsp;Nasopharynx</option>
<option value="Other_pharynx">&emsp;&emsp;&emsp;&emsp;Other pharynx</option>
<option value="Oesophagus_cancer">&emsp;&emsp;&emsp;Oesophagus cancer</option>
<option value="Stomach_cancer">&emsp;&emsp;&emsp;Stomach cancer</option>
<option value="Colon_and_rectum_cancers">&emsp;&emsp;&emsp;Colon and rectum cancers</option>
<option value="Liver_cancer">&emsp;&emsp;&emsp;Liver cancer</option>
<option value="Other_liver_cancer">&emsp;&emsp;&emsp;&emsp;Other liver cancer</option>
<option value="Pancreas_cancer">&emsp;&emsp;&emsp;Pancreas cancer</option>
<option value="Trachea_bronchus_lung_cancers">&emsp;&emsp;&emsp;Trachea, bronchus, lung cancers</option>
<option value="Melanoma_and_other_skin_cancers">&emsp;&emsp;&emsp;Melanoma and other skin cancers</option>
<option value="Malignant_skin_melanoma">&emsp;&emsp;&emsp;&emsp;Malignant skin melanoma</option>
<option value="Non-melanoma_skin_cancer">&emsp;&emsp;&emsp;&emsp;Non-melanoma skin cancer</option>
<option value="Breast_cancer">&emsp;&emsp;&emsp;Breast cancer</option>
<option value="Cervix_uteri_cancer">&emsp;&emsp;&emsp;Cervix uteri cancer</option>
<option value="Corpus_uteri_cancer">&emsp;&emsp;&emsp;Corpus uteri cancer</option>
<option value="Ovary_cancer">&emsp;&emsp;&emsp;Ovary cancer</option>
<option value="Prostate_cancer">&emsp;&emsp;&emsp;Prostate cancer</option>
<option value="Testicular_cancer">&emsp;&emsp;&emsp;Testicular cancer</option>
<option value="Kidney_cancer">&emsp;&emsp;&emsp;Kidney cancer</option>
<option value="Bladder_cancer">&emsp;&emsp;&emsp;Bladder cancer</option>
<option value="Brain_and_nervous_system_cancers">&emsp;&emsp;&emsp;Brain and nervous system cancers</option>
<option value="Gallbladder_and_biliary_tract_cancer">&emsp;&emsp;&emsp;Gallbladder and biliary tract cancer</option>
<option value="Larynx_cancer">&emsp;&emsp;&emsp;Larynx cancer</option>
<option value="Thyroid_cancer">&emsp;&emsp;&emsp;Thyroid cancer</option>
<option value="Mesothelioma">&emsp;&emsp;&emsp;Mesothelioma</option>
<option value="Lymphomas_multiple_myeloma">&emsp;&emsp;&emsp;Lymphomas, multiple myeloma</option>
<option value="Hodgkin_lymphoma">&emsp;&emsp;&emsp;&emsp;Hodgkin lymphoma</option>
<option value="Non-Hodgkin_lymphoma">&emsp;&emsp;&emsp;&emsp;Non-Hodgkin lymphoma</option>
<option value="Multiple_myeloma">&emsp;&emsp;&emsp;&emsp;Multiple myeloma</option>
<option value="Leukaemia">&emsp;&emsp;&emsp;Leukaemia</option>
<option value="Other_malignant_neoplasms">&emsp;&emsp;&emsp;Other malignant neoplasms</option>
<option value="Other_neoplasms">&emsp;&emsp;Other neoplasms</option>
<option value="Diabetes_mellitus">&emsp;&emsp;Diabetes mellitus</option>
<option value="Endocrine_blood_immune_disorders">Endocrine, blood, immune disorders</option>
<option value="Thalassaemias">&emsp;&emsp;&emsp;Thalassaemias</option>
<option value="Sickle_cell_disorders_and_trai">&emsp;&emsp;&emsp;Sickle cell disorders and trait</option>
<option value="Other_haemoglobinopathies_and_haemolytic_anaemias">&emsp;&emsp;&emsp;Other haemoglobinopathies and haemolytic anaemias</option>
<option value="Other_endocrine_blood_and_immune_disorders">&emsp;&emsp;&emsp;Other endocrine, blood and immune disorders</option>
<option value="Mental_and_substance_use_disorders">&emsp;&emsp;Mental and substance use disorders</option>
<option value="Depressive_disorders">&emsp;&emsp;&emsp;Depressive disorders</option>
<option value="Major_depressive_disorder">&emsp;&emsp;&emsp;&emsp;Major depressive disorder</option>
<option value="Dysthymia">&emsp;&emsp;&emsp;&emsp;Dysthymia</option>
<option value="Bipolar_disorder">&emsp;&emsp;&emsp;Bipolar disorder</option>
<option value="Schizophrenia">&emsp;&emsp;&emsp;Schizophrenia</option>
<option value="Alcohol_use_disorders">&emsp;&emsp;&emsp;Alcohol use disorders</option>
<option value="Liver_cancer_secondary_to_alcohol_use">&emsp;&emsp;&emsp;&emsp;Liver cancer secondary to alcohol use</option>
<option value="Cirrhosis_due_to_alcohol_use">&emsp;&emsp;&emsp;&emsp;Cirrhosis due to alcohol use</option>
<option value="Drug_use_disorders">&emsp;&emsp;&emsp;Drug use disorders</option>
<option value="Opioid_use_disorders">&emsp;&emsp;&emsp;&emsp;Opioid use disorders</option>
<option value="Cocaine_use_disorders">&emsp;&emsp;&emsp;&emsp;Cocaine use disorders</option>
<option value="Amphetamine_use_disorders">&emsp;&emsp;&emsp;&emsp;Amphetamine use disorders</option>
<option value="Cannabis_use_disorders">&emsp;&emsp;&emsp;&emsp;Cannabis use disorders</option>
<option value="Other_drug_use_disorders">&emsp;&emsp;&emsp;&emsp;Other drug use disorders</option>
<option value="Anxiety_disorders">&emsp;&emsp;&emsp;Anxiety disorders</option>
<option value="Eating_disorders">&emsp;&emsp;&emsp;Eating disorders</option>
<option value="Autism_and_Asperger_syndrome">&emsp;&emsp;&emsp;Autism and Asperger syndrome</option>
<option value="Childhood_behavioural_disorders">&emsp;&emsp;&emsp;Childhood behavioural disorders</option>
<option value="Attention_deficit/hyperactivity_syndrome">&emsp;&emsp;&emsp;&emsp;Attention deficit/hyperactivity syndrome</option>
<option value="Conduct_disorder">&emsp;&emsp;&emsp;&emsp;Conduct disorder</option>
<option value="Idiopathic_intellectual_disability">&emsp;&emsp;&emsp;Idiopathic intellectual disability</option>
<option value="Other_mental_and_behavioural_disorders">&emsp;&emsp;&emsp;Other mental and behavioural disorders</option>
<option value="Neurological_conditions">&emsp;&emsp;Neurological conditions</option>
<option value="Alzheimer_disease_and_other_dementias">&emsp;&emsp;&emsp;Alzheimer disease and other dementias</option>
<option value="Parkinson_disease">&emsp;&emsp;&emsp;Parkinson disease</option>
<option value="Epilepsy">&emsp;&emsp;&emsp;Epilepsy</option>
<option value="Multiple_sclerosis">&emsp;&emsp;&emsp;Multiple sclerosis</option>
<option value="Migraine">&emsp;&emsp;&emsp;Migraine</option>
<option value="Non-migraine_headache">&emsp;&emsp;&emsp;Non-migraine headache</option>
<option value="Other_neurological_conditions">&emsp;&emsp;&emsp;Other neurological conditions</option>
<option value="Sense_organt_diseases">&emsp;&emsp;Sense organ diseases</option>
<option value="Glaucoma">&emsp;&emsp;&emsp;Glaucoma</option>
<option value="Cataracts">&emsp;&emsp;&emsp;Cataracts</option>
<option value="Uncorrected_refractive_errors">&emsp;&emsp;&emsp;Uncorrected refractive errors</option>
<option value="Macular_degeneration">&emsp;&emsp;&emsp;Macular degeneration</option>
<option value="Other_vision_loss">&emsp;&emsp;&emsp;Other vision loss</option>
<option value="Other_hearing_loss">&emsp;&emsp;&emsp;Other hearing loss</option>
<option value="Other_sense_organ_disorders">&emsp;&emsp;&emsp;Other sense organ disorders</option>
<option value="Cardiovascular_diseases">&emsp;&emsp;Cardiovascular diseases</option>
<option value="Rheumatic_heart_disease">&emsp;&emsp;&emsp;Rheumatic heart disease</option>
<option value="Hypertensive_heart_disease">&emsp;&emsp;&emsp;Hypertensive heart disease</option>
<option value="Ischaemic_heart_disease">&emsp;&emsp;&emsp;Ischaemic heart disease</option>
<option value="Stroke">&emsp;&emsp;&emsp;Stroke</option>
<option value="Haemorrhagic_stroke">&emsp;&emsp;&emsp;Haemorrhagic stroke</option>
<option value="Ischaemic_stroke">&emsp;&emsp;&emsp;Ischaemic stroke</option>
<option value="Cardiomyopathy_myocarditis_endocarditis">&emsp;&emsp;&emsp;Cardiomyopathy, myocarditis, endocarditis</option>
<option value="Other_circulatory_diseases">&emsp;&emsp;&emsp;Other circulatory diseases</option>
<option value="Respiratory_diseases">&emsp;&emsp;Respiratory diseases</option>
<option value="Chronic_obstructive_pulmonary_disease">&emsp;&emsp;&emsp;Chronic obstructive pulmonary disease</option>
<option value="Asthma">&emsp;&emsp;&emsp;Asthma</option>
<option value="Other_respiratory_diseases">&emsp;&emsp;&emsp;Other respiratory diseases</option>
<option value="Digestive_diseases">&emsp;&emsp;Digestive diseases</option>
<option value="Peptic_ulcer_disease">&emsp;&emsp;&emsp;Peptic ulcer disease</option>
<option value="Cirrhosis_of_the_liver">&emsp;&emsp;&emsp;Cirrhosis of the liver</option>
<option value="Other_liver_cirrhosis">&emsp;&emsp;&emsp;Other liver cirrhosis</option>
<option value="Appendicitis">&emsp;&emsp;&emsp;Appendicitis</option>
<option value="Gastritis_and_duodenitis">&emsp;&emsp;&emsp;Gastritis and duodenitis</option>
<option value="Paralytic_ileus_and_intestinal_obstruction">&emsp;&emsp;&emsp;Paralytic ileus and intestinal obstruction</option>
<option value="Inflammatory_bowel_disease">&emsp;&emsp;&emsp;Inflammatory bowel disease</option>
<option value="Gallbladder_and_biliary_diseases">&emsp;&emsp;&emsp;Gallbladder and biliary diseases</option>
<option value="Pancreatitis">&emsp;&emsp;&emsp;Pancreatitis</option>
<option value="Other_digestive_diseases">&emsp;&emsp;&emsp;Other digestive diseases</option>
<option value="Genitourinary_diseases">&emsp;&emsp;Genitourinary diseases</option>
<option value="Kidney_diseases">&emsp;&emsp;&emsp;Kidney diseases</option>
<option value="Acute_glomerulonephritis">&emsp;&emsp;&emsp;&emsp;Acute glomerulonephritis</option>
<option value="Chronic_kidney_disease_due_to_diabetes">&emsp;&emsp;&emsp;&emsp;Chronic kidney disease due to diabetes</option>
<option value="Other_chronic_kidney_disease">&emsp;&emsp;&emsp;&emsp;Other chronic kidney disease</option>
<option value="Benign_prostatic_hyperplasia">&emsp;&emsp;&emsp;Benign prostatic hyperplasia</option>
<option value="Urolithiasis">&emsp;&emsp;&emsp;Urolithiasis</option>
<option value="Other_urinary_diseases">&emsp;&emsp;&emsp;Other urinary diseases</option>
<option value="Infertility">&emsp;&emsp;&emsp;Infertility</option>
<option value="Gynecological_diseases">&emsp;&emsp;&emsp;Gynecological diseases</option>
<option value="Skin_diseases">&emsp;&emsp;Skin diseases</option>
<option value="Musculoskeletal_diseases">&emsp;&emsp;Musculoskeletal diseases</option>
<option value="Rheumatoid_arthritis">&emsp;&emsp;&emsp;Rheumatoid arthritis</option>
<option value="Osteoarthritis">&emsp;&emsp;&emsp;Osteoarthritis</option>
<option value="Gout">&emsp;&emsp;&emsp;Gout</option>
<option value="Back_and_neck_pain">&emsp;&emsp;&emsp;Back and neck pain</option>
<option value="Other_musculoskeletal_disorders">&emsp;&emsp;&emsp;Other musculoskeletal disorders</option>
<option value="Congenital_anomalies">&emsp;&emsp;Congenital anomalies</option>
<option value="Neural_tube_defects">&emsp;&emsp;&emsp;Neural tube defects</option>
<option value="Cleft_lip_and_cleft_palate">&emsp;&emsp;&emsp;Cleft lip and cleft palate</option>
<option value="Down_syndrome">&emsp;&emsp;&emsp;Down syndrome</option>
<option value="Congenital_heart_anomalies">&emsp;&emsp;&emsp;Congenital heart anomalies</option>
<option value="Other_chromosomal_anomalies">&emsp;&emsp;&emsp;Other chromosomal anomalies</option>
<option value="Other_congenital_anomalies">&emsp;&emsp;&emsp;Other congenital anomalies</option>
<option value="Oral_conditions">&emsp;&emsp;Oral conditions</option>
<option value="Dental_caries">&emsp;&emsp;&emsp;Dental caries</option>
<option value="Periodontal_disease">&emsp;&emsp;&emsp;Periodontal disease</option>
<option value="Edentulism">&emsp;&emsp;&emsp;Edentulism</option>
<option value="Other_oral_disorders">&emsp;&emsp;&emsp;Other oral disorders</option>
<option value="Sudden_infant_death_syndrome">&emsp;&emsp;Sudden infant death syndrome</option>
<option value="Injuries">&emsp;Injuries</option>
<option value="Unintentional_injuries">&emsp;&emsp;Unintentional injuries</option>
<option value="Road_injury">&emsp;&emsp;&emsp;Road injury</option>
<option value="Poisonings">&emsp;&emsp;&emsp;Poisonings</option>
<option value="Falls">&emsp;&emsp;&emsp;Falls</option>
<option value="Fire_heat_and_hot_substances">&emsp;&emsp;&emsp;Fire, heat and hot substances</option>
<option value="Drowning">&emsp;&emsp;&emsp;Drowning</option>
<option value="Exposure_to_mechanical_forces">&emsp;&emsp;&emsp;Exposure to mechanical forces</option>
<option value="Natural_disasters">&emsp;&emsp;&emsp;Natural disasters</option>
<option value="Other_unintentional_injuries">&emsp;&emsp;&emsp;Other unintentional injuries</option>
<option value="Intentional_injuries">&emsp;&emsp;Intentional injuries</option>
<option value="Self-harm">&emsp;&emsp;&emsp;Self-harm</option>
<option value="Interpersonal_violence">&emsp;&emsp;&emsp;Interpersonal violence</option>
<option value="Collective_violence_and_legal_intervention">&emsp;&emsp;&emsp;Collective violence and legal intervention</option>
</select>
<select id='select_colorstyle' class='three columns'>
<option value='by_all_years' selected='selected'>Scale Colors By All Years</option>
<option value='by_sel_year'>Scale Colors By Selected Year</option>
</select>
<input type='range' min='2000' max='2015' value='2000' class='slider two columns' id='year_slct'>
</div>
<div id="choropleth" class='twelve columns'></div>
<div id="legend"></div>
<div id="chart_titles" class="hidden row"></div>
<div id="supplemental_graphs" class="hidden row">
<div id="sup_graph1" class="hidden six columns">
<div id="sg1_legend" class="hidden"></div>
</div>
<div id="data_table" class="hidden six columns">
<script id="template" type="x-tmpl-mustache">
<table>
<tr>
<th> Cause Name </th>
<td> Avg Deaths per 100k Pop</td>
</tr>
{{ #.}}
<tr>
<th> {{ key }}</th>
<td>{{ value }}</td>
</tr>
{{/.}}
</table>
</script>
</div>
</div>
<div id="initial">
<!-- <h5>Instructions</h5> -->
<ul>
<li>Change the mortality cause using the dropdown above the map.</li>
<li>Click a country to see death rates over time and top causes of death</li>
<li>Drag the Slider (or click it and use arrow keys) to change the year</li>
</ul>
</div>
<div class="footer">
<strong>Data Sources:</strong>Data from the <a href="http://www.who.int/healthinfo/statistics/mortality_rawdata/en/">World Health Organization</a> and normalized by <a href="https://data.worldbank.org/data-catalog/population-projection-tables">World Bank Population Data</a>. More details available in our <a href="https://github.com/MattTriano/csc595_final_project">project repo</a>
</div>
</div>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="//d3js.org/d3-geo-projection.v1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mustache.js/2.2.1/mustache.min.js"></script>
<script src="mort_map.js"></script>
</body>
</html>
body {
margin: 25px;
}
path {
stroke: #000;
stroke-width: 0.3px;
}
table {
margin-bottom: 0;
}
td, th {
padding: 6px 9px;
}
td {
text-align: right;
}
h3 {
margin-bottom: 0.1rem;
}
g.features {
stroke: #d8d8d8;
stroke-width: 0.5;
}
g.features path:hover {
opacity: 0.5;
}
.line {
fill: none;
stroke: black;
stroke-width: 1;
}
#legend {
border: 1px solid silver;
border-top: 0;
}
.legend-key path {
display: none;
}
.legend-key text {
font-size: 1rem;
}
.legend-key line {
stroke: #000;
shape-rendering: crispEdges;
}
.chart-legend {
shape-rendering:
}
.tooltip {
font-weight: bold;
font-size: 1.5rem;
padding: 1rem;
border: 2px #C0C0C0;
color: #090909;
background: #fff;
border-radius: 4px;
box-shadow: 0px 0px 3px 0px #a6a6a6;
opacity: 0.9;
position: absolute;
}
.hidden {
display: none;
}
.container {
width: 100%;
}
#details, #initial {
margin-top: 2rem;
}
#data_table {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
font-size: 1.1rem;
}
#choropleth {
font-size: 0; /* to prevent margin at bottom of map container */
border: 1px solid silver;
background: #E6E6E6;
background-color: #a7cdf2;
}
.feature.active {
border: 3px black;
}
.slider:hover {
opacity: 0.9;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 15px;
height: 38px;
background: #4CAF50;
cursor: pointer;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 20px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
#year_slct {
transform: translateY(0.7rem);
}
// Useful reading
// On accessing nested data: https://bost.ocks.org/mike/nest/
// On making a legend: https://bl.ocks.org/mbostock/4573883
// Lukas Vonlanthen's d3 map tutorial: http://data-map-d3.readthedocs.io/en/latest/index.html
// Setting height and width (should match the CSS)
var w = 1100;
var h = 580;
var active = d3.select(null);
var ctry_color;
// Initializing a default key and default year
var current_key = 'All_Causes';
var current_year = '2000';
var current_colorscale = 'by_all_year';
// This prepares a Mustache parser for the table of top causes of mortality
var template = d3.select('#template').html();
Mustache.parse(template);
// This was a hacky way of making data accessible for the line graph
var year_data = [
{
year: '2000',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2001',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2002',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2003',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2004',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2005',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2006',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2007',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2008',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2009',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2010',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2011',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2012',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2013',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2014',
all_cause_datum: -1,
key_cause_datum: -1
},
{
year: '2015',
all_cause_datum: -1,
key_cause_datum: -1
}
]
var svg = d3.select('#choropleth').append('svg')
.attr('preserveAspectRatio', 'xMidYMid')
.attr('viewBox', '0 0 ' + w + ' ' + h);
// Initializes a tooltip
var tooltip = d3.select("#choropleth")
.append("div")
.attr("class", "tooltip hidden");
// Setting the map projection
var projection = d3.geoNaturalEarth()
.scale(1);
// Setting a path object and applying our projection
var path = d3.geoPath()
.projection(projection);
// Innitializing a grouping on the SVG
var map_features = svg.append('g')
.attr('class', 'features.id');
// This prepares a scaler that determines what color to use for a choropleth path
var color_fill = d3.scaleQuantize()
.range(['#feedde','#fdd0a2','#fdae6b','#fd8d3c','#f16913','#d94801','#8c2d04']);
// Initializing an object to store data broken down by country
var data_by_country = d3.map();
var data_by_cause = d3.map();
// Initializing a variable to hold CSV (mort_data) and geojson data
var mort_data;
var geojson_data;
d3.select('#select_key').on('change', function(a) {
// Change the current key and call the function to update the colors.
current_key = d3.select(this).property('value');
update_map_colors();
});
d3.select('#select_year').on('change', function(a) {
// Change the current key and call the function to update the colors.
current_year = d3.select(this).property('value');
update_map_colors();
});
d3.select('#year_slct').on('change', function(a) {
// Change the current key and call the function to update the colors.
current_year = d3.select(this).property('value');
d3.select('#year_label').text(current_year);
update_map_colors();
});
d3.select('#select_colorstyle').on('change', function(a) {
// Change the current key and call the function to update the colors.
current_colorscale = d3.select(this).property('value');
update_map_colors();
});
// Code to prepare the legend
var format_value = d3.format('.0f');
var legend_scale = d3.scaleLinear();
var legend_x_axis = d3.axisBottom(legend_scale)
.tickSize(12)
.tickFormat( function(d) { return format_value(d); });
var legend_svg = d3.select('#legend')
.append('svg')
.attr('width', '100%')
.attr('height', '50');
var g = legend_svg.append('g')
.attr('transform', 'translate(' + 20 + ',' + 20 + ')');
g.selectAll('rect')
.data(color_fill.range()
.map(function(d) {
return color_fill.invertExtent(d);
}))
.enter()
.append('rect');
g.append('text')
.attr('class', 'legend_text')
.attr('fill', '#000')
.attr('font-weight', 'bold')
.attr('text-anchor', 'start')
.attr('y', -6)
// This listens to a window-resizing event and resizes the legend on event
window.onresize = update_legend;
// Now for that actual
// For this Gist, rather than include massive data files, I'll just reference them
var csv_datafile = 'https://raw.githubusercontent.com/MattTriano/csc595_final_project/master/WHO_mortality_data/mort_by_cause_per_capita_allages_btsx_avg.csv';
var geojson_file = 'https://raw.githubusercontent.com/MattTriano/csc595_final_project/master/countries_geo.json';
d3.json(geojson_file, function(geojson) {
var map_scale = map_scaler(geojson);
geojson_data = geojson;
projection.scale(map_scale.scale)
.center(map_scale.center)
.translate([w/2, h/2]);
d3.csv(csv_datafile, function(data) {
data_by_country = d3.nest()
.key( function(d) { return d.iso3; })
.key( function(d) { return d.causename; })
.rollup( function(d) { return d[0]; })
.map(data);
console.log(data_by_country); // this is the core data structure I use
data_by_cause = d3.nest()
.key( function(d) { return d.causename; })
.key( function(d) { return d.iso3; })
.rollup( function(d) { return data_by_cause_typesetter(d[0]); })
.map(data);
console.log(data_by_cause);
mort_data = data_by_country;
map_features.selectAll('path')
.data(geojson.features)
.enter().append('path')
.attr('d', path)
.on("click", clicked)
.on('mousemove', show_tooltip)
.on('mouseout', hide_tooltip);
update_map_colors();
});
});
// This function assists loading the data_by_cause data structure
// by setting datatypes for the values
function data_by_cause_typesetter(d_cause) {
var f=[];
var minmax = [];
var yr;
for (i = 2000; i <= 2016; i++){
yr = String(i);
f[yr] = parseFloat(d_cause[yr]);
if (f[yr] > 0) {
minmax.push(f[yr]);
}
}
f['max'] = Math.max.apply(null, minmax);
f['min'] = Math.min.apply(null, minmax);
f.avg_death_rate = parseFloat(d_cause.avg_death_rate);
f.country_name = d_cause.country_name;
f.iso3 = d_cause.iso3;
return f;
}
// This updates the colors of the map
function update_map_colors() {
if (current_colorscale === 'by_sel_year'){
color_fill.domain([
d3.min(geojson_data.features, function(d) {
return +(get_value_of_datum(data_by_country['$'.concat(d.id)])); }),
d3.max(geojson_data.features, function(d) {
return +(get_value_of_datum(data_by_country['$'.concat(d.id)])); })
]);
} else {
color_fill.domain([
d3.min(geojson_data.features, function(d) {
return +(get_max_min(d.id).min); }),
d3.max(geojson_data.features, function(d) {
return +(get_max_min(d.id).max); })
]);
};
map_features.selectAll('path')
.attr('fill', function(d) {
ctry_color = (get_value_of_datum(data_by_country['$'.concat(d.id)]));
if (typeof ctry_color != 'undefined') {
return color_fill(ctry_color);
} else {
return '#808080'; // Returns grey if the color is undefined (ie no data)
};
});
update_legend();
}
function get_max_min(d_id, ck=current_key) {
var tmp = data_by_cause['$'.concat(ck)] && data_by_cause['$'.concat(ck)]['$'.concat(d_id)];
if (typeof tmp != 'undefined'){
return tmp;
} else {
return {
'max' : 0,
'min': 0
};
}
return data_by_cause['$'.concat(ck)] && data_by_cause['$'.concat(ck)]['$'.concat(d_id)];
}
function update_legend() {
var legend_w = d3.select('#choropleth').node()
.getBoundingClientRect().width - 50;
// This sets evenly sized domain-spans to map the data to a color
var legend_domain = color_fill.range().map( function(d) {
var color_range = color_fill.invertExtent(d);
return color_range[1];
});
// This sets the lower end of the domain to the lowest observed value
legend_domain.unshift(color_fill.domain()[0]);
// This sets the domain and range for the legend bin widths
legend_scale.domain(color_fill.domain())
.range([0, legend_w]);
// This sets positions and widths for the rectangles in the legend
g.selectAll('rect')
.data(color_fill.range().map( function(d) {
return color_fill.invertExtent(d);
}))
.attr("height", 8)
.attr('x', function(d) { return legend_scale(d[0]); })
.attr('width', function(d) {
return legend_scale(d[1]) - legend_scale(d[0]);
})
.attr('fill', function(d, i) {
return color_fill.range()[i];
});
var dropdown_keys = d3.select('#select_key').node();
var selected_key = dropdown_keys.options[dropdown_keys.selectedIndex];
g.selectAll('text.legend_text').text(selected_key.text + ' [deaths per 100k pop. in ' + current_year +']');
legend_x_axis.tickValues(legend_domain);
g.call(legend_x_axis);
}
function clicked(d) {
if (active.node() === this) return reset();
active.classed("active", false);
active = d3.select(this).classed("active", true);
var bounds = path.bounds(d),
dx = bounds[1][0] - bounds[0][0],
dy = bounds[1][1] - bounds[0][1],
x = (bounds[0][0] + bounds[1][0]) / 2,
y = (bounds[0][1] + bounds[1][1]) / 2,
scale = .9 / Math.max(dx / w, dy / h),
translate = [w / 2 - scale * x, h / 2 - scale * y];
map_features.transition()
.duration(750)
.style("stroke-width", 1.5 / scale + "px")
.attr("transform", "translate(" + translate + ")scale(" + scale + ")");
get_year_data_for_cause(d);
mort_line_plot(d, year_data, graph1_svg);
show_top_causes(d.id);
d3.select('#initial').classed("hidden", true);
d3.select('#chart_titles').classed("hidden", false);
d3.select('#supplemental_graphs').classed("hidden", false);
d3.select('#sup_graph1').classed("hidden", false);
d3.select('#sg1_legend').classed("hidden", false);
d3.select('#data_table').classed("hidden", false);
}
var graph2_svg = d3.select('#data_table')
.append('svg')
.attr('width', '100%')
.attr('height', '200');
function show_top_causes(f, top_n=5) {
var sorted_data = get_sorted_ctry_data(f);
var sorted_slice = sorted_data.slice(0,top_n);
for (i=0; i<top_n; i++) {
sorted_slice[i].key = sorted_slice[i].key.replaceAll('_', ' ');
sorted_slice[i].value = format_value(sorted_slice[i].value);
}
var detailsHtml = Mustache.render(template, sorted_slice);
d3.select('#data_table').html(detailsHtml);
}
String.prototype.replaceAll = function(old, new_char) {
var this_string = this;
return this_string.split(old).join(new_char);
};
function tabulate_top_causes(d_slice, graph_svg) {
var table = graph_svg.append('foreignObject')
.attr('width', graph_svg.width)
.attr('height', graph_svg.height)
.append("xhtml:table");
var header = [
{ head: 'Cause',
cl: 'cause',
html: function(d) {return d[0]; }
},
{ head: 'Avg. Death Rate (per 100k pop)',
cl: 'center',
html: function(d) { return d[1]; }
}
];
table.append('table')
table.append('thead').append('tr')
.selectAll('th')
.data(header).enter()
.append('th')
.attr('class', function(d) { return d.cl; })
.style('width',graph_svg.width/2)
.text(function(d) { return d.head; });
}
function reset() {
active.classed("active", false);
active = d3.select(null);
map_features.transition()
.duration(750)
.style("stroke-width", "1.5px")
.attr("transform", "");
}
// This takes a country's geojson feature object
function show_tooltip(f) {
var id = f.id; // country id (iso3 code)
var d = data_by_country['$'.concat(id)];
// mouse contains a list containing the x and y pixel locations
// of the cursor, to use in positioning the tooltip
var mouse = d3.mouse(d3.select('#choropleth').node()).map(
function(d) { return parseInt(d); });
var ctry_name = get_country_name(f);
var left = Math.min( w - 4 * ctry_name.length, mouse[0] + 5);
var top = mouse[1] + 35;
var tt_deaths = format_value(get_value_of_year_datum(id, current_year, current_key));
tooltip.classed('hidden', false)
.attr("style", "left:" + left + "px; top:" + top + "px")
.html(ctry_name + '<br>' +
'Death rate by ' + current_key.replace('_', ' ') + ': '
+ tt_deaths);
}
function hide_tooltip() {
tooltip.classed('hidden', true);
}
function get_country_name(f) {
this_ctry_name = f.properties.name;
if (typeof this_ctry_name !== 'undefined') {
return this_ctry_name;
} else {
return 'Data Not Available';
}
}
// this redundent '&&' pattern prevents missing values from throwing errors
// when data produces an 'undefined' result (eg. Palestine isn't in this dataset
// but it is on the map, so it throws an error if we try to select deaths in
// Palestine in year 2000, for example)
function get_value_of_datum(d, yr=current_year) {
return d && d['$'.concat(current_key)][yr];
}
// f: iso3 country identifier
// yr: a year in the domain [2000, 2015]
// ck: key to get data for (default is current_key)
function get_value_of_year_datum(f, yr, ck=current_key) {
yr = parseInt(yr);
return mort_data['$'.concat(f)] && mort_data['$'.concat(f)]['$'.concat(ck)][yr];
}
// This takes a country iso3 id and returns a sorted array of
// causenames and avg death rates
function get_sorted_ctry_data(f) {
var sortable = [];
var local_sort = mort_data['$'.concat(f)].entries();
for (i = 0; i < local_sort.length; i++) {
sortable.push({key: local_sort[i].key, value: +local_sort[i].value.avg_death_rate});
}
local_sort = sortable.sort(function(a,b) { return b.value - a.value;});
return local_sort;
}
// This functiion updates the year_data object for the current cause
// f: a geojson features object, used to get a location id
function get_year_data_for_cause(f) {
this_ctry_id = f.id;
if (typeof mort_data['$'.concat(f.id)] !== 'undefined') {
for (yd in year_data) {
year_data[yd].key_cause_datum = +get_value_of_year_datum(this_ctry_id, year_data[yd].year);
year_data[yd].all_cause_datum = +get_value_of_year_datum(this_ctry_id, year_data[yd].year, 'All_Causes');
}
} else {
for (yr in year_data) {
year_data[yr].key_cause_datum = -1;
year_data[yr].all_cause_datum = -1;
}
}
}
var left_pad = 35;
var top_pad = 20;
var bot_pad = 30;
var right_pad = 30;
var graph1_svg = d3.select('#sup_graph1')
.append('svg')
.attr('width', '100%')
.attr('height', '200');
var parse_year = d3.timeParse("%Y");
var format_year = d3.timeFormat('%Y')
var time_scale = d3.scaleTime();
var death_scale = d3.scaleLinear();
function mort_line_plot(f, data, graph_svg) {
local_data = data;
graph_svg.selectAll('*').remove();
var frame_h = get_svg_height();
var frame_w = get_svg_width();
var this_w = 0.5 * frame_w;
var this_h = 200;
time_scale.domain([new Date(2000,0), new Date(2015,0)])
.range([left_pad, this_w-right_pad]);
death_scale.domain([0, 2250])
.range([this_h-bot_pad, right_pad]);
var time_axis = d3.axisBottom()
.scale(time_scale)
.ticks(16)
.tickFormat(format_year);
var death_axis = d3.axisLeft()
.scale(death_scale)
.ticks(6);
var all_cause_line = d3.line()
.x( function(d) { return time_scale(parse_year(String(d.year))); })
.y( function(d) { return death_scale(parseInt(d.all_cause_datum));});
var key_cause_line = d3.line()
.x( function(d) { return time_scale(parse_year(String(d.year))); })
.y( function(d) { return death_scale(parseInt(d.key_cause_datum));});
graph_svg.append('path')
.datum(local_data)
.attr('class', 'line')
.attr('d', all_cause_line)
.style('stroke', '#fc8d62');
graph_svg.append('path')
.datum(local_data)
.attr('class', 'line')
.attr('d', key_cause_line)
.style('stroke', '#66c2a5');
graph_svg.append("g")
.attr("class", "axis")
.attr("transform", "translate(0," + (this_h - bot_pad) + ")")
.call(time_axis)
.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".1em")
.attr("transform", "rotate(-60)");
graph_svg.append('g')
.attr('class', 'axis')
.attr('transform', 'translate ('+left_pad+',0)')
.call(death_axis);
graph_svg.append('text')
.attr('x', this_w/2)
.attr('y', top_pad*4/5)
.attr('text-anchor', 'middle')
.text('Deaths from All Causes and from '+current_key.replaceAll('_', ' ')+ ' for '+f.properties.name);
var legend_labels = [{ label: 'All Causes', color: '#fc8d62'},
{ label: 'Selected Cause', color: '#66c2a5'}];
var svg_legend = graph_svg.append('svg')
.attr('width', this_w*.15)
.attr('height', 40);
var this_legend = svg_legend.selectAll('#sg1_legend')
.data(legend_labels)
.enter().append('g')
.attr('id','sg1_legend')
.attr('transform', function(d, i) {
{
return 'translate(0,' + i*15 + ')'
}
});
var fant = 10;
graph_svg.append('rect')
.datum(legend_labels)
.attr('x',this_w*0.75)
.attr('y',30)
.attr('width',10)
.attr('height',2)
.style('fill', function(d) { return d[0].color; });
graph_svg.append('text')
.datum(legend_labels)
.attr('x',this_w*0.78)
.attr('y',35)
.text(function(d) { return d[0].label; })
.style('font-size',fant);
graph_svg.append('rect')
.datum(legend_labels)
.attr('x',this_w*0.75)
.attr('y',45)
.attr('width',10)
.attr('height',2)
.style('fill', function(d) { return d[1].color; });
graph_svg.append('text')
.datum(legend_labels)
.attr('x',this_w*0.78)
.attr('y',50)
.text(function(d) { return d[1].label; })
.style('font-size',fant);
// this is just a test object to confirm an image appears
// graph_svg.append('circle').attr('cx',30).attr('cy',30).attr('r',20);
}
// I made these functions to aid in resizing SVGs both initially and
// in response to window resizing events. I ran into some difficulties
// with this and time constraints didn't allow me to fully debug that
function get_svg_width() {
return d3.select(svg).node()._groups[0][0].width.animVal.value;
}
function get_svg_height() {
return d3.select(svg).node()._groups[0][0].width.animVal.value;
}
// This function takes a geojson features object and determines appropriate
// scale and center coordinates based on the extents of the geojson
// paths (ie the country boundaries) and the size of the SVG frame.
// Returns: an object containing the 'scale' and 'center'
function map_scaler(geojson) {
var path_bounds = path.bounds(geojson),
scale = 1/ Math.max(
(path_bounds[1][0] - path_bounds[0][0]) / w,
(path_bounds[1][1] - path_bounds[0][1]) / h
);
var feature_bounds = d3.geoBounds(geojson),
center = [
(feature_bounds[1][0] + feature_bounds[0][0]) / 2,
(feature_bounds[1][1] + feature_bounds[0][1]) / 2
];
return {
'scale' : scale,
'center': center
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment