function stateUnits(options) {
let cols = options.columns || 10;
let r = options.r * 2 || 10;
let spacing = options.spacing || 0;
let array = [];
let i = 0;
let votes = Array.from(electoral_votes).map(d => ({ ...d }));
votes.sort((a, b) => {
let leanA = leaningsByState.get(getState(a[0]));
let leanB = leaningsByState.get(getState(b[0]));
if (!leanA || !leanB) return 0;
return leanA.value - leanB.value;
});
votes.forEach(d => {
let state = d[0];
let count = d[1];
d3.range(count).forEach(j => {
let tx = margin.left + (i % cols) * (r + spacing);
let ty = margin.top + Math.floor(i / cols) * (r + spacing);
array.push({
i: i,
x: tx,
y: ty,
tx: tx,
ty: ty,
r: r,
state
});
i += 1;
});
});
return array;
}