|
@@ -22,15 +22,22 @@ import { Subject } from 'rxjs';
|
|
|
// }
|
|
|
export type RepresentationProps = { [k: string]: any }
|
|
|
|
|
|
+export interface RepresentationContext {
|
|
|
+ readonly webgl?: WebGLContext
|
|
|
+ readonly colorThemeRegistry: ColorTheme.Registry
|
|
|
+ readonly sizeThemeRegistry: SizeTheme.Registry
|
|
|
+}
|
|
|
+
|
|
|
export type RepresentationParamsGetter<D, P extends PD.Params> = (ctx: ThemeRegistryContext, data: D) => P
|
|
|
+export type RepresentationFactory<D, P extends PD.Params> = (ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>) => Representation<D, P>
|
|
|
|
|
|
//
|
|
|
|
|
|
export interface RepresentationProvider<D, P extends PD.Params> {
|
|
|
readonly label: string
|
|
|
readonly description: string
|
|
|
- readonly factory: (getParams: RepresentationParamsGetter<D, P>) => Representation<D, P>
|
|
|
- readonly getParams: (ctx: ThemeRegistryContext, data: D) => P
|
|
|
+ readonly factory: RepresentationFactory<D, P>
|
|
|
+ readonly getParams: RepresentationParamsGetter<D, P>
|
|
|
readonly defaultValues: PD.Values<P>
|
|
|
}
|
|
|
|
|
@@ -71,12 +78,6 @@ export class RepresentationRegistry<D> {
|
|
|
|
|
|
//
|
|
|
|
|
|
-export interface RepresentationContext {
|
|
|
- webgl?: WebGLContext
|
|
|
- colorThemeRegistry: ColorTheme.Registry
|
|
|
- sizeThemeRegistry: SizeTheme.Registry
|
|
|
-}
|
|
|
-
|
|
|
export { Representation }
|
|
|
interface Representation<D, P extends PD.Params = {}> {
|
|
|
readonly label: string
|
|
@@ -86,7 +87,7 @@ interface Representation<D, P extends PD.Params = {}> {
|
|
|
readonly renderObjects: ReadonlyArray<RenderObject>
|
|
|
readonly props: Readonly<PD.Values<P>>
|
|
|
readonly params: Readonly<P>
|
|
|
- createOrUpdate: (ctx: RepresentationContext, props?: Partial<PD.Values<P>>, data?: D) => Task<void>
|
|
|
+ createOrUpdate: (props?: Partial<PD.Values<P>>, data?: D) => Task<void>
|
|
|
getLoci: (pickingId: PickingId) => Loci
|
|
|
mark: (loci: Loci, action: MarkerAction) => boolean
|
|
|
setVisibility: (value: boolean) => void
|
|
@@ -105,9 +106,9 @@ namespace Representation {
|
|
|
destroy: () => {}
|
|
|
}
|
|
|
|
|
|
- export type Def<D, P extends PD.Params = {}> = { [k: string]: (getParams: RepresentationParamsGetter<D, P>) => Representation<any, P> }
|
|
|
+ export type Def<D, P extends PD.Params = {}> = { [k: string]: RepresentationFactory<D, P> }
|
|
|
|
|
|
- export function createMulti<D, P extends PD.Params = {}>(label: string, getParams: RepresentationParamsGetter<D, P>, reprDefs: Def<D, P>): Representation<D, P> {
|
|
|
+ export function createMulti<D, P extends PD.Params = {}>(label: string, ctx: RepresentationContext, getParams: RepresentationParamsGetter<D, P>, reprDefs: Def<D, P>): Representation<D, P> {
|
|
|
let version = 0
|
|
|
const updated = new Subject<number>()
|
|
|
|
|
@@ -118,7 +119,7 @@ namespace Representation {
|
|
|
const reprMap: { [k: number]: string } = {}
|
|
|
const reprList: Representation<D, P>[] = Object.keys(reprDefs).map((name, i) => {
|
|
|
reprMap[i] = name
|
|
|
- return reprDefs[name](getParams)
|
|
|
+ return reprDefs[name](ctx, getParams)
|
|
|
})
|
|
|
|
|
|
return {
|
|
@@ -154,7 +155,7 @@ namespace Representation {
|
|
|
return props as P
|
|
|
},
|
|
|
get params() { return currentParams },
|
|
|
- createOrUpdate: (ctx: RepresentationContext, props: Partial<P> = {}, data?: D) => {
|
|
|
+ createOrUpdate: (props: Partial<P> = {}, data?: D) => {
|
|
|
if (data && data !== currentData) {
|
|
|
currentParams = getParams(ctx, data)
|
|
|
currentData = data
|
|
@@ -167,7 +168,7 @@ namespace Representation {
|
|
|
return Task.create(`Creating '${label}' representation`, async runtime => {
|
|
|
for (let i = 0, il = reprList.length; i < il; ++i) {
|
|
|
if (!visuals || visuals.includes(reprMap[i])) {
|
|
|
- await reprList[i].createOrUpdate(ctx, currentProps, currentData).runInContext(runtime)
|
|
|
+ await reprList[i].createOrUpdate(currentProps, currentData).runInContext(runtime)
|
|
|
}
|
|
|
}
|
|
|
updated.next(version++)
|
|
@@ -209,9 +210,10 @@ namespace Representation {
|
|
|
//
|
|
|
|
|
|
export interface VisualContext {
|
|
|
- webgl?: WebGLContext
|
|
|
- runtime: RuntimeContext,
|
|
|
+ readonly runtime: RuntimeContext
|
|
|
+ readonly webgl?: WebGLContext
|
|
|
}
|
|
|
+// export type VisualFactory<D, P extends PD.Params> = (ctx: VisualContext) => Visual<D, P>
|
|
|
|
|
|
export interface Visual<D, P extends PD.Params> {
|
|
|
/** Number of addressable groups in all instances of the visual */
|