molstar
Version:
A comprehensive macromolecular library.
58 lines (57 loc) • 2.35 kB
JavaScript
/**
* Copyright (c) 2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Jason Pattle <jpattle@exscientia.co.uk>
* @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 its index.';
export var ModelIndexColorThemeParams = __assign({}, getPaletteParams({ type: 'colors', colorList: 'many-distinct' }));
export function getModelIndexColorThemeParams(ctx) {
return PD.clone(ModelIndexColorThemeParams);
}
export function ModelIndexColorTheme(ctx, props) {
var _a;
var color;
var legend;
if (ctx.structure) {
// max-index is the same for all models
var size = ((_a = Model.MaxIndex.get(ctx.structure.models[0]).value) !== null && _a !== void 0 ? _a : -1) + 1;
var palette_1 = getPalette(size, props);
legend = palette_1.legend;
color = function (location) {
if (StructureElement.Location.is(location)) {
return palette_1.color(Model.Index.get(location.unit.model).value || 0);
}
else if (Bond.isLocation(location)) {
return palette_1.color(Model.Index.get(location.aUnit.model).value || 0);
}
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" /* ColorTheme.Category.Chain */,
factory: ModelIndexColorTheme,
getParams: getModelIndexColorThemeParams,
defaultValues: PD.getDefaultValues(ModelIndexColorThemeParams),
isApplicable: function (ctx) { return !!ctx.structure && ctx.structure.elementCount > 0; }
};