Skip to content
Snippets Groups Projects
Commit 883c1b02 authored by Alexander Rose's avatar Alexander Rose
Browse files

better defaultParam handling

parent c0250539
No related branches found
No related tags found
No related merge requests found
...@@ -14,31 +14,31 @@ import { ParamDefinition as PD } from 'mol-util/param-definition'; ...@@ -14,31 +14,31 @@ import { ParamDefinition as PD } from 'mol-util/param-definition';
import { createTheme } from 'mol-theme/theme'; import { createTheme } from 'mol-theme/theme';
import { BuiltInStructureRepresentationsName } from 'mol-repr/structure/registry'; import { BuiltInStructureRepresentationsName } from 'mol-repr/structure/registry';
import { Structure } from 'mol-model/structure'; import { Structure } from 'mol-model/structure';
import { UnitsMeshParams } from 'mol-repr/structure/units-visual'; import { StructureParams } from 'mol-repr/structure/representation';
export namespace StructureRepresentation3DHelpers { export namespace StructureRepresentation3DHelpers {
export function getDefaultParams(ctx: PluginContext, name: BuiltInStructureRepresentationsName, structure: Structure, meshParams?: Partial<PD.Values<UnitsMeshParams>>): Transformer.Params<StructureRepresentation3D> { export function getDefaultParams(ctx: PluginContext, name: BuiltInStructureRepresentationsName, structure: Structure, structureParams?: Partial<PD.Values<StructureParams>>): Transformer.Params<StructureRepresentation3D> {
const type = ctx.structureRepresentation.registry.get(name); const type = ctx.structureRepresentation.registry.get(name);
const themeDataCtx = { structure }; const themeDataCtx = { structure };
const colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).getParams(themeDataCtx); const colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).getParams(themeDataCtx);
const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).getParams(themeDataCtx) const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).getParams(themeDataCtx)
const structureDefaultParams = PD.getDefaultValues(type.getParams(ctx.structureRepresentation.themeCtx, structure))
return ({ return ({
type: { name, params: meshParams ? { ...type.defaultValues, ...meshParams } : type.defaultValues }, type: { name, params: structureParams ? { ...structureDefaultParams, ...structureParams } : structureDefaultParams },
colorTheme: { name: type.defaultColorTheme, params: PD.getDefaultValues(colorParams) }, colorTheme: { name: type.defaultColorTheme, params: PD.getDefaultValues(colorParams) },
sizeTheme: { name: type.defaultSizeTheme, params: PD.getDefaultValues(sizeParams) } sizeTheme: { name: type.defaultSizeTheme, params: PD.getDefaultValues(sizeParams) }
}) })
} }
export function getDefaultParamsStatic(ctx: PluginContext, name: BuiltInStructureRepresentationsName, meshParams?: Partial<PD.Values<UnitsMeshParams>>): Transformer.Params<StructureRepresentation3D> { export function getDefaultParamsStatic(ctx: PluginContext, name: BuiltInStructureRepresentationsName, structureParams?: Partial<PD.Values<StructureParams>>): Transformer.Params<StructureRepresentation3D> {
const type = ctx.structureRepresentation.registry.get(name); const type = ctx.structureRepresentation.registry.get(name);
const colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).defaultValues; const colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).defaultValues;
const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).defaultValues const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).defaultValues
return ({ return ({
type: { name, params: meshParams ? { ...type.defaultValues, ...meshParams } : type.defaultValues }, type: { name, params: structureParams ? { ...type.defaultValues, ...structureParams } : type.defaultValues },
colorTheme: { name: type.defaultColorTheme, params: PD.getDefaultValues(colorParams) }, colorTheme: { name: type.defaultColorTheme, params: colorParams },
sizeTheme: { name: type.defaultSizeTheme, params: PD.getDefaultValues(sizeParams) } sizeTheme: { name: type.defaultSizeTheme, params: sizeParams }
}) })
} }
} }
......
...@@ -89,9 +89,9 @@ namespace ColorTheme { ...@@ -89,9 +89,9 @@ namespace ColorTheme {
return this._map.get(name) || EmptyProvider as unknown as Provider<P> return this._map.get(name) || EmptyProvider as unknown as Provider<P>
} }
create(id: string, ctx: ThemeDataContext, props = {}) { create(name: string, ctx: ThemeDataContext, props = {}) {
const provider = this.get(id) const provider = this.get(name)
return provider ? provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props }) : Empty return provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props })
} }
get list() { get list() {
......
...@@ -63,13 +63,13 @@ namespace SizeTheme { ...@@ -63,13 +63,13 @@ namespace SizeTheme {
this._map.delete(name) this._map.delete(name)
} }
get<P extends PD.Params>(id: string) { get<P extends PD.Params>(name: string): Provider<P> {
return this._map.get(id) || EmptyProvider as unknown as Provider<P> return this._map.get(name) || EmptyProvider as unknown as Provider<P>
} }
create(id: string, ctx: ThemeDataContext, props = {}) { create(name: string, ctx: ThemeDataContext, props = {}) {
const provider = this.get(id) const provider = this.get(name)
return provider ? provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props }) : Empty return provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props })
} }
get list() { get list() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment