Skip to content

Instantly share code, notes, and snippets.

@neogeek
Last active May 22, 2017 15:29
Show Gist options
  • Save neogeek/ae23d8294aa10b89eb72565ed3961e67 to your computer and use it in GitHub Desktop.
Save neogeek/ae23d8294aa10b89eb72565ed3961e67 to your computer and use it in GitHub Desktop.
const scaleLinear = (domain, range, value) => {
const sortedRange = range.slice().sort();
return Math.min(Math.max(range[0] + ((range[1] - range[0]) / 100) * ((value - domain[0]) / (domain[1] - domain[0]) * 100), sortedRange[0]), sortedRange[1]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment