UNPKG

molstar

Version:

A comprehensive macromolecular library.

75 lines 3.65 kB
"use strict"; /** * Copyright (c) 2018-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.ElementIndexColorThemeProvider = exports.ElementIndexColorTheme = exports.getElementIndexColorThemeParams = exports.ElementIndexColorThemeParams = void 0; var tslib_1 = require("tslib"); var color_1 = require("../../mol-util/color"); var structure_1 = require("../../mol-model/structure"); var int_1 = require("../../mol-data/int"); 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 element (atom or coarse sphere/gaussian) a unique color based on the position (index) of the element in the list of elements in the structure.'; exports.ElementIndexColorThemeParams = (0, tslib_1.__assign)({}, (0, palette_1.getPaletteParams)({ type: 'colors', colorList: 'red-yellow-blue' })); function getElementIndexColorThemeParams(ctx) { return exports.ElementIndexColorThemeParams; // TODO return copy } exports.getElementIndexColorThemeParams = getElementIndexColorThemeParams; function ElementIndexColorTheme(ctx, props) { var color; var legend; if (ctx.structure) { var units_1 = ctx.structure.root.units; var unitCount = units_1.length; var cummulativeElementCount_1 = new Map(); var unitIdIndex_1 = new Map(); var elementCount = 0; for (var i = 0; i < unitCount; ++i) { cummulativeElementCount_1.set(i, elementCount); elementCount += units_1[i].elements.length; unitIdIndex_1.set(units_1[i].id, i); } var palette_2 = (0, palette_1.getPalette)(elementCount, props); legend = palette_2.legend; color = function (location) { if (structure_1.StructureElement.Location.is(location)) { var unitIndex = unitIdIndex_1.get(location.unit.id); var unitElementIndex = int_1.OrderedSet.findPredecessorIndex(units_1[unitIndex].elements, location.element); return palette_2.color(cummulativeElementCount_1.get(unitIndex) + unitElementIndex); } else if (structure_1.Bond.isLocation(location)) { var unitIndex = unitIdIndex_1.get(location.aUnit.id); var unitElementIndex = int_1.OrderedSet.findPredecessorIndex(units_1[unitIndex].elements, location.aUnit.elements[location.aIndex]); return palette_2.color(cummulativeElementCount_1.get(unitIndex) + unitElementIndex); } return DefaultColor; }; } else { color = function () { return DefaultColor; }; } return { factory: ElementIndexColorTheme, granularity: 'groupInstance', preferSmoothing: true, color: color, props: props, description: Description, legend: legend }; } exports.ElementIndexColorTheme = ElementIndexColorTheme; exports.ElementIndexColorThemeProvider = { name: 'element-index', label: 'Element Index', category: "Atom Property" /* Atom */, factory: ElementIndexColorTheme, getParams: getElementIndexColorThemeParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.ElementIndexColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; } }; //# sourceMappingURL=element-index.js.map