Skip to content

AoDev/scale-number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deprecated

D3.js developers released their scaling functions into a separate package. I recommend to use these instead. d3-scale

Scale number

Let's you map a number from a range to another.


js-standard-style Build Status

Current status: Alpha, API might change until 1.0.0

Scales

createLinearScale(fromRange, toRange)

Returns a scaling function from an input range to an output range.

Ranges are expressed with arrays.

var scaleNumber = require('scale-numbers')
var scale = scaleNumber.createLinearScale([10, 20], [100, 200])

var number = scale(15)
console.log(number) // 150

If the value is out of the entry range, it will be mapped to the lowest or greatest value. (this behaviour might be available as an option later)

var scale = scaleNumber.createLinearScale([10, 20], [100, 200])

var number = scale(5)
console.log(number) // 100

Story

This project gets its inspiration from d3 scale.

https://github.com/mbostock/d3/wiki/Quantitative-Scales

I needed this functionality as stand alone.

Roadmap

done

  • linear scale

todo

  • other type of scales and options like logarithmic, discrete, rounded, etc.

About

Scale a number to a different range of numbers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published