medianIncomeScale = async (countyLatLng, allData, statsKey=null) => {
const incomeBounds = maxMin(allData.features.map(x => x.properties[medianIncome]).filter(x => x > 0));
const [countyMedianIncome, countyPopulation] = await censusCountyStat(countyLatLng, [medianIncome, population], statsKey);
return {
countyMedianIncome,
incomeBounds,
countyPopulation,
allData,
colorFn: d => {
const x = d.properties[medianIncome];
if (x < 0) return [0, 0, 0, 0];
const scaledX = scale(x, incomeBounds[0], countyMedianIncome, countyMedianIncome * 2 - incomeBounds[0]);
return brBgDiverging(scaledX);
},
tooltipFn: info => {
if (info.object == null) return;
if (info.object.type == 'Feature') {
const properties = info.object.properties;
const income = properties[medianIncome];
if (income > 0) {
return {
text: `$${income.toLocaleString()} median income`,
};
}
}
},
};
};