From 883c1b026f1853555050b59c4d06799e1fa3fd95 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Tue, 27 Nov 2018 14:56:16 -0800
Subject: [PATCH] better defaultParam handling

---
 .../state/transforms/representation.ts           | 16 ++++++++--------
 src/mol-theme/color.ts                           |  6 +++---
 src/mol-theme/size.ts                            | 10 +++++-----
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/mol-plugin/state/transforms/representation.ts b/src/mol-plugin/state/transforms/representation.ts
index 5ea400ae8..443148667 100644
--- a/src/mol-plugin/state/transforms/representation.ts
+++ b/src/mol-plugin/state/transforms/representation.ts
@@ -14,31 +14,31 @@ import { ParamDefinition as PD } from 'mol-util/param-definition';
 import { createTheme } from 'mol-theme/theme';
 import { BuiltInStructureRepresentationsName } from 'mol-repr/structure/registry';
 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 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 themeDataCtx = { structure };
         const colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).getParams(themeDataCtx);
         const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).getParams(themeDataCtx)
+        const structureDefaultParams = PD.getDefaultValues(type.getParams(ctx.structureRepresentation.themeCtx, structure))
         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) },
             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 colorParams = ctx.structureRepresentation.themeCtx.colorThemeRegistry.get(type.defaultColorTheme).defaultValues;
         const sizeParams = ctx.structureRepresentation.themeCtx.sizeThemeRegistry.get(type.defaultSizeTheme).defaultValues
         return ({
-            type: { name, params: meshParams ? { ...type.defaultValues, ...meshParams } : type.defaultValues },
-            colorTheme: { name: type.defaultColorTheme, params: PD.getDefaultValues(colorParams) },
-            sizeTheme: { name: type.defaultSizeTheme, params: PD.getDefaultValues(sizeParams) }
+            type: { name, params: structureParams ? { ...type.defaultValues, ...structureParams } : type.defaultValues },
+            colorTheme: { name: type.defaultColorTheme, params: colorParams },
+            sizeTheme: { name: type.defaultSizeTheme, params: sizeParams }
         })
     }
 }
diff --git a/src/mol-theme/color.ts b/src/mol-theme/color.ts
index 32f98d654..75bbc2eee 100644
--- a/src/mol-theme/color.ts
+++ b/src/mol-theme/color.ts
@@ -89,9 +89,9 @@ namespace ColorTheme {
             return this._map.get(name) || EmptyProvider as unknown as Provider<P>
         }
 
-        create(id: string, ctx: ThemeDataContext, props = {}) {
-            const provider = this.get(id)
-            return provider ? provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props }) : Empty
+        create(name: string, ctx: ThemeDataContext, props = {}) {
+            const provider = this.get(name)
+            return provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props })
         }
 
         get list() {
diff --git a/src/mol-theme/size.ts b/src/mol-theme/size.ts
index 6433b60f3..16179eb0d 100644
--- a/src/mol-theme/size.ts
+++ b/src/mol-theme/size.ts
@@ -63,13 +63,13 @@ namespace SizeTheme {
             this._map.delete(name)
         }
 
-        get<P extends PD.Params>(id: string) {
-            return this._map.get(id) || EmptyProvider as unknown as Provider<P>
+        get<P extends PD.Params>(name: string): Provider<P> {
+            return this._map.get(name) || EmptyProvider as unknown as Provider<P>
         }
 
-        create(id: string, ctx: ThemeDataContext, props = {}) {
-            const provider = this.get(id)
-            return provider ? provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props }) : Empty
+        create(name: string, ctx: ThemeDataContext, props = {}) {
+            const provider = this.get(name)
+            return provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props })
         }
 
         get list() {
-- 
GitLab