浏览代码

allow partial params in .createParams helper

Alexander Rose 5 年之前
父节点
当前提交
eeb09d9184
共有 1 个文件被更改,包括 9 次插入7 次删除
  1. 9 7
      src/mol-plugin/state/transforms/representation.ts

+ 9 - 7
src/mol-plugin/state/transforms/representation.ts

@@ -61,9 +61,9 @@ namespace StructureRepresentation3DHelpers {
 
     export function createParams<R extends RepresentationProvider<Structure, any, any>, C extends ColorTheme.Provider<any>, S extends SizeTheme.Provider<any>>(
             ctx: PluginContext, structure: Structure, params: {
-            repr?: R | [R, (r: R, ctx: ThemeRegistryContext, s: Structure) => RepresentationProvider.ParamValues<R>],
-            color?: C | [C, (c: C, ctx: ThemeRegistryContext) => ColorTheme.ParamValues<C>],
-            size?: S | [S, (c: S, ctx: ThemeRegistryContext) => SizeTheme.ParamValues<S>]
+            repr?: R | [R, (r: R, ctx: ThemeRegistryContext, s: Structure) => Partial<RepresentationProvider.ParamValues<R>>],
+            color?: C | [C, (c: C, ctx: ThemeRegistryContext) => Partial<ColorTheme.ParamValues<C>>],
+            size?: S | [S, (c: S, ctx: ThemeRegistryContext) => Partial<SizeTheme.ParamValues<S>>]
         }): StateTransformer.Params<StructureRepresentation3D> {
 
         const themeCtx = ctx.structureRepresentation.themeCtx
@@ -79,16 +79,18 @@ namespace StructureRepresentation3DHelpers {
         const color = params.color
             ? params.color instanceof Array ? params.color[0] : params.color
             : themeCtx.colorThemeRegistry.get(repr.defaultColorTheme);
+        const colorDefaultParams = PD.getDefaultValues(color.getParams(themeCtx))
         const colorParams = params.color instanceof Array
-            ? params.color[1](color as C, themeCtx)
-            : PD.getDefaultValues(color.getParams(themeCtx));
+            ? { ...colorDefaultParams, ...params.color[1](color as C, themeCtx) }
+            : colorDefaultParams;
 
         const size = params.size
             ? params.size instanceof Array ? params.size[0] : params.size
             : themeCtx.sizeThemeRegistry.get(repr.defaultSizeTheme);
+        const sizeDefaultParams = PD.getDefaultValues(size.getParams(themeCtx))
         const sizeParams = params.size instanceof Array
-            ? params.size[1](size as S, themeCtx)
-            : PD.getDefaultValues(size.getParams(themeCtx));
+            ? { ...sizeDefaultParams, ...params.size[1](size as S, themeCtx) }
+            : sizeDefaultParams;
 
         return ({
             type: { name: ctx.structureRepresentation.registry.getName(repr), params: reprParams },