UNPKG

molstar

Version:

A comprehensive macromolecular library.

52 lines (51 loc) 2.86 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 = 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("".concat(_, " has no associated UI component")); return void 0; } } exports.legendFor = legendFor; var ScaleLegend = /** @class */ (function (_super) { 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) ? "".concat(color_1.Color.toStyle(c[0]), " ").concat(100 * c[1], "%") : color_1.Color.toStyle(c); }).join(', '); return (0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: 'msp-scale-legend' }, { children: (0, jsx_runtime_1.jsxs)("div", tslib_1.__assign({ style: { background: "linear-gradient(to right, ".concat(colors, ")") } }, { children: [(0, jsx_runtime_1.jsx)("span", tslib_1.__assign({ style: { float: 'left' } }, { children: legend.minLabel })), (0, jsx_runtime_1.jsx)("span", tslib_1.__assign({ style: { float: 'right' } }, { children: legend.maxLabel }))] })) })); }; return ScaleLegend; }(React.PureComponent)); exports.ScaleLegend = ScaleLegend; var TableLegend = /** @class */ (function (_super) { 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", 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) } }), (0, jsx_runtime_1.jsx)("div", tslib_1.__assign({ className: 'msp-table-legend-text' }, { children: name }))] }, i); }) })); }; return TableLegend; }(React.PureComponent)); exports.TableLegend = TableLegend;