/** * @typedef {function} ColorFunction * @param {object} d An object containing a datum. * @param {object} d.datum A datum object. * @param {number} d.datum.value A value which the color function maps to a color. * @returns {string} A hex color. */ /** * @typedef {object} PaletteArgument * @property {number} index An index of a color to pick from the current palette. * @property {string} color A fallback color in case the palette does not find a color at given index. */ /** * @typedef {object} ColorSettings * @property {string} mode For instance 'measure' or 'dimension' * @property {string} type For instance 'categorical' * @property {string} nil Fallback color * @returns */ /** * @typedef {object} LegendConfig * @property {array} components Legend components. * @property {array} interactions Legend interactions. */ /** * @typedef {object} ColorService The color service instance, exposing the following methods. * @property {function():ColorFunction} getColor Returns a color function. * @property {function(PaletteArgument):string} getPaletteColor Returns a color from the palette. * @property {function():array} getData Returns configuration which can help extract coloring data from the hypercube. * @property {function():object} getDatumProps Returns datum properties, typically for configuring Picasso data props. * @property {function():object} getSnapshotData Returns coloring data needed for rendering a snapshot. * @property {function(number):ColorSettings} getSettingsForMeasure Returns color settings for the measure at given index. * @property {function():ColorSettings} getSettings Returns color settings. * @property {function(object, object):LegendConfig} getLegend Returns components and interactions to build a legend. * @property {function():object} getScales Returns scales configuration. * @property {function():array} getPalettes Returns an array of palette configurations or an empty array. * @property {function():boolean} isSelectionLocked Will become deprecated! Tells whether selections are locked or not. * @property {function():promise} initialize Creates and applies the configuration needed for the color service to work correctly. * @property {function():boolean} isInitialized Returns `true` if color service is initialized, otherwise `false`. * @property {{string: function(*):*}} [custom] A container object for your custom methods. Will be empty if you haven't defined any methods. */ /** * @typedef {object} CreateConfigArg * @param {function} getUseBaseColors Get the base colors inside your function to incorporate in your custom config. * @returns {object} Your custom configuration which will extend the initial and default configuration. */ /** * @param {object} c Configuration object for Color Service. * @param {object} c.picasso A picasso instance. * @param {object} c.model Enigma model. * @param {object} c.app App object. * @param {object} c.translator Translator function. * @param {LayoutService} [c.layoutService] A chart-modules LayoutService instance. * @param {function(CreateConfigArg)} [c.createConfig] A function returning your custom configuration of the coloring service. * @param {object} [c.config] Configuration which can be set during instantiation. * @param {function} [c.config.auto] A function which tells how to apply the automatic (i.e. default) coloring. * @param {string} c.config.localeInfo A string telling which locale. * @param {string} c.config.key A key for use when you have many coloring instances. * @param {object} c.config.theme The theme to use. * @param {object} [c.config.definitionPath='/qHyperCubeDef'] The path to the hypercube for attribute dimensions. * @param {object} [c.custom] An object container with your custom methods. Useful if you want to bind them to the color service. * @returns {ColorService} */ export default function createColorService({ picasso, model, app, translator, layoutService, createConfig: defaultCreateConfig, config, custom, }: { picasso: object; model: object; app: object; translator: object; layoutService?: any; createConfig?: ((arg0: CreateConfigArg) => any) | undefined; config?: { auto?: Function | undefined; localeInfo: string; key: string; theme: object; definitionPath?: object | undefined; } | undefined; custom?: object | undefined; }): ColorService; export type ColorFunction = Function; export type PaletteArgument = { /** * An index of a color to pick from the current palette. */ index: number; /** * A fallback color in case the palette does not find a color at given index. */ color: string; }; export type ColorSettings = { /** * For instance 'measure' or 'dimension' */ mode: string; /** * For instance 'categorical' */ type: string; /** * Fallback color */ nil: string; }; export type LegendConfig = { /** * Legend components. */ components: array; /** * Legend interactions. */ interactions: array; }; /** * The color service instance, exposing the following methods. */ export type ColorService = { /** * Returns a color function. */ getColor: () => ColorFunction; /** * Returns a color from the palette. */ getPaletteColor: (arg0: PaletteArgument) => string; /** * Returns configuration which can help extract coloring data from the hypercube. */ getData: () => array; /** * Returns datum properties, typically for configuring Picasso data props. */ getDatumProps: () => object; /** * Returns coloring data needed for rendering a snapshot. */ getSnapshotData: () => object; /** * Returns color settings for the measure at given index. */ getSettingsForMeasure: (arg0: number) => ColorSettings; /** * Returns color settings. */ getSettings: () => ColorSettings; /** * Returns components and interactions to build a legend. */ getLegend: (arg0: object, arg1: object) => LegendConfig; /** * Returns scales configuration. */ getScales: () => object; /** * Returns an array of palette configurations or an empty array. */ getPalettes: () => array; /** * Will become deprecated! Tells whether selections are locked or not. */ isSelectionLocked: () => boolean; /** * Creates and applies the configuration needed for the color service to work correctly. */ initialize: () => promise; /** * Returns `true` if color service is initialized, otherwise `false`. */ isInitialized: () => boolean; /** * A container object for your custom methods. Will be empty if you haven't defined any methods. */ custom?: { string: (arg0: any) => any; } | undefined; }; export type CreateConfigArg = object;