Select Git revision
param-definition.ts
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)
}