getDiseaseStateTable = fips => {
const stateName = statesGeoByFips.get(fips).properties.name;
const diseaseData = diseaseToData
.get(disease)
.find(d => d.locationdesc === stateName);
const data = Object.keys(diseaseData)
.slice(1)
.map(key => ({ name: key, value: diseaseData[key] }));
const table = d3.create("table");
const header = table.append("thead");
const body = table.append("tbody");
header
.append("tr")
.selectAll("th")
.data(["Race/Ethnicity", `Prevalence of ${disease}`])
.join("th")
.text(d => d);
body
.selectAll("tr")
.data(data)
.join("tr")
.each(renderRow);
function renderRow({ name, value }) {
const row = d3.select(this);
row.append("td").text(name);
const valueCell = row
.append("td")
.html(isValue(value) ? `${value}%` : "<em>no data</em>");
}
function isValue(value) {
return value !== undefined && value !== null && value !== "";
}
return table.node();
}