UNPKG

molstar

Version:

A comprehensive macromolecular library.

52 lines 2.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TableLegend = exports.ScaleLegend = exports.legendFor = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); /** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ var color_1 = require("../../mol-util/color"); var React = (0, tslib_1.__importStar)(require("react")); function legendFor(legend) { switch (legend.kind) { case 'scale-legend': return ScaleLegend; case 'table-legend': return TableLegend; default: var _ = legend; console.warn(_ + " has no associated UI component"); return void 0; } } exports.legendFor = legendFor; var ScaleLegend = /** @class */ (function (_super) { (0, tslib_1.__extends)(ScaleLegend, _super); function ScaleLegend() { return _super !== null && _super.apply(this, arguments) || this; } ScaleLegend.prototype.render = function () { var legend = this.props.legend; var colors = legend.colors.map(function (c) { return Array.isArray(c) ? color_1.Color.toStyle(c[0]) + " " + 100 * c[1] + "%" : color_1.Color.toStyle(c); }).join(', '); return (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-scale-legend' }, { children: (0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ style: { background: "linear-gradient(to right, " + colors + ")" } }, { children: [(0, jsx_runtime_1.jsx)("span", (0, tslib_1.__assign)({ style: { float: 'left' } }, { children: legend.minLabel }), void 0), (0, jsx_runtime_1.jsx)("span", (0, tslib_1.__assign)({ style: { float: 'right' } }, { children: legend.maxLabel }), void 0)] }), void 0) }), void 0); }; return ScaleLegend; }(React.PureComponent)); exports.ScaleLegend = ScaleLegend; var TableLegend = /** @class */ (function (_super) { (0, tslib_1.__extends)(TableLegend, _super); function TableLegend() { return _super !== null && _super.apply(this, arguments) || this; } TableLegend.prototype.render = function () { var legend = this.props.legend; return (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-table-legend' }, { children: legend.table.map(function (value, i) { var name = value[0], color = value[1]; return (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: 'msp-table-legend-color', style: { backgroundColor: color_1.Color.toStyle(color) } }, void 0), (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-table-legend-text' }, { children: name }), void 0)] }, i); }) }), void 0); }; return TableLegend; }(React.PureComponent)); exports.TableLegend = TableLegend; //# sourceMappingURL=legend.js.map