d3-color : added piecewise method

#25582
This commit is contained in:
Hugues Stefanski
2018-05-21 11:31:56 +02:00
parent 7983861f3e
commit 617a2a8ad8
2 changed files with 20 additions and 1 deletions
@@ -229,3 +229,16 @@ iString = d3Interpolate.interpolateCubehelixLong.gamma(2.2)('purple', 'orange');
iNum = d3Interpolate.interpolateBasis([1, 50, 30, 10]);
iNum = d3Interpolate.interpolateBasisClosed([1, 50, 30, 10]);
iString = d3Interpolate.piecewise(d3Interpolate.interpolateRgb.gamma(2.2), ['red', 'green', 'blue']);
iString = d3Interpolate.piecewise(d3Interpolate.interpolateCubehelix, ['red', 'green', 'blue']);
iZoom = d3Interpolate.piecewise(d3Interpolate.interpolateZoom, [[50, 50, 300], [100, 100, 500]] as d3Interpolate.ZoomView[]);
iNum = d3Interpolate.piecewise(d3Interpolate.interpolateNumber, [1, 2, 3]);
iNum = d3Interpolate.piecewise(d3Interpolate.interpolateRound, [1.1, 2.2, 3.3]);
iString = d3Interpolate.piecewise(d3Interpolate.interpolateString, ['a', 'b', 'c']);
iDate = d3Interpolate.piecewise(d3Interpolate.interpolateDate, [new Date(2018, 5, 1), new Date(2018, 5, 2), new Date(2018, 5, 3)]);
iArrayNum = d3Interpolate.piecewise<number[]>(d3Interpolate.interpolateArray, [1, 2, 4, 8]);
iArrayStr = d3Interpolate.piecewise<string[]>(d3Interpolate.interpolateArray, ['a', 'b', 'c', 'd']);
iArrayMixed = d3Interpolate.piecewise<[Date, string]>(d3Interpolate.interpolateArray, [new Date(2016, 6, 1), 'b: 1']);
iString = d3Interpolate.piecewise(d3Interpolate.interpolateTransformCss, ['rotate(0deg)', 'rotate(60deg)']);
iString = d3Interpolate.piecewise(d3Interpolate.interpolateTransformSvg, ['rotate(0)', 'rotate(60)']);
+7 -1
View File
@@ -55,7 +55,9 @@ export function interpolateString(a: string | { toString(): string }, b: string
export function interpolateDate(a: Date, b: Date): ((t: number) => Date);
export function interpolateArray<A extends any[]>(a: any[], b: A): ((t: number) => A);
type ArrayInterpolator<A = any[]> = ((t: number) => A);
export function interpolateArray<A extends any[]>(a: any[], b: A): ArrayInterpolator<A>;
export function interpolateObject<U extends any>(a: any, b: U): ((t: number) => U); // TODO: extends 'any' should become 'object' with TS 2.2+ definitions
export function interpolateObject(a: { [key: string]: any }, b: { [key: string]: any }): ((t: number) => { [key: string]: any });
@@ -89,3 +91,7 @@ export const interpolateCubehelixLong: ColorGammaInterpolationFactory;
export function interpolateBasis(splineNodes: number[]): ((t: number) => number);
export function interpolateBasisClosed(splineNodes: number[]): ((t: number) => number);
export function piecewise(interpolate: (a: ZoomView, b: ZoomView) => ZoomInterpolator, values: ZoomView[]): ZoomInterpolator;
export function piecewise<A extends any[]>(interpolate: (a: any[], b: A) => ArrayInterpolator<A>, values: A): ArrayInterpolator<A>;
export function piecewise<TData, Interpolator>(interpolate: (a: TData, b: TData) => Interpolator, values: TData[]): (t: number) => any;