/** * @typedef {object} SelectionService The selection service instance, exposing the following methods. * @property {function(number):boolean} getIsDimensionLocked Find out if dimension at given index is locked. * @property {function():boolean} getIsSelectionLocked Find out if selections are locked. * @property {function([number]):boolean} getIsSingleSelect Find out if dimension at given index (defaults to first unlocked dim or last index) should be treated as single select. * @property {function():boolean} getCanSelect Find out if you can do selections. * @property {function():object} getSelectionsObject Returns the selections API object. * @property {function():object} getSelectionInfo Returns the selectionInfo object. * @property {function(object):undefined} setLayout Update the service with the latest layout. * @property {function(object):undefined} setFilteredFields Set filtered fields. Used to remap fields during selection. * @property {function(object):undefined} setBrushAliases Set brush aliases. * @property {function():undefined} destroy Unbinds all registered event listeners and cleans up. * @property {object} custom A container object for your custom methods. Will be empty if you haven't defined any methods. */ /** * * @typedef {object} Actions * @property {object} select Exposes an interface for connecting to select action events. * @property {function(string, function):undefined} select.on Event registering method. * @property {function(string, [function]):undefined} select.removeListener Event unregistering method. * @property {object} lasso Exposes the lasso active state and an action for toggling this state. * @property {function():boolean} lasso.active Returns the active state. * @property {function():undefined} lasso.action Toggles the activation state. */ /** * * @typedef {object} Selections An object exposing "native" selection events and actions. * @property {function(string, function):undefined} on Function for registering events. * @property {function(string, [function]):undefined} removeListener Function for unregistering events. * @property {function():boolean} isActive Returns its activation state. * @property {function(object):undefined} select Selects a value. * @property {function():boolean} isModal Returns true if in modal mode. * @property {function():undefined} confirm Confirms selections (which will make it escape from modal mode). * @property {function():boolean} isLocked Returns the locked selections state. */ /** * * @typedef {object} BrushRange * @property {string} key Path to a dimensionInfo item appended by value type, e.g. 'qHyperCube/qDimensionInfo/0:numeric' * @property {boolean} includeMax */ /** * * @typedef {function(object[]):object[]} Interceptor Takes in added values and returns filtered values. */ /** * @typedef {object} ClearArg If an argument properties are sent in into the functions, they will override default ones. * @property {function(object):undefined} clearDiscrete Clears discrete range. * @property {function(object):undefined} clearMinor Clears minor range. * @property {function(object):undefined} clearRange Clears range. * @property {function(object):undefined} clearTap Clears tap. * @property {function(object):undefined} clearLegend Clears legend range. * @property {Selections} selections * @property {object} selectionInfo * @property {object} chart A picasso chart instance. * @property {object} document * @property {boolean} cleared Equals true if the call originates in the default selectionEvents.cleared listener. */ /** * @typedef {object} SelectionsConfig An object holding all desired initial configurations of the selection service. * @property {boolean|string[]} allowSimultaneous Allow simultaneous selections from these dimensions/measures. If true, it will be defined as the first 15 measures. * @property {object} [majorScale] A major scale, or just send in an object containing below method. * @property {function():number} [majorScale.max] Should return the max value from the majorScale. * @property {object} [selectionActions] Selection actions. Set to false to disable registering selection events containing these actions (currently, all selection events). * @property {(function(ClearArg):undefined|false)} [selectionActions.clear] Action called on clear. Will receive an object containing all default clear functions. Set to false to disable registering default listeners containing this action. * @property {(function():undefined|false)} [selectionActions.reset] Action called on reset. Set to false to disable registering default listeners containing this action. * @property {(object|boolean)} [selectionEvents] Selection events which can be overridden. Set to false to disable all selectionEvents (and/or set selectionActions to false). * @property {function(object):undefined} [selectionEvents.deactivated] Called on deactivated. Will receive original function as property 'defaultFunc'. * @property {function(object):undefined} [selectionEvents.canceled] Called on canceled. Will receive original function as property 'defaultFunc'. * @property {function(object):undefined} [selectionEvents.cleared] Called on cleared. Will receive original function as property 'defaultFunc'. * @property {function(object):undefined} [selectionEvents.start] Called on start. Not required but defaults to an empty function. Must call setSelectionInfo() sent in as a parameter. * @property {object} [brushEvents] Exposes an interface for binding to brush events. * @property {function(object)} [brushEvents.update] Called on brush update. * @property {function(object)} [brushEvents.end] Called on brush end. * @property {string} [brushName] Name of the brush to configure. Defaults to 'selection'. * @property {number} [brushMaxListeners] Maximum number of allowed brush listeners. Default is 20. * @property {(boolean|BrushRange[])} [brushRanges] If true, it will set the default brush range. If false it will not set anything. * @property {{string: ((Interceptor|Interceptor[]))}} [interceptors] Interceptor or interceptors (array) mapped by selection type. * @property {function(object):object[]} [selectionsFn] Selection function. * @property {{string: function(*):*}} [custom] An object with custom methods accessible from instance.custom.yourMethod() * @property {string} [legendAlias] An alias path (a "key") used for getting the data path for the legend. * @property {function(object)} [setBrushAliases] A function for overriding the default one. Will receive the default function as defaultFunc inside the first argument object. * */ /** * @param {object} c Configurations and dependencies for Color Service. * @param {object} c.chart A picasso chart instance. * @param {Selections} c.selections Selections API Object. * @param {Actions} [c.actions] An object holding the lasso and select objects. * @param {SelectionsConfig} c.config Configuration for customizing the behaviour. * @returns {SelectionService} */ export default function createSelectionService({ chart, selections, actions, config }: { chart: object; selections: Selections; actions?: Actions | undefined; config: SelectionsConfig; }): SelectionService; /** * The selection service instance, exposing the following methods. */ export type SelectionService = { /** * Find out if dimension at given index is locked. */ getIsDimensionLocked: (arg0: number) => boolean; /** * Find out if selections are locked. */ getIsSelectionLocked: () => boolean; /** * Find out if dimension at given index (defaults to first unlocked dim or last index) should be treated as single select. */ getIsSingleSelect: (arg0: [number]) => boolean; /** * Find out if you can do selections. */ getCanSelect: () => boolean; /** * Returns the selections API object. */ getSelectionsObject: () => object; /** * Returns the selectionInfo object. */ getSelectionInfo: () => object; /** * Update the service with the latest layout. */ setLayout: (arg0: object) => undefined; /** * Set filtered fields. Used to remap fields during selection. */ setFilteredFields: (arg0: object) => undefined; /** * Set brush aliases. */ setBrushAliases: (arg0: object) => undefined; /** * Unbinds all registered event listeners and cleans up. */ destroy: () => undefined; /** * A container object for your custom methods. Will be empty if you haven't defined any methods. */ custom: object; }; export type Actions = { /** * Exposes an interface for connecting to select action events. */ select: { on: (arg0: string, arg1: Function) => undefined; removeListener: (arg0: string, arg1: [Function]) => undefined; }; /** * Exposes the lasso active state and an action for toggling this state. */ lasso: { active: () => boolean; action: () => undefined; }; }; /** * An object exposing "native" selection events and actions. */ export type Selections = { /** * Function for registering events. */ on: (arg0: string, arg1: Function) => undefined; /** * Function for unregistering events. */ removeListener: (arg0: string, arg1: [Function]) => undefined; /** * Returns its activation state. */ isActive: () => boolean; /** * Selects a value. */ select: (arg0: object) => undefined; /** * Returns true if in modal mode. */ isModal: () => boolean; /** * Confirms selections (which will make it escape from modal mode). */ confirm: () => undefined; /** * Returns the locked selections state. */ isLocked: () => boolean; }; export type BrushRange = { /** * Path to a dimensionInfo item appended by value type, e.g. 'qHyperCube/qDimensionInfo/0:numeric' */ key: string; includeMax: boolean; }; /** * Takes in added values and returns filtered values. */ export type Interceptor = (arg0: object[]) => object[]; /** * If an argument properties are sent in into the functions, they will override default ones. */ export type ClearArg = { /** * Clears discrete range. */ clearDiscrete: (arg0: object) => undefined; /** * Clears minor range. */ clearMinor: (arg0: object) => undefined; /** * Clears range. */ clearRange: (arg0: object) => undefined; /** * Clears tap. */ clearTap: (arg0: object) => undefined; /** * Clears legend range. */ clearLegend: (arg0: object) => undefined; selections: Selections; selectionInfo: object; /** * A picasso chart instance. */ chart: object; document: object; /** * Equals true if the call originates in the default selectionEvents.cleared listener. */ cleared: boolean; }; /** * An object holding all desired initial configurations of the selection service. */ export type SelectionsConfig = { /** * Allow simultaneous selections from these dimensions/measures. If true, it will be defined as the first 15 measures. */ allowSimultaneous: boolean | string[]; /** * A major scale, or just send in an object containing below method. */ majorScale?: { /** * Should return the max value from the majorScale. */ max?: (() => number) | undefined; } | undefined; /** * Selection actions. Set to false to disable registering selection events containing these actions (currently, all selection events). */ selectionActions?: { /** * Action called on clear. Will receive an object containing all default clear functions. Set to false to disable registering default listeners containing this action. */ clear?: ((arg0: ClearArg) => undefined | false) | undefined; /** * Action called on reset. Set to false to disable registering default listeners containing this action. */ reset?: (() => undefined | false) | undefined; } | undefined; /** * Selection events which can be overridden. Set to false to disable all selectionEvents (and/or set selectionActions to false). */ selectionEvents?: boolean | object | undefined; /** * Called on deactivated. Will receive original function as property 'defaultFunc'. */ deactivated?: ((arg0: object) => undefined) | undefined; /** * Called on canceled. Will receive original function as property 'defaultFunc'. */ canceled?: ((arg0: object) => undefined) | undefined; /** * Called on cleared. Will receive original function as property 'defaultFunc'. */ cleared?: ((arg0: object) => undefined) | undefined; /** * Called on start. Not required but defaults to an empty function. Must call setSelectionInfo() sent in as a parameter. */ start?: ((arg0: object) => undefined) | undefined; /** * Exposes an interface for binding to brush events. */ brushEvents?: { /** * Called on brush update. */ update?: ((arg0: object) => any) | undefined; /** * Called on brush end. */ end?: ((arg0: object) => any) | undefined; } | undefined; /** * Name of the brush to configure. Defaults to 'selection'. */ brushName?: string | undefined; /** * Maximum number of allowed brush listeners. Default is 20. */ brushMaxListeners?: number | undefined; /** * If true, it will set the default brush range. If false it will not set anything. */ brushRanges?: boolean | BrushRange[] | undefined; /** * Interceptor or interceptors (array) mapped by selection type. */ interceptors?: { string: ((Interceptor | Interceptor[])); } | undefined; /** * Selection function. */ selectionsFn?: ((arg0: object) => object[]) | undefined; /** * An object with custom methods accessible from instance.custom.yourMethod() */ custom?: { string: (arg0: any) => any; } | undefined; /** * An alias path (a "key") used for getting the data path for the legend. */ legendAlias?: string | undefined; /** * A function for overriding the default one. Will receive the default function as defaultFunc inside the first argument object. */ setBrushAliases?: ((arg0: object) => any) | undefined; };