UNPKG

molstar

Version:

A comprehensive macromolecular library.

65 lines 3.55 kB
"use strict"; /** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.LabelRepresentation = exports.LabelParams = void 0; var tslib_1 = require("tslib"); var loci_1 = require("../../../mol-model/loci"); var text_1 = require("../../../mol-geo/geometry/text/text"); var param_definition_1 = require("../../../mol-util/param-definition"); var representation_1 = require("../representation"); var representation_2 = require("../../representation"); var shape_1 = require("../../../mol-model/shape"); var text_builder_1 = require("../../../mol-geo/geometry/text/text-builder"); var geometry_1 = require("../../../mol-math/geometry"); var label_1 = require("../../../mol-theme/label"); var common_1 = require("./common"); var TextParams = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, common_1.LociLabelTextParams), { offsetZ: param_definition_1.ParamDefinition.Numeric(2, { min: 0, max: 10, step: 0.1 }) }); var LabelVisuals = { 'text': function (ctx, getParams) { return (0, representation_1.ShapeRepresentation)(getTextShape, text_1.Text.Utils, { modifyState: function (s) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, s), { pickable: false })); } }); }, }; exports.LabelParams = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, TextParams), { scaleByRadius: param_definition_1.ParamDefinition.Boolean(true), visuals: param_definition_1.ParamDefinition.MultiSelect(['text'], param_definition_1.ParamDefinition.objectToOptions(LabelVisuals)) }); // var tmpSphere = (0, geometry_1.Sphere3D)(); function label(info, condensed) { if (condensed === void 0) { condensed = false; } return info.label || (0, label_1.lociLabel)(info.loci, { hidePrefix: true, htmlStyling: false, condensed: condensed }); } function getLabelName(data) { return data.infos.length === 1 ? label(data.infos[0]) : data.infos.length + " Labels"; } // function buildText(data, props, text) { var builder = text_builder_1.TextBuilder.create(props, 128, 64, text); var customLabel = props.customText.trim(); for (var i = 0, il = data.infos.length; i < il; ++i) { var info = data.infos[i]; var sphere = loci_1.Loci.getBoundingSphere(info.loci, tmpSphere); if (!sphere) continue; var center = sphere.center, radius = sphere.radius; var text_2 = customLabel || label(info, true); builder.add(text_2, center[0], center[1], center[2], props.scaleByRadius ? radius / 0.9 : 0, props.scaleByRadius ? Math.max(1, radius) : 1, i); } return builder.getText(); } function getTextShape(ctx, data, props, shape) { var text = buildText(data, props, shape && shape.geometry); var name = getLabelName(data); var customLabel = props.customText.trim(); var getLabel = customLabel ? function (groupId) { return customLabel; } : function (groupId) { return label(data.infos[groupId]); }; return shape_1.Shape.create(name, data, text, function () { return props.textColor; }, function () { return props.textSize; }, getLabel); } function LabelRepresentation(ctx, getParams) { return representation_2.Representation.createMulti('Label', ctx, getParams, representation_2.Representation.StateBuilder, LabelVisuals); } exports.LabelRepresentation = LabelRepresentation; //# sourceMappingURL=label.js.map