Skip to content

Commit

Permalink
Updated entity type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
dsehnal committed Jan 25, 2017
1 parent 04314ab commit c075025
Show file tree
Hide file tree
Showing 15 changed files with 192 additions and 251 deletions.
256 changes: 99 additions & 157 deletions dist/js/LiteMol-plugin.d.ts

Large diffs are not rendered by default.

14 changes: 3 additions & 11 deletions dist/js/LiteMol-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -68387,7 +68387,7 @@ var LiteMol;
];
Default.Transparency = { alpha: 1.0, writeDepth: false };
Default.Theme = Default.Themes[0];
Default.Style = { type: {}, params: Default.Params, theme: { template: Default.Theme, colors: Default.Theme.colors, transparency: Default.Transparency, interactive: false, disableFog: false } };
Default.Style = { type: 'Density', params: Default.Params, theme: { template: Default.Theme, colors: Default.Theme.colors, transparency: Default.Transparency, interactive: false, disableFog: false } };
})(Default = Density.Default || (Density.Default = {}));
})(Density = Visualization.Density || (Visualization.Density = {}));
})(Visualization = Bootstrap.Visualization || (Bootstrap.Visualization = {}));
Expand Down Expand Up @@ -68588,13 +68588,6 @@ var LiteMol;
Entity.Root = Entity.create({ name: 'Root', typeClass: 'Root', shortName: 'R', description: 'Where everything begins.' });
Entity.Group = Entity.create({ name: 'Group', typeClass: 'Group', shortName: 'G', description: 'A group on entities.' });
Entity.Action = Entity.create({ name: 'Action', typeClass: 'Action', shortName: 'A', description: 'Represents an action performed on the entity tree.' });
var Behaviour;
(function (Behaviour) {
function create(info, traits) {
return Entity.create(info, traits);
}
Behaviour.create = create;
})(Behaviour = Entity.Behaviour || (Entity.Behaviour = {}));
/* Data */
var Data;
(function (Data) {
Expand All @@ -68604,7 +68597,6 @@ var LiteMol;
Data.CifDictionary = Entity.create({ name: 'Cif Dictionary', typeClass: 'Data', shortName: 'CD', description: 'Represents parsed CIF data.' });
Data.Json = Entity.create({ name: 'JSON Data', typeClass: 'Data', shortName: 'JS_D', description: 'Represents JSON data.' });
})(Data = Entity.Data || (Entity.Data = {}));
// /* Visual props */
var Visual;
(function (Visual) {
Visual.Surface = Entity.create({ name: 'Surface Visual', typeClass: 'Visual', shortName: 'V_S', description: 'A surface visual.' }, { isFocusable: true });
Expand All @@ -68618,15 +68610,15 @@ var LiteMol;
Molecule_1.Visual = Entity.create({ name: 'Molecule Visual', typeClass: 'Visual', shortName: 'V_M', description: 'A visual of a molecule.' }, { isFocusable: true });
var CoordinateStreaming;
(function (CoordinateStreaming) {
CoordinateStreaming.Behaviour = Entity.Behaviour.create({ name: 'Coordinate Streaming', typeClass: 'Behaviour', shortName: 'CS', description: 'Behaviour that downloads surrounding residues when an atom or residue is selected.' });
CoordinateStreaming.Behaviour = Entity.create({ name: 'Coordinate Streaming', typeClass: 'Behaviour', shortName: 'CS', description: 'Behaviour that downloads surrounding residues when an atom or residue is selected.' });
})(CoordinateStreaming = Molecule_1.CoordinateStreaming || (Molecule_1.CoordinateStreaming = {}));
})(Molecule = Entity.Molecule || (Entity.Molecule = {}));
/* Density */
var Density;
(function (Density) {
Density.Data = Entity.create({ name: 'Density Data', typeClass: 'Object', shortName: 'DD', description: 'Density data.' });
Density.Visual = Entity.create({ name: 'Density Visual', typeClass: 'Visual', shortName: 'V_DD', description: 'A visual of density data.' }, { isFocusable: true });
Density.InteractiveSurface = Behaviour.create({ name: 'Interactive Surface', typeClass: 'Behaviour', shortName: 'B_IS', description: 'Behaviour that creates an interactive surface when an atom or residue is selected.' });
Density.InteractiveSurface = Entity.create({ name: 'Interactive Surface', typeClass: 'Behaviour', shortName: 'B_IS', description: 'Behaviour that creates an interactive surface when an atom or residue is selected.' });
})(Density = Entity.Density || (Entity.Density = {}));
})(Entity = Bootstrap.Entity || (Bootstrap.Entity = {}));
})(Bootstrap = LiteMol.Bootstrap || (LiteMol.Bootstrap = {}));
Expand Down
16 changes: 8 additions & 8 deletions dist/js/LiteMol-plugin.min.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions docs/migrating/1-to-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ export const Behaviour = Entity.create<Behaviour, BehaviourType, BehaviourProps>
### 2.0

```TypeScript
export const Annotation = Entity.create<{ query: Query.Source; color: Visualization.Color; }>({ name: 'PDBe Sequence Annotation', typeClass: 'Object', shortName: 'SA', description: 'Represents PDBe sequence annotation.' }, { isSilent: true, isFocusable: true });
export type Annotation = typeof Annotation.Entity
export interface Annotation extends Entity<{ query: Query.Source; color: Visualization.Color; }> { }
export const Annotation = Entity.create<Annotation>({ name: 'PDBe Sequence Annotation', typeClass: 'Object', shortName: 'SA', description: 'Represents PDBe sequence annotation.' }, { isSilent: true, isFocusable: true })
```

Creating a behaviour:
Creating a behaviour entity:

```TypeScript
export interface Behaviour extends Entity.Behaviour<Interactivity.Behaviour, {}> { }
export const Behaviour = Entity.create<Behaviour>({ name: 'PDBe Sequence Annotation Behaviour', typeClass: 'Behaviour', shortName: 'SA', description: 'Represents PDBe sequence annoation behaviour.' });
```

Creating a visual entity:

```TypeScript
export const Behaviour = Entity.Behaviour.create<Interactivity.Behaviour, {}>({ name: 'PDBe Sequence Annotation Behaviour', typeClass: 'Behaviour', shortName: 'SA', description: 'Represents PDBe sequence annoation behaviour.' });
export type Behaviour = typeof Behaviour.Entity
export interface Visual extends Entity.Visual<Bootstrap.Visualization.Molecule.Type, { }> { }
export const Visual = Entity.create<Visual>({ name: 'Molecule Visual', typeClass: 'Visual', shortName: 'V_M', description: 'A visual of a molecule.' }, { isFocusable: true });
```

Transform Declaration
Expand Down
5 changes: 3 additions & 2 deletions examples/CustomDensity/src/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace LiteMol.Custom {
import Entity = Bootstrap.Entity;
import Transformer = Bootstrap.Entity.Transformer;

export const DensityLoader = Entity.create<{ id: string }>({ name: 'Density Loader', typeClass: 'Data', shortName: 'DL', description: 'Represents density loader entity.' });
export type DensityLoader = typeof DensityLoader.Entity
export interface DensityLoader extends Entity<{ id: string }> { }
export const DensityLoader = Entity.create<DensityLoader>({ name: 'Density Loader', typeClass: 'Data', shortName: 'DL', description: 'Represents density loader entity.' });


export const CreateDensityLoader = Bootstrap.Tree.Transformer.create<Entity.Root, DensityLoader, { id?: string }>({
id: 'litemol-custom_density_example-create-loader',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
"merge2": "^1.0.2",
"ts-node": "^2.0.0",
"typedoc": "^0.5.5",
"typescript": "^2.2.0-dev.20170124"
"typescript": "^2.2.0-dev.20170125"
}
}
2 changes: 1 addition & 1 deletion src/Bootstrap/Behaviour/Basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace LiteMol.Bootstrap.Behaviour {

latestModel = info.source.props.model;
latestIndices = info.elements;
latestModel.applySelection(latestIndices!, LiteMol.Visualization.Selection.Action.Select);
latestModel!.applySelection(latestIndices!, LiteMol.Visualization.Selection.Action.Select);
});
}

Expand Down
13 changes: 6 additions & 7 deletions src/Bootstrap/Entity/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace LiteMol.Bootstrap {
"use strict";

export interface Entity<Props extends Entity.CommonProps> extends Tree.Node<Props, Entity.State, Entity.TypeInfo> {
export interface Entity<Props> extends Tree.Node<Props & Entity.CommonProps, Entity.State, Entity.TypeInfo> {
}

export namespace Entity {
Expand All @@ -20,7 +20,7 @@ namespace LiteMol.Bootstrap {
export const enum Visibility { Full, Partial, None }
export interface State { isCollapsed?: boolean; visibility?: Visibility; }

export interface Any extends Entity<CommonProps> { }
export interface Any extends Entity<{}> { }

export type Tree = Bootstrap.Tree<Any>

Expand Down Expand Up @@ -49,11 +49,10 @@ namespace LiteMol.Bootstrap {
traits: TypeTraits;
}

export interface Type<P extends CommonProps> extends Tree.Node.Type<TypeInfo, P, Entity<P>> {
readonly Entity: Entity<P>,
export interface Type<P> extends Tree.Node.Type<TypeInfo, P, Entity<P>> {
create(transform: Tree.Transform<Any, Entity<P>, any>, props: P): Entity<P>
}
export type AnyType = Type<CommonProps>
export type AnyType = Type<{}>

export const RootClass:TypeClass = 'Root';
export const GroupClass:TypeClass = 'Group';
Expand Down Expand Up @@ -94,8 +93,8 @@ namespace LiteMol.Bootstrap {
}
}

export function create<Props extends { }>(info: TypeInfoBase, traits?: TypeTraits): Type<Props & CommonProps> {
return new TypeImpl(Utils.generateUUID(), info, traits ? traits : { }) as Type<Props & CommonProps>;
export function create<T extends Any>(info: TypeInfoBase, traits?: TypeTraits): Type<T['props']> {
return new TypeImpl(Utils.generateUUID(), info, traits ? traits : { }) as Type<T['props']>;
}
}
}
2 changes: 1 addition & 1 deletion src/Bootstrap/Entity/Transformer/Molecule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace LiteMol.Bootstrap.Entity.Transformer.Molecule {
.add(a, Data.OpenFile, { file: t.params.file, type: format.isBinary ? 'Binary' : 'String' })
.then(CreateFromData, { format }, { isBinding: true })
.then(Molecule.CreateModel, { modelIndex: 0 }, { isBinding: false })
})
});

export interface CreateFromDataParams {
format: Core.Formats.FormatInfo,
Expand Down
86 changes: 43 additions & 43 deletions src/Bootstrap/Entity/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,89 +25,89 @@ namespace LiteMol.Bootstrap.Entity {
/* Base */

export const RootTransform = Tree.Transform.create<Root, Root, {}>({}, {}, <any>void 0);

export interface Root extends Entity<{}> {}
export const Root = create<Root>({ name: 'Root', typeClass: 'Root', shortName: 'R', description: 'Where everything begins.' } );

export const Root = create({ name: 'Root', typeClass: 'Root', shortName: 'R', description: 'Where everything begins.' } );
export type Root = typeof Root.Entity

export const Group = create({ name: 'Group', typeClass: 'Group', shortName: 'G', description: 'A group on entities.' } );
export type Group = typeof Group.Entity
export interface Group extends Entity<{}> {}
export const Group = create<Group>({ name: 'Group', typeClass: 'Group', shortName: 'G', description: 'A group on entities.' } );

export const Action = create({ name: 'Action', typeClass: 'Action', shortName: 'A', description: 'Represents an action performed on the entity tree.' });
export type Action = typeof Action.Entity
export interface Action extends Entity<{}> {}
export const Action = create<Action>({ name: 'Action', typeClass: 'Action', shortName: 'A', description: 'Represents an action performed on the entity tree.' });

export interface Behaviour<T extends Bootstrap.Behaviour.Dynamic, Props> extends Entity<{ behaviour: T } & Props> { }

export namespace Behaviour {
export interface Any extends Entity<{ behaviour: Bootstrap.Behaviour.Dynamic } & CommonProps> { }

export function create<B extends Bootstrap.Behaviour.Dynamic, Props extends { }>(info: TypeInfoBase, traits?: TypeTraits): Type<{ behaviour: B } & Props & CommonProps> {
return Entity.create<{ behaviour: B } & Props & CommonProps>(info, traits);
}
}

/* Data */

export namespace Data {
export type Type = 'String' | 'Binary'
export const Types:Type[] = ['String', 'Binary'];
export const String = create<{ data: string }>({ name: 'String Data', typeClass: 'Data', shortName: 'S_D', description: 'A string.' });
export type String = typeof String.Entity
export const Binary = create<{ data: ArrayBuffer }>( { name: 'Binary Data', typeClass: 'Data', shortName: 'B_D', description: 'A binary blob.' });
export type Binary = typeof Binary.Entity
export const CifDictionary = create<{ dictionary: Core.Formats.CIF.File }>({ name: 'Cif Dictionary', typeClass: 'Data', shortName: 'CD', description: 'Represents parsed CIF data.' });
export type CifDictionary = typeof CifDictionary.Entity

export interface String extends Entity<{ data: string }> { }
export const String = create<String>({ name: 'String Data', typeClass: 'Data', shortName: 'S_D', description: 'A string.' });

export interface Binary extends Entity<{ data: ArrayBuffer }> { }
export const Binary = create<Binary>( { name: 'Binary Data', typeClass: 'Data', shortName: 'B_D', description: 'A binary blob.' });

export interface CifDictionary extends Entity<{ dictionary: Core.Formats.CIF.File }> { }
export const CifDictionary = create<CifDictionary>({ name: 'Cif Dictionary', typeClass: 'Data', shortName: 'CD', description: 'Represents parsed CIF data.' });

export const Json = create<{ data: any }>({ name: 'JSON Data', typeClass: 'Data', shortName: 'JS_D', description: 'Represents JSON data.' });
export type Json = typeof Json.Entity
export interface Json extends Entity<{ data: any }> { }
export const Json = create<Json>({ name: 'JSON Data', typeClass: 'Data', shortName: 'JS_D', description: 'Represents JSON data.' });
}

// /* Visual props */

export interface Visual<Type, Props> extends Entity<Visual.Props<Type> & Props> { }

export namespace Visual {
export interface Props<Type> {
model: LiteMol.Visualization.Model,
style: Visualization.Style<Type, any>,
isSelectable: boolean
}

export interface Any extends Entity<Props<any> & CommonProps> { }
export interface Any extends Visual<any, {}> { }

export const Surface = create<Entity.Visual.Props<"Surface"> & { tag: any }>({ name: 'Surface Visual', typeClass: 'Visual', shortName: 'V_S', description: 'A surface visual.' }, { isFocusable: true });
export type Surface = typeof Surface.Entity
export interface Surface extends Visual<"Surface", { tag: any }> { }
export const Surface = create<Surface>({ name: 'Surface Visual', typeClass: 'Visual', shortName: 'V_S', description: 'A surface visual.' }, { isFocusable: true });
}

/* Molecule */

export namespace Molecule {
export const Molecule = create<{ molecule: Core.Structure.Molecule }>({ name: 'Molecule', typeClass: 'Object', shortName: 'M', description: 'A molecule that might contain one or more models.' });
export type Molecule = typeof Molecule.Entity
export namespace Molecule {
export interface Molecule extends Entity<{ molecule: Core.Structure.Molecule }> { }
export const Molecule = create<Molecule>({ name: 'Molecule', typeClass: 'Object', shortName: 'M', description: 'A molecule that might contain one or more models.' });

export const Model = create<{ model: Core.Structure.Molecule.Model }>( { name: 'Molecule Model', typeClass: 'Object', shortName: 'M_M', description: 'A model of a molecule.' });
export type Model = typeof Model.Entity
export interface Model extends Entity<{ model: Core.Structure.Molecule.Model }> { }
export const Model = create<Model>( { name: 'Molecule Model', typeClass: 'Object', shortName: 'M_M', description: 'A model of a molecule.' });

export const Selection = create<{ indices: number[] }>( { name: 'Molecule Model Selection', typeClass: 'Selection', shortName: 'S_M', description: 'A selection of atoms.' }, { isFocusable: true });
export type Selection = typeof Selection.Entity
export interface Selection extends Entity<{ indices: number[] }> { }
export const Selection = create<Selection>( { name: 'Molecule Model Selection', typeClass: 'Selection', shortName: 'S_M', description: 'A selection of atoms.' }, { isFocusable: true });

export const Visual = create<Entity.Visual.Props<Bootstrap.Visualization.Molecule.Type>>({ name: 'Molecule Visual', typeClass: 'Visual', shortName: 'V_M', description: 'A visual of a molecule.' }, { isFocusable: true });
export type Visual = typeof Visual.Entity
export interface Visual extends Entity.Visual<Bootstrap.Visualization.Molecule.Type, { }> { }
export const Visual = create<Visual>({ name: 'Molecule Visual', typeClass: 'Visual', shortName: 'V_M', description: 'A visual of a molecule.' }, { isFocusable: true });

export namespace CoordinateStreaming {
export const Behaviour = Entity.Behaviour.create<Bootstrap.Behaviour.Molecule.CoordinateStreaming, {}>({ name: 'Coordinate Streaming', typeClass: 'Behaviour', shortName: 'CS', description: 'Behaviour that downloads surrounding residues when an atom or residue is selected.' });
export type Behaviour = typeof CoordinateStreaming.Behaviour.Entity
export interface Behaviour extends Entity.Behaviour<Bootstrap.Behaviour.Molecule.CoordinateStreaming, {}> {}
export const Behaviour = create<Behaviour>({ name: 'Coordinate Streaming', typeClass: 'Behaviour', shortName: 'CS', description: 'Behaviour that downloads surrounding residues when an atom or residue is selected.' });
}
}

/* Density */

export namespace Density {
export const Data = create<{ data: Core.Formats.Density.Data }>({ name: 'Density Data', typeClass: 'Object', shortName: 'DD', description: 'Density data.' });
export type Data = typeof Data.Entity
export namespace Density {
export interface Data extends Entity<{ data: Core.Formats.Density.Data }> { }
export const Data = create<Data>({ name: 'Density Data', typeClass: 'Object', shortName: 'DD', description: 'Density data.' });

export const Visual = create<Entity.Visual.Props<{}>>({ name: 'Density Visual', typeClass: 'Visual', shortName: 'V_DD', description: 'A visual of density data.' }, { isFocusable: true });
export type Visual = typeof Visual.Entity
export interface Visual extends Entity.Visual<'Density', {}> { }
export const Visual = create<Visual>({ name: 'Density Visual', typeClass: 'Visual', shortName: 'V_DD', description: 'A visual of density data.' }, { isFocusable: true });

export const InteractiveSurface = Behaviour.create<Bootstrap.Behaviour.Density.ShowDynamicDensity, {}>({ name: 'Interactive Surface', typeClass: 'Behaviour', shortName: 'B_IS', description: 'Behaviour that creates an interactive surface when an atom or residue is selected.' });
export type InteractiveSurface = typeof InteractiveSurface.Entity
export interface InteractiveSurface extends Behaviour<Bootstrap.Behaviour.Density.ShowDynamicDensity, {}> {}
export const InteractiveSurface = create<InteractiveSurface>({ name: 'Interactive Surface', typeClass: 'Behaviour', shortName: 'B_IS', description: 'Behaviour that creates an interactive surface when an atom or residue is selected.' });
}
}
Loading

0 comments on commit c075025

Please sign in to comment.