Browse Source

moved label-options out of palette-params

Alexander Rose 4 years ago
parent
commit
8d6557e51c

+ 2 - 3
src/extensions/cellpack/color/generate.ts

@@ -46,10 +46,9 @@ export function CellPackGenerateColorTheme(ctx: ThemeDataContext, props: PD.Valu
             name: 'generate',
             params: {
                 hue, chroma: [30, 80], luminance: [15, 85],
-                clusteringStepCount: 50, minSampleCount: 800, maxCount: 75,
-                minLabel: 'Min', maxLabel: 'Max', valueLabel: (i: number) => `${i + 1}`,
+                clusteringStepCount: 50, minSampleCount: 800, maxCount: 75
             }
-        }});
+        }}, { minLabel: 'Min', maxLabel: 'Max' });
         legend = palette.legend;
         const modelColor = new Map<number, Color>();
         for (let i = 0, il = models.length; i < il; ++i) {

+ 2 - 2
src/mol-theme/color/chain-id.ts

@@ -84,9 +84,9 @@ export function ChainIdColorTheme(ctx: ThemeDataContext, props: PD.Values<ChainI
         const asymIdSerialMap = getAsymIdSerialMap(ctx.structure.root, props.asymId);
 
         const labelTable = Array.from(asymIdSerialMap.keys());
-        props.palette.params.valueLabel = (i: number) => labelTable[i];
+        const valueLabel = (i: number) => labelTable[i];
 
-        const palette = getPalette(asymIdSerialMap.size, props);
+        const palette = getPalette(asymIdSerialMap.size, props, { valueLabel });
         legend = palette.legend;
 
         color = (location: Location): Color => {

+ 2 - 2
src/mol-theme/color/entity-source.ts

@@ -131,9 +131,9 @@ export function EntitySourceColorTheme(ctx: ThemeDataContext, props: PD.Values<E
         const { seqToSrcByModelEntity, srcKeySerialMap } = getMaps(models);
 
         const labelTable = getLabelTable(srcKeySerialMap);
-        props.palette.params.valueLabel = (i: number) => labelTable[i];
+        const valueLabel = (i: number) => labelTable[i];
 
-        const palette = getPalette(srcKeySerialMap.size, props);
+        const palette = getPalette(srcKeySerialMap.size, props, { valueLabel });
         legend = palette.legend;
 
         const getSrcColor = (location: StructureElement.Location) => {

+ 6 - 4
src/mol-theme/color/operator-hkl.ts

@@ -85,11 +85,13 @@ export function OperatorHklColorTheme(ctx: ThemeDataContext, props: PD.Values<Op
             else labelTable[i] += `, ${label}`;
         });
 
-        props.palette.params.minLabel = formatHkl(min);
-        props.palette.params.maxLabel = formatHkl(max);
-        props.palette.params.valueLabel = (i: number) => labelTable[i];
+        const labelOptions = {
+            minLabel: formatHkl(min),
+            maxLabel: formatHkl(max),
+            valueLabel: (i: number) => labelTable[i]
+        };
 
-        const palette = getPalette(map.size, props);
+        const palette = getPalette(map.size, props, labelOptions);
         legend = palette.legend;
 
         color = (location: Location): Color => {

+ 2 - 2
src/mol-theme/color/operator-name.ts

@@ -43,9 +43,9 @@ export function OperatorNameColorTheme(ctx: ThemeDataContext, props: PD.Values<O
         const operatorNameSerialMap = getOperatorNameSerialMap(ctx.structure.root);
 
         const labelTable = Array.from(operatorNameSerialMap.keys());
-        props.palette.params.valueLabel = (i: number) => labelTable[i];
+        const valueLabel = (i: number) => labelTable[i];
 
-        const palette = getPalette(operatorNameSerialMap.size, props);
+        const palette = getPalette(operatorNameSerialMap.size, props, { valueLabel });
         legend = palette.legend;
 
         color = (location: Location): Color => {

+ 2 - 2
src/mol-theme/color/polymer-id.ts

@@ -94,9 +94,9 @@ export function PolymerIdColorTheme(ctx: ThemeDataContext, props: PD.Values<Poly
         const polymerAsymIdSerialMap = getPolymerAsymIdSerialMap(ctx.structure.root);
 
         const labelTable = Array.from(polymerAsymIdSerialMap.keys());
-        props.palette.params.valueLabel = (i: number) => labelTable[i];
+        const valueLabel = (i: number) => labelTable[i];
 
-        const palette = getPalette(polymerAsymIdSerialMap.size, props);
+        const palette = getPalette(polymerAsymIdSerialMap.size, props, { valueLabel });
         legend = palette.legend;
 
         color = (location: Location): Color => {

+ 12 - 12
src/mol-util/color/palette.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  * @author David Sehnal <david.sehnal@gmail.com>
@@ -20,22 +20,14 @@ const DefaultGetPaletteProps = {
 };
 type GetPaletteProps = typeof DefaultGetPaletteProps
 
-const LabelParams = {
-    valueLabel: PD.Value((i: number) => `${i + 1}`, { isHidden: true }),
-    minLabel: PD.Value('Start', { isHidden: true }),
-    maxLabel: PD.Value('End', { isHidden: true })
-};
-
 export function getPaletteParams(props: Partial<GetPaletteProps> = {}) {
     const p = { ...DefaultGetPaletteProps, ...props };
     return {
         palette: PD.MappedStatic(p.type, {
             colors: PD.Group({
-                ...LabelParams,
                 list: PD.ColorList(p.colorList),
             }, { isFlat: true }),
             generate: PD.Group({
-                ...LabelParams,
                 ...DistinctColorsParams,
                 maxCount: PD.Numeric(75, { min: 1, max: 250, step: 1 }),
             }, { isFlat: true })
@@ -51,18 +43,26 @@ export function getPaletteParams(props: Partial<GetPaletteProps> = {}) {
 const DefaultPaletteProps = PD.getDefaultValues(getPaletteParams());
 type PaletteProps = typeof DefaultPaletteProps
 
+const DefaultLabelOptions = {
+    valueLabel: (i: number) => `${i + 1}`,
+    minLabel: 'Start',
+    maxLabel: 'End'
+};
+type LabelOptions = typeof DefaultLabelOptions
+
 export interface Palette {
     color: (i: number) => Color
     legend?: TableLegend | ScaleLegend
 }
 
-export function getPalette(count: number, props: PaletteProps) {
+export function getPalette(count: number, props: PaletteProps, labelOptions: Partial<LabelOptions> = {}) {
     let color: (i: number) => Color;
     let legend: ScaleLegend | TableLegend | undefined;
 
     if (props.palette.name === 'colors' && props.palette.params.list.kind === 'interpolate') {
-        const { list, minLabel, maxLabel } = props.palette.params;
+        const { list } = props.palette.params;
         const domain: [number, number] = [0, count - 1];
+        const { minLabel, maxLabel } = { ...DefaultLabelOptions, ...labelOptions };
 
         let colors = list.colors;
         if (colors.length === 0) colors = getColorListFromName(DefaultGetPaletteProps.colorList).list;
@@ -79,7 +79,7 @@ export function getPalette(count: number, props: PaletteProps) {
             count = Math.min(count, props.palette.params.maxCount);
             colors = distinctColors(count, props.palette.params);
         }
-        const valueLabel = props.palette.params.valueLabel || (i => '' + i);
+        const valueLabel = labelOptions.valueLabel ?? DefaultLabelOptions.valueLabel;
         const colorsLength = colors.length;
         const table: [string, Color][] = [];
         for (let i = 0; i < count; ++i) {