Scale an array preserving order to a discrete or continuous scale
Install
$ npm install --save scaler
Usage
var scaler = ;var scaledArray; // scale a simple array with default step = 1scaledArray = scaler;console;//=> [1, 2, 3] // scale a simple array with a custom stepscaledArray = scaler min: 1 step: 2);console;//=> [1, 3, 5] // provide max value to validate fitting (using unique items)scaledArray = scaler min: 1 max: 2);//=> Error: Count of unique items (3) is more than spread (2) / step (1) // works with negative numbers and negative rangescaledArray = scaler min: -5 step: 1);console;//=> [-5, -3, -4] // Get a continuous scalescaledArray = scaler;console;//=> [1, 1.5, 3]
API
.scale(array, params)
array
Type: array
required
The array you want to scale
params
min
Type: number
required
The minimum number to start the scale with.
max
Type: number
Default: Infinity
The maximum number to fit the scale into. If supplied - validation will be done to make sure the number of unique items in the array will fit the range.
continuous
Type: boolean
Default: false
Whether to use a continuous
scale. Default is to use a discrete
scale.
step
Type: number
Default: 1
Step to use when scaling in discrete
mode. Has no effect in continuous
mode.
License
MIT @Gilad Peleg