plotly.js
Version:
The open source javascript graphing library that powers plotly
28 lines (22 loc) • 762 B
JavaScript
var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray;
/*
* Map an array of x or y coordinates (c) to screen-space pixel coordinates (p).
* The output array is optional, but if provided, it will be reused without
* reallocation to the extent possible.
*/
module.exports = function mapArray(out, data, func) {
var i;
if(!isArrayOrTypedArray(out)) {
// If not an array, make it an array:
out = [];
} else if(out.length > data.length) {
// If too long, truncate. (If too short, it will grow
// automatically so we don't care about that case)
out = out.slice(0, data.length);
}
for(i = 0; i < data.length; i++) {
out[i] = func(data[i]);
}
return out;
};
;