From 3e07b95c8b50c1b3a5f2c6cbca990ddf31455653 Mon Sep 17 00:00:00 2001 From: Alexander Rose <alex.rose@rcsb.org> Date: Mon, 20 Aug 2018 16:31:01 -0700 Subject: [PATCH] wip, custom Loci and Location --- src/mol-model/location.ts | 15 ++++++++++++++- src/mol-model/loci.ts | 15 ++++++++++++++- src/mol-view/label.ts | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/mol-model/location.ts b/src/mol-model/location.ts index c3361122a..2ce2fdb16 100644 --- a/src/mol-model/location.ts +++ b/src/mol-model/location.ts @@ -14,4 +14,17 @@ export function isNullLocation(x: any): x is NullLocation { return !!x && x.kind === 'null-location'; } -export type Location = StructureElement | Link.Location | NullLocation \ No newline at end of file +/** A custom Location */ +export interface CustomLocation<D = any, K = any> { + readonly kind: 'custom-location' + data: D + key: K +} +export function CustomLocation<D, K>(data: D, key: K): CustomLocation<D, K> { + return { kind: 'custom-location', data, key } +} +export function isCustomLocation(x: any): x is CustomLocation<any, any> { + return !!x && x.kind === 'custom-location'; +} + +export type Location = StructureElement | Link.Location | NullLocation | CustomLocation \ No newline at end of file diff --git a/src/mol-model/loci.ts b/src/mol-model/loci.ts index 37a679c9c..47c737cee 100644 --- a/src/mol-model/loci.ts +++ b/src/mol-model/loci.ts @@ -6,6 +6,7 @@ import { StructureElement } from './structure' import { Link } from './structure/structure/unit/links' +import { CustomLocation } from './location'; /** A Loci that includes every loci */ export const EveryLoci = { kind: 'every-loci' as 'every-loci' } @@ -21,4 +22,16 @@ export function isEmptyLoci(x: any): x is EmptyLoci { return !!x && x.kind === 'empty-loci'; } -export type Loci = StructureElement.Loci | Link.Loci | EveryLoci | EmptyLoci \ No newline at end of file +/** A Loci of custom locations */ +export interface CustomLoci<D = any, K = any> { + readonly kind: 'custom-loci' + readonly locations: ReadonlyArray<CustomLocation> +} +export function CustomLoci<D, K>(locations: CustomLocation<D, K>[]): CustomLoci<D, K> { + return { kind: 'custom-loci', locations } +} +export function isCustomLoci(x: any): x is CustomLoci { + return !!x && x.kind === 'custom-loci'; +} + +export type Loci = StructureElement.Loci | Link.Loci | EveryLoci | EmptyLoci | CustomLoci \ No newline at end of file diff --git a/src/mol-view/label.ts b/src/mol-view/label.ts index 288eae467..2211c5da2 100644 --- a/src/mol-view/label.ts +++ b/src/mol-view/label.ts @@ -36,6 +36,8 @@ export function labelFirst(loci: Loci): string { } else { return 'Unknown' } + case 'custom-loci': + return 'Custom' case 'every-loci': return 'Everything' case 'empty-loci': -- GitLab