|
@@ -11,7 +11,7 @@ import { CarbohydrateSymbolColorThemeProvider } from './color/carbohydrate-symbo
|
|
import { UniformColorTheme, UniformColorThemeProvider } from './color/uniform';
|
|
import { UniformColorTheme, UniformColorThemeProvider } from './color/uniform';
|
|
import { deepEqual } from 'mol-util';
|
|
import { deepEqual } from 'mol-util';
|
|
import { ParamDefinition as PD } from 'mol-util/param-definition';
|
|
import { ParamDefinition as PD } from 'mol-util/param-definition';
|
|
-import { ThemeDataContext } from 'mol-theme/theme';
|
|
|
|
|
|
+import { ThemeDataContext } from './theme';
|
|
import { ChainIdColorThemeProvider } from './color/chain-id';
|
|
import { ChainIdColorThemeProvider } from './color/chain-id';
|
|
import { CrossLinkColorThemeProvider } from './color/cross-link';
|
|
import { CrossLinkColorThemeProvider } from './color/cross-link';
|
|
import { ElementIndexColorThemeProvider } from './color/element-index';
|
|
import { ElementIndexColorThemeProvider } from './color/element-index';
|
|
@@ -23,27 +23,11 @@ import { SecondaryStructureColorThemeProvider } from './color/secondary-structur
|
|
import { SequenceIdColorThemeProvider } from './color/sequence-id';
|
|
import { SequenceIdColorThemeProvider } from './color/sequence-id';
|
|
import { ShapeGroupColorThemeProvider } from './color/shape-group';
|
|
import { ShapeGroupColorThemeProvider } from './color/shape-group';
|
|
import { UnitIndexColorThemeProvider } from './color/unit-index';
|
|
import { UnitIndexColorThemeProvider } from './color/unit-index';
|
|
|
|
+import { ScaleLegend } from 'mol-util/color/scale';
|
|
|
|
+import { TableLegend } from 'mol-util/color/tables';
|
|
|
|
|
|
export type LocationColor = (location: Location, isSecondary: boolean) => Color
|
|
export type LocationColor = (location: Location, isSecondary: boolean) => Color
|
|
|
|
|
|
-export interface ScaleLegend {
|
|
|
|
- kind: 'scale-legend'
|
|
|
|
- minLabel: string,
|
|
|
|
- maxLabel: string,
|
|
|
|
- colors: Color[]
|
|
|
|
-}
|
|
|
|
-export function ScaleLegend(minLabel: string, maxLabel: string, colors: Color[]): ScaleLegend {
|
|
|
|
- return { kind: 'scale-legend', minLabel, maxLabel, colors }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export interface TableLegend {
|
|
|
|
- kind: 'table-legend'
|
|
|
|
- table: [ string, Color ][]
|
|
|
|
-}
|
|
|
|
-export function TableLegend(table: [ string, Color ][]): TableLegend {
|
|
|
|
- return { kind: 'table-legend', table }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
export type ColorThemeProps = { [k: string]: any }
|
|
export type ColorThemeProps = { [k: string]: any }
|
|
|
|
|
|
export { ColorTheme }
|
|
export { ColorTheme }
|
|
@@ -63,34 +47,40 @@ namespace ColorTheme {
|
|
}
|
|
}
|
|
|
|
|
|
export interface Provider<P extends PD.Params> {
|
|
export interface Provider<P extends PD.Params> {
|
|
|
|
+ readonly label: string
|
|
readonly factory: (ctx: ThemeDataContext, props: PD.Values<P>) => ColorTheme<PD.Values<P>>
|
|
readonly factory: (ctx: ThemeDataContext, props: PD.Values<P>) => ColorTheme<PD.Values<P>>
|
|
- readonly params: (ctx: ThemeDataContext) => P
|
|
|
|
|
|
+ readonly getParams: (ctx: ThemeDataContext) => P
|
|
}
|
|
}
|
|
|
|
+ export const EmptyProvider: Provider<{}> = { label: '', factory: () => Empty, getParams: () => ({}) }
|
|
|
|
|
|
export class Registry {
|
|
export class Registry {
|
|
private _list: { name: string, provider: Provider<any> }[] = []
|
|
private _list: { name: string, provider: Provider<any> }[] = []
|
|
private _map = new Map<string, Provider<any>>()
|
|
private _map = new Map<string, Provider<any>>()
|
|
|
|
|
|
|
|
+ get default() { return this._list[0]; }
|
|
|
|
+ get types(): [string, string][] {
|
|
|
|
+ return this._list.map(e => [e.name, e.provider.label] as [string, string]);
|
|
|
|
+ }
|
|
|
|
+
|
|
constructor() {
|
|
constructor() {
|
|
Object.keys(BuiltInColorThemes).forEach(name => {
|
|
Object.keys(BuiltInColorThemes).forEach(name => {
|
|
const p = (BuiltInColorThemes as { [k: string]: Provider<any> })[name]
|
|
const p = (BuiltInColorThemes as { [k: string]: Provider<any> })[name]
|
|
- this.add(name, p.factory, p.params)
|
|
|
|
|
|
+ this.add(name, p)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
- add<P extends PD.Params>(name: string, factory: Provider<P>['factory'], params: Provider<P>['params']) {
|
|
|
|
- const provider = { factory, params } as Provider<P>
|
|
|
|
|
|
+ add<P extends PD.Params>(name: string, provider: Provider<P>) {
|
|
this._list.push({ name, provider })
|
|
this._list.push({ name, provider })
|
|
this._map.set(name, provider)
|
|
this._map.set(name, provider)
|
|
}
|
|
}
|
|
|
|
|
|
- get(id: string) {
|
|
|
|
- return this._map.get(id)
|
|
|
|
|
|
+ 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 = {}) {
|
|
create(id: string, ctx: ThemeDataContext, props = {}) {
|
|
const provider = this.get(id)
|
|
const provider = this.get(id)
|
|
- return provider ? provider.factory(ctx, { ...PD.getDefaultValues(provider.params(ctx)), ...props }) : Empty
|
|
|
|
|
|
+ return provider ? provider.factory(ctx, { ...PD.getDefaultValues(provider.getParams(ctx)), ...props }) : Empty
|
|
}
|
|
}
|
|
|
|
|
|
get list() {
|
|
get list() {
|
|
@@ -116,4 +106,5 @@ export const BuiltInColorThemes = {
|
|
}
|
|
}
|
|
export type BuiltInColorThemeName = keyof typeof BuiltInColorThemes
|
|
export type BuiltInColorThemeName = keyof typeof BuiltInColorThemes
|
|
export const BuiltInColorThemeNames = Object.keys(BuiltInColorThemes)
|
|
export const BuiltInColorThemeNames = Object.keys(BuiltInColorThemes)
|
|
-export const BuiltInColorThemeOptions = BuiltInColorThemeNames.map(n => [n, n] as [BuiltInColorThemeName, string])
|
|
|
|
|
|
+export const BuiltInColorThemeOptions = BuiltInColorThemeNames.map(n => [n, n] as [BuiltInColorThemeName, string])
|
|
|
|
+export const getBuiltInColorThemeParams = (name: string, ctx: ThemeDataContext = {}) => PD.Group((BuiltInColorThemes as { [k: string]: ColorTheme.Provider<any> })[name].getParams(ctx))
|