Skip to content

Instantly share code, notes, and snippets.

@ivalkenburg
Created August 16, 2020 21:47
Show Gist options
  • Save ivalkenburg/ab5e527d781daafeb0e315b0eafafac8 to your computer and use it in GitHub Desktop.
Save ivalkenburg/ab5e527d781daafeb0e315b0eafafac8 to your computer and use it in GitHub Desktop.
export const interpolatedSteps = (geojson, numSteps = 4) => {
let minMax = [];
if (geojson.features.length < 1) {
minMax = [1, numSteps];
} else {
minMax = geojson.features.reduce((minMax, feature) => {
minMax[0] = Math.min(minMax[0] || feature.properties.hits, feature.properties.hits);
minMax[1] = Math.max(minMax[1], feature.properties.hits);
return minMax;
}, [null, null]);
if ((minMax[1] - minMax[0]) < (numSteps - 1)) {
minMax[1] = minMax[0] + (numSteps - 1);
}
}
const stepSize = (minMax[1] - minMax[0]) / (numSteps - 1);
const steps = [minMax[0]];
for (let i = 1; i <= numSteps - 1; i++) {
steps.push(Math.round(minMax[0] + (stepSize * i)));
}
return steps;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment