pdbe-molstar
Version:
Molstar implementation for PDBe
61 lines (60 loc) • 4.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SequenceColorThemeProperty = void 0;
const tslib_1 = require("tslib");
const custom_structure_property_1 = require("molstar/lib/mol-model-props/common/custom-structure-property");
const custom_property_1 = require("molstar/lib/mol-model/custom-property");
const structure_1 = require("molstar/lib/mol-model/structure");
const names_1 = require("molstar/lib/mol-util/color/names");
const object_1 = require("molstar/lib/mol-util/object");
const param_definition_1 = require("molstar/lib/mol-util/param-definition");
const AnyParams = param_definition_1.ParamDefinition.Value({}, { description: 'Parameter description not available' });
var SequenceColorThemeProperty;
(function (SequenceColorThemeProperty) {
/** Provider name (key) for this custom property */
SequenceColorThemeProperty.Name = 'sequence-color-theme';
/** Create parameter definition for this custom property, using information from a color theme registry.
* If `colorThemeRegistry` is undefined, the `theme` parameter will be typed as `any` (i.e. no UI support). */
function makeParams(colorThemeRegistry) {
return {
useTheme: param_definition_1.ParamDefinition.Boolean(false, { description: 'Turn on/off background sequence color theme' }),
theme: colorThemeRegistry ?
param_definition_1.ParamDefinition.Mapped('uniform', colorThemeRegistry.types, name => {
try {
return param_definition_1.ParamDefinition.Group(colorThemeRegistry.get(name).getParams({ structure: structure_1.Structure.Empty }));
}
catch (err) {
console.warn(`Failed to obtain parameter definition for theme "${name}"`);
return AnyParams;
}
}, { hideIf: p => !p.useTheme })
: param_definition_1.ParamDefinition.Group({ name: param_definition_1.ParamDefinition.Text(), params: AnyParams }, { hideIf: p => !p.useTheme }),
themeStrength: param_definition_1.ParamDefinition.Numeric(1, { min: 0, max: 1, step: 0.01 }, { hideIf: p => !p.useTheme, description: 'Allows to "dilute" color coming from background sequence color theme' }),
dilutionColor: param_definition_1.ParamDefinition.Color(names_1.ColorNames.white, { hideIf: p => !p.useTheme || p.themeStrength === 1, description: 'Color used for "diluting" background sequence color theme' }),
};
}
SequenceColorThemeProperty.makeParams = makeParams;
/** Create a provider for this custom property, using information from a color theme registry.
* If `colorThemeRegistry` is undefined, the provider will work, but parameter definitions will not be inferred (i.e. limited UI support). */
function makeProvider(colorThemeRegistry) {
const params = makeParams(colorThemeRegistry);
return custom_structure_property_1.CustomStructureProperty.createProvider({
label: 'Sequence Color Theme',
descriptor: (0, custom_property_1.CustomPropertyDescriptor)({
name: SequenceColorThemeProperty.Name,
}),
type: 'root',
defaultParams: params,
getParams: (data) => params,
isApplicable: (data) => data.root === data,
obtain: (ctx, data, props) => tslib_1.__awaiter(this, void 0, void 0, function* () {
const fullProps = Object.assign(Object.assign({}, param_definition_1.ParamDefinition.getDefaultValues(params)), props);
return { value: (0, object_1.deepClone)(fullProps) };
}),
});
}
SequenceColorThemeProperty.makeProvider = makeProvider;
/** Default provider for this custom property, without type information from a color theme registry (i.e. limited UI support).
* Use `makeProvider` to get a provider with full UI support. */
SequenceColorThemeProperty.Provider = makeProvider(undefined);
})(SequenceColorThemeProperty || (exports.SequenceColorThemeProperty = SequenceColorThemeProperty = {}));