Skip to content

Miscellaneous

andreaferretti edited this page Feb 16, 2015 · 1 revision

Other than the modules offering API for paths, shapes and graphs, Paths.js has the linear and ops modules. The linear module contains a function that can be used to generate linear scale, that is, functions that interpolate linearly a source interval on a target one (affine functions of one variable). An example of use to map the interval [0, 3] on the interval [10, 40] would be

var Linear = require('paths/linear');
var scale = Linear([0, 3], [10, 40]);
var x = scale(2); // yields 30

It can be also useful to invert linear scales, say to map coordinates on the screen to data points. This is done with the invert method on a linear scale. Continuing the example above

var inverse = scale.inverse();
var y = inverse(30); // yields 2

The ops module contains various utility functions that are used internally. It is not meant for external use, hence it is not documented, but curious folks can have a look at its tests.