Browse Source

use ColorTypeLocation as default

- for backwards compatibility
- most used
Alexander Rose 3 years ago
parent
commit
856e6a8b74

+ 2 - 2
src/mol-geo/geometry/color-data.ts

@@ -31,7 +31,7 @@ export type ColorData = {
     dUsePalette: ValueCell<boolean>,
 }
 
-export function createColors(locationIt: LocationIterator, positionIt: LocationIterator, colorTheme: ColorTheme<any>, colorData?: ColorData): ColorData {
+export function createColors(locationIt: LocationIterator, positionIt: LocationIterator, colorTheme: ColorTheme<any, any>, colorData?: ColorData): ColorData {
     const data = _createColors(locationIt, positionIt, colorTheme, colorData);
     if (colorTheme.palette) {
         ValueCell.updateIfChanged(data.dUsePalette, true);
@@ -42,7 +42,7 @@ export function createColors(locationIt: LocationIterator, positionIt: LocationI
     return data;
 }
 
-function _createColors(locationIt: LocationIterator, positionIt: LocationIterator, colorTheme: ColorTheme<any>, colorData?: ColorData): ColorData {
+function _createColors(locationIt: LocationIterator, positionIt: LocationIterator, colorTheme: ColorTheme<any, any>, colorData?: ColorData): ColorData {
     switch (colorTheme.granularity) {
         case 'uniform': return createUniformColor(locationIt, colorTheme.color, colorData);
         case 'instance':

+ 11 - 11
src/mol-theme/color.ts

@@ -49,8 +49,8 @@ export interface ColorVolume {
 
 export { ColorTheme };
 
-type ColorThemeShared<P extends PD.Params> = {
-    readonly factory: ColorTheme.Factory<P>
+type ColorThemeShared<P extends PD.Params, G extends ColorType> = {
+    readonly factory: ColorTheme.Factory<P, G>
     readonly props: Readonly<PD.Values<P>>
     /**
      * if palette is defined, 24bit RGB color value normalized to interval [0, 1]
@@ -66,18 +66,18 @@ type ColorThemeShared<P extends PD.Params> = {
 type ColorThemeLocation<P extends PD.Params> = {
     readonly granularity: ColorTypeLocation
     readonly color: LocationColor
-} & ColorThemeShared<P>
+} & ColorThemeShared<P, ColorTypeLocation>
 
 type ColorThemeGrid<P extends PD.Params> = {
     readonly granularity: ColorTypeGrid
     readonly grid: ColorVolume
-} & ColorThemeShared<P>
+} & ColorThemeShared<P, ColorTypeGrid>
 
 type ColorThemeDirect<P extends PD.Params> = {
     readonly granularity: ColorTypeDirect
-} & ColorThemeShared<P>
+} & ColorThemeShared<P, ColorTypeDirect>
 
-type ColorTheme<P extends PD.Params, G extends ColorType = any> =
+type ColorTheme<P extends PD.Params, G extends ColorType = ColorTypeLocation> =
     G extends ColorTypeLocation ? ColorThemeLocation<P> :
         G extends ColorTypeGrid ? ColorThemeGrid<P> :
             G extends ColorTypeDirect ? ColorThemeDirect<P> : never
@@ -100,7 +100,7 @@ namespace ColorTheme {
     export const PaletteScale = (1 << 24) - 1;
 
     export type Props = { [k: string]: any }
-    export type Factory<P extends PD.Params> = (ctx: ThemeDataContext, props: PD.Values<P>) => ColorTheme<P>
+    export type Factory<P extends PD.Params, G extends ColorType> = (ctx: ThemeDataContext, props: PD.Values<P>) => ColorTheme<P, G>
     export const EmptyFactory = () => Empty;
     const EmptyColor = Color(0xCCCCCC);
     export const Empty: ColorTheme<{}> = {
@@ -110,16 +110,16 @@ namespace ColorTheme {
         props: {}
     };
 
-    export function areEqual(themeA: ColorTheme<any>, themeB: ColorTheme<any>) {
+    export function areEqual(themeA: ColorTheme<any, any>, themeB: ColorTheme<any, any>) {
         return themeA.contextHash === themeB.contextHash && themeA.factory === themeB.factory && deepEqual(themeA.props, themeB.props);
     }
 
-    export interface Provider<P extends PD.Params = any, Id extends string = string> extends ThemeProvider<ColorTheme<P>, P, Id> { }
+    export interface Provider<P extends PD.Params = any, Id extends string = string, G extends ColorType = ColorType> extends ThemeProvider<ColorTheme<P, G>, P, Id, G> { }
     export const EmptyProvider: Provider<{}> = { name: '', label: '', category: '', factory: EmptyFactory, getParams: () => ({}), defaultValues: {}, isApplicable: () => true };
 
-    export type Registry = ThemeRegistry<ColorTheme<any>>
+    export type Registry = ThemeRegistry<ColorTheme<any, any>>
     export function createRegistry() {
-        return new ThemeRegistry(BuiltIn as { [k: string]: Provider<any> }, EmptyProvider);
+        return new ThemeRegistry(BuiltIn as { [k: string]: Provider<any, any, any> }, EmptyProvider);
     }
 
     export const BuiltIn = {

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

@@ -12,7 +12,6 @@ import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { ThemeDataContext } from '../../mol-theme/theme';
 import { getPaletteParams, getPalette } from '../../mol-util/color/palette';
 import { TableLegend, ScaleLegend } from '../../mol-util/legend';
-import { ColorTypeLocation } from '../../mol-geo/geometry/color-data';
 
 const DefaultList = 'many-distinct';
 const DefaultColor = Color(0xFAFAFA);
@@ -76,7 +75,7 @@ function getAsymIdSerialMap(structure: Structure, type: AsymIdType) {
     return map;
 }
 
-export function ChainIdColorTheme(ctx: ThemeDataContext, props: PD.Values<ChainIdColorThemeParams>): ColorTheme<ChainIdColorThemeParams, ColorTypeLocation> {
+export function ChainIdColorTheme(ctx: ThemeDataContext, props: PD.Values<ChainIdColorThemeParams>): ColorTheme<ChainIdColorThemeParams> {
     let color: LocationColor;
     let legend: ScaleLegend | TableLegend | undefined;
 

+ 1 - 2
src/mol-theme/color/entity-id.ts

@@ -12,7 +12,6 @@ import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { ThemeDataContext } from '../../mol-theme/theme';
 import { getPaletteParams, getPalette } from '../../mol-util/color/palette';
 import { TableLegend, ScaleLegend } from '../../mol-util/legend';
-import { ColorTypeLocation } from '../../mol-geo/geometry/color-data';
 
 const DefaultList = 'many-distinct';
 const DefaultColor = Color(0xFAFAFA);
@@ -66,7 +65,7 @@ function getEntityId(location: StructureElement.Location): string {
     }
 }
 
-export function EntityIdColorTheme(ctx: ThemeDataContext, props: PD.Values<EntityIdColorThemeParams>): ColorTheme<EntityIdColorThemeParams, ColorTypeLocation> {
+export function EntityIdColorTheme(ctx: ThemeDataContext, props: PD.Values<EntityIdColorThemeParams>): ColorTheme<EntityIdColorThemeParams> {
     let color: LocationColor;
     let legend: ScaleLegend | TableLegend | undefined;
 

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

@@ -17,7 +17,6 @@ import { TableLegend, ScaleLegend } from '../../mol-util/legend';
 import { isInteger } from '../../mol-util/number';
 import { ColorLists, getColorListFromName } from '../../mol-util/color/lists';
 import { MmcifFormat } from '../../mol-model-formats/structure/mmcif';
-import { ColorTypeLocation } from '../../mol-geo/geometry/color-data';
 
 const DefaultList = 'dark-2';
 const DefaultColor = Color(0xFAFAFA);
@@ -122,7 +121,7 @@ function getLabelTable(srcKeySerialMap: Map<string, number>) {
     });
 }
 
-export function EntitySourceColorTheme(ctx: ThemeDataContext, props: PD.Values<EntitySourceColorThemeParams>): ColorTheme<EntitySourceColorThemeParams, ColorTypeLocation> {
+export function EntitySourceColorTheme(ctx: ThemeDataContext, props: PD.Values<EntitySourceColorThemeParams>): ColorTheme<EntitySourceColorThemeParams> {
     let color: LocationColor;
     let legend: ScaleLegend | TableLegend | undefined;
 

+ 1 - 2
src/mol-theme/color/molecule-type.ts

@@ -15,7 +15,6 @@ import { ThemeDataContext } from '../theme';
 import { TableLegend } from '../../mol-util/legend';
 import { getAdjustedColorMap } from '../../mol-util/color/color';
 import { getColorMapParams } from '../../mol-util/color/params';
-import { ColorTypeLocation } from '../../mol-geo/geometry/color-data';
 
 export const MoleculeTypeColors = ColorMap({
     water: 0x386cb0,
@@ -58,7 +57,7 @@ export function moleculeTypeColor(colorMap: MoleculeTypeColors, unit: Unit, elem
     return DefaultMoleculeTypeColor;
 }
 
-export function MoleculeTypeColorTheme(ctx: ThemeDataContext, props: PD.Values<MoleculeTypeColorThemeParams>): ColorTheme<MoleculeTypeColorThemeParams, ColorTypeLocation> {
+export function MoleculeTypeColorTheme(ctx: ThemeDataContext, props: PD.Values<MoleculeTypeColorThemeParams>): ColorTheme<MoleculeTypeColorThemeParams> {
     const colorMap = getAdjustedColorMap(props.colors.name === 'default' ? MoleculeTypeColors : props.colors.params, props.saturation, props.lightness);
 
     function color(location: Location): Color {

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

@@ -12,7 +12,6 @@ import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { ThemeDataContext } from '../theme';
 import { getPaletteParams, getPalette } from '../../mol-util/color/palette';
 import { ScaleLegend, TableLegend } from '../../mol-util/legend';
-import { ColorTypeLocation } from '../../mol-geo/geometry/color-data';
 
 const DefaultList = 'many-distinct';
 const DefaultColor = Color(0xCCCCCC);
@@ -36,7 +35,7 @@ function getOperatorNameSerialMap(structure: Structure) {
     return map;
 }
 
-export function OperatorNameColorTheme(ctx: ThemeDataContext, props: PD.Values<OperatorNameColorThemeParams>): ColorTheme<OperatorNameColorThemeParams, ColorTypeLocation> {
+export function OperatorNameColorTheme(ctx: ThemeDataContext, props: PD.Values<OperatorNameColorThemeParams>): ColorTheme<OperatorNameColorThemeParams> {
     let color: LocationColor;
     let legend: ScaleLegend | TableLegend | undefined;
 

+ 1 - 2
src/mol-theme/color/uniform.ts

@@ -10,7 +10,6 @@ import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { ThemeDataContext } from '../theme';
 import { TableLegend } from '../../mol-util/legend';
 import { defaults } from '../../mol-util';
-import { ColorTypeLocation } from '../../mol-geo/geometry/color-data';
 
 const DefaultColor = Color(0xCCCCCC);
 const Description = 'Gives everything the same, uniform color.';
@@ -23,7 +22,7 @@ export function getUniformColorThemeParams(ctx: ThemeDataContext) {
     return UniformColorThemeParams; // TODO return copy
 }
 
-export function UniformColorTheme(ctx: ThemeDataContext, props: PD.Values<UniformColorThemeParams>): ColorTheme<UniformColorThemeParams, ColorTypeLocation> {
+export function UniformColorTheme(ctx: ThemeDataContext, props: PD.Values<UniformColorThemeParams>): ColorTheme<UniformColorThemeParams> {
     const color = defaults(props.value, DefaultColor);
 
     return {

+ 2 - 1
src/mol-theme/color/volume-value.ts

@@ -9,6 +9,7 @@ import { Color, ColorScale } from '../../mol-util/color';
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { ThemeDataContext } from '../theme';
 import { ColorNames } from '../../mol-util/color/names';
+import { ColorTypeDirect } from '../../mol-geo/geometry/color-data';
 
 const Description = 'Assign color based on the given value of a volume cell.';
 
@@ -29,7 +30,7 @@ export function getVolumeValueColorThemeParams(ctx: ThemeDataContext) {
     return VolumeValueColorThemeParams; // TODO return copy
 }
 
-export function VolumeValueColorTheme(ctx: ThemeDataContext, props: PD.Values<VolumeValueColorThemeParams>): ColorTheme<VolumeValueColorThemeParams> {
+export function VolumeValueColorTheme(ctx: ThemeDataContext, props: PD.Values<VolumeValueColorThemeParams>): ColorTheme<VolumeValueColorThemeParams, ColorTypeDirect> {
     const scale = ColorScale.create({ domain: [0, 1], listOrName: props.colorList.colors });
 
     const colors: Color[] = [];

+ 5 - 4
src/mol-theme/theme.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -12,6 +12,7 @@ import { ParamDefinition as PD } from '../mol-util/param-definition';
 import { Shape } from '../mol-model/shape';
 import { CustomProperty } from '../mol-model-props/common/custom-property';
 import { objectForEach } from '../mol-util/object';
+import { ColorType } from '../mol-geo/geometry/color-data';
 
 export interface ThemeRegistryContext {
     colorThemeRegistry: ColorTheme.Registry
@@ -28,7 +29,7 @@ export interface ThemeDataContext {
 export { Theme };
 
 interface Theme {
-    color: ColorTheme<any>
+    color: ColorTheme<any, any>
     size: SizeTheme<any>
     // label: LabelTheme // TODO
 }
@@ -65,7 +66,7 @@ namespace Theme {
 
 //
 
-export interface ThemeProvider<T extends ColorTheme<P> | SizeTheme<P>, P extends PD.Params, Id extends string = string> {
+export interface ThemeProvider<T extends ColorTheme<P, G> | SizeTheme<P>, P extends PD.Params, Id extends string = string, G extends ColorType = ColorType> {
     readonly name: Id
     readonly label: string
     readonly category: string
@@ -83,7 +84,7 @@ function getTypes(list: { name: string, provider: ThemeProvider<any, any> }[]) {
     return list.map(e => [e.name, e.provider.label, e.provider.category] as [string, string, string]);
 }
 
-export class ThemeRegistry<T extends ColorTheme<any> | SizeTheme<any>> {
+export class ThemeRegistry<T extends ColorTheme<any, any> | SizeTheme<any>> {
     private _list: { name: string, provider: ThemeProvider<T, any> }[] = [];
     private _map = new Map<string, ThemeProvider<T, any>>();
     private _name = new Map<ThemeProvider<T, any>, string>();