UNPKG

ucsc-xena-client

Version:

UCSC Xena Client. Functional genomics visualizations.

112 lines (92 loc) 5 kB
'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 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"); } }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var React = require('react'); var tickPadding = 3; function horzLayout(domain, range, scale, tickfn, tickHeight) { return tickfn.apply(null, domain).map(function (x) { return [[scale(x), 0], [0, tickHeight], [0, tickHeight + tickPadding], x.toLocaleString(), 'middle', '.71em']; }); } function vertLayout(domain, range, scale, tickfn, tickHeight) { return tickfn.apply(null, domain).map(function (y) { return [[0, scale(y)], [-tickHeight, 0], [-(tickHeight + tickPadding), 0], y.toLocaleString(), 'end', '.32em']; }); } var layout = { bottom: horzLayout, left: vertLayout }; var domainPath = { bottom: function bottom(_ref, height) { var _ref2 = _slicedToArray(_ref, 2), start = _ref2[0], end = _ref2[1]; return 'M' + start + ',' + height + 'V0H' + end + 'V' + height; }, left: function left(_ref3, height) { var _ref4 = _slicedToArray(_ref3, 2), start = _ref4[0], end = _ref4[1]; return 'M' + -height + ',' + start + 'H0V' + end + 'H' + -height; } }; var Axis = function (_React$Component) { _inherits(Axis, _React$Component); function Axis() { _classCallCheck(this, Axis); return _possibleConstructorReturn(this, (Axis.__proto__ || Object.getPrototypeOf(Axis)).apply(this, arguments)); } _createClass(Axis, [{ key: 'render', value: function render() { var _props = this.props, domain = _props.domain, range = _props.range, scale = _props.scale, tickfn = _props.tickfn, orientation = _props.orientation, _props$groupProps = _props.groupProps, groupProps = _props$groupProps === undefined ? {} : _props$groupProps, _props$tickHeight = _props.tickHeight, tickHeight = _props$tickHeight === undefined ? 6 : _props$tickHeight; var ticks = layout[orientation](domain, range, scale, tickfn, tickHeight); return React.createElement( 'g', groupProps, React.createElement('path', { className: 'domain', d: domainPath[orientation](range, tickHeight) }), ticks.map(function (_ref5, i) { var _ref6 = _slicedToArray(_ref5, 6), _ref6$ = _slicedToArray(_ref6[0], 2), x = _ref6$[0], y = _ref6$[1], _ref6$2 = _slicedToArray(_ref6[1], 2), dx = _ref6$2[0], dy = _ref6$2[1], _ref6$3 = _slicedToArray(_ref6[2], 2), lx = _ref6$3[0], ly = _ref6$3[1], label = _ref6[3], anchor = _ref6[4], off = _ref6[5]; return React.createElement( 'g', { key: i, transform: 'translate(' + x + ', ' + y + ')' }, React.createElement('line', { x2: dx, y2: dy }), React.createElement( 'text', { dy: off, y: ly, x: lx, style: { textAnchor: anchor } }, label ) ); }), this.props.children ); } }]); return Axis; }(React.Component); module.exports = Axis;