import { AbstractFormatter } from '../Formatter'; import { TypedValue } from '../DataPrimitive'; import { DataSeries } from '../DataSeries'; import { DataPoint } from '../DataPoint'; export declare const DEFAULT_MIN_COLOR = "rgba(123,86,219,0.4)"; export declare const DEFAULT_MAX_COLOR = "rgba(123,86,219,1)"; export interface GradientConfig { stops?: number[]; colors: string[]; } /** * Based on stops and colors, this formatter maps the value to an interpolated color. * * The `config` follows this criteria: `{ stops: [0, 100, 230], colors: ['red', 'green', 'blue'] }` * * If no config is specified, the default `colors` are `['rgba(123,86,219,0.4)', 'rgba(123,86,219,1)']`. The default `stops` are dependent on the DataSeries provided. * * Given a DataSeries with n values, the stops would consist of [min, ...(configured stops), max] if stops values are contained in [min, max] - recommended. * And min/max map to 'rgba(123,86,219,0.4)'/'rgba(123,86,219,1)', respectively. * * For example, if 0 < value < 100, the corresponding interpolated color will be between red and green. * * ```js * primary | seriesByIndex(0) | gradient(gradientConfig)' // it maps [0, 50, 230] to ['#7B56DB66', '#FF0000', '#7B56DB'] * colorOption1: '> primary | seriesByIndex(1) | gradient(gradientConfig)' // it maps [50, 100, 150] to ['red', 'green', 'blue'] * }} * dataSources={{ * data: { * primary: { * columns: [[0, 50, 230], [50, 100, 150]], * fields: [{ name: 'foo' }, { name: 'bar' }] * } * } * }} * /> * ``` * * DataFrame (table) usage: * When the input is a DataFrame (for example, a table), the formatter computes a global min/max across * all numeric series in the frame. Those min/max are then used to build stops, and the formatter returns * a new DataFrame of type `'color'` with each numeric cell mapped to its interpolated color. * * Minimal DSL example with a DataFrame in context as `table`: * * ```js * table | gradient(gradientConfig)' * }} * dataSources={{ * data: { * primary: { * columns: [[0, 50, 230], [50, 100, 150]], * fields: [{ name: 'foo' }, { name: 'bar' }] * } * } * }} * /> * ``` * * If no `stops` are provided, they are derived from the global DataFrame min/max. * * @extends AbstractFormatter */ export declare class Gradient extends AbstractFormatter<'number', 'color'> { readonly config: GradientConfig; readonly colors: string[]; readonly stops: number[]; constructor(config?: GradientConfig); static readonly sortArray: (array: number[]) => void; /** * Computes numeric min and max over a DataSeries by coercing each point's value * to a number. This avoids lexicographic ordering from DataSeries.min()/max(), * which compares coercedValue strings (e.g. '10' < '2') for string-typed points. * Returns { min: NaN, max: NaN } if no numeric values are found. */ private static numericMinMax; static readonly addDefaultEndingColors: (colors: string[], n: number) => void; static readonly ignoreMinMaxWhenNeeded: (min: number, max: number, stops: number[], newStops: number[], newColors: string[]) => void; private prepareStopsAndColors; private static computeNoStopsCase; private static computeColorsForStopsOnly; private static alignColorsWithStops; private static colorForValue; format(dataPrimitive: any): any; private prepareColorsAndStopsSeries; private prepareColorsAndStopsPoint; protected formatTypedValue(p: DataPoint<'number'>, series: DataSeries): TypedValue<'color'>; }