UNPKG

viridis

Version:

Color gradients for data visualization

61 lines (60 loc) 2.24 kB
import { Color } from './Color'; /** * Represents a linear, uniform color gradient. */ export declare class Gradient { readonly colors: Array<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 * ```js * const redBlue = new Gradient([ * new Color(255, 0, 0), * new Color(0, 0, 255), * ]); * ``` */ constructor(colors: Array<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 * ```js * const myColor = redBlue.getColor(0.5); * // Returns interpolated color (127.5, 0, 127.5) * ``` */ getColor(x: number, min?: number, max?: number): Color; /** * Return a string representation of this gradient. * @param deg The direction of this color gradient, in degrees * @returns A valid CSS color gradient * @example * ```js * const str = redBlue.toString(180); * // linear-gradient(180deg,rgba(255,0,0,100%),rgba(0,0,255,100%)) * ``` */ toString(deg?: number): 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 * ```js * const linearGrad = grad.toSVG('myGrad'); * // Returns a <linearGradient> element to be appended onto <defs> * ``` */ toSVG(id: string, deg?: number): SVGLinearGradientElement; }