molstar
Version:
A comprehensive macromolecular library.
85 lines • 5.39 kB
JavaScript
/**
* Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStructureSizeThemeParams = exports.createStructureColorThemeParams = exports.getStructureThemeTypes = exports.createStructureRepresentationParams = void 0;
var structure_1 = require("../../mol-model/structure");
var param_definition_1 = require("../../mol-util/param-definition");
function createStructureRepresentationParams(ctx, structure, props) {
if (props === void 0) { props = {}; }
var p = props;
if (typeof p.type === 'string' || typeof p.color === 'string' || typeof p.size === 'string')
return createParamsByName(ctx, structure || structure_1.Structure.Empty, props);
return createParamsProvider(ctx, structure || structure_1.Structure.Empty, props);
}
exports.createStructureRepresentationParams = createStructureRepresentationParams;
function getStructureThemeTypes(ctx, structure) {
var themeCtx = ctx.representation.structure.themes;
if (!structure)
return themeCtx.colorThemeRegistry.types;
return themeCtx.colorThemeRegistry.getApplicableTypes({ structure: structure });
}
exports.getStructureThemeTypes = getStructureThemeTypes;
function createStructureColorThemeParams(ctx, structure, typeName, themeName, params) {
var _a = ctx.representation.structure, registry = _a.registry, themes = _a.themes;
var repr = registry.get(typeName || registry.default.name);
var color = themes.colorThemeRegistry.get(themeName || repr.defaultColorTheme.name);
var colorDefaultParams = param_definition_1.ParamDefinition.getDefaultValues(color.getParams({ structure: structure || structure_1.Structure.Empty }));
if (color.name === repr.defaultColorTheme.name)
Object.assign(colorDefaultParams, repr.defaultColorTheme.props);
return { name: color.name, params: Object.assign(colorDefaultParams, params) };
}
exports.createStructureColorThemeParams = createStructureColorThemeParams;
function createStructureSizeThemeParams(ctx, structure, typeName, themeName, params) {
var _a = ctx.representation.structure, registry = _a.registry, themes = _a.themes;
var repr = registry.get(typeName || registry.default.name);
var size = themes.sizeThemeRegistry.get(themeName || repr.defaultSizeTheme.name);
var sizeDefaultParams = param_definition_1.ParamDefinition.getDefaultValues(size.getParams({ structure: structure || structure_1.Structure.Empty }));
if (size.name === repr.defaultSizeTheme.name)
Object.assign(sizeDefaultParams, repr.defaultSizeTheme.props);
return { name: size.name, params: Object.assign(sizeDefaultParams, params) };
}
exports.createStructureSizeThemeParams = createStructureSizeThemeParams;
function createParamsByName(ctx, structure, props) {
var typeProvider = (props.type && ctx.representation.structure.registry.get(props.type))
|| ctx.representation.structure.registry.default.provider;
var colorProvider = (props.color && ctx.representation.structure.themes.colorThemeRegistry.get(props.color))
|| ctx.representation.structure.themes.colorThemeRegistry.get(typeProvider.defaultColorTheme.name);
var sizeProvider = (props.size && ctx.representation.structure.themes.sizeThemeRegistry.get(props.size))
|| ctx.representation.structure.themes.sizeThemeRegistry.get(typeProvider.defaultSizeTheme.name);
return createParamsProvider(ctx, structure, {
type: typeProvider,
typeParams: props.typeParams,
color: colorProvider,
colorParams: props.colorParams,
size: sizeProvider,
sizeParams: props.sizeParams
});
}
function createParamsProvider(ctx, structure, props) {
if (props === void 0) { props = {}; }
var themeCtx = ctx.representation.structure.themes;
var themeDataCtx = { structure: structure };
var repr = props.type || ctx.representation.structure.registry.default.provider;
var reprDefaultParams = param_definition_1.ParamDefinition.getDefaultValues(repr.getParams(themeCtx, structure));
var reprParams = Object.assign(reprDefaultParams, props.typeParams);
var color = props.color || themeCtx.colorThemeRegistry.get(repr.defaultColorTheme.name);
var colorDefaultParams = param_definition_1.ParamDefinition.getDefaultValues(color.getParams(themeDataCtx));
if (color.name === repr.defaultColorTheme.name)
Object.assign(colorDefaultParams, repr.defaultColorTheme.props);
var colorParams = Object.assign(colorDefaultParams, props.colorParams);
var size = props.size || themeCtx.sizeThemeRegistry.get(repr.defaultSizeTheme.name);
var sizeDefaultParams = param_definition_1.ParamDefinition.getDefaultValues(size.getParams(themeDataCtx));
if (size.name === repr.defaultSizeTheme.name)
Object.assign(sizeDefaultParams, repr.defaultSizeTheme.props);
var sizeParams = Object.assign(sizeDefaultParams, props.sizeParams);
return ({
type: { name: repr.name, params: reprParams },
colorTheme: { name: color.name, params: colorParams },
sizeTheme: { name: size.name, params: sizeParams }
});
}
//# sourceMappingURL=structure-representation-params.js.map
;