ucsc-xena-client
Version:
UCSC Xena Client. Functional genomics visualizations.
119 lines (96 loc) • 4.41 kB
JavaScript
'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 _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _CanvasDrawing = require('../CanvasDrawing2');
var _CanvasDrawing2 = _interopRequireDefault(_CanvasDrawing);
var _color_helper = require('../color_helper');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
//// Styles
var compStyles = require('./BandLegend.module.css');
function draw(vg, opts) {
var _opts$range = opts.range,
min = _opts$range.min,
max = _opts$range.max,
colorScale = opts.colorScale,
width = opts.width,
height = opts.zoom.height,
ctx = vg.context(),
img = ctx.createImageData(width, height);
for (var i = 0; i < width; ++i) {
var color = (0, _color_helper.rgb)(colorScale((max - min) * i / width + min));
for (var j = 0; j < height + 4; ++j) {
var k = 4 * (j * width + i);
img.data[k] = color[0];
img.data[k + 1] = color[1];
img.data[k + 2] = color[2];
img.data[k + 3] = 255;
}
}
ctx.putImageData(img, 0, 0);
}
var addClass = function addClass(className) {
return function (el, i) {
return _react2.default.cloneElement(el, { className: className, key: i });
};
};
var BandLegend = function (_React$Component) {
_inherits(BandLegend, _React$Component);
function BandLegend() {
_classCallCheck(this, BandLegend);
return _possibleConstructorReturn(this, (BandLegend.__proto__ || Object.getPrototypeOf(BandLegend)).apply(this, arguments));
}
_createClass(BandLegend, [{
key: 'render',
value: function render() {
var _props = this.props,
range = _props.range,
multiScaled = _props.multiScaled,
width = _props.width,
height = _props.height,
footnotes = _props.footnotes,
colorScale = _props.colorScale,
labels = multiScaled ? { min: 'low', max: 'high' } : { min: range.min.toPrecision(2), max: range.max.toPrecision(2) },
drawing = _react2.default.createElement(_CanvasDrawing2.default, {
style: { width: '100%', height: height },
draw: draw,
range: range,
width: width,
colorScale: colorScale,
zoom: { height: height } });
return _react2.default.createElement(
'div',
{ className: compStyles.Legend },
_react2.default.createElement(
'div',
{ className: compStyles.container },
_react2.default.createElement(
'div',
{ className: compStyles.right },
labels.max
),
_react2.default.createElement(
'div',
{ className: compStyles.center },
_react2.default.createElement(
'div',
{ className: compStyles.left },
labels.min
),
_react2.default.createElement(
'div',
{ className: compStyles.center },
drawing
)
)
),
footnotes ? footnotes.map(addClass(compStyles.footnotes)) : null
);
}
}]);
return BandLegend;
}(_react2.default.Component);
module.exports = BandLegend;