UNPKG

molstar

Version:

A comprehensive macromolecular library.

70 lines 3.2 kB
/** * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign } from "tslib"; import { Color } from '../../mol-util/color'; import { StructureElement, Bond } from '../../mol-model/structure'; import { OrderedSet } from '../../mol-data/int'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; import { getPaletteParams, getPalette } from '../../mol-util/color/palette'; var DefaultColor = 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.'; export var ElementIndexColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: 'red-yellow-blue' })); export function getElementIndexColorThemeParams(ctx) { return ElementIndexColorThemeParams; // TODO return copy } export 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_1 = getPalette(elementCount, props); legend = palette_1.legend; color = function (location) { if (StructureElement.Location.is(location)) { var unitIndex = unitIdIndex_1.get(location.unit.id); var unitElementIndex = OrderedSet.findPredecessorIndex(units_1[unitIndex].elements, location.element); return palette_1.color(cummulativeElementCount_1.get(unitIndex) + unitElementIndex); } else if (Bond.isLocation(location)) { var unitIndex = unitIdIndex_1.get(location.aUnit.id); var unitElementIndex = OrderedSet.findPredecessorIndex(units_1[unitIndex].elements, location.aUnit.elements[location.aIndex]); return palette_1.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 }; } export var ElementIndexColorThemeProvider = { name: 'element-index', label: 'Element Index', category: "Atom Property" /* Atom */, factory: ElementIndexColorTheme, getParams: getElementIndexColorThemeParams, defaultValues: PD.getDefaultValues(ElementIndexColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure; } }; //# sourceMappingURL=element-index.js.map