From 9ecd90e9e8a715b8435315b540e0bde8eda6bb04 Mon Sep 17 00:00:00 2001 From: Tom Wanzek Date: Thu, 8 Feb 2018 16:50:46 -0500 Subject: [PATCH] refactor(*): refactor d3-scale and d3-scale-chromatic BREAKING CHANGE: * refactor(d3-scale) update to major version 2.0. As a breaking change all color related features are removed. schemeCategory20x features are removed without replacement. All other color features are moved to d3-scale-chromatic 1.2 * refactor(d3-scale-chromatic): update to minor version 1.2 by including refactored features dropped from d3-scale 2.0: schemeCategory10 and color interpolators. * fix(d3-scale) All input arguments for domain or range arrays now also permit ReadonlyArray as inputs. This change allows seamless integration with the color schemes defined in d3-scale-chromatic. This change has been applied to both d3-scale 1.x and 2.x. * chore(d3-scale-chromatic) activate strictNullChecks * chore(d3-scale) move d3-scale 1.x into legacy folder `v1` and update tsconfig.json including path mapping for d3-scale itself to pick up legacy version in its own legacy tests * test(d3-scale) update tests including integration test with d3-scale-chromatic * test(d3-scale-chromatic) update tests. Including generalized assignment tests for interplators and schemes. * chore(*) update version numbers for d3-scale and d3-scale-chromatic --- .../d3-scale-chromatic-tests.ts | 91 + types/d3-scale-chromatic/index.d.ts | 179 +- types/d3-scale-chromatic/tsconfig.json | 4 +- types/d3-scale/d3-scale-tests.ts | 51 +- types/d3-scale/index.d.ts | 118 +- types/d3-scale/v1/d3-scale-tests.ts | 970 +++++++++ types/d3-scale/v1/index.d.ts | 1840 +++++++++++++++++ types/d3-scale/v1/tsconfig.json | 28 + types/d3-scale/v1/tslint.json | 8 + 9 files changed, 3087 insertions(+), 202 deletions(-) create mode 100644 types/d3-scale/v1/d3-scale-tests.ts create mode 100644 types/d3-scale/v1/index.d.ts create mode 100644 types/d3-scale/v1/tsconfig.json create mode 100644 types/d3-scale/v1/tslint.json diff --git a/types/d3-scale-chromatic/d3-scale-chromatic-tests.ts b/types/d3-scale-chromatic/d3-scale-chromatic-tests.ts index ccf736d43b..c6ff839994 100644 --- a/types/d3-scale-chromatic/d3-scale-chromatic-tests.ts +++ b/types/d3-scale-chromatic/d3-scale-chromatic-tests.ts @@ -8,9 +8,29 @@ import * as d3ScaleChromatic from 'd3-scale-chromatic'; +// ----------------------------------------------------------------------- +// Preparatory Steps +// ----------------------------------------------------------------------- + +let colorInterpolator: ((t: number) => string); +let simpleScheme: ReadonlyArray; +let nestedScheme: ReadonlyArray>; + // ----------------------------------------------------------------------- // Categorical // ----------------------------------------------------------------------- + +simpleScheme = d3ScaleChromatic.schemeCategory10; +simpleScheme = d3ScaleChromatic.schemeAccent; +simpleScheme = d3ScaleChromatic.schemeDark2; +simpleScheme = d3ScaleChromatic.schemePaired; +simpleScheme = d3ScaleChromatic.schemePastel1; +simpleScheme = d3ScaleChromatic.schemePastel2; +simpleScheme = d3ScaleChromatic.schemeSet1; +simpleScheme = d3ScaleChromatic.schemeSet2; +simpleScheme = d3ScaleChromatic.schemeSet3; + +const category10: string = d3ScaleChromatic.schemeCategory10[0]; // #1f77b4 const accent: string = d3ScaleChromatic.schemeAccent[0]; // #7fc97f const dark: string = d3ScaleChromatic.schemeDark2[0]; // #1b9e77 const paired: string = d3ScaleChromatic.schemePaired[0]; // #a6cee3 @@ -23,6 +43,17 @@ const set3: string = d3ScaleChromatic.schemeSet3[0]; // #8dd3c7 // ----------------------------------------------------------------------- // Diverging // ----------------------------------------------------------------------- + +colorInterpolator = d3ScaleChromatic.interpolateBrBG; +colorInterpolator = d3ScaleChromatic.interpolatePRGn; +colorInterpolator = d3ScaleChromatic.interpolatePiYG; +colorInterpolator = d3ScaleChromatic.interpolatePuOr; +colorInterpolator = d3ScaleChromatic.interpolateRdBu; +colorInterpolator = d3ScaleChromatic.interpolateRdGy; +colorInterpolator = d3ScaleChromatic.interpolateRdYlBu; +colorInterpolator = d3ScaleChromatic.interpolateRdYlGn; +colorInterpolator = d3ScaleChromatic.interpolateSpectral; + const BrBG: string = d3ScaleChromatic.interpolateBrBG(0); // rgb(84, 48, 5) const PRGn: string = d3ScaleChromatic.interpolatePRGn(0); // rgb(64, 0, 75) const PiYG: string = d3ScaleChromatic.interpolatePiYG(0); // rgb(142, 1, 82) @@ -33,6 +64,16 @@ const RdYlBu: string = d3ScaleChromatic.interpolateRdYlBu(0); // rgb(103, 0, 31) const RdYlGn: string = d3ScaleChromatic.interpolateRdYlGn(0); // rgb(103, 0, 31) const Spectral: string = d3ScaleChromatic.interpolateSpectral(0); // rgb(158, 1, 66) +nestedScheme = d3ScaleChromatic.schemeBrBG; +nestedScheme = d3ScaleChromatic.schemePRGn; +nestedScheme = d3ScaleChromatic.schemePiYG; +nestedScheme = d3ScaleChromatic.schemePuOr; +nestedScheme = d3ScaleChromatic.schemeRdBu; +nestedScheme = d3ScaleChromatic.schemeRdGy; +nestedScheme = d3ScaleChromatic.schemeRdYlBu; +nestedScheme = d3ScaleChromatic.schemeRdYlGn; +nestedScheme = d3ScaleChromatic.schemeSpectral; + const schemeBrBG: string = d3ScaleChromatic.schemeBrBG[3][0]; // #d8b365 const schemePRGn: string = d3ScaleChromatic.schemePRGn[3][0]; // #af8dc3 const schemePiYG: string = d3ScaleChromatic.schemePiYG[3][0]; // #e9a3c9 @@ -46,6 +87,14 @@ const schemeSpectral: string = d3ScaleChromatic.schemeSpectral[3][0]; // #fc8d59 // ----------------------------------------------------------------------- // Sequential // ----------------------------------------------------------------------- + +colorInterpolator = d3ScaleChromatic.interpolateBlues; +colorInterpolator = d3ScaleChromatic.interpolateGreens; +colorInterpolator = d3ScaleChromatic.interpolateGreys; +colorInterpolator = d3ScaleChromatic.interpolateOranges; +colorInterpolator = d3ScaleChromatic.interpolatePurples; +colorInterpolator = d3ScaleChromatic.interpolateReds; + const Blue: string = d3ScaleChromatic.interpolateBlues(1); // rgb(8, 48, 107) const Green: string = d3ScaleChromatic.interpolateGreens(1); // rgb(0, 68, 27) const Grey: string = d3ScaleChromatic.interpolateGreys(1); // rgb(0, 0, 0) @@ -53,6 +102,13 @@ const Orange: string = d3ScaleChromatic.interpolateOranges(1); // rgb(127, 39, 4 const Purple: string = d3ScaleChromatic.interpolatePurples(1); // rgb(63, 0, 125) const Red: string = d3ScaleChromatic.interpolateReds(1); // rgb(103, 0, 13) +nestedScheme = d3ScaleChromatic.schemeBlues; +nestedScheme = d3ScaleChromatic.schemeGreens; +nestedScheme = d3ScaleChromatic.schemeGreys; +nestedScheme = d3ScaleChromatic.schemeOranges; +nestedScheme = d3ScaleChromatic.schemePurples; +nestedScheme = d3ScaleChromatic.schemeReds; + const schemeBlues: string = d3ScaleChromatic.schemeBlues[3][0]; // #deebf7 const schemeGreens: string = d3ScaleChromatic.schemeGreens[3][0]; // #e5f5e0 const schemeGreys: string = d3ScaleChromatic.schemeGreys[3][0]; // #f0f0f0 @@ -63,6 +119,28 @@ const schemeReds: string = d3ScaleChromatic.schemeReds[3][0]; // #fee0d2 // ----------------------------------------------------------------------- // Sequential(Multi-Hue) // ----------------------------------------------------------------------- + +colorInterpolator = d3ScaleChromatic.interpolateViridis; +colorInterpolator = d3ScaleChromatic.interpolateMagma; +colorInterpolator = d3ScaleChromatic.interpolateInferno; +colorInterpolator = d3ScaleChromatic.interpolatePlasma; +colorInterpolator = d3ScaleChromatic.interpolateRainbow; +colorInterpolator = d3ScaleChromatic.interpolateWarm; +colorInterpolator = d3ScaleChromatic.interpolateCool; +colorInterpolator = d3ScaleChromatic.interpolateCubehelixDefault; +colorInterpolator = d3ScaleChromatic.interpolateBuGn; +colorInterpolator = d3ScaleChromatic.interpolateBuPu; +colorInterpolator = d3ScaleChromatic.interpolateGnBu; +colorInterpolator = d3ScaleChromatic.interpolateOrRd; +colorInterpolator = d3ScaleChromatic.interpolatePuBuGn; +colorInterpolator = d3ScaleChromatic.interpolatePuBu; +colorInterpolator = d3ScaleChromatic.interpolatePuRd; +colorInterpolator = d3ScaleChromatic.interpolateRdPu; +colorInterpolator = d3ScaleChromatic.interpolateYlGnBu; +colorInterpolator = d3ScaleChromatic.interpolateYlGn; +colorInterpolator = d3ScaleChromatic.interpolateYlOrBr; +colorInterpolator = d3ScaleChromatic.interpolateYlOrRd; + const BuGn: string = d3ScaleChromatic.interpolateBuGn(1); // rgb(0, 68, 27) const BuPu: string = d3ScaleChromatic.interpolateBuPu(1); // rgb(77, 0, 75) const GnBu: string = d3ScaleChromatic.interpolateGnBu(1); // rgb(8, 64, 129) @@ -76,6 +154,19 @@ const YlGn: string = d3ScaleChromatic.interpolateYlGn(1); // rgb(0, 69, 41) const YlOrBr: string = d3ScaleChromatic.interpolateYlOrBr(1); // rgb(102, 37, 6) const YlOrRd: string = d3ScaleChromatic.interpolateYlOrRd(1); // rgb(128, 0, 38) +nestedScheme = d3ScaleChromatic.schemeBuGn; +nestedScheme = d3ScaleChromatic.schemeBuPu; +nestedScheme = d3ScaleChromatic.schemeGnBu; +nestedScheme = d3ScaleChromatic.schemeOrRd; +nestedScheme = d3ScaleChromatic.schemePuBuGn; +nestedScheme = d3ScaleChromatic.schemePuBu; +nestedScheme = d3ScaleChromatic.schemePuRd; +nestedScheme = d3ScaleChromatic.schemeRdPu; +nestedScheme = d3ScaleChromatic.schemeYlGnBu; +nestedScheme = d3ScaleChromatic.schemeYlGn; +nestedScheme = d3ScaleChromatic.schemeYlOrBr; +nestedScheme = d3ScaleChromatic.schemeYlOrRd; + const schemeBuGn: string = d3ScaleChromatic.schemeBuGn[3][0]; // #e5f5f9 const schemeBuPu: string = d3ScaleChromatic.schemeBuPu[3][0]; // #e0ecf4 const schemeGnBu: string = d3ScaleChromatic.schemeGnBu[3][0]; // #e0f3db diff --git a/types/d3-scale-chromatic/index.d.ts b/types/d3-scale-chromatic/index.d.ts index 1345371e2a..93c0285a17 100644 --- a/types/d3-scale-chromatic/index.d.ts +++ b/types/d3-scale-chromatic/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for D3JS d3-scale-chromatic module 1.1 +// Type definitions for D3JS d3-scale-chromatic module 1.2 // Project: https://github.com/d3/d3-scale-chromatic/ // Definitions by: Hugues Stefanski , // Alex Ford , @@ -6,11 +6,15 @@ // Henrique Machado // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 1.0.2 +// Last module patch version validated against: 1.2.0 // ----------------------------------------------------------------------- // Categorical // ----------------------------------------------------------------------- +/** + * An array of ten categorical colors represented as RGB hexadecimal strings. + */ +export const schemeCategory10: ReadonlyArray; /** * An array of eight categorical colors represented as RGB hexadecimal strings. */ @@ -48,11 +52,11 @@ export const schemeSet3: ReadonlyArray; // Diverging // ----------------------------------------------------------------------- /** - * Given a number value in the range [0,1], returns the corresponding color from the “BrBG” diverging color scheme represented as an RGB string. + * Given a number t in the range [0,1], returns the corresponding color from the “BrBG” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateBrBG(value: number): string; +export function interpolateBrBG(t: number): string; /** * An array of arrays of hexadecimal color strings from the “BrBG” diverging color scheme. The kth element of this array contains @@ -64,9 +68,9 @@ export const schemeBrBG: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “PRGn” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolatePRGn(value: number): string; +export function interpolatePRGn(t: number): string; /** * An array of arrays of hexadecimal color strings from the “PRGn” diverging color scheme. The kth element of this array contains @@ -78,9 +82,9 @@ export const schemePRGn: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “PiYG” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolatePiYG(value: number): string; +export function interpolatePiYG(t: number): string; /** * An array of arrays of hexadecimal color strings from the “PiYG” diverging color scheme. The kth element of this array contains @@ -92,9 +96,9 @@ export const schemePiYG: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “PuOr” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolatePuOr(value: number): string; +export function interpolatePuOr(t: number): string; /** * An array of arrays of hexadecimal color strings from the “PuOr” diverging color scheme. The kth element of this array contains @@ -106,9 +110,9 @@ export const schemePuOr: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “RdBu” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateRdBu(value: number): string; +export function interpolateRdBu(t: number): string; /** * An array of arrays of hexadecimal color strings from the “RdBu” diverging color scheme. The kth element of this array contains @@ -120,9 +124,9 @@ export const schemeRdBu: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “RdGy” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateRdGy(value: number): string; +export function interpolateRdGy(t: number): string; /** * An array of arrays of hexadecimal color strings from the “RdGy” diverging color scheme. The kth element of this array contains @@ -134,9 +138,9 @@ export const schemeRdGy: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “RdYlBu” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateRdYlBu(value: number): string; +export function interpolateRdYlBu(t: number): string; /** * An array of arrays of hexadecimal color strings from the “RdYlBu” diverging color scheme. The kth element of this array contains @@ -148,9 +152,9 @@ export const schemeRdYlBu: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “RdYlGn” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateRdYlGn(value: number): string; +export function interpolateRdYlGn(t: number): string; /** * An array of arrays of hexadecimal color strings from the “RdYlGn” diverging color scheme. The kth element of this array contains @@ -162,9 +166,9 @@ export const schemeRdYlGn: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “Spectral” diverging color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateSpectral(value: number): string; +export function interpolateSpectral(t: number): string; /** * An array of arrays of hexadecimal color strings from the “Spectral” diverging color scheme. The kth element of this array contains @@ -179,9 +183,9 @@ export const schemeSpectral: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “Blues” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateBlues(value: number): string; +export function interpolateBlues(t: number): string; /** * An array of arrays of hexadecimal color strings from the “Blues” sequential color scheme. The kth element of this array contains @@ -193,9 +197,9 @@ export const schemeBlues: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “Greens” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateGreens(value: number): string; +export function interpolateGreens(t: number): string; /** * An array of arrays of hexadecimal color strings from the “Greens” sequential color scheme. The kth element of this array contains @@ -207,9 +211,9 @@ export const schemeGreens: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “Greys” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateGreys(value: number): string; +export function interpolateGreys(t: number): string; /** * An array of arrays of hexadecimal color strings from the “Greys” sequential color scheme. The kth element of this array contains @@ -221,9 +225,9 @@ export const schemeGreys: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “Oranges” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateOranges(value: number): string; +export function interpolateOranges(t: number): string; /** * An array of arrays of hexadecimal color strings from the “Oranges” sequential color scheme. The kth element of this array contains @@ -235,9 +239,9 @@ export const schemeOranges: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “Purples” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolatePurples(value: number): string; +export function interpolatePurples(t: number): string; /** * An array of arrays of hexadecimal color strings from the “Purples” sequential color scheme. The kth element of this array contains @@ -249,9 +253,9 @@ export const schemePurples: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “Reds” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateReds(value: number): string; +export function interpolateReds(t: number): string; /** * An array of arrays of hexadecimal color strings from the “Reds” sequential color scheme. The kth element of this array contains @@ -264,12 +268,73 @@ export const schemeReds: ReadonlyArray>; // Sequential(Multi-Hue) // ----------------------------------------------------------------------- +/** + * Given a number t in the range [0,1], returns the corresponding color from the “viridis” perceptually-uniform color scheme designed by van der Walt, Smith and Firing for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateViridis(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from the “inferno” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateInferno(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from the “magma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateMagma(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from the “plasma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolatePlasma(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from a 180° rotation of Niccoli’s perceptual rainbow, represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateWarm(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from Niccoli’s perceptual rainbow, represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateCool(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from d3.interpolateWarm scale from [0.0, 0.5] followed by the d3.interpolateCool scale from [0.5, 1.0], + * thus implementing the cyclical less-angry rainbow color scheme. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateRainbow(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from Green’s default Cubehelix represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateCubehelixDefault(t: number): string; + /** * Given a number t in the range [0,1], returns the corresponding color from the “BuGn” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateBuGn(value: number): string; +export function interpolateBuGn(t: number): string; /** * An array of arrays of hexadecimal color strings from the “BuGn” sequential color scheme. The kth element of this array contains @@ -281,9 +346,9 @@ export const schemeBuGn: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “BuPu” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateBuPu(value: number): string; +export function interpolateBuPu(t: number): string; /** * An array of arrays of hexadecimal color strings from the “BuPu” sequential color scheme. The kth element of this array contains @@ -295,9 +360,9 @@ export const schemeBuPu: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “GnBu” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateGnBu(value: number): string; +export function interpolateGnBu(t: number): string; /** * An array of arrays of hexadecimal color strings from the “GnBu” sequential color scheme. The kth element of this array contains @@ -309,9 +374,9 @@ export const schemeGnBu: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “OrRd” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateOrRd(value: number): string; +export function interpolateOrRd(t: number): string; /** * An array of arrays of hexadecimal color strings from the “OrRd” sequential color scheme. The kth element of this array contains @@ -323,9 +388,9 @@ export const schemeOrRd: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “PuBuGn” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolatePuBuGn(value: number): string; +export function interpolatePuBuGn(t: number): string; /** * An array of arrays of hexadecimal color strings from the “PuBuGn” sequential color scheme. The kth element of this array contains @@ -337,9 +402,9 @@ export const schemePuBuGn: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “PuBu” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolatePuBu(value: number): string; +export function interpolatePuBu(t: number): string; /** * An array of arrays of hexadecimal color strings from the “PuBu” sequential color scheme. The kth element of this array contains @@ -351,9 +416,9 @@ export const schemePuBu: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “PuRd” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolatePuRd(value: number): string; +export function interpolatePuRd(t: number): string; /** * An array of arrays of hexadecimal color strings from the “PuRd” sequential color scheme. The kth element of this array contains @@ -365,9 +430,9 @@ export const schemePuRd: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “RdPu” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateRdPu(value: number): string; +export function interpolateRdPu(t: number): string; /** * An array of arrays of hexadecimal color strings from the “RdPu” sequential color scheme. The kth element of this array contains @@ -379,9 +444,9 @@ export const schemeRdPu: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “YlGnBu” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateYlGnBu(value: number): string; +export function interpolateYlGnBu(t: number): string; /** * An array of arrays of hexadecimal color strings from the “YlGnBu” sequential color scheme. The kth element of this array contains @@ -393,9 +458,9 @@ export const schemeYlGnBu: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “YlGn” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateYlGn(value: number): string; +export function interpolateYlGn(t: number): string; /** * An array of arrays of hexadecimal color strings from the “YlGn” sequential color scheme. The kth element of this array contains @@ -407,9 +472,9 @@ export const schemeYlGn: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “YlOrBr” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateYlOrBr(value: number): string; +export function interpolateYlOrBr(t: number): string; /** * An array of arrays of hexadecimal color strings from the “YlOrBr” sequential color scheme. The kth element of this array contains @@ -421,9 +486,9 @@ export const schemeYlOrBr: ReadonlyArray>; /** * Given a number t in the range [0,1], returns the corresponding color from the “YlOrRd” sequential color scheme represented as an RGB string. * - * @param value Number in the range [0, 1]. + * @param t Number in the range [0, 1]. */ -export function interpolateYlOrRd(value: number): string; +export function interpolateYlOrRd(t: number): string; /** * An array of arrays of hexadecimal color strings from the “YlOrRd” sequential color scheme. The kth element of this array contains diff --git a/types/d3-scale-chromatic/tsconfig.json b/types/d3-scale-chromatic/tsconfig.json index 60c78baedc..404fba89ea 100644 --- a/types/d3-scale-chromatic/tsconfig.json +++ b/types/d3-scale-chromatic/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -21,4 +21,4 @@ "index.d.ts", "d3-scale-chromatic-tests.ts" ] -} \ No newline at end of file +} diff --git a/types/d3-scale/d3-scale-tests.ts b/types/d3-scale/d3-scale-tests.ts index f317e342ec..8fa070d992 100644 --- a/types/d3-scale/d3-scale-tests.ts +++ b/types/d3-scale/d3-scale-tests.ts @@ -9,6 +9,12 @@ import * as d3Scale from 'd3-scale'; import { interpolateCubehelix } from 'd3-interpolate'; import { timeHour } from 'd3-time'; +import { + schemePuRd, + interpolateRainbow, + interpolateCool, + interpolateInferno +} from 'd3-scale-chromatic'; // ------------------------------------------------------------------------------- // Preparatory Steps @@ -549,8 +555,8 @@ const copiedTimeScale: d3Scale.ScaleTime = localTimeScaleNumStri let sequentialScaleColorString: d3Scale.ScaleSequential; -sequentialScaleColorString = d3Scale.scaleSequential(d3Scale.interpolateRainbow); -sequentialScaleColorString = d3Scale.scaleSequential(d3Scale.interpolateCool); // inferred Output type string +sequentialScaleColorString = d3Scale.scaleSequential(interpolateRainbow); +sequentialScaleColorString = d3Scale.scaleSequential(interpolateCool); // inferred Output type string // ScaleSequential Interface ======================================================== @@ -567,7 +573,7 @@ clampFlag = sequentialScaleColorString.clamp(); // interpolate(...) ----------------------------------------------------------------- -sequentialScaleColorString = sequentialScaleColorString.interpolator(d3Scale.interpolateInferno); +sequentialScaleColorString = sequentialScaleColorString.interpolator(interpolateInferno); let sequentialInterpolator: (t: number) => string; sequentialInterpolator = sequentialScaleColorString.interpolator(); @@ -580,28 +586,6 @@ outputString = sequentialScaleColorString(10); const copiedSequentialScale: d3Scale.ScaleSequential = sequentialScaleColorString.copy(); -// ------------------------------------------------------------------------------- -// Color Interpolators for Sequential Scale Factory -// ------------------------------------------------------------------------------- - -let colorInterpolator: ((t: number) => string); - -colorInterpolator = d3Scale.interpolateViridis; - -colorInterpolator = d3Scale.interpolateMagma; - -colorInterpolator = d3Scale.interpolateInferno; - -colorInterpolator = d3Scale.interpolatePlasma; - -colorInterpolator = d3Scale.interpolateRainbow; - -colorInterpolator = d3Scale.interpolateWarm; - -colorInterpolator = d3Scale.interpolateCool; - -colorInterpolator = d3Scale.interpolateCubehelixDefault; - // ------------------------------------------------------------------------------- // Quantize Scale Factory // ------------------------------------------------------------------------------- @@ -764,7 +748,9 @@ let ordinalScaleStringString: d3Scale.ScaleOrdinal; let ordinalScaleStringNumber: d3Scale.ScaleOrdinal; ordinalScaleStringString = d3Scale.scaleOrdinal(); +ordinalScaleStringString = d3Scale.scaleOrdinal(schemePuRd[3]); ordinalScaleStringNumber = d3Scale.scaleOrdinal(); +ordinalScaleStringString = d3Scale.scaleOrdinal(schemePuRd[3]); // ScaleOrdinal Interface ======================================================== @@ -778,6 +764,7 @@ ordinalScaleStringNumber = ordinalScaleStringNumber.domain(['negative', 'neutral // range(...) ----------------------------------------------------------------- ordinalScaleStringString = ordinalScaleStringString.range(['crimson', 'midnightblue', 'seagreen']); +ordinalScaleStringString = ordinalScaleStringString.range(schemePuRd[3]); rangeStrings = ordinalScaleStringString.range(); ordinalScaleStringNumber = ordinalScaleStringNumber.range([-1, 0, 1]); @@ -950,17 +937,3 @@ outputNumberMaybe = pointScaleCoercible(new StringCoercible('negative')); // copy(...) ----------------------------------------------------------------- const copiedPointScale: d3Scale.ScalePoint = pointScaleCoercible.copy(); - -// ------------------------------------------------------------------------------- -// Categorical Color Schemas for Ordinal Scales -// ------------------------------------------------------------------------------- - -let colorStrings: string[]; - -colorStrings = d3Scale.schemeCategory10; - -colorStrings = d3Scale.schemeCategory20; - -colorStrings = d3Scale.schemeCategory20b; - -colorStrings = d3Scale.schemeCategory20c; diff --git a/types/d3-scale/index.d.ts b/types/d3-scale/index.d.ts index d6cccdedfc..203590ce7e 100644 --- a/types/d3-scale/index.d.ts +++ b/types/d3-scale/index.d.ts @@ -1,9 +1,9 @@ -// Type definitions for D3JS d3-scale module 1.0 +// Type definitions for D3JS d3-scale module 2.0 // Project: https://github.com/d3/d3-scale/ // Definitions by: Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 1.0.4 +// Last module patch version validated against: 2.0.0 import { CountableTimeInterval, TimeInterval } from 'd3-time'; @@ -87,7 +87,7 @@ export interface ScaleContinuousNumeric { * * @param range Array of range values. */ - range(range: Range[]): this; + range(range: Range[] | ReadonlyArray): this; /** * Sets the scale’s range to the specified array of values while also setting the scale’s interpolator to interpolateRound. @@ -756,7 +756,7 @@ export interface ScaleTime { * * @param range Array of range values. */ - range(range: Range[]): this; + range(range: Range[] | ReadonlyArray): this; /** * Sets the scale’s range to the specified array of values while also setting the scale’s interpolator to interpolateRound. @@ -1081,71 +1081,6 @@ export interface ScaleSequential { */ export function scaleSequential(interpolator: ((t: number) => Output)): ScaleSequential; -// ------------------------------------------------------------------------------- -// Color Interpolators for Sequential Scale Factory -// ------------------------------------------------------------------------------- - -/** - * Given a number t in the range [0,1], returns the corresponding color from the “viridis” perceptually-uniform color scheme designed by van der Walt, Smith and Firing for matplotlib, - * represented as an RGB string. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolateViridis(t: number): string; - -/** - * Given a number t in the range [0,1], returns the corresponding color from the “inferno” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, - * represented as an RGB string. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolateInferno(t: number): string; - -/** - * Given a number t in the range [0,1], returns the corresponding color from the “magma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, - * represented as an RGB string. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolateMagma(t: number): string; - -/** - * Given a number t in the range [0,1], returns the corresponding color from the “plasma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, - * represented as an RGB string. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolatePlasma(t: number): string; - -/** - * Given a number t in the range [0,1], returns the corresponding color from a 180° rotation of Niccoli’s perceptual rainbow, represented as an RGB string. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolateWarm(t: number): string; - -/** - * Given a number t in the range [0,1], returns the corresponding color from Niccoli’s perceptual rainbow, represented as an RGB string. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolateCool(t: number): string; - -/** - * Given a number t in the range [0,1], returns the corresponding color from d3.interpolateWarm scale from [0.0, 0.5] followed by the d3.interpolateCool scale from [0.5, 1.0], - * thus implementing the cyclical less-angry rainbow color scheme. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolateRainbow(t: number): string; - -/** - * Given a number t in the range [0,1], returns the corresponding color from Green’s default Cubehelix represented as an RGB string. - * - * @param t A number in the interval [0, 1]. - */ -export function interpolateCubehelixDefault(t: number): string; - // ------------------------------------------------------------------------------- // Quantize Scale Factory // ------------------------------------------------------------------------------- @@ -1195,7 +1130,7 @@ export interface ScaleQuantize { * * @param range Array of range values. */ - range(range: Range[]): this; + range(range: Range[] | ReadonlyArray): this; /** * Returns approximately count representative values from the scale’s domain. @@ -1311,7 +1246,7 @@ export interface ScaleQuantile { * * @param range Array of range values. */ - range(range: Range[]): this; + range(range: Range[] | ReadonlyArray): this; /** * Returns the quantile thresholds. If the range contains n discrete values, the returned array will contain n - 1 thresholds. @@ -1385,7 +1320,7 @@ export interface ScaleThreshold { * * @param domain Array of domain values. */ - domain(domain: Domain[]): this; + domain(domain: Domain[] | ReadonlyArray): this; /** * Returns the scale’s current range. @@ -1398,7 +1333,7 @@ export interface ScaleThreshold { * * @param range Array of range values. */ - range(range: Range[]): this; + range(range: Range[] | ReadonlyArray): this; /** * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. @@ -1463,7 +1398,7 @@ export interface ScaleOrdinal { * * @param domain Array of domain values. */ - domain(domain: Domain[]): this; + domain(domain: Domain[] | ReadonlyArray): this; /** * Returns the scale's current range. @@ -1478,7 +1413,7 @@ export interface ScaleOrdinal { * * @param range Array of range values. */ - range(range: Range[]): this; + range(range: Range[] | ReadonlyArray): this; /** * Returns the current unknown value, which defaults to "implicit". @@ -1509,7 +1444,7 @@ export interface ScaleOrdinal { * * @parm range An optional array of range values to initialize the scale with. */ -export function scaleOrdinal(range?: Range[]): ScaleOrdinal; +export function scaleOrdinal(range?: Range[] | ReadonlyArray): ScaleOrdinal; /** * Constructs a new ordinal scale with an empty domain and the specified range. * If a range is not specified, it defaults to the empty array; an ordinal scale always returns undefined until a non-empty range is defined. @@ -1522,7 +1457,7 @@ export function scaleOrdinal(range?: Range[]): ScaleOrdinal(range?: Range[]): ScaleOrdinal; +export function scaleOrdinal(range?: Range[] | ReadonlyArray): ScaleOrdinal; /** * A special value for ordinal.unknown that enables implicit domain construction: unknown values are implicitly added to the domain. @@ -1561,7 +1496,7 @@ export interface ScaleBand { * * @param domain Array of domain values. */ - domain(domain: Domain[]): this; + domain(domain: Domain[] | ReadonlyArray): this; /** * Returns the scale’s current range, which defaults to [0, 1]. @@ -1713,7 +1648,7 @@ export interface ScalePoint { * * @param domain Array of domain values. */ - domain(domain: Domain[]): this; + domain(domain: Domain[] | ReadonlyArray): this; /** * Returns the scale’s current range, which defaults to [0, 1]. @@ -1813,28 +1748,3 @@ export function scalePoint(): ScalePoint; * The generic corresponds to the data type of domain elements. */ export function scalePoint(): ScalePoint; - -// ------------------------------------------------------------------------------- -// Categorical Color Schemas for Ordinal Scales -// ------------------------------------------------------------------------------- - -/** - * An array of ten categorical colors represented as RGB hexadecimal strings. - */ -export const schemeCategory10: string[]; - -/** - * An array of twenty categorical colors represented as RGB hexadecimal strings. - */ -export const schemeCategory20: string[]; - -/** - * An array of twenty categorical colors represented as RGB hexadecimal strings. - */ -export const schemeCategory20b: string[]; - -/** - * An array of twenty categorical colors represented as RGB hexadecimal strings. - * This color scale includes color specifications and designs developed by Cynthia Brewer (colorbrewer2.org). - */ -export const schemeCategory20c: string[]; diff --git a/types/d3-scale/v1/d3-scale-tests.ts b/types/d3-scale/v1/d3-scale-tests.ts new file mode 100644 index 0000000000..749b45894b --- /dev/null +++ b/types/d3-scale/v1/d3-scale-tests.ts @@ -0,0 +1,970 @@ +/** + * Typescript definition tests for d3/d3-scale module + * + * Note: These tests are intended to test the definitions only + * in the sense of typing and call signature consistency. They + * are not intended as functional tests. + */ + +import * as d3Scale from 'd3-scale'; +import { interpolateCubehelix } from 'd3-interpolate'; +import { timeHour } from 'd3-time'; +import { schemePuRd } from 'd3-scale-chromatic'; + +// ------------------------------------------------------------------------------- +// Preparatory Steps +// ------------------------------------------------------------------------------- + +class NumCoercible { + a: number; + + constructor(a: number) { + this.a = a; + } + valueOf() { + return this.a; + } +} + +class StringCoercible { + txt: string; + + constructor(txt: string) { + this.txt = txt; + } + toString() { + return this.txt; + } +} + +let num: number; +let date: Date; + +let clampFlag: boolean; + +let outputNumber: number; +let outputString: string; + +let domainNumbers: number[] = [1, 100]; +const domainNumeric: NumCoercible[] = [new NumCoercible(0), new NumCoercible(100)]; +let domainStrings: string[]; +let domainDates: Date[] = [new Date(2016, 0, 15), new Date(2016, 5, 15)]; + +let ticksNumbers: number[]; +let ticksDates: Date[]; + +let tickFormatNumberFn: ((d: number | { valueOf(): number }) => string); +let tickFormatDateFn: ((d: Date) => string); + +let rangeNumbers: number[] = [2, 200]; +let rangeStrings: string[] = ['2px', '200px']; + +let numExtent: [number, number]; +let numOrUndefinedExtent: [number | undefined, number | undefined]; + +let outputNumberMaybe: number | undefined; +// ------------------------------------------------------------------------------- +// Linear Scale Factory +// ------------------------------------------------------------------------------- + +// scaleLinear() ----------------------------------------------------------------- + +let linearScaleNumber: d3Scale.ScaleLinear; +let linearScaleString: d3Scale.ScaleLinear; +let linearScaleNumString: d3Scale.ScaleLinear; + +linearScaleNumber = d3Scale.scaleLinear(); +linearScaleString = d3Scale.scaleLinear(); +linearScaleNumString = d3Scale.scaleLinear(); + +// ScaleLinear Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +linearScaleNumber = linearScaleNumber.domain(domainNumeric); +linearScaleNumber = linearScaleNumber.domain(domainNumbers); +domainNumbers = linearScaleNumber.domain(); + +linearScaleString = linearScaleString.domain(domainNumeric); +linearScaleString = linearScaleString.domain([10, 100]); +domainNumbers = linearScaleString.domain(); + +linearScaleNumString = linearScaleNumString.domain(domainNumeric); +linearScaleNumString = linearScaleNumString.domain(domainNumbers); +domainNumbers = linearScaleNumString.domain(); + +// range(...) ----------------------------------------------------------------- + +linearScaleNumber = linearScaleNumber.range(rangeNumbers); +rangeNumbers = linearScaleNumber.range(); + +linearScaleString = linearScaleString.range(['steelblue', 'brown']); +rangeStrings = linearScaleString.range(); + +linearScaleNumString = linearScaleNumString.range(rangeNumbers); +rangeNumbers = linearScaleNumString.range(); + +// invert(...) ----------------------------------------------------------------- + +num = linearScaleNumber.invert(500); // has number range, so inversion is possible +num = linearScaleNumber.invert(new NumCoercible(500)); // has number range, so inversion is possible + +num = linearScaleNumString.invert(500); // has number range, so inversion is possible +num = linearScaleNumString.invert(new NumCoercible(500)); // has number range, so inversion is possible + +// rangeRound(...) ----------------------------------------------------------------- + +linearScaleNumber = linearScaleNumber.rangeRound(rangeNumbers); + +// clamp(...) ----------------------------------------------------------------- + +linearScaleNumber = linearScaleNumber.clamp(true); +clampFlag = linearScaleNumber.clamp(); + +// interpolate(...) ----------------------------------------------------------------- + +linearScaleString = linearScaleString.interpolate(interpolateCubehelix.gamma(3)); + +linearScaleNumString = linearScaleNumString.interpolate((a, b) => { + // take two numbers + return (t: number) => (a * (1 - t) + b * t) + 'px'; // a and b are numbers based on Range Type, return value of interpolator is string based on Output type +}); + +// Changes scale output type (inferred generic) +linearScaleNumString = linearScaleNumber.interpolate((a, b) => { + // take two numbers + return (t: number) => (a * (1 - t) + b * t) + 'px'; // a and b are numbers based on Range Type, return value of interpolator is string based on Output type +}); + +// nice(...) ----------------------------------------------------------------------- + +// chainable +linearScaleNumber = linearScaleNumber.nice(); +linearScaleNumber = linearScaleNumber.nice(5); + +// ticks(...) ----------------------------------------------------------------- + +ticksNumbers = linearScaleNumber.ticks(); +ticksNumbers = linearScaleNumber.ticks(5); + +// tickFormat(...) ----------------------------------------------------------------- + +tickFormatNumberFn = linearScaleNumber.tickFormat(); +tickFormatNumberFn = linearScaleNumber.tickFormat(5); +tickFormatNumberFn = linearScaleNumber.tickFormat(5, '+%'); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = linearScaleNumber(10); + +outputString = linearScaleString(10); + +outputString = linearScaleNumString(10); + +// copy(...) ----------------------------------------------------------------- + +const copiedLinearScale: d3Scale.ScaleLinear = linearScaleNumString.copy(); + +// ------------------------------------------------------------------------------- +// Power Scale Factories +// ------------------------------------------------------------------------------- + +// scalePow() and scaleSqrt() ---------------------------------------------------- + +let powerScaleNumber: d3Scale.ScalePower; +let powerScaleString: d3Scale.ScalePower; +let powerScaleNumString: d3Scale.ScalePower; + +powerScaleNumber = d3Scale.scalePow(); +powerScaleString = d3Scale.scalePow(); +powerScaleNumString = d3Scale.scalePow(); + +let squarerootScaleNumber: d3Scale.ScalePower; +let squarerootScaleString: d3Scale.ScalePower; +let squarerootScaleNumString: d3Scale.ScalePower; + +squarerootScaleNumber = d3Scale.scaleSqrt(); +squarerootScaleString = d3Scale.scaleSqrt(); +squarerootScaleNumString = d3Scale.scaleSqrt(); + +// ScalePower Interface ======================================================== + +// exponent -------------------------------------------------------------------- + +const exponent: number = squarerootScaleNumber.exponent(); + +powerScaleNumber = powerScaleNumber.exponent(5); + +// domain(...) ----------------------------------------------------------------- + +powerScaleNumber = powerScaleNumber.domain(domainNumeric); +powerScaleNumber = powerScaleNumber.domain(domainNumbers); +domainNumbers = powerScaleNumber.domain(); + +powerScaleString = powerScaleString.domain(domainNumeric); +powerScaleString = powerScaleString.domain([10, 100]); +domainNumbers = powerScaleString.domain(); + +powerScaleNumString = powerScaleNumString.domain(domainNumeric); +powerScaleNumString = powerScaleNumString.domain(domainNumbers); +domainNumbers = powerScaleNumString.domain(); + +// range(...) ----------------------------------------------------------------- + +powerScaleNumber = powerScaleNumber.range(rangeNumbers); +rangeNumbers = powerScaleNumber.range(); + +powerScaleString = powerScaleString.range(['steelblue', 'brown']); +rangeStrings = powerScaleString.range(); + +powerScaleNumString = powerScaleNumString.range(rangeNumbers); +rangeNumbers = powerScaleNumString.range(); + +// invert(...) ----------------------------------------------------------------- + +num = powerScaleNumber.invert(500); // has number range, so inversion is possible +num = powerScaleNumber.invert(new NumCoercible(500)); // has number range, so inversion is possible + +num = powerScaleNumString.invert(500); // has number range, so inversion is possible +num = powerScaleNumString.invert(new NumCoercible(500)); // has number range, so inversion is possible + +// rangeRound(...) ----------------------------------------------------------------- + +powerScaleNumber = powerScaleNumber.rangeRound(rangeNumbers); + +// clamp(...) ----------------------------------------------------------------- + +powerScaleNumber = powerScaleNumber.clamp(true); +clampFlag = powerScaleNumber.clamp(); + +// interpolate(...) ----------------------------------------------------------------- + +powerScaleString = powerScaleString.interpolate(interpolateCubehelix.gamma(3)); + +powerScaleNumString = powerScaleNumString.interpolate((a, b) => { + // take two numbers + return (t: number) => (a * (1 - t) + b * t) + 'px'; // a and b are numbers based on Range Type, return value of interpolator is string based on Output type +}); + +// nice(...) ----------------------------------------------------------------------- + +// chainable +powerScaleNumber = powerScaleNumber.nice(); +powerScaleNumber = powerScaleNumber.nice(5); + +// ticks(...) ----------------------------------------------------------------- + +ticksNumbers = powerScaleNumber.ticks(); +ticksNumbers = powerScaleNumber.ticks(5); + +// tickFormat(...) ----------------------------------------------------------------- + +tickFormatNumberFn = powerScaleNumber.tickFormat(); +tickFormatNumberFn = powerScaleNumber.tickFormat(5); +tickFormatNumberFn = powerScaleNumber.tickFormat(5, '+%'); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = powerScaleNumber(10); + +outputString = powerScaleString(10); + +outputString = powerScaleNumString(10); + +// copy(...) ----------------------------------------------------------------- + +const copiedPowerScale: d3Scale.ScalePower = powerScaleNumString.copy(); + +// ------------------------------------------------------------------------------- +// Logarithmic Scale Factory +// ------------------------------------------------------------------------------- + +// scaleLog() --------------------------------------------------------------------- + +let logScaleNumber: d3Scale.ScaleLogarithmic; +let logScaleString: d3Scale.ScaleLogarithmic; +let logScaleNumString: d3Scale.ScaleLogarithmic; + +logScaleNumber = d3Scale.scaleLog(); +logScaleString = d3Scale.scaleLog(); +logScaleNumString = d3Scale.scaleLog(); + +// ScaleLogarithmic Interface ======================================================== + +// base -------------------------------------------------------------------- + +const base: number = logScaleNumber.base(); + +logScaleNumber = logScaleNumber.base(42); + +// domain(...) ----------------------------------------------------------------- + +logScaleNumber = logScaleNumber.domain(domainNumeric); +logScaleNumber = logScaleNumber.domain(domainNumbers); +domainNumbers = logScaleNumber.domain(); + +logScaleString = logScaleString.domain(domainNumeric); +logScaleString = logScaleString.domain([10, 100]); +domainNumbers = logScaleString.domain(); + +logScaleNumString = logScaleNumString.domain(domainNumeric); +logScaleNumString = logScaleNumString.domain(domainNumbers); +domainNumbers = logScaleNumString.domain(); + +// range(...) ----------------------------------------------------------------- + +logScaleNumber = logScaleNumber.range(rangeNumbers); +rangeNumbers = logScaleNumber.range(); + +logScaleString = logScaleString.range(['steelblue', 'brown']); +rangeStrings = logScaleString.range(); + +logScaleNumString = logScaleNumString.range(rangeNumbers); +rangeNumbers = logScaleNumString.range(); + +// invert(...) ----------------------------------------------------------------- + +num = logScaleNumber.invert(500); // has number range, so inversion is possible +num = logScaleNumber.invert(new NumCoercible(500)); // has number range, so inversion is possible + +num = logScaleNumString.invert(500); // has number range, so inversion is possible +num = logScaleNumString.invert(new NumCoercible(500)); // has number range, so inversion is possible + +// rangeRound(...) ----------------------------------------------------------------- + +logScaleNumber = logScaleNumber.rangeRound(rangeNumbers); + +// clamp(...) ----------------------------------------------------------------- + +logScaleNumber = logScaleNumber.clamp(true); +clampFlag = logScaleNumber.clamp(); + +// interpolate(...) ----------------------------------------------------------------- + +logScaleString = logScaleString.interpolate(interpolateCubehelix.gamma(3)); + +logScaleNumString = logScaleNumString.interpolate((a, b) => { + // take two numbers + return (t: number) => (a * (1 - t) + b * t) + 'px'; // a and b are numbers based on Range Type, return value of interpolator is string based on Output type +}); + +// nice(...) ----------------------------------------------------------------------- + +// chainable +logScaleNumber = logScaleNumber.nice(); +// logScaleNumber = logScaleNumber.nice(5); // fails, logarithmic scale does not support count parameter. + +// ticks(...) ----------------------------------------------------------------- + +ticksNumbers = logScaleNumber.ticks(); +ticksNumbers = logScaleNumber.ticks(5); + +// tickFormat(...) ----------------------------------------------------------------- + +tickFormatNumberFn = logScaleNumber.tickFormat(); +tickFormatNumberFn = logScaleNumber.tickFormat(5); +tickFormatNumberFn = logScaleNumber.tickFormat(5, '+%'); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = logScaleNumber(10); + +outputString = logScaleString(10); + +outputString = logScaleNumString(10); + +// copy(...) ----------------------------------------------------------------- + +const copiedLogScale: d3Scale.ScaleLogarithmic = logScaleNumString.copy(); + +// ------------------------------------------------------------------------------- +// Identity Scale Factory +// ------------------------------------------------------------------------------- + +// scaleIdentity ----------------------------------------------------------------- + +let identityScale: d3Scale.ScaleIdentity; + +identityScale = d3Scale.scaleIdentity(); + +// ScaleIdentity Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +identityScale = identityScale.domain(domainNumeric); +identityScale = identityScale.domain(domainNumbers); +domainNumbers = identityScale.domain(); + +// range(...) ----------------------------------------------------------------- + +identityScale = identityScale.range(rangeNumbers); +rangeNumbers = identityScale.range(); + +// invert(...) ----------------------------------------------------------------- + +num = identityScale.invert(500); // has number range, so inversion is possible +num = identityScale.invert(new NumCoercible(500)); // has number range, so inversion is possible + +// nice(...) ----------------------------------------------------------------------- + +// chainable +identityScale = identityScale.nice(); +identityScale = identityScale.nice(5); + +// ticks(...) ----------------------------------------------------------------- + +ticksNumbers = identityScale.ticks(); +ticksNumbers = identityScale.ticks(5); + +// tickFormat(...) ----------------------------------------------------------------- + +tickFormatNumberFn = identityScale.tickFormat(); +tickFormatNumberFn = identityScale.tickFormat(5); +tickFormatNumberFn = identityScale.tickFormat(5, '+%'); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = identityScale(10); + +// copy(...) ----------------------------------------------------------------- + +const copiedIdentityScale: d3Scale.ScaleIdentity = identityScale.copy(); + +// ------------------------------------------------------------------------------- +// Time Scale Factories +// ------------------------------------------------------------------------------- + +// scaleTime() and scaleUtc() ---------------------------------------------------- + +let localTimeScaleNumber: d3Scale.ScaleTime; +let localTimeScaleString: d3Scale.ScaleTime; +let localTimeScaleNumString: d3Scale.ScaleTime; + +localTimeScaleNumber = d3Scale.scaleTime(); +localTimeScaleString = d3Scale.scaleTime(); +localTimeScaleNumString = d3Scale.scaleTime(); + +let utcScaleNumber: d3Scale.ScaleTime; +let utcScaleString: d3Scale.ScaleTime; +let utcScaleNumString: d3Scale.ScaleTime; + +utcScaleNumber = d3Scale.scaleUtc(); +utcScaleString = d3Scale.scaleUtc(); +utcScaleNumString = d3Scale.scaleUtc(); + +// domain(...) ----------------------------------------------------------------- + +localTimeScaleNumber = localTimeScaleNumber.domain(domainDates); + +domainDates = localTimeScaleNumber.domain(); + +localTimeScaleString = localTimeScaleString.domain([new Date(2016, 6, 1), Date.now()]); +domainDates = localTimeScaleString.domain(); + +localTimeScaleNumString = localTimeScaleNumString.domain(domainDates); +domainDates = localTimeScaleNumString.domain(); + +// range(...) ----------------------------------------------------------------- + +localTimeScaleNumber = localTimeScaleNumber.range(rangeNumbers); +rangeNumbers = localTimeScaleNumber.range(); + +localTimeScaleString = localTimeScaleString.range(['steelblue', 'brown']); +rangeStrings = localTimeScaleString.range(); + +localTimeScaleNumString = localTimeScaleNumString.range(rangeNumbers); +rangeNumbers = localTimeScaleNumString.range(); + +// invert(...) ----------------------------------------------------------------- + +date = localTimeScaleNumber.invert(500); // has number range, so inversion is possible +date = localTimeScaleNumber.invert(new NumCoercible(500)); // has number range, so inversion is possible + +date = localTimeScaleNumString.invert(500); // has number range, so inversion is possible +date = localTimeScaleNumString.invert(new NumCoercible(500)); // has number range, so inversion is possible + +// rangeRound(...) ----------------------------------------------------------------- + +localTimeScaleNumber = localTimeScaleNumber.rangeRound(rangeNumbers); + +// clamp(...) ----------------------------------------------------------------- + +localTimeScaleNumber = localTimeScaleNumber.clamp(true); +clampFlag = localTimeScaleNumber.clamp(); + +// interpolate(...) ----------------------------------------------------------------- + +localTimeScaleString = localTimeScaleString.interpolate(interpolateCubehelix.gamma(3)); + +localTimeScaleNumString = localTimeScaleNumString.interpolate((a, b) => { + // take two numbers + return (t: number) => (a * (1 - t) + b * t) + 'px'; // a and b are numbers based on Range Type, return value of interpolator is string based on Output type +}); + +// nice(...) ----------------------------------------------------------------------- + +// chainable +localTimeScaleNumber = localTimeScaleNumber.nice(); +localTimeScaleNumber = localTimeScaleNumber.nice(5); +localTimeScaleNumber = localTimeScaleNumber.nice(timeHour); +localTimeScaleNumber = localTimeScaleNumber.nice(timeHour, 5); + +// localTimeScaleNumber = localTimeScaleNumber.nice(timeHour.every(5)); // fails, requires CountableTimeInterval + +// ticks(...) ----------------------------------------------------------------- + +const timeInterval = timeHour.every(5); + +ticksDates = localTimeScaleNumber.ticks(); +ticksDates = localTimeScaleNumber.ticks(50); + +if (timeInterval !== null) { + ticksDates = localTimeScaleNumString.ticks(timeInterval); +} + +// tickFormat(...) ----------------------------------------------------------------- + +tickFormatDateFn = localTimeScaleNumber.tickFormat(); +tickFormatDateFn = localTimeScaleNumber.tickFormat(50, '%I %p'); +if (timeInterval !== null) { + tickFormatDateFn = localTimeScaleNumber.tickFormat(timeInterval, '%I %p'); +} + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = localTimeScaleNumber(new Date(2016, 6, 4)); + +outputString = localTimeScaleString(new Date(2016, 6, 4)); + +outputString = localTimeScaleNumString(new Date(2016, 6, 4)); + +// copy(...) ----------------------------------------------------------------- + +const copiedTimeScale: d3Scale.ScaleTime = localTimeScaleNumString.copy(); + +// ------------------------------------------------------------------------------- +// Sequential Scale Factory +// ------------------------------------------------------------------------------- + +// scaleSequential() ----------------------------------------------------------------- + +let sequentialScaleColorString: d3Scale.ScaleSequential; + +sequentialScaleColorString = d3Scale.scaleSequential(d3Scale.interpolateRainbow); +sequentialScaleColorString = d3Scale.scaleSequential(d3Scale.interpolateCool); // inferred Output type string + +// ScaleSequential Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +sequentialScaleColorString = sequentialScaleColorString.domain([0, 1]); +sequentialScaleColorString = sequentialScaleColorString.domain([new NumCoercible(0), new NumCoercible(100)]); +const domainSequential: [number, number] = sequentialScaleColorString.domain(); + +// clamp(...) ----------------------------------------------------------------- + +sequentialScaleColorString = sequentialScaleColorString.clamp(true); +clampFlag = sequentialScaleColorString.clamp(); + +// interpolate(...) ----------------------------------------------------------------- + +sequentialScaleColorString = sequentialScaleColorString.interpolator(d3Scale.interpolateInferno); + +let sequentialInterpolator: (t: number) => string; +sequentialInterpolator = sequentialScaleColorString.interpolator(); + +// (...) value mapping from domain to output ----------------------------------- + +outputString = sequentialScaleColorString(10); + +// copy(...) ----------------------------------------------------------------- + +const copiedSequentialScale: d3Scale.ScaleSequential = sequentialScaleColorString.copy(); + +// ------------------------------------------------------------------------------- +// Color Interpolators for Sequential Scale Factory +// ------------------------------------------------------------------------------- + +let colorInterpolator: ((t: number) => string); + +colorInterpolator = d3Scale.interpolateViridis; + +colorInterpolator = d3Scale.interpolateMagma; + +colorInterpolator = d3Scale.interpolateInferno; + +colorInterpolator = d3Scale.interpolatePlasma; + +colorInterpolator = d3Scale.interpolateRainbow; + +colorInterpolator = d3Scale.interpolateWarm; + +colorInterpolator = d3Scale.interpolateCool; + +colorInterpolator = d3Scale.interpolateCubehelixDefault; + +// ------------------------------------------------------------------------------- +// Quantize Scale Factory +// ------------------------------------------------------------------------------- + +// scaleQuantize() ----------------------------------------------------------------- + +let quantizeScaleNumber: d3Scale.ScaleQuantize; +let quantizeScaleString: d3Scale.ScaleQuantize; + +quantizeScaleNumber = d3Scale.scaleQuantize(); +quantizeScaleString = d3Scale.scaleQuantize(); + +// ScaleQuantize Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +quantizeScaleNumber = quantizeScaleNumber.domain([0, 1]); +quantizeScaleNumber = quantizeScaleNumber.domain([new NumCoercible(0), new NumCoercible(100)]); +const domainQuantize: [number, number] = quantizeScaleNumber.domain(); + +// range(...) ----------------------------------------------------------------- + +quantizeScaleNumber = quantizeScaleNumber.range(rangeNumbers); +rangeNumbers = quantizeScaleNumber.range(); + +quantizeScaleString = quantizeScaleString.range(['steelblue', 'brown']); +rangeStrings = quantizeScaleString.range(); + +// invertExtent(...) ----------------------------------------------------------------- + +numExtent = quantizeScaleNumber.invertExtent(500); + +numExtent = quantizeScaleString.invertExtent('steelblue'); + +// nice(...) ----------------------------------------------------------------------- + +// chainable +quantizeScaleNumber = quantizeScaleNumber.nice(); +quantizeScaleNumber = quantizeScaleNumber.nice(5); + +// ticks(...) ----------------------------------------------------------------- + +ticksNumbers = quantizeScaleNumber.ticks(); +ticksNumbers = quantizeScaleNumber.ticks(5); + +// tickFormat(...) ----------------------------------------------------------------- + +tickFormatNumberFn = quantizeScaleNumber.tickFormat(); +tickFormatNumberFn = quantizeScaleNumber.tickFormat(5); +tickFormatNumberFn = quantizeScaleNumber.tickFormat(5, '+%'); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = quantizeScaleNumber(0.51); + +// copy(...) ----------------------------------------------------------------- + +const copiedQuantizeScale: d3Scale.ScaleQuantize = quantizeScaleNumber.copy(); + +// ------------------------------------------------------------------------------- +// Quantile Scale Factory +// ------------------------------------------------------------------------------- + +// scaleQuantile() ----------------------------------------------------------------- + +let quantileScaleNumber: d3Scale.ScaleQuantile; +let quantileScaleString: d3Scale.ScaleQuantile; + +quantileScaleNumber = d3Scale.scaleQuantile(); +quantileScaleString = d3Scale.scaleQuantile(); + +// ScaleQuantile Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +quantileScaleNumber = quantileScaleNumber.domain(domainNumbers); + +domainNumbers = quantileScaleNumber.domain(); + +quantileScaleString = quantileScaleString.domain(domainNumeric); + +// range(...) ----------------------------------------------------------------- + +quantileScaleNumber = quantileScaleNumber.range([1, 2, 3, 4]); +rangeNumbers = quantileScaleNumber.range(); + +quantileScaleString = quantileScaleString.range(['q25', 'q50', 'q75']); +rangeStrings = quantileScaleString.range(); + +// invertExtent(...) ----------------------------------------------------------------- + +numExtent = quantileScaleNumber.invertExtent(2); + +numExtent = quantileScaleString.invertExtent('q50'); + +// quantile() ----------------------------------------------------------------------- + +const quantiles: number[] = quantileScaleNumber.quantiles(); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = quantileScaleNumber(0.51); + +// copy(...) ----------------------------------------------------------------- + +const copiedQuantileScale: d3Scale.ScaleQuantile = quantileScaleNumber.copy(); + +// ------------------------------------------------------------------------------- +// Threshold Scale Factory +// ------------------------------------------------------------------------------- + +// scaleThreshold() ----------------------------------------------------------------- + +let thresholdScaleNumberNumber: d3Scale.ScaleThreshold; +let thresholdScaleNumberString: d3Scale.ScaleThreshold; + +thresholdScaleNumberNumber = d3Scale.scaleThreshold(); +thresholdScaleNumberString = d3Scale.scaleThreshold(); + +// ScaleThreshold Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +thresholdScaleNumberNumber = thresholdScaleNumberNumber.domain([0.5]); +domainNumbers = thresholdScaleNumberNumber.domain(); + +thresholdScaleNumberString = thresholdScaleNumberString.domain([0.2, 0.8]); + +// range(...) ----------------------------------------------------------------- + +thresholdScaleNumberNumber = thresholdScaleNumberNumber.range([100, 200]); +rangeNumbers = thresholdScaleNumberNumber.range(); + +thresholdScaleNumberString = thresholdScaleNumberString.range(['steelblue', 'seagreen', 'brown']); +rangeStrings = thresholdScaleNumberString.range(); + +// invertExtent(...) ----------------------------------------------------------------- + +numOrUndefinedExtent = thresholdScaleNumberNumber.invertExtent(100); + +numOrUndefinedExtent = thresholdScaleNumberString.invertExtent('seagreen'); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumber = thresholdScaleNumberNumber(0.51); + +outputString = thresholdScaleNumberString(0.9); + +// copy(...) ----------------------------------------------------------------- + +const copiedThresholdScale: d3Scale.ScaleThreshold = thresholdScaleNumberString.copy(); + +// ------------------------------------------------------------------------------- +// Ordinal Scale Factory +// ------------------------------------------------------------------------------- + +// scaleOrdinal() ----------------------------------------------------------------- + +let ordinalScaleStringString: d3Scale.ScaleOrdinal; +let ordinalScaleStringNumber: d3Scale.ScaleOrdinal; + +ordinalScaleStringString = d3Scale.scaleOrdinal(); +ordinalScaleStringString = d3Scale.scaleOrdinal(schemePuRd[3]); +ordinalScaleStringNumber = d3Scale.scaleOrdinal(); +ordinalScaleStringString = d3Scale.scaleOrdinal(schemePuRd[3]); + +// ScaleOrdinal Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +ordinalScaleStringString = ordinalScaleStringString.domain(['negative', 'neutral', 'positive']); +domainStrings = ordinalScaleStringString.domain(); + +ordinalScaleStringNumber = ordinalScaleStringNumber.domain(['negative', 'neutral', 'positive']); + +// range(...) ----------------------------------------------------------------- + +ordinalScaleStringString = ordinalScaleStringString.range(['crimson', 'midnightblue', 'seagreen']); +ordinalScaleStringString = ordinalScaleStringString.range(schemePuRd[3]); +rangeStrings = ordinalScaleStringString.range(); + +ordinalScaleStringNumber = ordinalScaleStringNumber.range([-1, 0, 1]); +rangeNumbers = ordinalScaleStringNumber.range(); + +// unknown(...) and d3Scale.scaleImplicit -------------------------------------- + +const implicit: { name: 'implicit' } = d3Scale.scaleImplicit; + +ordinalScaleStringString = ordinalScaleStringString.unknown(d3Scale.scaleImplicit); + +ordinalScaleStringNumber = ordinalScaleStringNumber.unknown(0); + +const unknownValue: string | { name: 'implicit' } = ordinalScaleStringString.unknown(); + +if (typeof unknownValue === 'string') { + console.log(unknownValue); +} else { + console.log(unknownValue.name); +} + +// (...) value mapping from domain to output ----------------------------------- + +outputString = ordinalScaleStringString('neutral'); + +outputNumber = ordinalScaleStringNumber('negative'); + +// copy(...) ----------------------------------------------------------------- + +const copiedOrdinalScale: d3Scale.ScaleOrdinal = ordinalScaleStringNumber.copy(); + +// ------------------------------------------------------------------------------- +// Band Scale Factory +// ------------------------------------------------------------------------------- + +// scaleBand() ----------------------------------------------------------------- + +let bandScaleString: d3Scale.ScaleBand; +let bandScaleCoercible: d3Scale.ScaleBand; + +bandScaleString = d3Scale.scaleBand(); +bandScaleCoercible = d3Scale.scaleBand(); + +// ScaleBand Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +bandScaleString = bandScaleString.domain(['negative', 'neutral', 'positive']); +domainStrings = bandScaleString.domain(); + +bandScaleCoercible = bandScaleCoercible.domain([new StringCoercible('negative'), new StringCoercible('neutral'), new StringCoercible('positive')]); + +// range(...) ----------------------------------------------------------------- + +bandScaleString = bandScaleString.range([0, 300]); +let rangeExtent: [number, number] = bandScaleString.range(); + +bandScaleCoercible = bandScaleCoercible.range([0, 300]); +rangeExtent = bandScaleCoercible.range(); + +// rangeRound(...) ----------------------------------------------------------------- + +bandScaleString = bandScaleString.rangeRound([0, 300]); + +// round(...) ----------------------------------------------------------------- + +bandScaleCoercible = bandScaleCoercible.round(true); +let roundingFlag: boolean = bandScaleCoercible.round(); + +// paddingInner(...) ----------------------------------------------------------------- + +bandScaleString = bandScaleString.paddingInner(0.1); +num = bandScaleString.paddingInner(); + +// paddingOuter(...) ----------------------------------------------------------------- + +bandScaleString = bandScaleString.paddingOuter(0.1); +num = bandScaleString.paddingOuter(); + +// padding(...) ----------------------------------------------------------------- + +bandScaleString = bandScaleString.padding(0.1); +num = bandScaleString.padding(); + +// align(...) ----------------------------------------------------------------- + +bandScaleString = bandScaleString.align(0.5); +num = bandScaleString.align(); + +// bandwidth(...) ----------------------------------------------------------------- + +num = bandScaleString.bandwidth(); + +// step(...) ----------------------------------------------------------------- + +num = bandScaleString.step(); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumberMaybe = bandScaleString('neutral'); + +outputNumberMaybe = bandScaleCoercible(new StringCoercible('negative')); + +// copy(...) ----------------------------------------------------------------- + +const copiedBandScale: d3Scale.ScaleBand = bandScaleCoercible.copy(); + +// ------------------------------------------------------------------------------- +// Point Scale Factory +// ------------------------------------------------------------------------------- + +// scalePoint() ----------------------------------------------------------------- + +let pointScaleString: d3Scale.ScalePoint; +let pointScaleCoercible: d3Scale.ScalePoint; + +pointScaleString = d3Scale.scalePoint(); +pointScaleCoercible = d3Scale.scalePoint(); + +// ScalePoint Interface ======================================================== + +// domain(...) ----------------------------------------------------------------- + +pointScaleString = pointScaleString.domain(['negative', 'neutral', 'positive']); +domainStrings = pointScaleString.domain(); + +pointScaleCoercible = pointScaleCoercible.domain([new StringCoercible('negative'), new StringCoercible('neutral'), new StringCoercible('positive')]); + +// range(...) ----------------------------------------------------------------- + +pointScaleString = pointScaleString.range([0, 300]); +rangeExtent = pointScaleString.range(); + +pointScaleCoercible = pointScaleCoercible.range([0, 300]); +rangeExtent = pointScaleCoercible.range(); + +// rangeRound(...) ----------------------------------------------------------------- + +pointScaleString = pointScaleString.rangeRound([0, 300]); + +// round(...) ----------------------------------------------------------------- + +pointScaleCoercible = pointScaleCoercible.round(true); +roundingFlag = pointScaleCoercible.round(); + +// padding(...) ----------------------------------------------------------------- + +pointScaleString = pointScaleString.padding(0.1); +num = pointScaleString.padding(); + +// align(...) ----------------------------------------------------------------- + +pointScaleString = pointScaleString.align(0.5); +num = pointScaleString.align(); + +// bandwidth(...) ----------------------------------------------------------------- + +num = pointScaleString.bandwidth(); + +// step(...) ----------------------------------------------------------------- + +num = pointScaleString.step(); + +// (...) value mapping from domain to output ----------------------------------- + +outputNumberMaybe = pointScaleString('neutral'); + +outputNumberMaybe = pointScaleCoercible(new StringCoercible('negative')); + +// copy(...) ----------------------------------------------------------------- + +const copiedPointScale: d3Scale.ScalePoint = pointScaleCoercible.copy(); + +// ------------------------------------------------------------------------------- +// Categorical Color Schemas for Ordinal Scales +// ------------------------------------------------------------------------------- + +let colorStrings: string[]; + +colorStrings = d3Scale.schemeCategory10; + +colorStrings = d3Scale.schemeCategory20; + +colorStrings = d3Scale.schemeCategory20b; + +colorStrings = d3Scale.schemeCategory20c; diff --git a/types/d3-scale/v1/index.d.ts b/types/d3-scale/v1/index.d.ts new file mode 100644 index 0000000000..4831974f16 --- /dev/null +++ b/types/d3-scale/v1/index.d.ts @@ -0,0 +1,1840 @@ +// Type definitions for D3JS d3-scale module 1.0 +// Project: https://github.com/d3/d3-scale/ +// Definitions by: Tom Wanzek , Alex Ford , Boris Yankov +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// Last module patch version validated against: 1.0.7 + +import { CountableTimeInterval, TimeInterval } from 'd3-time'; + +// ------------------------------------------------------------------------------- +// Shared Types and Interfaces +// ------------------------------------------------------------------------------- + +/** + * An Interpolator factory returns an interpolator function. + * + * The first generic correponds to the data type of the interpolation boundaries. + * The second generic corresponds to the data type of the return type of the interpolator. + */ +export interface InterpolatorFactory { + /** + * Construct a new interpolator function, based on the provided interpolation boundaries. + * + * @param a Start boundary of the interpolation interval. + * @param b End boundary of the interpolation interval. + */ + (a: T, b: T): ((t: number) => U); +} + +/** + * A helper interface for a continuous scale defined over a numeric domain. + */ +export interface ScaleContinuousNumeric { + /** + * Given a value from the domain, returns the corresponding value from the range, subject to interpolation, if any. + * + * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range. + * + * Note: The interpolation function applied by the scale may change the output type from the range type as part of the interpolation. + * + * @param value A numeric value from the domain. + */ + (value: number | { valueOf(): number }): Output; + + /** + * Given a value from the range, returns the corresponding value from the domain. Inversion is useful for interaction, + * say to determine the data value corresponding to the position of the mouse. + * + * If the given value is outside the range, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the domain. + * + * IMPORTANT: This method is only supported if the range is numeric. If the range is not numeric, returns NaN. + * + * For a valid value y in the range, continuous(continuous.invert(y)) approximately equals y; + * similarly, for a valid value x in the domain, continuous.invert(continuous(x)) approximately equals x. + * The scale and its inverse may not be exact due to the limitations of floating point precision. + * + * @param value A numeric value from the range. + */ + invert(value: number | { valueOf(): number }): number; + + /** + * Returns a copy of the scale’s current domain. + */ + domain(): number[]; + /** + * Sets the scale’s domain to the specified array of numbers. The array must contain two or more elements. + * If the elements in the given array are not numbers, they will be coerced to numbers + * + * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale. + * + * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value. + * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed. + * + * @param domain Array of numeric domain values. + */ + domain(domain: Array): this; + + /** + * Returns a copy of the scale’s current range. + */ + range(): Range[]; + /** + * Sets the scale’s range to the specified array of values. + * + * The array must contain two or more elements. Unlike the domain, elements in the given array need not be numbers; + * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert. + * + * @param range Array of range values. + */ + range(range: Range[] | ReadonlyArray): this; + + /** + * Sets the scale’s range to the specified array of values while also setting the scale’s interpolator to interpolateRound. + * + * The rounding interpolator is sometimes useful for avoiding antialiasing artifacts, + * though also consider the shape-rendering “crispEdges” styles. Note that this interpolator can only be used with numeric ranges. + * + * The array must contain two or more elements. Unlike the domain, elements in the given array need not be numbers; + * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert. + * + * @param range Array of range values. + */ + rangeRound(range: Array): this; + + /** + * Returns whether or not the scale currently clamps values to within the range. + */ + clamp(): boolean; + /** + * Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain, + * the scale may return a value outside the range through extrapolation. + * + * If clamping is enabled, the return value of the scale is always within the scale’s range. Clamping similarly applies to the "invert" method. + * + * @param clamp A flag to enable (true) or disable (false) clamping. + */ + clamp(clamp: boolean): this; + + /** + * Returns approximately count representative values from the scale’s domain. + * + * If count is not specified, it defaults to 10. + * + * The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), + * and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. + * The specified count is only a hint; the scale may return more or fewer values depending on the domain. See also d3-array’s ticks. + * + * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10. + */ + ticks(count?: number): number[]; + + /** + * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values. + * The specified count should have the same value as the count that is used to generate the tick values. + * + * @param count Approximate number of ticks to be used when calculating precision for the number format function. + * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval. + * If specifier uses the format type "s", the scale will return a SI-prefix format based on the largest value in the domain. + * If the specifier already specifies a precision, this method is equivalent to locale.format. + */ + tickFormat(count?: number, specifier?: string): ((d: number | { valueOf(): number }) => string); + + /** + * Extends the domain so that it starts and ends on nice round values. + * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. + * An optional tick count argument allows greater control over the step size used to extend the bounds, + * guaranteeing that the returned ticks will exactly cover the domain. + * Nicing is useful if the domain is computed from data, say using extent, and may be irregular. + * For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0]. + * If the domain has more than two values, nicing the domain only affects the first and last value. + * + * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain. + * You must re-nice the scale after setting the new domain, if desired. + * + * @param count An optional number of ticks expected to be used. + */ + nice(count?: number): this; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +// ------------------------------------------------------------------------------- +// Linear Scale Factory +// ------------------------------------------------------------------------------- + +/** + * A linear continuous scale defined over a numeric domain. + * + * Continuous scales map a continuous, quantitative input domain to a continuous output range. + * Each range value y can be expressed as a function of the domain value x: y = mx + b. + * + * If the range is also numeric, the mapping may be inverted. + * + * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale. + * + * The first generic corresponds to the data type of the range elements. + * + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + */ +export interface ScaleLinear extends ScaleContinuousNumeric { + /** + * Returns the scale’s current interpolator factory, which defaults to interpolate. + */ + interpolate(): InterpolatorFactory; + + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): this; + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): ScaleLinear; +} + +/** + * Constructs a new continuous linear scale with the unit domain [0, 1], the unit range [0, 1], the default interpolator and clamping disabled. + * + * The scale will have range and output of data type number. + */ +export function scaleLinear(): ScaleLinear; +/** + * Constructs a new continuous linear scale with the unit domain [0, 1], the default interpolator and clamping disabled. + * + * The generic correponds to the data type of the range and output elements to be used. + * + * As range type and output type are the same, the interpolator factory used with the scale must match this behaviour. + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleLinear(): ScaleLinear; +/** + * Constructs a new continuous linear scale with the unit domain [0, 1], the default interpolator and clamping disabled. + * + * The first generic corresponds to the data type of the range elements. + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleLinear(): ScaleLinear; + +// ------------------------------------------------------------------------------- +// Power Scale Factories +// ------------------------------------------------------------------------------- + +/** + * A continuous power scale defined over a numeric domain. + * + * Continuous scales map a continuous, quantitative input domain to a continuous output range. + * + * Each range value y can be expressed as a function of the domain value x: y = mx^k + b, where k is the exponent value. + * Power scales also support negative domain values, in which case the input value and the resulting output value are multiplied by -1. + * + * If the range is also numeric, the mapping may be inverted. + * + * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale. + * + * The first generic corresponds to the data type of the range elements. + * + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + */ +export interface ScalePower extends ScaleContinuousNumeric { + /** + * Returns the scale’s current interpolator factory, which defaults to interpolate. + */ + interpolate(): InterpolatorFactory; + + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): this; + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): ScalePower; + + /** + * If exponent is not specified, returns the current exponent, which defaults to 1. + * (Note that this is effectively a linear scale until you set a different exponent.) + */ + exponent(): number; + /** + * Sets the current exponent to the given numeric value. + * (Note that this is effectively a linear scale until you set a different exponent.) + */ + exponent(exponent: number): this; +} + +/** + * Constructs a new continuous power scale with the unit domain [0, 1], the unit range [0, 1], the exponent 1, the default interpolator and clamping disabled. + * (Note that this is effectively a linear scale until you set a different exponent.) + * + * The scale will have range and output of data type number. + */ +export function scalePow(): ScalePower; +/** + * Constructs a new continuous power scale with the unit domain [0, 1], the exponent 1, the default interpolator and clamping disabled. + * (Note that this is effectively a linear scale until you set a different exponent.) + * + * The generic correponds to the data type of the range and output elements to be used. + * + * As range type and output type are the same, the interpolator factory used with the scale must match this behaviour. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scalePow(): ScalePower; +/** + * Constructs a new continuous power scale with the unit domain [0, 1], the exponent 1, the default interpolator and clamping disabled. + * (Note that this is effectively a linear scale until you set a different exponent.) + * + * The first generic corresponds to the data type of the range elements. + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scalePow(): ScalePower; + +/** + * Constructs a new continuous power scale with the unit domain [0, 1], the unit range [0, 1], the exponent 0.5, the default interpolator and clamping disabled. + * This is a convenience method equivalent to d3.scalePow().exponent(0.5). + * + * The scale will have range and output of data type number. + */ +export function scaleSqrt(): ScalePower; +/** + * Constructs a new continuous power scale with the unit domain [0, 1], the exponent 0.5, the default interpolator and clamping disabled. + * This is a convenience method equivalent to d3.scalePow().exponent(0.5). + * + * The generic correponds to the data type of the range and output elements to be used. + * + * As range type and output type are the same, the interpolator factory used with the scale must match this behaviour. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleSqrt(): ScalePower; +/** + * Constructs a new continuous power scale with the unit domain [0, 1], the exponent 0.5, the default interpolator and clamping disabled. + * This is a convenience method equivalent to d3.scalePow().exponent(0.5). + * + * The first generic corresponds to the data type of the range elements. + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleSqrt(): ScalePower; + +// ------------------------------------------------------------------------------- +// Logarithmic Scale Factory +// ------------------------------------------------------------------------------- + +/** + * A continuous logarithmic scale defined over a numeric domain. + * + * Continuous scales map a continuous, quantitative input domain to a continuous output range. + * + * The mapping to the range value y can be expressed as a function of the domain value x: y = m log(x) + b. + * + * As log(0) = -∞, a log scale domain must be strictly-positive or strictly-negative; the domain must not include or cross zero. + * A log scale with a positive domain has a well-defined behavior for positive values, and a log scale with a negative domain has a well-defined behavior for negative values. + * (For a negative domain, input and output values are implicitly multiplied by -1.) + * The behavior of the scale is undefined if you pass a negative value to a log scale with a positive domain or vice versa. + * + * If the range is also numeric, the mapping may be inverted. + * + * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale. + * + * The first generic corresponds to the data type of the range elements. + * + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + */ +export interface ScaleLogarithmic extends ScaleContinuousNumeric { + /** + * Returns a copy of the scale’s current domain. + */ + domain(): number[]; + /** + * Sets the scale’s domain to the specified array of numbers. The array must contain two or more elements. + * If the elements in the given array are not numbers, they will be coerced to numbers + * + * As log(0) = -∞, a log scale domain must be strictly-positive or strictly-negative; the domain must not include or cross zero. + * A log scale with a positive domain has a well-defined behavior for positive values, and a log scale with a negative domain has a well-defined behavior for negative values. + * (For a negative domain, input and output values are implicitly multiplied by -1.) + * The behavior of the scale is undefined if you pass a negative value to a log scale with a positive domain or vice versa. + * + * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale. + * + * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value. + * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed. + * + * @param domain Array of numeric domain values. + */ + domain(domain: Array): this; + + /** + * Returns the scale’s current interpolator factory, which defaults to interpolate. + */ + interpolate(): InterpolatorFactory; + + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): this; + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): ScaleLogarithmic; + + /** + * Returns approximately count representative values from the scale’s domain. + * + * If count is not specified, it defaults to 10. + * + * If the base is an integer, the returned ticks are uniformly spaced within each integer power of base; otherwise, one tick per power of base is returned. + * The returned ticks are guaranteed to be within the extent of the domain. If the orders of magnitude in the domain is greater than count, then at most one tick per power is returned. + * Otherwise, the tick values are unfiltered, but note that you can use log.tickFormat to filter the display of tick labels. + * + * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10. + */ + ticks(count?: number): number[]; + + /** + * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values. + * + * The specified count typically has the same value as the count that is used to generate the tick values. + * If there are too many ticks, the formatter may return the empty string for some of the tick labels; + * however, note that the ticks are still shown. + * To disable filtering, specify a count of Infinity. When specifying a count, you may also provide a format specifier or format function. + * For example, to get a tick formatter that will display 20 ticks of a currency, say log.tickFormat(20, "$,f"). + * If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format. + * This provides a convenient way of specifying a format whose precision will be automatically set by the scale. + * + * @param count Approximate number of ticks to be used when calculating precision for the number format function. + * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval. + * For example, to get a tick formatter that will display 20 ticks of a currency, say log.tickFormat(20, "$,f"). + * If the specifier does not have a defined precision, the precision will be set automatically by the scale, returning the appropriate format. + * This provides a convenient way of specifying a format whose precision will be automatically set by the scale. + */ + tickFormat(count?: number, specifier?: string): ((d: number | { valueOf(): number }) => string); + + /** + * Extends the domain to integer powers of base. For example, for a domain of [0.201479…, 0.996679…], and base 10, the nice domain is [0.1, 1]. + * If the domain has more than two values, nicing the domain only affects the first and last value. + * + * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain. + * You must re-nice the scale after setting the new domain, if desired. + */ + nice(): this; + + /** + * Returns the current base, which defaults to 10. + */ + base(): number; + /** + * Sets the base for this logarithmic scale to the specified value. + */ + base(base: number): this; +} + +/** + * Constructs a new continuous logarithmic scale with the domain [1, 10], the unit range [0, 1], the base 10, the default interpolator and clamping disabled. + * + * The scale will have range and output of data type number. + */ +export function scaleLog(): ScaleLogarithmic; +/** + * Constructs a new continuous logarithmic scale with the domain [1, 10], the base 10, the default interpolator and clamping disabled. + * + * The generic correponds to the data type of the range and output elements to be used. + * + * As range type and output type are the same, the interpolator factory used with the scale must match this behaviour. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleLog(): ScaleLogarithmic; +/** + * Constructs a new continuous logarithmic scale with the domain [1, 10], the base 10, the default interpolator and clamping disabled. + * + * The first generic corresponds to the data type of the range elements. + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleLog(): ScaleLogarithmic; + +// ------------------------------------------------------------------------------- +// Identity Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Identity scales are a special case of linear scales where the domain and range are identical; the scale and its invert method are thus the identity function. + * These scales are occasionally useful when working with pixel coordinates, say in conjunction with an axis or brush. + */ +export interface ScaleIdentity { + /** + * Given a value from the domain, returns the corresponding value from the range, subject to interpolation, if any. + * + * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range. + * + * Note: The interpolation function applied by the scale may change the output type from the range type as part of the interpolation. + * + * @param value A numeric value from the domain. + */ + (value: number | { valueOf(): number }): number; + + /** + * Given a value from the range, returns the corresponding value from the domain. Inversion is useful for interaction, + * say to determine the data value corresponding to the position of the mouse. + * + * If the given value is outside the range, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the domain. + * + * IMPORTANT: This method is only supported if the range is numeric. If the range is not numeric, returns NaN. + * + * For a valid value y in the range, continuous(continuous.invert(y)) approximately equals y; + * similarly, for a valid value x in the domain, continuous.invert(continuous(x)) approximately equals x. + * The scale and its inverse may not be exact due to the limitations of floating point precision. + * + * @param value A numeric value from the range. + */ + invert(value: number | { valueOf(): number }): number; + + /** + * Returns a copy of the scale’s current domain. + */ + domain(): number[]; + /** + * Sets the scale’s domain to the specified array of numbers. The array must contain two or more elements. + * If the elements in the given array are not numbers, they will be coerced to numbers + * + * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale. + * + * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value. + * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed. + * + * @param domain Array of numeric domain values. + */ + domain(domain: Array): this; + + /** + * Returns a copy of the scale’s current range. + */ + range(): number[]; + /** + * Sets the scale’s range to the specified array of values. + * + * The array must contain two or more elements. Unlike the domain, elements in the given array need not be numbers; + * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert. + * + * @param range Array of range values. + */ + range(range: Array): this; + + /** + * Returns approximately count representative values from the scale’s domain. + * + * If count is not specified, it defaults to 10. + * + * The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), + * and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. + * The specified count is only a hint; the scale may return more or fewer values depending on the domain. See also d3-array’s ticks. + * + * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10. + */ + ticks(count?: number): number[]; + + /** + * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values. + * The specified count should have the same value as the count that is used to generate the tick values. + * + * @param count Approximate number of ticks to be used when calculating precision for the number format function. + * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval. + * If specifier uses the format type "s", the scale will return a SI-prefix format based on the largest value in the domain. + * If the specifier already specifies a precision, this method is equivalent to locale.format. + */ + tickFormat(count?: number, specifier?: string): ((d: number | { valueOf(): number }) => string); + + /** + * Extends the domain so that it starts and ends on nice round values. + * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. + * An optional tick count argument allows greater control over the step size used to extend the bounds, + * guaranteeing that the returned ticks will exactly cover the domain. + * Nicing is useful if the domain is computed from data, say using extent, and may be irregular. + * For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0]. + * If the domain has more than two values, nicing the domain only affects the first and last value. + * + * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain. + * You must re-nice the scale after setting the new domain, if desired. + * + * @param count An optional number of ticks expected to be used. + */ + nice(count?: number): this; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): ScaleIdentity; +} + +/** + * Constructs a new identity scale with the unit domain [0, 1] and the unit range [0, 1]. + */ +export function scaleIdentity(): ScaleIdentity; + +// ------------------------------------------------------------------------------- +// Time Scale Factories +// ------------------------------------------------------------------------------- + +/** + * A linear scale defined over a temporal domain. + * + * Time scales implement ticks based on calendar intervals, taking the pain out of generating axes for temporal domains. + * + * If the range is numeric, the mapping may be inverted to return a date. + * + * Note that the data types of the range and output of the scale must be compatible with the interpolator applied by the scale. + * + * The first generic corresponds to the data type of the range elements. + * + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + */ +export interface ScaleTime { + /** + * Given a value from the domain, returns the corresponding value from the range, subject to interpolation, if any. + * + * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range. + * + * Note: The interpolation function applied by the scale may change the output type from the range type as part of the interpolation. + * + * @param value A temporal value from the domain. If the value is not a Date, it will be coerced to Date. + */ + (value: Date | number | { valueOf(): number }): Output; + + /** + * Given a value from the range, returns the corresponding value from the domain. Inversion is useful for interaction, + * say to determine the data value corresponding to the position of the mouse. + * + * If the given value is outside the range, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the domain. + * + * IMPORTANT: This method is only supported if the range is numeric. If the range is not numeric, returns Invalid Date. + * + * For a valid value y in the range, time(time.invert(y)) equals y; similarly, for a valid value x in the domain, time.invert(time(x)) equals x. + * The invert method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse. + * + * @param value A numeric value from the range. + */ + invert(value: number | { valueOf(): number }): Date; + + /** + * Returns a copy of the scale’s current domain. + */ + domain(): Date[]; + + /** + * Sets the scale’s domain to the specified array of temporal domain values. The array must contain two or more elements. + * If the elements in the given array are not dates, they will be coerced to dates. + * + * Although continuous scales typically have two values each in their domain and range, specifying more than two values produces a piecewise scale. + * + * Internally, a piecewise scale performs a binary search for the range interpolator corresponding to the given domain value. + * Thus, the domain must be in ascending or descending order. If the domain and range have different lengths N and M, only the first min(N,M) elements in each are observed. + * + * @param domain Array of temporal domain values. Numeric values will be coerced to dates. + */ + domain(domain: Array): this; + + /** + * Returns a copy of the scale’s current range. + */ + range(): Range[]; + /** + * Sets the scale’s range to the specified array of values. + * + * The array must contain two or more elements. Unlike the domain, elements in the given array need not be temporal domain values; + * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert. + * + * @param range Array of range values. + */ + range(range: Range[] | ReadonlyArray): this; + + /** + * Sets the scale’s range to the specified array of values while also setting the scale’s interpolator to interpolateRound. + * + * The rounding interpolator is sometimes useful for avoiding antialiasing artifacts, + * though also consider the shape-rendering “crispEdges” styles. Note that this interpolator can only be used with numeric ranges. + * + * The array must contain two or more elements. Unlike the domain, elements in the given array need not be temporal domain values; + * any value that is supported by the underlying interpolator will work, though note that numeric ranges are required for invert. + * + * @param range Array of range values. + */ + rangeRound(range: Array): this; + + /** + * Returns whether or not the scale currently clamps values to within the range. + */ + clamp(): boolean; + /** + * Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain, + * the scale may return a value outside the range through extrapolation. + * + * If clamping is enabled, the return value of the scale is always within the scale’s range. Clamping similarly applies to the "invert" method. + * + * @param clamp A flag to enable (true) or disable (false) clamping. + */ + clamp(clamp: boolean): this; + + /** + * Returns the scale’s current interpolator factory, which defaults to interpolate. + */ + interpolate(): InterpolatorFactory; + + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): this; + /** + * Sets the scale’s range interpolator factory. This interpolator factory is used to create interpolators for each adjacent pair of values from the range; + * these interpolators then map a normalized domain parameter t in [0, 1] to the corresponding value in the range. + * + * Note: the default interpolator may reuse return values. For example, if the range values are objects, then the value interpolator always returns the same object, modifying it in-place. + * If the scale is used to set an attribute or style, this is typically acceptable (and desirable for performance); + * however, if you need to store the scale’s return value, you must specify your own interpolator or make a copy as appropriate. + * + * As part of the interpolation process the interpotaled value from the range may be converted to a corresponding output value. + * + * The generic "NewOutput" can be used to change the scale to have a different output element type corresponding to the new interpolation factory. + * + * @param interpolate An interpolation factory. The generics for Range and Output of the scale must correpond to the interpolation factory applied to the scale. + */ + interpolate(interpolate: InterpolatorFactory): ScaleTime; + + /** + * Returns representative dates from the scale’s domain. The returned tick values are uniformly-spaced (mostly), + * have sensible values (such as every day at midnight), and are guaranteed to be within the extent of the domain. + * Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. + * + * Without specifying a count or time interval to control the number of ticks returned, a default count of 10 is used. + * The specified count is only a hint; the scale may return more or fewer values depending on the domain. + */ + ticks(): Date[]; + /** + * Returns representative dates from the scale’s domain. The returned tick values are uniformly-spaced (mostly), + * have sensible values (such as every day at midnight), and are guaranteed to be within the extent of the domain. + * Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. + * + * The specified count controls the number of ticks to be returned. The specified count is only a hint; + * the scale may return more or fewer values depending on the domain. + * + * @param count Expected number of ticks. + */ + ticks(count: number): Date[]; + /** + * Returns representative dates from the scale’s domain. The returned tick values are uniformly-spaced (mostly), + * have sensible values (such as every day at midnight), and are guaranteed to be within the extent of the domain. + * Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. + * + * The specified time interval controls the ticks generated and returned. To prune the generated ticks for a given time interval, + * use interval.every(...) or interval.filter(...). + * + * @param interval A time interval to specify the expected ticks. + */ + ticks(interval: TimeInterval): Date[]; + + /** + * Returns a time format function suitable for displaying tick values. + * + * The default multi-scale time format chooses a human-readable representation based on the specified date as follows: + * + * - %Y - for year boundaries, such as 2011. + * - %B - for month boundaries, such as February. + * - %b %d - for week boundaries, such as Feb 06. + * - %a %d - for day boundaries, such as Mon 07. + * - %I %p - for hour boundaries, such as 01 AM. + * - %I:%M - for minute boundaries, such as 01:23. + * - :%S - for second boundaries, such as :45. + * - .%L - milliseconds for all other times, such as .012. + * + * Although somewhat unusual, this default behavior has the benefit of providing both local and global context: + * for example, formatting a sequence of ticks as [11 PM, Mon 07, 01 AM] reveals information about hours, dates, and day simultaneously, + * rather than just the hours [11 PM, 12 AM, 01 AM]. + */ + tickFormat(): ((d: Date) => string); + /** + * Returns a time format function suitable for displaying tick values. + * + * The specified count is currently ignored, but is accepted for consistency with other scales such as continuous.tickFormat. + * + * @param count Expected number of ticks. (Currently ignored) + * @param specifier An optional valid date format specifier string (see d3-time-format). + */ + tickFormat(count: number, specifier?: string): ((d: Date) => string); + /** + * Returns a time format function suitable for displaying tick values. + * + * The specified time interval is currently ignored, but is accepted for consistency with other scales such as continuous.tickFormat. + * + * @param interval A time interval to specify the expected ticks. (Currently ignored) + * @param specifier An optional valid date format specifier string (see d3-time-format). + */ + tickFormat(interval: TimeInterval, specifier?: string): ((d: Date) => string); + + /** + * Extends the domain so that it starts and ends on nice round values. + * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. + * + * Nicing is useful if the domain is computed from data, say using extent, and may be irregular. + * For example, for a domain of [2009-07-13T00:02, 2009-07-13T23:48], the nice domain is [2009-07-13, 2009-07-14]. + * If the domain has more than two values, nicing the domain only affects the first and last value. + */ + nice(): this; + /** + * Extends the domain so that it starts and ends on nice round values. + * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. + * + * A tick count argument allows greater control over the step size used to extend the bounds, guaranteeing that the returned ticks will exactly cover the domain. + * + * Nicing is useful if the domain is computed from data, say using extent, and may be irregular. + * For example, for a domain of [2009-07-13T00:02, 2009-07-13T23:48], the nice domain is [2009-07-13, 2009-07-14]. + * If the domain has more than two values, nicing the domain only affects the first and last value. + * + * @param count Expected number of ticks. + */ + nice(count: number): this; + /** + * Extends the domain so that it starts and ends on nice round values. + * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. + * + * a time interval may be specified to explicitly set the ticks. If an interval is specified, an optional step may also be specified to skip some ticks. + * For example, time.nice(d3.timeSecond, 10) will extend the domain to an even ten seconds (0, 10, 20, etc.). + * + * Nicing is useful if the domain is computed from data, say using extent, and may be irregular. + * For example, for a domain of [2009-07-13T00:02, 2009-07-13T23:48], the nice domain is [2009-07-13, 2009-07-14]. + * If the domain has more than two values, nicing the domain only affects the first and last value. + * + * @param interval A time interval to specify the expected ticks. + * @param step An optional step number to be applied to the time interval when considering ticks. + */ + nice(interval: CountableTimeInterval, step?: number): this; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +/** + * Constructs a new time scale using local time with the domain [2000-01-01, 2000-01-02], the unit range [0, 1], the default interpolator and clamping disabled. + * + * The scale will have range and output of data type number. + */ +export function scaleTime(): ScaleTime; +/** + * Constructs a new time scale using local time with the domain [2000-01-01, 2000-01-02], the default interpolator and clamping disabled. + * + * The generic correponds to the data type of the range and output elements to be used. + * + * As range type and output type are the same, the interpolator factory used with the scale must match this behaviour. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleTime(): ScaleTime; +/** + * Constructs a new time scale using local time with the domain [2000-01-01, 2000-01-02], the default interpolator and clamping disabled. + * + * The first generic corresponds to the data type of the range elements. + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleTime(): ScaleTime; + +/** + * Constructs a new time scale using Coordinated Universal Time (UTC) with the domain [2000-01-01, 2000-01-02], the unit range [0, 1], the default interpolator and clamping disabled. + * + * The scale will have range and output of data type number. + */ +export function scaleUtc(): ScaleTime; +/** + * Constructs a new time scale using Coordinated Universal Time (UTC) with the domain [2000-01-01, 2000-01-02], the default interpolator and clamping disabled. + * + * The generic correponds to the data type of the range and output elements to be used. + * + * As range type and output type are the same, the interpolator factory used with the scale must match this behaviour. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleUtc(): ScaleTime; +/** + * Constructs a new time scale using Coordinated Universal Time (UTC) with the domain [2000-01-01, 2000-01-02], the default interpolator and clamping disabled. + * + * The first generic corresponds to the data type of the range elements. + * The second generic corresponds to the data type of the output elements generated by the scale. + * + * If range element and output element type differ, the interpolator factory used with the scale must match this behaviour and + * convert the interpolated range element to a corresponding output element. + * + * The range must be set in accordance with the range element type. + * + * The interpolator factory may be set using the interpolate(...) method of the scale. + */ +export function scaleUtc(): ScaleTime; + +// ------------------------------------------------------------------------------- +// Sequential Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Sequential scales are similar to continuous scales in that they map a continuous, + * numeric input domain to a continuous output range. However, unlike continuous scales, + * the output range of a sequential scale is fixed by its interpolator and not configurable. + * + * The generic corresponds to the data type of the output of the interpolator underlying the scale. + */ +export interface ScaleSequential { + /** + * Given a value from the domain, returns the corresponding value from the output range, subject to interpolation. + * + * If the given value is outside the domain, and clamping is not enabled, the mapping may be extrapolated such that the returned value is outside the range. + * + * @param value A numeric value from the domain. + */ + (value: number | { valueOf(): number }): Output; + + /** + * Returns a copy of the scale’s current domain. + */ + domain(): [number, number]; + /** + * Sets the scale’s domain to the specified array of numbers. The array must contain exactly two elements. + * If the elements in the given array are not numbers, they will be coerced to numbers + * + * @param domain A two-element array of numeric domain values. + */ + domain(domain: [number | { valueOf(): number }, number | { valueOf(): number }]): this; + + /** + * Returns whether or not the scale currently clamps values to within the range. + */ + clamp(): boolean; + /** + * Enables or disables clamping, respectively. If clamping is disabled and the scale is passed a value outside the domain, + * the scale may return a value outside the range through extrapolation. + * + * If clamping is enabled, the return value of the scale is always within the scale’s range. Clamping similarly applies to the "invert" method. + * + * @param clamp A flag to enable (true) or disable (false) clamping. + */ + clamp(clamp: boolean): this; + + /** + * Returns the current interpolator underlying the scale. + */ + interpolator(): ((t: number) => Output); + /** + * Sets the scale’s interpolator to the specified function. + * + * @param interpolator An interpolator function mapping a value from the [0, 1] interval to an output value. + */ + interpolator(interpolator: ((t: number) => Output)): this; + /** + * Sets the scale’s interpolator to the specified function. + * + * The generic corresponds to a the new output type of the scale. The output type of the scale is determined by the output type of the interpolator function. + * + * @param interpolator An interpolator function mapping a value from the [0, 1] interval to an output value. + */ + interpolator(interpolator: ((t: number) => NewOutput)): ScaleSequential; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): ScaleSequential; +} + +/** + * Constructs a new sequential scale with the given interpolator function. When the scale is applied, the interpolator will be invoked with a value typically in the range [0, 1], + * where 0 represents the start of the domain, and 1 represents the end of the domain. + * + * The generic corresponds to the data type of the output of the interpolator underlying the scale. + * + * @param interpolator The interpolator function to be used with the scale. + */ +export function scaleSequential(interpolator: ((t: number) => Output)): ScaleSequential; + +// ------------------------------------------------------------------------------- +// Color Interpolators for Sequential Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Given a number t in the range [0,1], returns the corresponding color from the “viridis” perceptually-uniform color scheme designed by van der Walt, Smith and Firing for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateViridis(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from the “inferno” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateInferno(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from the “magma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateMagma(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from the “plasma” perceptually-uniform color scheme designed by van der Walt and Smith for matplotlib, + * represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolatePlasma(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from a 180° rotation of Niccoli’s perceptual rainbow, represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateWarm(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from Niccoli’s perceptual rainbow, represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateCool(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from d3.interpolateWarm scale from [0.0, 0.5] followed by the d3.interpolateCool scale from [0.5, 1.0], + * thus implementing the cyclical less-angry rainbow color scheme. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateRainbow(t: number): string; + +/** + * Given a number t in the range [0,1], returns the corresponding color from Green’s default Cubehelix represented as an RGB string. + * + * @param t A number in the interval [0, 1]. + */ +export function interpolateCubehelixDefault(t: number): string; + +// ------------------------------------------------------------------------------- +// Quantize Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Quantize scales are similar to linear scales, except they use a discrete rather than continuous range. + * The continuous input domain is divided into uniform segments based on the number of values in (i.e., the cardinality of) the output range. + * + * Each range value y can be expressed as a quantized linear function of the domain value x: y = m round(x) + b. + * + * The generic corresponds to the data type of the range elements. + */ +export interface ScaleQuantize { + /** + * Given a value in the input domain, returns the corresponding value in the output range. + */ + (value: number | { valueOf(): number }): Range; + /** + * Returns the extent of values in the domain [x0, x1] for the corresponding value in the range: the inverse of quantize. + * This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse. + * + * If an invalid range value is entered, returns [NaN, NaN]. + * + * @param value A value from the range. + */ + invertExtent(value: Range): [number, number]; + + /** + * Returns the scale’s current domain. + */ + domain(): [number, number]; + + /** + * Sets the scale’s domain to the specified two-element array of numbers. + * If the elements in the given array are not numbers, they will be coerced to numbers. + * + * @param domain A two-element array of numeric values defining the domain. + */ + domain(domain: [number | { valueOf(): number }, number | { valueOf(): number }]): this; + + /** + * Returns the scale’s current range. + */ + range(): Range[]; + /** + * Sets the scale’s range to the specified array of values. The array may contain any number of discrete values. + * + * @param range Array of range values. + */ + range(range: Range[] | ReadonlyArray): this; + + /** + * Returns approximately count representative values from the scale’s domain. + * + * If count is not specified, it defaults to 10. + * + * The returned tick values are uniformly spaced, have human-readable values (such as multiples of powers of 10), + * and are guaranteed to be within the extent of the domain. Ticks are often used to display reference lines, or tick marks, in conjunction with the visualized data. + * The specified count is only a hint; the scale may return more or fewer values depending on the domain. See also d3-array’s ticks. + * + * @param count Optional approximate number of ticks to be returned. If count is not specified, it defaults to 10. + */ + ticks(count?: number): number[]; + + /** + * Returns a number format function suitable for displaying a tick value, automatically computing the appropriate precision based on the fixed interval between tick values. + * The specified count should have the same value as the count that is used to generate the tick values. + * + * @param count Approximate number of ticks to be used when calculating precision for the number format function. + * @param specifier An optional valid format specifier string which allows a custom format where the precision of the format is automatically set by the scale as appropriate for the tick interval. + * If specifier uses the format type "s", the scale will return a SI-prefix format based on the largest value in the domain. + * If the specifier already specifies a precision, this method is equivalent to locale.format. + */ + tickFormat(count?: number, specifier?: string): ((d: number | { valueOf(): number }) => string); + + /** + * Extends the domain so that it starts and ends on nice round values. + * This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. + * + * Nicing is useful if the domain is computed from data, say using extent, and may be irregular. + * For example, for a domain of [0.201479…, 0.996679…], a nice domain might be [0.2, 1.0]. + * + * Nicing a scale only modifies the current domain; it does not automatically nice domains that are subsequently set using continuous.domain. + * You must re-nice the scale after setting the new domain, if desired. + * + * @param count An optional number of ticks expected to be used. + */ + nice(count?: number): this; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +/** + * Constructs a new quantize scale with the unit domain [0, 1] and the unit range [0, 1]. + * Thus, the default quantize scale is equivalent to the Math.round function. + */ +export function scaleQuantize(): ScaleQuantize; + +/** + * Constructs a new quantize scale with the unit domain [0, 1]. + * + * The range must be set corresponding to the type of the range elements. + * + * The generic corresponds to the data type of the range elements. + */ +export function scaleQuantize(): ScaleQuantize; + +// ------------------------------------------------------------------------------- +// Quantile Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Quantile scales map a sampled input domain to a discrete range. + * The domain is considered continuous and thus the scale will accept any reasonable input value; + * however, the domain is specified as a discrete set of sample values. + * The number of values in (the cardinality of) the output range determines the number of quantiles that will be computed from the domain. + * To compute the quantiles, the domain is sorted, and treated as a population of discrete values; see d3-array’s quantile. + * + * The generic correponds to the data type of range elements. + */ +export interface ScaleQuantile { + /** + * Given a value in the input domain, returns the corresponding value in the output range. + * + * @param value A numeric value in the input domain. + */ + (value: number | { valueOf(): number }): Range; + + /** + * Returns the extent of values in the domain [x0, x1] for the corresponding value in the range: the inverse of quantile. + * This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse. + * + * @param value A value from the range. + */ + invertExtent(value: Range): [number, number]; + + /** + * Returns the scale’s current domain. + */ + domain(): number[]; + /** + * Sets the domain of the quantile scale to the specified set of discrete numeric values. + * The array must not be empty, and must contain at least one numeric value; NaN, null and undefined values are ignored and not considered part of the sample population. + * + * If the elements in the given array are not numbers, they will be coerced to numbers. A copy of the input array is sorted and stored internally. + * + * @param domain Array of domain values. + */ + domain(domain: Array): this; + + /** + * Returns the current range. + */ + range(): Range[]; + /** + * Sets the discrete values in the range. The array must not be empty. + * The number of values in (the cardinality, or length, of) the range array determines the number of quantiles that are computed. + * + * For example, to compute quartiles, range must be an array of four elements such as [0, 1, 2, 3]. + * + * @param range Array of range values. + */ + range(range: Range[] | ReadonlyArray): this; + + /** + * Returns the quantile thresholds. If the range contains n discrete values, the returned array will contain n - 1 thresholds. + * Values less than the first threshold are considered in the first quantile; + * values greater than or equal to the first threshold but less than the second threshold are in the second quantile, and so on. + * Internally, the thresholds array is used with bisect to find the output quantile associated with the given input value. + */ + quantiles(): number[]; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +/** + * Constructs a new quantile scale with an empty domain and an empty range. + * The quantile scale is invalid until both a domain and range are specified. + */ +export function scaleQuantile(): ScaleQuantile; + +/** + * Constructs a new quantile scale with an empty domain and an empty range. + * The quantile scale is invalid until both a domain and range are specified. + * + * The generic correponds to the data type of range elements. + */ +export function scaleQuantile(): ScaleQuantile; + +// ------------------------------------------------------------------------------- +// Threshold Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Threshold scales are similar to quantize scales, except they allow you to map arbitrary subsets of the domain to discrete values in the range. + * The input domain is still continuous, and divided into slices based on a set of threshold values. + * + * If the number of values in the scale’s range is N+1, the number of values in the scale’s domain must be N. + * If there are fewer than N elements in the domain, the additional values in the range are ignored. + * If there are more than N elements in the domain, the scale may return undefined for some inputs. + * + * The first generic corresponds to the data type of domain values. + * The second generic corresponds to the data type of range values. + */ +export interface ScaleThreshold { + /** + * Given a value in the input domain, returns the corresponding value in the output range. + * + * @param value A domain value. + */ + (value: Domain): Range; + + /** + * Returns the extent of values in the domain [x0, x1] for the corresponding value in the range, representing the inverse mapping from range to domain. + * This method is useful for interaction, say to determine the value in the domain that corresponds to the pixel location under the mouse. + * + * @param value A range value. + */ + invertExtent(value: Range): [Domain | undefined, Domain | undefined]; + + /** + * Returns the scale’s current domain. + */ + domain(): Domain[]; + /** + * Sets the scale’s domain to the specified array of values. The values must be in sorted ascending order, or the behavior of the scale is undefined. + * The values are typically numbers, but any naturally ordered values (such as strings) will work; a threshold scale can be used to encode any type that is ordered. + * If the number of values in the scale’s range is N+1, the number of values in the scale’s domain must be N. + * If there are fewer than N elements in the domain, the additional values in the range are ignored. + * If there are more than N elements in the domain, the scale may return undefined for some inputs. + * + * @param domain Array of domain values. + */ + domain(domain: Domain[] | ReadonlyArray): this; + + /** + * Returns the scale’s current range. + */ + range(): Range[]; + /** + * Sets the scale’s range to the specified array of values. If the number of values in the scale’s domain is N, the number of values in the scale’s range must be N+1. + * If there are fewer than N+1 elements in the range, the scale may return undefined for some inputs. + * If there are more than N+1 elements in the range, the additional values are ignored. + * + * @param range Array of range values. + */ + range(range: Range[] | ReadonlyArray): this; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +/** + * Constructs a new threshold scale with the default domain [0.5] and the default range [0, 1]. + * Thus, the default threshold scale is equivalent to the Math.round function for numbers; for example threshold(0.49) returns 0, and threshold(0.51) returns 1. + */ +export function scaleThreshold(): ScaleThreshold; +/** + * Constructs a new threshold scale. The domain and range must be set corresponding to the type of the corresponding generic. + * + * The first generic corresponds to the data type of domain values. + * The second generic corresponds to the data type of range values. + */ +export function scaleThreshold(): ScaleThreshold; + +// ------------------------------------------------------------------------------- +// Ordinal Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Unlike continuous scales, ordinal scales have a discrete domain and range. For example, an ordinal scale might map a set of named categories to a set of colors, + * or determine the horizontal positions of columns in a column chart. + * + * The first element in the domain will be mapped to the first element in range, the second domain value to the second range value, and so on. + * If there are fewer elements in the range than in the domain, the scale will reuse values from the start of the range. + * + * The first generic corresponds to the data type of domain values. + * The second generic corresponds to the data type of range values. + */ +export interface ScaleOrdinal { + /** + * Given a value in the input domain, returns the corresponding value in the output range. + * If the given value is not in the scale’s domain, returns the unknown; or, if the unknown value is implicit (the default), + * then the value is implicitly added to the domain and the next-available value in the range is assigned to value, + * such that this and subsequent invocations of the scale given the same input value return the same output value. + * + * @param x A value from the domain. + */ + (x: Domain): Range; + + /** + * Returns the scale's current domain. + */ + domain(): Domain[]; + /** + * Sets the domain to the specified array of values. + * + * The first element in domain will be mapped to the first element in the range, + * the second domain value to the second range value, and so on. + * + * Domain values are stored internally in a map from stringified value to index; the resulting index is then used to retrieve a value from the range. + * Thus, an ordinal scale’s values must be coercible to a string, and the stringified version of the domain value uniquely identifies the corresponding range value. + * + * Setting the domain on an ordinal scale is optional if the unknown value is implicit (the default). + * In this case, the domain will be inferred implicitly from usage by assigning each unique value passed to the scale a new value from the range. + * Note that an explicit domain is recommended to ensure deterministic behavior, as inferring the domain from usage will be dependent on ordering. + * + * @param domain Array of domain values. + */ + domain(domain: Domain[] | ReadonlyArray): this; + + /** + * Returns the scale's current range. + */ + range(): Range[]; + /** + * Sets the range of the ordinal scale to the specified array of values. + * + * The first element in the domain will be mapped to the first element in range, the second domain value to the second range value, and so on. + * + * If there are fewer elements in the range than in the domain, the scale will reuse values from the start of the range. + * + * @param range Array of range values. + */ + range(range: Range[] | ReadonlyArray): this; + + /** + * Returns the current unknown value, which defaults to "implicit". + */ + unknown(): Range | { name: 'implicit' }; + /** + * Sets the output value of the scale for unknown input values and returns this scale. + * The implicit value enables implicit domain construction. scaleImplicit can be used as a convenience to set the implicit value. + * + * @param value Unknown value to be used or scaleImplicit to set implicit scale generation. + */ + unknown(value: Range | { name: 'implicit' }): this; + + /** + * Returns an exact copy of this ordinal scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +/** + * Constructs a new ordinal scale with an empty domain and the specified range. + * If a range is not specified, it defaults to the empty array; an ordinal scale always returns undefined until a non-empty range is defined. + * + * By default, the domain is configured to generate implicitly, if the scale is invoked with an unknown value. + * See the "unknown(...)" method of the scale to change this behavior. + * + * The generic corresponds to the data type of range elements. + * + * @parm range An optional array of range values to initialize the scale with. + */ +export function scaleOrdinal(range?: Range[] | ReadonlyArray): ScaleOrdinal; +/** + * Constructs a new ordinal scale with an empty domain and the specified range. + * If a range is not specified, it defaults to the empty array; an ordinal scale always returns undefined until a non-empty range is defined. + * + * By default, the domain is configured to generate implicitly, if the scale is invoked with an unknown value. + * See the "unknown(...)" method of the scale to change this behavior. + * + * The first generic corresponds to the data type of domain elements. + * The second generic corresponds to the data type of range elements. + * + * @parm range An optional array of range values to initialize the scale with. + */ +export function scaleOrdinal(range?: Range[] | ReadonlyArray): ScaleOrdinal; + +/** + * A special value for ordinal.unknown that enables implicit domain construction: unknown values are implicitly added to the domain. + */ +export const scaleImplicit: { name: 'implicit' }; + +// ------------------------------------------------------------------------------- +// Band Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Band scales are like ordinal scales except the output range is continuous and numeric. + * Discrete output values are automatically computed by the scale by dividing the continuous range into uniform bands. + * Band scales are typically used for bar charts with an ordinal or categorical dimension. + * The unknown value of a band scale is effectively undefined: they do not allow implicit domain construction. + * + * The generic corresponds to the data type of domain elements. + */ +export interface ScaleBand { + /** + * Given a value in the input domain, returns the start of the corresponding band derived from the output range. + * If the given value is not in the scale’s domain, returns undefined. + * + * @param x A value from the domain. + */ + (x: Domain): number | undefined; + + /** + * Returns to scale's current domain + */ + domain(): Domain[]; + /** + * Sets the domain to the specified array of values. The first element in domain will be mapped to the first band, the second domain value to the second band, and so on. + * Domain values are stored internally in a map from stringified value to index; the resulting index is then used to determine the band. + * Thus, a band scale’s values must be coercible to a string, and the stringified version of the domain value uniquely identifies the corresponding band. + * + * @param domain Array of domain values. + */ + domain(domain: Domain[] | ReadonlyArray): this; + + /** + * Returns the scale’s current range, which defaults to [0, 1]. + */ + range(): [number, number]; + /** + * Sets the scale’s range to the specified two-element array of numbers. If the elements in the given array are not numbers, they will be coerced to numbers. + * The default range is [0, 1]. + * + * @param range A two-element array of numeric values. + */ + range(range: [number | { valueOf(): number }, number | { valueOf(): number }]): this; + + /** + * Sets the scale’s range to the specified two-element array of numbers while also enabling rounding. + * If the elements in the given array are not numbers, they will be coerced to numbers. + * + * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles. + * + * @param range A two-element array of numeric values. + */ + rangeRound(range: [number | { valueOf(): number }, number | { valueOf(): number }]): this; + + /** + * Returns the current rounding status for the scale: enabled (= true) or disabled (= false). + */ + round(): boolean; + /** + * Enables or disables rounding accordingly. If rounding is enabled, the start and stop of each band will be integers. + * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles. + * Note that if the width of the domain is not a multiple of the cardinality of the range, there may be leftover unused space, even without padding! + * Use band.align to specify how the leftover space is distributed. + * + * @param round Enable rounding (= true), disable rounding (= false). + */ + round(round: boolean): this; + + /** + * Returns the current inner padding which defaults to 0. + */ + paddingInner(): number; + /** + * Sets the inner padding to the specified value which must be in the range [0, 1]. + * The inner padding determines the ratio of the range that is reserved for blank space between bands. + * + * The default setting is 0. + * + * @param padding Value for inner padding in [0, 1] interval. + */ + paddingInner(padding: number): this; + + /** + * Returns the current outer padding which defaults to 0. + */ + paddingOuter(): number; + /** + * Sets the outer padding to the specified value which must be in the range [0, 1]. + * The outer padding determines the ratio of the range that is reserved for blank space before the first band and after the last band. + * + * The default setting is 0. + * + * @param padding Value for outer padding in [0, 1] interval. + */ + paddingOuter(padding: number): this; + + /** + * Returns the inner padding. + */ + padding(): number; + /** + * A convenience method for setting the inner and outer padding to the same padding value. + * + * @param padding Value for inner and outer padding in [0, 1] interval. + */ + padding(padding: number): this; + + /** + * Returns the current alignment which defaults to 0.5. + */ + align(): number; + /** + * Sets the alignment to the specified value which must be in the range [0, 1]. + * + * The default is 0.5. + * + * The alignment determines how any leftover unused space in the range is distributed. + * A value of 0.5 indicates that the leftover space should be equally distributed before the first band and after the last band; + * i.e., the bands should be centered within the range. A value of 0 or 1 may be used to shift the bands to one side, say to position them adjacent to an axis. + * + * @param align Value for alignment setting in [0, 1] interval. + */ + align(align: number): this; + + /** + * Returns the width of each band. + */ + bandwidth(): number; + + /** + * Returns the distance between the starts of adjacent bands. + */ + step(): number; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +/** + * Constructs a new band scale with the empty domain, the unit range [0, 1], no padding, no rounding and center alignment. + */ +export function scaleBand(): ScaleBand; +/** + * Constructs a new band scale with the empty domain, the unit range [0, 1], no padding, no rounding and center alignment. + * + * The generic correponds to the data type of domain elements. + */ +export function scaleBand(): ScaleBand; + +// ------------------------------------------------------------------------------- +// Point Scale Factory +// ------------------------------------------------------------------------------- + +/** + * Point scales are a variant of band scales with the bandwidth fixed to zero. + * Point scales are typically used for scatterplots with an ordinal or categorical dimension. + * The unknown value of a point scale is always undefined: they do not allow implicit domain construction. + * + * The generic corresponds to the data type of domain elements. + */ +export interface ScalePoint { + /** + * Given a value in the input domain, returns the corresponding point derived from the output range. + * If the given value is not in the scale’s domain, returns undefined. + * + * @param x A value from the domain. + */ + (x: Domain): number | undefined; + + /** + * Returns the scale's current domain. + */ + domain(): Domain[]; + /** + * Sets the domain to the specified array of values. The first element in domain will be mapped to the first point, the second domain value to the second point, and so on. + * Domain values are stored internally in a map from stringified value to index; the resulting index is then used to determine the point. + * Thus, a point scale’s values must be coercible to a string, and the stringified version of the domain value uniquely identifies the corresponding point. + * + * @param domain Array of domain values. + */ + domain(domain: Domain[] | ReadonlyArray): this; + + /** + * Returns the scale’s current range, which defaults to [0, 1]. + */ + range(): [number, number]; + /** + * Sets the scale’s range to the specified two-element array of numbers. + * If the elements in the given array are not numbers, they will be coerced to numbers. + * The default range is [0, 1]. + * + * @param range A two-element array of numeric values. + */ + range(range: [number | { valueOf(): number }, number | { valueOf(): number }]): this; + + /** + * Sets the scale’s range to the specified two-element array of numbers while also enabling rounding. + * If the elements in the given array are not numbers, they will be coerced to numbers. + * + * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles. + * + * @param range A two-element array of numeric values. + */ + rangeRound(range: [number | { valueOf(): number }, number | { valueOf(): number }]): this; + + /** + * Returns the current rounding status for the scale: enabled (= true) or disabled (= false). + */ + round(): boolean; + /** + * Enables or disables rounding accordingly. If rounding is enabled, the position of each point will be integers. + * Rounding is sometimes useful for avoiding antialiasing artifacts, though also consider the shape-rendering “crispEdges” styles. + * Note that if the width of the domain is not a multiple of the cardinality of the range, there may be leftover unused space, even without padding! + * Use point.align to specify how the leftover space is distributed. + * + * @param round Enable rounding (= true), disable rounding (= false). + */ + round(round: boolean): this; + + /** + * Returns the current outer padding which defaults to 0. + * The outer padding determines the ratio of the range that is reserved for blank space + * before the first point and after the last point. + * + */ + padding(): number; + /** + * Sets the outer padding to the specified value which must be in the range [0, 1]. + * The outer padding determines the ratio of the range that is reserved for blank space + * before the first point and after the last point. + * + * The default is 0. + * + * @param padding Value for outer padding in [0, 1] interval. + */ + padding(padding: number): this; + + /** + * Returns the current alignment which defaults to 0.5. + */ + align(): number; + /** + * Sets the alignment to the specified value which must be in the range [0, 1]. + * + * The alignment determines how any leftover unused space in the range is distributed. + * A value of 0.5 indicates that the leftover space should be equally distributed before the first point and after the last point; + * i.e., the points should be centered within the range. A value of 0 or 1 may be used to shift the points to one side, say to position them adjacent to an axis. + * + * The default value is 0.5. + * + * @param align Value for alignment setting in [0, 1] interval. + */ + align(align: number): this; + + /** + * Return 0. + */ + bandwidth(): number; + + /** + * Returns the distance between the starts of adjacent points. + */ + step(): number; + + /** + * Returns an exact copy of this scale. Changes to this scale will not affect the returned scale, and vice versa. + */ + copy(): this; +} + +/** + * Constructs a new point scale with the empty domain, the unit range [0, 1], no padding, no rounding and center alignment. + */ +export function scalePoint(): ScalePoint; +/** + * Constructs a new point scale with the empty domain, the unit range [0, 1], no padding, no rounding and center alignment. + * + * The generic corresponds to the data type of domain elements. + */ +export function scalePoint(): ScalePoint; + +// ------------------------------------------------------------------------------- +// Categorical Color Schemas for Ordinal Scales +// ------------------------------------------------------------------------------- + +/** + * An array of ten categorical colors represented as RGB hexadecimal strings. + */ +export const schemeCategory10: string[]; + +/** + * An array of twenty categorical colors represented as RGB hexadecimal strings. + */ +export const schemeCategory20: string[]; + +/** + * An array of twenty categorical colors represented as RGB hexadecimal strings. + */ +export const schemeCategory20b: string[]; + +/** + * An array of twenty categorical colors represented as RGB hexadecimal strings. + * This color scale includes color specifications and designs developed by Cynthia Brewer (colorbrewer2.org). + */ +export const schemeCategory20c: string[]; diff --git a/types/d3-scale/v1/tsconfig.json b/types/d3-scale/v1/tsconfig.json new file mode 100644 index 0000000000..d0a2eef03f --- /dev/null +++ b/types/d3-scale/v1/tsconfig.json @@ -0,0 +1,28 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "paths": { + "d3-scale": ["d3-scale/v1"] + }, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "d3-scale-tests.ts" + ] +} diff --git a/types/d3-scale/v1/tslint.json b/types/d3-scale/v1/tslint.json new file mode 100644 index 0000000000..9846c79a4d --- /dev/null +++ b/types/d3-scale/v1/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "unified-signatures": false, + "callable-types": false, + "no-unnecessary-generics": false + } +}