UNPKG

molstar

Version:

A comprehensive macromolecular library.

66 lines 2.9 kB
/** * Copyright (c) 2019-2020 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, Model } from '../../mol-model/structure'; 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 model a unique color based on the position (index) of the model in the list of models in the structure.'; export var ModelIndexColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: 'purples' })); export function getModelIndexColorThemeParams(ctx) { return ModelIndexColorThemeParams; // TODO return copy } export function ModelIndexColorTheme(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 = Model.TrajectoryInfo.get(m)) === null || _a === void 0 ? void 0 : _a.size) || 0); } var palette = getPalette(size, props); legend = palette.legend; var modelColor_1 = new Map(); for (var i = 0, il = models.length; i < il; ++i) { var idx = ((_b = 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 (StructureElement.Location.is(location)) { return modelColor_1.get(Model.TrajectoryInfo.get(location.unit.model).index); } else if (Bond.isLocation(location)) { return modelColor_1.get(Model.TrajectoryInfo.get(location.aUnit.model).index); } return DefaultColor; }; } else { color = function () { return DefaultColor; }; } return { factory: ModelIndexColorTheme, granularity: 'instance', color: color, props: props, description: Description, legend: legend }; } export var ModelIndexColorThemeProvider = { name: 'model-index', label: 'Model Index', category: "Chain Property" /* Chain */, factory: ModelIndexColorTheme, getParams: getModelIndexColorThemeParams, defaultValues: PD.getDefaultValues(ModelIndexColorThemeParams), isApplicable: function (ctx) { return !!ctx.structure && ctx.structure.elementCount > 0 && Model.TrajectoryInfo.get(ctx.structure.models[0]).size > 1; } }; //# sourceMappingURL=model-index.js.map