-
Notifications
You must be signed in to change notification settings - Fork 0
ds.normalize
metmajer edited this page Mar 15, 2013
·
3 revisions
normalize(values, [lower=0], [upper=1], [propertyName])
Normalizes a data series to fit the range [lower
, upper
].
The minimum value of the series is mapped to lower
and the maximum value is mapped to upper
, the values between limits are scaled linearly.
ds.normalize(ds.range(0, 5));
// => [0, 0.2, 0.4, 0.6, 0.8, 1]
ds.normalize(ds.range(2, 7));
// => [0, 0.2, 0.4, 0.6, 0.8, 1]
ds.normalize(ds.range(-2, 3));
// => [0, 0.2, 0.4, 0.6, 0.8, 1]
ds.normalize([{x: 0, y: 0}, {x: 1, y: 1}, {x: 2, y: 2}], 0, 1, 'y');
// => [{x: 0, y: 0},
// {x: 1, y: 0.5},
// {x: 2, y: 1}]
-
Array values The data series to normalize.
-
Number [lower=0] The lower limit of the resulting data series.
-
Number [upper=1] The upper limit of the resulting data series.
-
Function() [propertyName] A name of the property subject to normalization within an element in
values
.
- Array Returns the normalized data series.
-
Error Throws if
values
is not an array. -
Error Throws if
lower
orupper
is not a number, or iflower
>=upper
. -
Error Throws if
propertyName
is provided and is not a string, or ifpropertyName
does not exist. -
Error Throws if normalization is attempted on non-numeric data.