molstar
Version:
A comprehensive macromolecular library.
73 lines • 3.37 kB
JavaScript
/**
* 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.UnitIndexColorThemeProvider = exports.UnitIndexColorTheme = exports.getUnitIndexColorThemeParams = exports.UnitIndexColorThemeParams = 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 lists_1 = require("../../mol-util/color/lists");
var DefaultList = 'dark-2';
var DefaultColor = (0, color_1.Color)(0xCCCCCC);
var Description = 'Gives every chain instance (single chain or collection of single elements) a unique color based on the position (index) of the chain in the list of chains in the structure.';
exports.UnitIndexColorThemeParams = (0, tslib_1.__assign)({}, (0, palette_1.getPaletteParams)({ type: 'colors', colorList: DefaultList }));
function getUnitIndexColorThemeParams(ctx) {
var params = param_definition_1.ParamDefinition.clone(exports.UnitIndexColorThemeParams);
if (ctx.structure) {
if (ctx.structure.root.units.length > lists_1.ColorLists[DefaultList].list.length) {
params.palette.defaultValue.name = 'colors';
params.palette.defaultValue.params = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, params.palette.defaultValue.params), { list: { kind: 'interpolate', colors: (0, lists_1.getColorListFromName)(DefaultList).list } });
}
}
return params;
}
exports.getUnitIndexColorThemeParams = getUnitIndexColorThemeParams;
function UnitIndexColorTheme(ctx, props) {
var color;
var legend;
if (ctx.structure) {
var units = ctx.structure.root.units;
var palette = (0, palette_1.getPalette)(units.length, props);
legend = palette.legend;
var unitIdColor_1 = new Map();
for (var i = 0, il = units.length; i < il; ++i) {
unitIdColor_1.set(units[i].id, palette.color(i));
}
color = function (location) {
if (structure_1.StructureElement.Location.is(location)) {
return unitIdColor_1.get(location.unit.id);
}
else if (structure_1.Bond.isLocation(location)) {
return unitIdColor_1.get(location.aUnit.id);
}
return DefaultColor;
};
}
else {
color = function () { return DefaultColor; };
}
return {
factory: UnitIndexColorTheme,
granularity: 'instance',
color: color,
props: props,
description: Description,
legend: legend
};
}
exports.UnitIndexColorTheme = UnitIndexColorTheme;
exports.UnitIndexColorThemeProvider = {
name: 'unit-index',
label: 'Chain Instance',
category: "Chain Property" /* Chain */,
factory: UnitIndexColorTheme,
getParams: getUnitIndexColorThemeParams,
defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.UnitIndexColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; }
};
//# sourceMappingURL=unit-index.js.map
;