UNPKG

molstar

Version:

A comprehensive macromolecular library.

71 lines (70 loc) 3.44 kB
"use strict"; /** * Copyright (c) 2019-2020 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.TrajectoryIndexColorThemeProvider = exports.TrajectoryIndexColorTheme = exports.getTrajectoryIndexColorThemeParams = exports.TrajectoryIndexColorThemeParams = void 0; var tslib_1 = require("tslib"); var color_1 = require("../../mol-util/color"); var structure_1 = require("../../mol-model/structure"); var param_definition_1 = require("../../mol-util/param-definition"); var palette_1 = require("../../mol-util/color/palette"); var DefaultColor = (0, color_1.Color)(0xCCCCCC); var Description = 'Gives every model (frame) a unique color based on the index in its trajectory.'; exports.TrajectoryIndexColorThemeParams = tslib_1.__assign({}, (0, palette_1.getPaletteParams)({ type: 'colors', colorList: 'purples' })); function getTrajectoryIndexColorThemeParams(ctx) { return param_definition_1.ParamDefinition.clone(exports.TrajectoryIndexColorThemeParams); } exports.getTrajectoryIndexColorThemeParams = getTrajectoryIndexColorThemeParams; function TrajectoryIndexColorTheme(ctx, props) { var _a, _b; var color; var legend; if (ctx.structure) { var models = ctx.structure.root.models; var size = 0; for (var _i = 0, models_1 = models; _i < models_1.length; _i++) { var m = models_1[_i]; size = Math.max(size, ((_a = structure_1.Model.TrajectoryInfo.get(m)) === null || _a === void 0 ? void 0 : _a.size) || 0); } var palette = (0, palette_1.getPalette)(size, props); legend = palette.legend; var modelColor_1 = new Map(); for (var i = 0, il = models.length; i < il; ++i) { var idx = ((_b = structure_1.Model.TrajectoryInfo.get(models[i])) === null || _b === void 0 ? void 0 : _b.index) || 0; modelColor_1.set(idx, palette.color(idx)); } color = function (location) { if (structure_1.StructureElement.Location.is(location)) { return modelColor_1.get(structure_1.Model.TrajectoryInfo.get(location.unit.model).index); } else if (structure_1.Bond.isLocation(location)) { return modelColor_1.get(structure_1.Model.TrajectoryInfo.get(location.aUnit.model).index); } return DefaultColor; }; } else { color = function () { return DefaultColor; }; } return { factory: TrajectoryIndexColorTheme, granularity: 'instance', color: color, props: props, description: Description, legend: legend }; } exports.TrajectoryIndexColorTheme = TrajectoryIndexColorTheme; exports.TrajectoryIndexColorThemeProvider = { name: 'trajectory-index', label: 'Trajectory Index', category: "Chain Property" /* ColorTheme.Category.Chain */, factory: TrajectoryIndexColorTheme, getParams: getTrajectoryIndexColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.TrajectoryIndexColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure && ctx.structure.elementCount > 0 && structure_1.Model.TrajectoryInfo.get(ctx.structure.models[0]).size > 1; } };