UNPKG

viridis

Version:

Color gradients for data visualization

55 lines (54 loc) 2.3 kB
import { Color } from './Color'; /** * Represents a linear, uniform color gradient. */ export declare class Gradient { readonly colors: Color[]; /** * Define a new linear color gradient using an array of * color stops. Gradients can include any number of color * stops, which are all equally spaced from one another. * @param colors An array of colors to define this color gradient * @example * const redBlue = new Gradient([ * new Color(255, 0, 0), * new Color(0, 0, 255), * ]); */ constructor(colors: Color[]); /** * Linearly interpolate between color stops to get a color along this gradient. * @param x A value between `min, max` to use for selecting a color along this * gradient. An `x` value of `min` will select the first color stop, and an `x` * value of `max` will select the last color stop. If `min` and `max` are not * present, `x` should be a normalized value. * @param min The minimum range of the color scale * @param max The maximum range of the color scale * @returns The interpolated color * @example * const myColor = redBlue.getColor(0.5); * // Returns interpolated color #7F007F */ getColor(x: number, min?: number, max?: number): Color; /** * Return a string representation of this gradient. * @param type The gradient pattern shape * @param repeat The number of times to repeat this gradient * @param options Options to add before the color stops * @returns A valid CSS color gradient * @example * const str = redBlue.toString('linear', 2, '45deg'); * // repeating-linear-gradient(45deg,#FF0000,#0000FF 50%) */ toString(type?: 'linear' | 'radial' | 'conic', repeat?: number, ...options: string[]): string; /** * Generate an SVG linear gradient element. * @param id The ID of this linear gradient, to be obtained with `url(#id)` * @param deg The angle of this color gradient, in degrees clockwise from the vertical * @returns A valid SVG color gradient * @example * const linearGrad = grad.toSVG('myGrad'); * // Returns a <linearGradient> element to be appended onto <defs> */ toSVG(id: string, deg?: number): SVGLinearGradientElement; }