polylinear-scale
Create piecewise linear scales à la d3
Last updated 3 years ago by elcontraption .
GPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install polylinear-scale 
SYNC missed versions from official npm registry.

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 -->
<script src="https://unpkg.com/polylinear-scale/dist/polylinear-scale.min.js"></script>

<!-- Un-minified -->
<script src="https://unpkg.com/polylinear-scale/dist/polylinear-scale.js"></script>

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 is false).

Returns

  • (Function): The resulting scaling function.

Examples

const polylinearScale = require('polylinear-scale')

// Create a linear scale
const linear = polylinearScale([0, 1], [0, 100])
console.log(linear(0.5)) // 50

// Create a polylinear scale
const polylinear = polylinearScale([0, 100, 300], [0, 50, 100])
console.log(polylinear(10)) // 5
console.log(polylinear(-10)) // -5

// Clamp results to the given range
const clamped = polylinearScale([-10, 0, 10], [-5, 2, 10], true)
console.log(clamped(11)) // 10

Contributing

Uses JavaScript Standard Style.

# test
$ npm run test

Current Tags

  • 1.1.6                                ...           latest (3 years ago)

17 Versions

  • 1.1.6                                ...           3 years ago
  • 1.1.5                                ...           4 years ago
  • 1.1.3                                ...           4 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.10                                ...           4 years ago
  • 1.0.9                                ...           4 years ago
  • 1.0.8                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 17
Last Day 0
Last Week 17
Last Month 17
Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |