Skip to content
Snippets Groups Projects
Select Git revision
  • 9d730e95fb89c5ac74e2d919ec5d69a83910ae9c
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

param-definition.ts

Blame
  • param-definition.ts 11.61 KiB
    /**
     * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     * @author David Sehnal <david.sehnal@gmail.com>
     */
    
    import { Color as ColorData } from './color';
    import { shallowEqual } from 'mol-util';
    import { Vec2 as Vec2Data, Vec3 as Vec3Data } from 'mol-math/linear-algebra';
    import { deepClone } from './object';
    
    export namespace ParamDefinition {
        export interface Info {
            label?: string,
            description?: string,
            isHidden?: boolean,
        }
    
        function setInfo<T extends Info>(param: T, info?: Info): T {
            if (!info) return param;
            if (info.description) param.description = info.description;
            if (info.label) param.label = info.label;
            if (info.isHidden) param.isHidden = info.isHidden;
            return param;
        }
    
        export interface Base<T> extends Info {
            isOptional?: boolean,
            defaultValue: T
        }
    
        export function makeOptional<T>(p: Base<T>): Base<T | undefined> {
            p.isOptional = true;
            return p;
        }
    
        export interface Value<T> extends Base<T> {
            type: 'value'
        }
        export function Value<T>(defaultValue: T, info?: Info): Value<T> {
            return setInfo<Value<T>>({ type: 'value', defaultValue }, info);
        }
    
        export interface Select<T extends string | number> extends Base<T> {
            type: 'select'
            /** array of (value, label) tuples */
            options: [T, string][]
        }
        export function Select<T extends string | number>(defaultValue: T, options: [T, string][], info?: Info): Select<T> {
            return setInfo<Select<T>>({ type: 'select', defaultValue, options }, info)
        }
    
        export interface ColorScale<T extends string> extends Base<T> {
            type: 'color-scale'
            /** array of (value, label) tuples */
            options: [T, string][]
        }
        export function ColorScale<T extends string>(defaultValue: T, options: [T, string][], info?: Info): ColorScale<T> {
            return setInfo<ColorScale<T>>({ type: 'color-scale', defaultValue, options }, info)
        }
    
        export interface MultiSelect<E extends string, T = E[]> extends Base<T> {
            type: 'multi-select'
            /** array of (value, label) tuples */
            options: [E, string][]
        }
        export function MultiSelect<E extends string, T = E[]>(defaultValue: T, options: [E, string][], info?: Info): MultiSelect<E, T> {
            return setInfo<MultiSelect<E, T>>({ type: 'multi-select', defaultValue, options }, info)
        }