# @types/d3-interpolate

- Version 3.0.4
- Published
- 24.5 kB
- 1 dependency
- MIT license

## Install

`npm i @types/d3-interpolate`

`yarn add @types/d3-interpolate`

`pnpm add @types/d3-interpolate`

## Overview

TypeScript definitions for d3-interpolate

## Index

### Variables

### Functions

- interpolate()
- interpolateArray()
- interpolateBasis()
- interpolateBasisClosed()
- interpolateDate()
- interpolateDiscrete()
- interpolateHcl()
- interpolateHclLong()
- interpolateHsl()
- interpolateHslLong()
- interpolateHue()
- interpolateLab()
- interpolateNumber()
- interpolateNumberArray()
- interpolateObject()
- interpolateRgbBasis()
- interpolateRgbBasisClosed()
- interpolateRound()
- interpolateString()
- interpolateTransformCss()
- interpolateTransformSvg()
- interpolateZoom()
- piecewise()
- quantize()

### Interfaces

### Type Aliases

## Variables

### variable interpolateCubehelix

`const interpolateCubehelix: ColorGammaInterpolationFactory;`

Returns a Cubehelix color space interpolator between the two colors

`a`

and`b`

using a configurable`gamma`

. If the gamma is not specified, it defaults to 1.0. The colors`a`

and`b`

need not be in Cubehelix; they will be converted to Cubehelix using [`d3.cubehelix`

](https://github.com/d3/d3-color#cubehelix). If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string.

### variable interpolateCubehelixLong

`const interpolateCubehelixLong: ColorGammaInterpolationFactory;`

Like

`interpolateCubehelix`

, but does not use the shortest path between hues.

### variable interpolateRgb

`const interpolateRgb: ColorGammaInterpolationFactory;`

Returns an RGB color space interpolator between the two colors

`a`

and`b`

with a configurable gamma. If the gamma is not specified, it defaults to 1.0. The colors`a`

and`b`

need not be in RGB; they will be converted to RGB using [`d3.rgb`

](https://github.com/d3/d3-color#rgb). The return value of the interpolator is an RGB string.

## Functions

### function interpolate

`interpolate: { (a: any, b: null): (t: number) => null; (a: any, b: boolean): (t: number) => boolean; (a: any, b: ColorCommonInstance): (t: number) => string; (a: Date, b: Date): (t: number) => Date; (a: number | { valueOf(): number }, b: number | { valueOf(): number }): ( t: number ) => number; <T extends NumberArray>(a: NumberArray | number[], b: T): (t: number) => T; (a: string | { toString(): string }, b: string): (t: number) => string; <U extends any[]>(a: any[], b: U): (t: number) => U; <U extends object>(a: any, b: U): (t: number) => U;};`

Returns an

`null`

constant interpolator.Returns an boolean constant interpolator of value

`b`

.Returns a

`interpolateRgb`

interpolator.Returns a

`interpolateDate`

interpolator.Returns a

`interpolateNumber`

interpolator.Returns a

`interpolateNumberArray`

interpolator.Returns a

`interpolateString`

interpolator. If`b`

is a string coercible to a color use use`interpolateRgb`

.Returns a

`interpolateArray`

interpolator.Returns a

`interpolateObject`

interpolator.

### function interpolateArray

`interpolateArray: { <A extends any[]>(a: any[], b: A): ArrayInterpolator<A>; <T extends NumberArray>(a: NumberArray | number[], b: T): (t: number) => T;};`

Returns an interpolator between the two arrays

`a`

and`b`

. Internally, an array template is created that is the same length in`b`

. For each element in`b`

, if there exists a corresponding element in`a`

, a generic interpolator is created for the two elements using`interpolate`

. If there is no such element, the static value from`b`

is used in the template. Then, for the given parameter`t`

, the template’s embedded interpolators are evaluated. The updated array template is then returned.For example, if

`a`

is the array`[0, 1]`

and`b`

is the array`[1, 10, 100]`

, then the result of the interpolator for`t = 0.5`

is the array`[0.5, 5.5, 100]`

.Note: *no defensive copy* of the template array is created; modifications of the returned array may adversely affect subsequent evaluation of the interpolator. No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions.

interpolateNumberArray is called

### function interpolateBasis

`interpolateBasis: (splineNodes: number[]) => (t: number) => number;`

Returns a uniform nonrational B-spline interpolator through the specified array of

`values`

, which must be numbers. Implicit control points are generated such that the interpolator returns`values[0]`

at`t`

= 0 and`values[values.length - 1]`

at`t`

= 1. See also [`d3.curveBasis`

](https://github.com/d3/d3-shape#curveBasis).

### function interpolateBasisClosed

`interpolateBasisClosed: (splineNodes: number[]) => (t: number) => number;`

Returns a uniform nonrational B-spline interpolator through the specified array of

`values`

, which must be numbers. The control points are implicitly repeated such that the resulting one-dimensional spline has cyclical C² continuity when repeated around`t`

in [0,1]. See also [`d3.curveBasisClosed`

](https://github.com/d3/d3-shape#curveBasisClosed).

### function interpolateDate

`interpolateDate: (a: Date, b: Date) => (t: number) => Date;`

Returns an interpolator between the two dates

`a`

and`b`

.Note: *no defensive copy* of the returned date is created; the same Date instance is returned for every evaluation of the interpolator. No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions.

### function interpolateDiscrete

`interpolateDiscrete: <T>(values: T[]) => (t: number) => T;`

Returns a discrete interpolator for the given array of values. The returned interpolator maps

`t`

in`[0, 1 / n)`

to values[0],`t`

in`[1 / n, 2 / n)`

to`values[1]`

, and so on, where`n = values.length`

. In effect, this is a lightweight quantize scale with a fixed domain of [0, 1].

### function interpolateHcl

`interpolateHcl: ( a: string | ColorCommonInstance, b: string | ColorCommonInstance) => (t: number) => string;`

Returns an HCL color space interpolator between the two colors

`a`

and`b`

. The colors`a`

and`b`

need not be in HCL; they will be converted to HCL using`d3.hcl`

. If either color’s hue or chroma is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string.

### function interpolateHclLong

`interpolateHclLong: ( a: string | ColorCommonInstance, b: string | ColorCommonInstance) => (t: number) => string;`

Like

`interpolateHcl`

, but does not use the shortest path between hues.

### function interpolateHsl

`interpolateHsl: ( a: string | ColorCommonInstance, b: string | ColorCommonInstance) => (t: number) => string;`

Returns an HSL color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in HSL; they will be converted to HSL using

`d3.hsl`

. If either color’s hue or saturation is NaN, the opposing color’s channel value is used. The shortest path between hues is used. The return value of the interpolator is an RGB string.

### function interpolateHslLong

`interpolateHslLong: ( a: string | ColorCommonInstance, b: string | ColorCommonInstance) => (t: number) => string;`

Like

`interpolateHsl`

, but does not use the shortest path between hues.

### function interpolateHue

`interpolateHue: (a: number, b: number) => (t: number) => number;`

Returns an interpolator between the two hue angles

`a`

and`b`

. If either hue is NaN, the opposing value is used. The shortest path between hues is used. The return value of the interpolator is a number in`[0, 360)`

.

### function interpolateLab

`interpolateLab: ( a: string | ColorCommonInstance, b: string | ColorCommonInstance) => (t: number) => string;`

Returns a Lab color space interpolator between the two colors *a* and *b*. The colors *a* and *b* need not be in Lab; they will be converted to Lab using

`d3.lab`

. The return value of the interpolator is an RGB string.

### function interpolateNumber

`interpolateNumber: ( a: number | { valueOf(): number }, b: number | { valueOf(): number }) => (t: number) => number;`

Returns an interpolator between the two numbers

`a`

and`b`

. The returned interpolator is equivalent to:`(t) => a * (1 - t) + b * t`

.

### function interpolateNumberArray

`interpolateNumberArray: <T extends NumberArray | number[]>( a: NumberArray | number[], b: T) => (t: number) => T;`

Returns an interpolator between the two arrays of numbers a and b. Internally, an array template is created that is the same type and length as b. For each element in b, if there exists a corresponding element in a, the values are directly interpolated in the array template. If there is no such element, the static value from b is copied. The updated array template is then returned.

Note: For performance reasons, no defensive copy is made of the template array and the arguments a and b; modifications of these arrays may affect subsequent evaluation of the interpolator.

### function interpolateObject

`interpolateObject: <U extends object>(a: any, b: U) => (t: number) => U;`

Returns an interpolator between the two objects

`a`

and`b`

. Internally, an object template is created that has the same properties as`b`

. For each property in`b`

, if there exists a corresponding property in`a`

, a generic interpolator is created for the two elements using`interpolate`

. If there is no such property, the static value from`b`

is used in the template. Then, for the given parameter`t`

, the template's embedded interpolators are evaluated and the updated object template is then returned.For example, if

`a`

is the object`{x: 0, y: 1}`

and`b`

is the object`{x: 1, y: 10, z: 100}`

, the result of the interpolator for`t = 0.5`

is the object`{x: 0.5, y: 5.5, z: 100}`

.Note: *no defensive copy* of the template object is created; modifications of the returned object may adversely affect subsequent evaluation of the interpolator. No copy is made for performance reasons; interpolators are often part of the inner loop of animated transitions.

### function interpolateRgbBasis

`interpolateRgbBasis: ( colors: Array<string | ColorCommonInstance>) => (t: number) => string;`

Returns a uniform nonrational B-spline interpolator through the specified array of *colors*, which are converted to RGB color space. Implicit control points are generated such that the interpolator returns

`colors[0]`

at`t = 0`

and`colors[colors.length - 1]`

at`t = 1`

. Opacity interpolation is not currently supported. See also`d3.interpolateBasis`

, and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples.

### function interpolateRgbBasisClosed

`interpolateRgbBasisClosed: ( colors: Array<string | ColorCommonInstance>) => (t: number) => string;`

Returns a uniform nonrational B-spline interpolator through the specified array of colors, which are converted to RGB color space. The control points are implicitly repeated such that the resulting spline has cyclical C² continuity when repeated around

`t`

in [0,1]; this is useful, for example, to create cyclical color scales. Opacity interpolation is not currently supported. See also `d3.interpolateBasisClosed, and see [d3-scale-chromatic](https://github.com/d3/d3-scale-chromatic) for examples.

### function interpolateRound

`interpolateRound: ( a: number | { valueOf(): number }, b: number | { valueOf(): number }) => (t: number) => number;`

Returns an interpolator between the two numbers

`a`

and`b`

; the interpolator is similar to`interpolateNumber`

, except it will round the resulting value to the nearest integer.

### function interpolateString

`interpolateString: ( a: string | { toString(): string }, b: string | { toString(): string }) => (t: number) => string;`

Returns an interpolator between the two strings

`a`

and`b`

. The string interpolator finds numbers embedded in`a`

and`b`

, where each number is of the form understood by JavaScript. A few examples of numbers that will be detected within a string:`-1`

,`42`

,`3.14159`

, and`6.0221413e+23`

.For each number embedded in

`b`

, the interpolator will attempt to find a corresponding number in`a`

. If a corresponding number is found, a numeric interpolator is created using`interpolateNumber`

. The remaining parts of the string`b`

are used as a template.For example, if

`a`

is`"300 12px sans-serif"`

, and`b`

is`"500 36px Comic-Sans"`

, two embedded numbers are found. The remaining static parts (of string`b`

) are a space between the two numbers (`" "`

), and the suffix (`"px Comic-Sans"`

). The result of the interpolator at`t`

= 0.5 is`"400 24px Comic-Sans"`

.

### function interpolateTransformCss

`interpolateTransformCss: (a: string, b: string) => (t: number) => string;`

Returns an interpolator between the two 2D CSS transforms represented by

`a`

and`b`

. Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated. This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition).

### function interpolateTransformSvg

`interpolateTransformSvg: (a: string, b: string) => (t: number) => string;`

Returns an interpolator between the two 2D SVG transforms represented by

`a`

and`b`

. Each transform is decomposed to a standard representation of translate, rotate, *x*-skew and scale; these component transformations are then interpolated. This behavior is standardized by CSS: see [matrix decomposition for animation](http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition).

### function interpolateZoom

`interpolateZoom: (a: ZoomView, b: ZoomView) => ZoomInterpolator;`

Returns an interpolator between the two views

`a`

and`b`

of a two-dimensional plane, based on [“Smooth and efficient zooming and panning”](http://www.win.tue.nl/~vanwijk/zoompan.pdf). Each view is defined as an array of three numbers: *cx*, *cy* and *width*. The first two coordinates *cx*, *cy* represent the center of the viewport; the last coordinate *width* represents the size of the viewport.The returned interpolator exposes a *duration* property which encodes the recommended transition duration in milliseconds. This duration is based on the path length of the curved trajectory through *x,y* space. If you want to a slower or faster transition, multiply this by an arbitrary scale factor (*V* as described in the original paper).

### function piecewise

`piecewise: { (values: ZoomView[]): ZoomInterpolator; ( interpolate: (a: ZoomView, b: ZoomView) => ZoomInterpolator, values: ZoomView[] ): ZoomInterpolator; <A extends any[]>(values: A[]): ArrayInterpolator<A>; <A extends any[]>( interpolate: (a: any[], b: A) => ArrayInterpolator<A>, values: A[] ): ArrayInterpolator<A>; (values: unknown[]): (t: number) => any; <TData>(interpolate: (a: TData, b: TData) => unknown, values: TData[]): ( t: number ) => any;};`

Returns a piecewise zoom interpolator, composing zoom interpolators for each adjacent pair of zoom view. The returned interpolator maps

`t`

in`[0, 1 / (n - 1)]`

to`interpolate(values[0], values[1])`

,`t`

in`[1 / (n - 1), 2 / (n - 1)]`

to`interpolate(values[1], values[2])`

, and so on, where`n = values.length`

. In effect, this is a lightweight linear scale. For example, to blend through three different zoom views:`d3.piecewise(d3.interpolateZoom, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`

.interpolate defaults to d3.interpolate.

Returns a piecewise zoom interpolator, composing zoom interpolators for each adjacent pair of zoom view. The returned interpolator maps

`t`

in`[0, 1 / (n - 1)]`

to`interpolate(values[0], values[1])`

,`t`

in`[1 / (n - 1), 2 / (n - 1)]`

to`interpolate(values[1], values[2])`

, and so on, where`n = values.length`

. In effect, this is a lightweight linear scale. For example, to blend through three different zoom views:`d3.piecewise(d3.interpolateZoom, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`

.Returns a piecewise array interpolator, composing array interpolators for each adjacent pair of arrays. The returned interpolator maps

`t`

in`[0, 1 / (n - 1)]`

to`interpolate(values[0], values[1])`

,`t`

in`[1 / (n - 1), 2 / (n - 1)]`

to`interpolate(values[1], values[2])`

, and so on, where`n = values.length`

. In effect, this is a lightweight linear scale. For example, to blend through three different arrays:`d3.piecewise(d3.interpolateArray, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`

.interpolate defaults to d3.interpolate.

Returns a piecewise array interpolator, composing array interpolators for each adjacent pair of arrays. The returned interpolator maps

`t`

in`[0, 1 / (n - 1)]`

to`interpolate(values[0], values[1])`

,`t`

in`[1 / (n - 1), 2 / (n - 1)]`

to`interpolate(values[1], values[2])`

, and so on, where`n = values.length`

. In effect, this is a lightweight linear scale. For example, to blend through three different arrays:`d3.piecewise(d3.interpolateArray, [[0, 0, 1], [0, 0, 10], [0, 0, 15]])`

.Returns a piecewise interpolator, composing interpolators for each adjacent pair of values. The returned interpolator maps

`t`

in`[0, 1 / (n - 1)]`

to`interpolate(values[0], values[1])`

,`t`

in`[1 / (n - 1), 2 / (n - 1)]`

to`interpolate(values[1], values[2])`

, and so on, where`n = values.length`

. In effect, this is a lightweight linear scale. For example, to blend through red, green and blue:`d3.piecewise(d3.interpolateRgb.gamma(2.2), ["red", "green", "blue"])`

.interpolate defaults to d3.interpolate.

Returns a piecewise interpolator, composing interpolators for each adjacent pair of values. The returned interpolator maps

`t`

in`[0, 1 / (n - 1)]`

to`interpolate(values[0], values[1])`

,`t`

in`[1 / (n - 1), 2 / (n - 1)]`

to`interpolate(values[1], values[2])`

, and so on, where`n = values.length`

. In effect, this is a lightweight linear scale. For example, to blend through red, green and blue:`d3.piecewise(d3.interpolateRgb.gamma(2.2), ["red", "green", "blue"])`

.

### function quantize

`quantize: <T>(interpolator: (t: number) => T, n: number) => T[];`

Returns

`n`

uniformly-spaced samples from the specified`interpolator`

, where`n`

is an integer greater than one. The first sample is always at`t = 0`

, and the last sample is always at`t = 1`

. This can be useful in generating a fixed number of samples from a given interpolator, such as to derive the range of a [quantize scale](https://github.com/d3/d3-scale#quantize-scales) from a [continuous interpolator](https://github.com/d3/d3-scale#interpolateWarm).Caution: this method will not work with interpolators that do not return defensive copies of their output, such as

`d3.interpolateArray`

,`d3.interpolateDate`

and`d3.interpolateObject`

. For those interpolators, you must wrap the interpolator and create a copy for each returned value.

## Interfaces

### interface ColorGammaInterpolationFactory

`interface ColorGammaInterpolationFactory extends Function {}`

### method gamma

`gamma: (g: number) => ColorGammaInterpolationFactory;`

Returns a new interpolator factory of the same type using the specified *gamma*. For example, to interpolate from purple to orange with a gamma of 2.2 in RGB space:

`d3.interpolateRgb.gamma(2.2)("purple", "orange")`

. See Eric Brasseur’s article, [Gamma error in picture scaling](https://web.archive.org/web/20160112115812/http://www.4p8.com/eric.brasseur/gamma.html), for more on gamma correction.

### call signature

`(a: string | ColorCommonInstance, b: string | ColorCommonInstance): ( t: number) => string;`

### interface ZoomInterpolator

`interface ZoomInterpolator extends Function {}`

### property duration

`duration: number;`

Recommended duration of zoom transition in milliseconds.

### method rho

`rho: (rho: number) => this;`

Given a zoom interpolator, returns a new zoom interpolator using the specified curvature rho. When rho is close to 0, the interpolator is almost linear. The default curvature is sqrt(2).

#### Parameter rho

### call signature

`(t: number): ZoomView;`

## Type Aliases

### type ArrayInterpolator

`type ArrayInterpolator<A extends any[]> = (t: number) => A;`

### type NumberArray

`type NumberArray = TypedArray | DataView;`

### type TypedArray

`type TypedArray = | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;`

### type ZoomView

`type ZoomView = [number, number, number];`

Type zoomView is used to represent a numeric array with three elements. In order of appearance the elements correspond to: - cx: *x*-coordinate of the center of the viewport - cy: *y*-coordinate of the center of the viewport - width: size of the viewport

## Package Files (1)

## Dependencies (1)

## Dev Dependencies (0)

No dev dependencies.

## Peer Dependencies (0)

No peer dependencies.

## Badge

To add a badge like this oneto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to `https://www.jsdocs.io/package/@types/d3-interpolate`

.

- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/d3-interpolate)
- HTML<a href="https://www.jsdocs.io/package/@types/d3-interpolate"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>

- Updated .

Package analyzed in 4134 ms. - Missing or incorrect documentation? Open an issue for this package.