polylinear-scale
Create piecewise linear scales à la d3:
Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale.
- Supports domains and ranges with more than two values each.
- Supports clamping to range.
- No dependencies.
For many more features, see d3-scale.
For an even simpler version that does not support multiple piecewise scales, see simple-linear-scale.
Setup
As a Node.js module:
$ yarn add polylinear-scale # or $ npm install polylinear-scale
CDN version:
<!-- Minified --> <!-- Un-minified -->
Arguments
domain (Array)
: The input domain (default is[0, 1]
).range (Array)
: The output range (default is[0, 1]
).clamp (Boolean)
: Enable or disable clamping (default isfalse
).
Returns
(Function)
: The resulting scaling function.
Examples
const polylinearScale = // Create a linear scaleconst linear = console // 50 // Create a polylinear scaleconst polylinear = console // 5console // -5 // Clamp results to the given rangeconst clamped = console // 10
Contributing
Uses JavaScript Standard Style.
# test $ npm run test