ソースを参照

wip, custom Loci and Location

Alexander Rose 6 年 前
コミット
3e07b95c8b
3 ファイル変更30 行追加2 行削除
  1. 14 1
      src/mol-model/location.ts
  2. 14 1
      src/mol-model/loci.ts
  3. 2 0
      src/mol-view/label.ts

+ 14 - 1
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
+/** 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

+ 14 - 1
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
+/** 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

+ 2 - 0
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':