molstar
Version:
A comprehensive macromolecular library.
68 lines • 2.89 kB
JavaScript
/**
* 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 { ParamDefinition as PD } from '../../mol-util/param-definition';
import { getPaletteParams, getPalette } from '../../mol-util/color/palette';
import { ColorLists, getColorListFromName } from '../../mol-util/color/lists';
var DefaultList = 'dark-2';
var DefaultColor = 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.';
export var UnitIndexColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: DefaultList }));
export function getUnitIndexColorThemeParams(ctx) {
var params = PD.clone(UnitIndexColorThemeParams);
if (ctx.structure) {
if (ctx.structure.root.units.length > ColorLists[DefaultList].list.length) {
params.palette.defaultValue.name = 'colors';
params.palette.defaultValue.params = __assign(__assign({}, params.palette.defaultValue.params), { list: { kind: 'interpolate', colors: getColorListFromName(DefaultList).list } });
}
}
return params;
}
export function UnitIndexColorTheme(ctx, props) {
var color;
var legend;
if (ctx.structure) {
var units = ctx.structure.root.units;
var palette = 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 (StructureElement.Location.is(location)) {
return unitIdColor_1.get(location.unit.id);
}
else if (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
};
}
export var UnitIndexColorThemeProvider = {
name: 'unit-index',
label: 'Chain Instance',
category: "Chain Property" /* Chain */,
factory: UnitIndexColorTheme,
getParams: getUnitIndexColorThemeParams,
defaultValues: PD.getDefaultValues(UnitIndexColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure; }
};
//# sourceMappingURL=unit-index.js.map