{
let div = DOM.element('div');
let states = Object.keys(excessStates).map(name => excessStates[name].code);
let trace = {
type: 'choropleth',
locationmode: 'USA-states',
locations: states,
z: states.map(s => {
let stname = statecode.filter(x => x.code == s)[0].state;
let stateData = excessStates[stname];
let allCause = stateData.all
.map(x => (x['All Cause'] || 0) - x['Average 2015-2019'])
.reduce((a, b) => a + b);
let ofCovid = stateData.covid.map(
x => (x['of COVID'] || 0) - x['Average 2015-2019']
);
if (ofCovid.length > 0) {
ofCovid = ofCovid.reduce((a, b) => a + b);
} else {
ofCovid = NaN;
}
return Math.round(100 * Math.max(1 - ofCovid / allCause, 0));
}),
text: states.map(s => statecode.filter(x => x.code == s)[0].state)
};
Plotly.plot(div, [trace], {
title: '% of additional mortality that is not by COVID',
geo: {
scope: 'usa',
showlakes: true,
lakecolor: 'rgb(255,255,255)'
},
dragmode: false
});
return div;
}