Published
Edited
Jan 6, 2022
9 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
adjust = (values) => {
// step 1
const blurred = blur(values);
const adjustments = values.map((d, i) => (blurred[i] - d) / 4);

// step 2
let totalAdjustments = new Array(numTracts).fill(0);
ids.forEach((d, i) => {
totalAdjustments[d] += adjustments[i];
});

// step 3

let decrementedAdjustment = adjustments.map((d, i) => {
// which tract this belong to
const tractId = ids[i];
// total number of cells in that tract
const numCells = numCellsByTract[tractId];

const decrementingFactor = totalAdjustments[tractId] / numCells;

return d - decrementingFactor;
});

const adjustedOnce = values
.map((d, i) => d + decrementedAdjustment[i])
.map((d) => (d < 0 ? 0 : d));

// step 4

let newPops = new Array(numTracts).fill(0);
ids.forEach((tractIndex, i) => {
newPops[tractIndex] += adjustedOnce[i];
});

const adjustment2 = ids.map((tractIndex, i) => {
return (
(populationByTract[tractIndex] - newPops[tractIndex]) /
numCellsByTract[tractIndex]
);
});

const adjustedTwice = adjustedOnce.map((d, i) => d + adjustment2[i]);

return adjustedTwice;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more