Skip to content

Instantly share code, notes, and snippets.

@Fishrock123
Last active December 16, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fishrock123/5375141 to your computer and use it in GitHub Desktop.
Save Fishrock123/5375141 to your computer and use it in GitHub Desktop.
Takes a numeric value 'x' and it's current scale as min / max, and converts it to a scale with a different min / max.
(function() {
function convertScale(x, min, max, min2, max2) {
var distance, percent;
distance = max - min;
percent = (x - min) / distance * 100;
percent = percent > 0 ? percent : -percent;
distance = max2 - min2;
return distance * percent / 100;
};
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment