Created
August 16, 2020 21:47
-
-
Save ivalkenburg/ab5e527d781daafeb0e315b0eafafac8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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