D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
danielsamson
Full window
Github gist
JS Bin // source http://jsbin.com/duwocuhama
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <script id="jsbin-javascript"> var mapRange = function(val, inputStart, inputEnd, outputStart, outputEnd) { var slope = (outputEnd - outputStart) / (inputEnd - inputStart); return outputStart + slope * (val - inputStart); }; console.log(mapRange(255, 0, 255, 0, 1)); </script> <script id="jsbin-source-javascript" type="text/javascript">var mapRange = function(val, inputStart, inputEnd, outputStart, outputEnd) { var slope = (outputEnd - outputStart) / (inputEnd - inputStart); return outputStart + slope * (val - inputStart); }; console.log(mapRange(255, 0, 255, 0, 1));</script></body> </html>