UNPKG

ucsc-xena-client

Version:

UCSC Xena Client. Functional genomics visualizations.

81 lines (65 loc) 2.91 kB
'use strict'; var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); var _ = require('underscore'); // We could use d3 for scale & ticks. Avoiding it here because // of wanting to minimize dependencies, it's more than we need, // and there are performance issues with d3 color scales when // the data is largish. // If domain is inverted, invert domain and range. function swapInvs(_ref, _ref2) { var _ref4 = _slicedToArray(_ref, 2), dstart = _ref4[0], dend = _ref4[1]; var _ref3 = _slicedToArray(_ref2, 2), rstart = _ref3[0], rend = _ref3[1]; return dstart > dend ? [[dend, dstart], [rend, rstart]] : [[dstart, dend], [rstart, rend]]; } // linear scale function linear(domain, range) { var _swapInvs = swapInvs(domain, range), _swapInvs2 = _slicedToArray(_swapInvs, 2), _swapInvs2$ = _slicedToArray(_swapInvs2[0], 2), dlow = _swapInvs2$[0], dhigh = _swapInvs2$[1], _swapInvs2$2 = _slicedToArray(_swapInvs2[1], 2), rlow = _swapInvs2$2[0], rhigh = _swapInvs2$2[1]; return function (x) { return x < dlow ? rlow : x > dhigh ? rhigh : (x - dlow) * (rhigh - rlow) / (dhigh - dlow) + rlow; }; } function swapInv(start, end) { return start > end ? [end, start] : [start, end]; } function linearTicks(start, end) { var _swapInv = swapInv(start, end), _swapInv2 = _slicedToArray(_swapInv, 2), low = _swapInv2[0], high = _swapInv2[1], _toExponential$match = (high - low).toExponential().match(/-?([0-9])[0-9.]*e([+-][0-9]+)/), _toExponential$match2 = _slicedToArray(_toExponential$match, 3), digit = _toExponential$match2[1], exp = _toExponential$match2[2], nticks = parseInt(digit, 10) + 1, scale = Math.pow(10, exp), t; // For digit n, there will be n + 1 nticks if using 1 * scale. if (nticks > 9) { // 10 nticks. Halve it by doubling scale. t = scale * 2; } else if (nticks > 4) { t = scale; // 5 or more nticks at scale, which is fine. } else if (nticks > 2) { t = 0.5 * scale; // 3-4 nticks, use half scale to get 6-8 } else { t = 0.25 * scale; // 1-2 nticks, use quarter scale to get 4-8 } return _.range(Math.ceil(low / t), Math.floor(high / t) + 1).map(function (i) { return i * t; }); } module.exports = { linear: linear, linearTicks: linearTicks };