|
@@ -7,19 +7,24 @@
|
|
|
|
|
|
import { Color as ColorData } from './color';
|
|
import { Color as ColorData } from './color';
|
|
import { shallowClone } from 'mol-util';
|
|
import { shallowClone } from 'mol-util';
|
|
|
|
+import { Vec2 } from 'mol-math/linear-algebra';
|
|
|
|
+import { camelCaseToWords } from './string';
|
|
|
|
|
|
export namespace ParamDefinition {
|
|
export namespace ParamDefinition {
|
|
- export interface Base<T> {
|
|
|
|
- label: string
|
|
|
|
- description: string
|
|
|
|
|
|
+ export interface Info {
|
|
|
|
+ label?: string
|
|
|
|
+ description?: string
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ export interface Base<T> extends Info {
|
|
defaultValue: T
|
|
defaultValue: T
|
|
}
|
|
}
|
|
|
|
|
|
export interface Value<T> extends Base<T> {
|
|
export interface Value<T> extends Base<T> {
|
|
type: 'value'
|
|
type: 'value'
|
|
}
|
|
}
|
|
- export function Value<T>(label: string, description: string, defaultValue: T): Value<T> {
|
|
|
|
- return { type: 'value', label, description, defaultValue }
|
|
|
|
|
|
+ export function Value<T>(defaultValue: T, info: Info = {}): Value<T> {
|
|
|
|
+ return { type: 'value', defaultValue, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface Select<T extends string> extends Base<T> {
|
|
export interface Select<T extends string> extends Base<T> {
|
|
@@ -27,8 +32,8 @@ export namespace ParamDefinition {
|
|
/** array of (value, label) tuples */
|
|
/** array of (value, label) tuples */
|
|
options: [T, string][]
|
|
options: [T, string][]
|
|
}
|
|
}
|
|
- export function Select<T extends string>(label: string, description: string, defaultValue: T, options: [T, string][]): Select<T> {
|
|
|
|
- return { type: 'select', label, description, defaultValue, options }
|
|
|
|
|
|
+ export function Select<T extends string>(defaultValue: T, options: [T, string][], info: Info = {}): Select<T> {
|
|
|
|
+ return { type: 'select', defaultValue, options, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface MultiSelect<E extends string, T = E[]> extends Base<T> {
|
|
export interface MultiSelect<E extends string, T = E[]> extends Base<T> {
|
|
@@ -36,66 +41,67 @@ export namespace ParamDefinition {
|
|
/** array of (value, label) tuples */
|
|
/** array of (value, label) tuples */
|
|
options: [E, string][]
|
|
options: [E, string][]
|
|
}
|
|
}
|
|
- export function MultiSelect<E extends string, T = E[]>(label: string, description: string, defaultValue: T, options: [E, string][]): MultiSelect<E, T> {
|
|
|
|
- return { type: 'multi-select', label, description, defaultValue, options }
|
|
|
|
|
|
+ export function MultiSelect<E extends string, T = E[]>(defaultValue: T, options: [E, string][], info: Info = {}): MultiSelect<E, T> {
|
|
|
|
+ return { type: 'multi-select', defaultValue, options, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface Boolean extends Base<boolean> {
|
|
export interface Boolean extends Base<boolean> {
|
|
type: 'boolean'
|
|
type: 'boolean'
|
|
}
|
|
}
|
|
- export function Boolean(label: string, description: string, defaultValue: boolean): Boolean {
|
|
|
|
- return { type: 'boolean', label, description, defaultValue }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- export interface Range extends Base<number> {
|
|
|
|
- type: 'range'
|
|
|
|
- min: number
|
|
|
|
- max: number
|
|
|
|
- /** if an `integer` parse value with parseInt, otherwise use parseFloat */
|
|
|
|
- step: number
|
|
|
|
- }
|
|
|
|
- export function Range(label: string, description: string, defaultValue: number, min: number, max: number, step: number): Range {
|
|
|
|
- return { type: 'range', label, description, defaultValue, min, max, step }
|
|
|
|
|
|
+ export function Boolean(defaultValue: boolean, info: Info = {}): Boolean {
|
|
|
|
+ return { type: 'boolean', defaultValue, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface Text extends Base<string> {
|
|
export interface Text extends Base<string> {
|
|
type: 'text'
|
|
type: 'text'
|
|
}
|
|
}
|
|
- export function Text(label: string, description: string, defaultValue: string = ''): Text {
|
|
|
|
- return { type: 'text', label, description, defaultValue }
|
|
|
|
|
|
+ export function Text(defaultValue: string = '', info: Info = {}): Text {
|
|
|
|
+ return { type: 'text', defaultValue, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface Color extends Base<ColorData> {
|
|
export interface Color extends Base<ColorData> {
|
|
type: 'color'
|
|
type: 'color'
|
|
}
|
|
}
|
|
- export function Color(label: string, description: string, defaultValue: ColorData): Color {
|
|
|
|
- return { type: 'color', label, description, defaultValue }
|
|
|
|
|
|
+ export function Color(defaultValue: ColorData, info: Info = {}): Color {
|
|
|
|
+ return { type: 'color', defaultValue, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface Numeric extends Base<number> {
|
|
export interface Numeric extends Base<number> {
|
|
type: 'number'
|
|
type: 'number'
|
|
- min: number
|
|
|
|
- max: number
|
|
|
|
- /** if an `integer` parse value with parseInt, otherwise use parseFloat */
|
|
|
|
- step: number
|
|
|
|
|
|
+ /** If given treat as a range. */
|
|
|
|
+ min?: number
|
|
|
|
+ /** If given treat as a range. */
|
|
|
|
+ max?: number
|
|
|
|
+ /**
|
|
|
|
+ * If given treat as a range.
|
|
|
|
+ * If an `integer` parse value with parseInt, otherwise use parseFloat.
|
|
|
|
+ */
|
|
|
|
+ step?: number
|
|
}
|
|
}
|
|
- export function Numeric(label: string, description: string, defaultValue: number, min: number, max: number, step: number): Numeric {
|
|
|
|
- return { type: 'number', label, description, defaultValue, min, max, step }
|
|
|
|
|
|
+ export function Numeric(defaultValue: number, range: { min?: number, max?: number, step?: number } = {}, info: Info = {}): Numeric {
|
|
|
|
+ return { type: 'number', defaultValue, ...range, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface Interval extends Base<[number, number]> {
|
|
export interface Interval extends Base<[number, number]> {
|
|
type: 'interval'
|
|
type: 'interval'
|
|
}
|
|
}
|
|
- export function Interval(label: string, description: string, defaultValue: [number, number]): Interval {
|
|
|
|
- return { type: 'interval', label, description, defaultValue }
|
|
|
|
|
|
+ export function Interval(defaultValue: [number, number], info: Info = {}): Interval {
|
|
|
|
+ return { type: 'interval', defaultValue, ...info }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ export interface LineGraph extends Base<Vec2[]> {
|
|
|
|
+ type: 'line-graph'
|
|
|
|
+ }
|
|
|
|
+ export function LineGraph(defaultValue: Vec2[], info: Info = {}): LineGraph {
|
|
|
|
+ return { type: 'line-graph', defaultValue, ...info }
|
|
}
|
|
}
|
|
|
|
|
|
export interface Group<T> extends Base<T> {
|
|
export interface Group<T> extends Base<T> {
|
|
type: 'group',
|
|
type: 'group',
|
|
params: Params
|
|
params: Params
|
|
}
|
|
}
|
|
- export function Group<P extends Params>(label: string, description: string, params: P): Group<Values<P>> {
|
|
|
|
- return { type: 'group', label, description, defaultValue: getDefaultValues(params) as any, params };
|
|
|
|
|
|
+ export function Group<P extends Params>(params: P, info: Info = {}): Group<Values<P>> {
|
|
|
|
+ return { type: 'group', defaultValue: getDefaultValues(params) as any, params };
|
|
}
|
|
}
|
|
|
|
|
|
export interface Mapped<T> extends Base<{ name: string, params: T }> {
|
|
export interface Mapped<T> extends Base<{ name: string, params: T }> {
|
|
@@ -103,18 +109,23 @@ export namespace ParamDefinition {
|
|
select: Select<string>,
|
|
select: Select<string>,
|
|
map(name: string): Any
|
|
map(name: string): Any
|
|
}
|
|
}
|
|
- export function Mapped<T>(label: string, description: string, defaultKey: string, names: [string, string][], map: Mapped<T>['map']): Mapped<T> {
|
|
|
|
|
|
+ export function Mapped<T>(defaultKey: string, names: [string, string][], map: Mapped<T>['map'], info: Info = {}): Mapped<T> {
|
|
return {
|
|
return {
|
|
type: 'mapped',
|
|
type: 'mapped',
|
|
- label,
|
|
|
|
- description,
|
|
|
|
defaultValue: { name: defaultKey, params: map(defaultKey).defaultValue as any },
|
|
defaultValue: { name: defaultKey, params: map(defaultKey).defaultValue as any },
|
|
- select: Select<string>(label, description, defaultKey, names),
|
|
|
|
|
|
+ select: Select<string>(defaultKey, names, info),
|
|
map
|
|
map
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- export type Any = Value<any> | Select<any> | MultiSelect<any> | Boolean | Range | Text | Color | Numeric | Interval | Group<any> | Mapped<any>
|
|
|
|
|
|
+ export interface Converted<T, C> extends Base<T> {
|
|
|
|
+ type: 'converted',
|
|
|
|
+ convertedControl: Base<C>,
|
|
|
|
+ fromValue(v: T): C,
|
|
|
|
+ toValue(v: C): T
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ export type Any = Value<any> | Select<any> | MultiSelect<any> | Boolean | Text | Color | Numeric | Interval | LineGraph | Group<any> | Mapped<any> | Converted<any, any>
|
|
|
|
|
|
export type Params = { [k: string]: Any }
|
|
export type Params = { [k: string]: Any }
|
|
export type Values<T extends Params> = { [k in keyof T]: T[k]['defaultValue'] }
|
|
export type Values<T extends Params> = { [k in keyof T]: T[k]['defaultValue'] }
|
|
@@ -125,6 +136,15 @@ export namespace ParamDefinition {
|
|
return d as Values<T>
|
|
return d as Values<T>
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ export function getLabels<T extends Params>(params: T) {
|
|
|
|
+ const d: { [k: string]: string } = {}
|
|
|
|
+ Object.keys(params).forEach(k => {
|
|
|
|
+ const label = params[k].label
|
|
|
|
+ d[k] = label === undefined ? camelCaseToWords(k) : label
|
|
|
|
+ })
|
|
|
|
+ return d as { [k in keyof T]: string }
|
|
|
|
+ }
|
|
|
|
+
|
|
export function clone<P extends Params>(params: P): P {
|
|
export function clone<P extends Params>(params: P): P {
|
|
return shallowClone(params)
|
|
return shallowClone(params)
|
|
}
|
|
}
|