diff --git a/types/d3-array/d3-array-tests.ts b/types/d3-array/d3-array-tests.ts index e5239b41bde996..b526581b03424f 100644 --- a/types/d3-array/d3-array-tests.ts +++ b/types/d3-array/d3-array-tests.ts @@ -369,6 +369,13 @@ float64Array = d3Array.rank(mixedObjectArray, accessorMixedObjectToNum); float64Array = d3Array.rank(mixedObjectOrUndefinedArray, accessorMixedObjectToNumOrUndefined); float64Array = d3Array.rank(readonlyMixedObjectOrUndefinedArray, accessorReadOnlyMixedObjectToNumOrUndefined); +float64Array = d3Array.rank(mixedObjectArray, (a: any, b: any) => +a.date.valueOf() - b.date.valueOf()); +float64Array = d3Array.rank(mixedObjectOrUndefinedArray, (a: any, b: any) => +a?.date.valueOf() - b?.date.valueOf()); +float64Array = d3Array.rank(readonlyMixedObjectOrUndefinedArray, (a: any, b: any) => +a?.date.valueOf() - b?.date.valueOf()); + // variance() ------------------------------------------------------------------ numOrUndefined = d3Array.variance(numbersArray); diff --git a/types/d3-array/index.d.ts b/types/d3-array/index.d.ts index 394eadfdba2bc7..b6041232717705 100644 --- a/types/d3-array/index.d.ts +++ b/types/d3-array/index.d.ts @@ -6,9 +6,10 @@ // denisname // Hugues Stefanski // Nathan Bierema +// Fil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 3.1.0 +// Last module patch version validated against: 3.1.6 // -------------------------------------------------------------------------- // Shared Types and Interfaces @@ -235,21 +236,23 @@ export function quantileSorted( ): number | undefined; /** - * Returns an array with the rank of each value in the iterable, i.e. the index of the value when the iterable is sorted. + * Returns an array with the rank of each value in the iterable, i.e. the zero-based index of the value when the iterable is sorted. * Nullish values are sorted to the end and ranked NaN. - * An optional accessor function may be specified, which is equivalent to calling array.map(accessor) before computing the ranks. + * An optional comparator or accessor function may be specified; the latter is equivalent to calling array.map(accessor) before computing the ranks. + * If comparator is not specified, it defaults to ascending. * Ties (equivalent values) all get the same rank, defined as the first time the value is found. */ export function rank(iterable: Iterable): Float64Array; /** - * Returns an array with the rank of each value in the iterable, i.e. the index of the value when the iterable is sorted. + * Returns an array with the rank of each value in the iterable, i.e. the zero-based index of the value when the iterable is sorted. * Nullish values are sorted to the end and ranked NaN. - * An optional accessor function may be specified, which is equivalent to calling array.map(accessor) before computing the ranks. + * An optional comparator or accessor function may be specified; the latter is equivalent to calling array.map(accessor) before computing the ranks. + * If comparator is not specified, it defaults to ascending. * Ties (equivalent values) all get the same rank, defined as the first time the value is found. */ export function rank( iterable: Iterable, - accessor: (datum: T, index: number, array: Iterable) => number | undefined | null + accessorOrComparator: ((datum: T, index: number, array: Iterable) => number | undefined | null) | ((a: T, b: T) => number | undefined | null) ): Float64Array; /** diff --git a/types/d3-color/d3-color-tests.ts b/types/d3-color/d3-color-tests.ts index 19037c52a648a2..c4bdb20d03675b 100644 --- a/types/d3-color/d3-color-tests.ts +++ b/types/d3-color/d3-color-tests.ts @@ -36,10 +36,12 @@ cRGB = cRGB.darker(0.2); cRGB = cRGB.copy(); cRGB = cRGB.copy({ r: 0.5 }); cRGB = cRGB.rgb(); +cRGB = cRGB.clamp(); displayable = cRGB.displayable(); cString = cRGB.toString(); cString = cRGB.hex(); cString = cRGB.formatHex(); +cString = cRGB.formatHex8(); cString = cRGB.formatHsl(); cString = cRGB.formatRgb(); console.log('Channels = (r : %d, g: %d, b: %d)', cRGB.r, cRGB.g, cRGB.b); @@ -57,10 +59,12 @@ cHSL = cHSL.darker(0.2); cHSL = cHSL.copy(); cHSL = cHSL.copy({ opacity: 0.5 }); cRGB = cHSL.rgb(); +cHSL = cHSL.clamp(); displayable = cHSL.displayable(); cString = cHSL.toString(); cString = cHSL.hex(); cString = cHSL.formatHex(); +cString = cHSL.formatHex8(); cString = cHSL.formatHsl(); cString = cHSL.formatRgb(); console.log('Channels = (h : %d, s: %d, l: %d)', cHSL.h, cHSL.s, cHSL.l); @@ -86,6 +90,7 @@ displayable = cLab.displayable(); cString = cLab.toString(); cString = cLab.hex(); cString = cLab.formatHex(); +cString = cLab.formatHex8(); cString = cLab.formatHsl(); cString = cLab.formatRgb(); console.log('Channels = (l : %d, a: %d, b: %d)', cLab.l, cLab.a, cLab.b); @@ -115,6 +120,7 @@ displayable = cHcl.displayable(); cString = cHcl.toString(); cString = cHcl.hex(); cString = cHcl.formatHex(); +cString = cHcl.formatHex8(); cString = cHcl.formatHsl(); cString = cHcl.formatRgb(); console.log('Channels = (h : %d, c: %d, l: %d)', cHcl.h, cHcl.c, cHcl.l); @@ -146,6 +152,7 @@ displayable = cCubehelix.displayable(); cString = cCubehelix.toString(); cString = cCubehelix.hex(); cString = cCubehelix.formatHex(); +cString = cCubehelix.formatHex8(); cString = cCubehelix.formatHsl(); cString = cCubehelix.formatRgb(); console.log('Channels = (h : %d, s: %d, l: %d)', cCubehelix.h, cCubehelix.s, cCubehelix.l); diff --git a/types/d3-color/index.d.ts b/types/d3-color/index.d.ts index b5aa8989acd1df..929dcd2f420828 100644 --- a/types/d3-color/index.d.ts +++ b/types/d3-color/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for D3JS d3-color module 3.0 +// Type definitions for D3JS d3-color module 3.1 // Project: https://github.com/d3/d3-color/, https://d3js.org/d3-color // Definitions by: Tom Wanzek // Alex Ford @@ -6,9 +6,10 @@ // denisname // Hugues Stefanski // Nathan Bierema +// Fil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 3.0.1 +// Last module patch version validated against: 3.1.0 // --------------------------------------------------------------------------- // Shared Type Definitions and Interfaces @@ -85,6 +86,12 @@ export interface Color { * For example, RGB channel values greater than 255 are clamped to 255. */ formatHex(): string; + /** + * Returns a hexadecimal string representing this color in RGBA space, such as #f7eaba90. + * If this color is not displayable, a suitable displayable color is returned instead. + * For example, RGB channel values greater than 255 are clamped to 255. + */ + formatHex8(): string; /** * Returns a string representing this color according to the CSS Color Module Level 3 specification, such as hsl(257, 50%, 80%) or hsla(257, 50%, 80%, 0.2). * If this color is not displayable, a suitable displayable color is returned instead by clamping S and L channel values to the interval [0, 100]. @@ -168,6 +175,11 @@ export interface RGBColor extends Color { * @param values If values is specified, any enumerable own properties of values are assigned to the new returned color. */ copy(values?: { r?: number | undefined; g?: number | undefined; b?: number | undefined; opacity?: number | undefined }): this; + /** + * Returns a new RGB color where the r, g, and b channels are clamped to the range [0, 255] and rounded to the nearest integer value, + * and the opacity is clamped to the range [0, 1]. + */ + clamp(): this; } /** @@ -249,6 +261,10 @@ export interface HSLColor extends Color { * @param values If values is specified, any enumerable own properties of values are assigned to the new returned color. */ copy(values?: { h?: number | undefined; s?: number | undefined; l?: number | undefined; opacity?: number | undefined }): this; + /** + * Returns a new HSL color where the h channel is clamped to the range [0, 360), and the s, l, and opacity channels are clamped to the range [0, 1]. + */ + clamp(): this; } /** diff --git a/types/d3-hierarchy/d3-hierarchy-tests.ts b/types/d3-hierarchy/d3-hierarchy-tests.ts index 23cb62b5512dd2..e5f6caf7d446f4 100644 --- a/types/d3-hierarchy/d3-hierarchy-tests.ts +++ b/types/d3-hierarchy/d3-hierarchy-tests.ts @@ -250,6 +250,13 @@ stratificatorizer = stratificatorizer.parentId((d, i, data) => { idStringAccessor = stratificatorizer.parentId(); +// path(...) + +stratificatorizer = stratificatorizer.path((d, i, data) => d.name); + +let pathStringAccessor: ((d: TabularHierarchyDatum, i: number, data: TabularHierarchyDatum[]) => string) | null | undefined; +pathStringAccessor = stratificatorizer.path(); + // Use Stratify Operator ------------------------------------------------ const stratifiedRootNode: d3Hierarchy.HierarchyNode = stratificatorizer(tabularData); diff --git a/types/d3-hierarchy/index.d.ts b/types/d3-hierarchy/index.d.ts index 251f6e11a74f74..320e8fe59846f1 100644 --- a/types/d3-hierarchy/index.d.ts +++ b/types/d3-hierarchy/index.d.ts @@ -1,13 +1,14 @@ -// Type definitions for D3JS d3-hierarchy module 3.0 +// Type definitions for D3JS d3-hierarchy module 3.1 // Project: https://github.com/d3/d3-hierarchy/, https://d3js.org/d3-hierarchy // Definitions by: Tom Wanzek // Alex Ford // Boris Yankov // denisname // Nathan Bierema +// Fil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 3.0.1 +// Last module patch version validated against: 3.1.2 // ----------------------------------------------------------------------- // Hierarchy @@ -216,6 +217,21 @@ export interface StratifyOperator { * @param parentId The parent id accessor. */ parentId(parentId: (d: Datum, i: number, data: Datum[]) => (string | null | '' | undefined)): this; + + /** + * Returns the current path accessor, which defaults to undefined. + */ + path(): ((d: Datum, i: number, data: Datum[]) => string) | null | undefined; + /** + * If path is specified, sets the path accessor to the given function and returns this stratify operator. + * Otherwise, returns the current path accessor, which defaults to undefined. + * If a path accessor is set, the id and parentId arguments are ignored, + * and a unix-like hierarchy is computed on the slash-delimited strings + * returned by the path accessor, imputing parent nodes and ids as necessary. + * + * @param path The path accessor. + */ + path(path: ((d: Datum, i: number, data: Datum[]) => string) | null | undefined): this; } /** diff --git a/types/d3-shape/d3-shape-tests.ts b/types/d3-shape/d3-shape-tests.ts index 2f2d8355c04ff2..b1236c9e68f3be 100644 --- a/types/d3-shape/d3-shape-tests.ts +++ b/types/d3-shape/d3-shape-tests.ts @@ -1384,15 +1384,22 @@ pathStringMaybe = sym.getPathString({ size: 10, type: 'circle' }); // Test pre-fab symbols =============================================================== -const symbolArray: d3Shape.SymbolType[] = d3Shape.symbols; +let symbolArray: d3Shape.SymbolType[] = d3Shape.symbolsFill; +symbolArray = d3Shape.symbolsStroke; +customSymbol = d3Shape.symbolAsterisk; customSymbol = d3Shape.symbolCircle; customSymbol = d3Shape.symbolCross; customSymbol = d3Shape.symbolDiamond; +customSymbol = d3Shape.symbolDiamond2; +customSymbol = d3Shape.symbolPlus; customSymbol = d3Shape.symbolSquare; +customSymbol = d3Shape.symbolSquare2; customSymbol = d3Shape.symbolStar; customSymbol = d3Shape.symbolTriangle; +customSymbol = d3Shape.symbolTriangle2; customSymbol = d3Shape.symbolWye; +customSymbol = d3Shape.symbolX; // ----------------------------------------------------------------------------------- // Test pointRadial diff --git a/types/d3-shape/index.d.ts b/types/d3-shape/index.d.ts index cb2124c010f3cd..5ce15c6d49e5af 100644 --- a/types/d3-shape/index.d.ts +++ b/types/d3-shape/index.d.ts @@ -1,13 +1,14 @@ -// Type definitions for D3JS d3-shape module 3.0 +// Type definitions for D3JS d3-shape module 3.1 // Project: https://github.com/d3/d3-shape/, https://d3js.org/d3-shape // Definitions by: Tom Wanzek // Alex Ford // Boris Yankov // denisname // Nathan Bierema +// Fil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 3.0.1 +// Last module patch version validated against: 3.1.0 import { Path } from 'd3-path'; @@ -1934,15 +1935,46 @@ export interface Link { } /** - * Constructs a new default link generator with horizontal tangents, for example, to visualize links in a tree diagram - * rooted on the left edge of the display. + * Returns a new link generator using the specified curve. For example, to visualize links in a tree diagram rooted on the top edge of the display + * + * With the default settings the link generator accepts a link object conforming to the DefaultLinkObject interface. + */ +export function link(curve: CurveFactory): Link; +/** + * Returns a new link generator using the specified curve. For example, to visualize links in a tree diagram rooted on the top edge of the display + * + * Important: Ensure that the accessor functions are configured to work with the link and node datum types + * specified in the generics. + * + * The first generic corresponds to the datum type of the link object for which the link is to be generated. + * + * The second generic corresponds to the datum type of the source/target node contained in the link object. + */ +// tslint:disable-next-line:no-unnecessary-generics +export function link(curve: CurveFactory): Link; +/** + * Returns a new link generator using the specified curve. For example, to visualize links in a tree diagram rooted on the top edge of the display + * + * Important: Ensure that the accessor functions are configured to work with the link and node datum types + * specified in the generics. + * + * The first generic corresponds to the type of the "this" context within which the link generator and its accessor functions will be invoked. + * + * The second generic corresponds to the datum type of the link object for which the link is to be generated. + * + * The third generic corresponds to the datum type of the source/target node contained in the link object. + */ +// tslint:disable-next-line:no-unnecessary-generics +export function link(curve: CurveFactory): Link; + +/** + * Shorthand for d3.link with d3.curveBumpX; suitable for visualizing links in a tree diagram rooted on the left edge of the display. * * With the default settings the link generator accepts a link object conforming to the DefaultLinkObject interface. */ export function linkHorizontal(): Link; /** - * Constructs a new link generator with horizontal tangents, for example, to visualize links in a tree diagram - * rooted on the left edge of the display. + * Shorthand for d3.link with d3.curveBumpX; suitable for visualizing links in a tree diagram rooted on the left edge of the display. * * Important: Ensure that the accessor functions are configured to work with the link and node datum types * specified in the generics. @@ -1954,8 +1986,7 @@ export function linkHorizontal(): Link // tslint:disable-next-line:no-unnecessary-generics export function linkHorizontal(): Link; /** - * Constructs a new link generator with horizontal tangents, for example, to visualize links in a tree diagram - * rooted on the left edge of the display. + * Shorthand for d3.link with d3.curveBumpX; suitable for visualizing links in a tree diagram rooted on the left edge of the display. * * Important: Ensure that the accessor functions are configured to work with the link and node datum types * specified in the generics. @@ -1970,15 +2001,13 @@ export function linkHorizontal(): Link(): Link; /** - * Constructs a new default link generator with vertical tangents, for example, to visualize links in a tree diagram - * rooted on the top edge of the display. + * Shorthand for d3.link with d3.curveBumpX; suitable for visualizing links in a tree diagram rooted on the left edge of the display. * * With the default settings the link generator accepts a link object conforming to the DefaultLinkObject interface. */ export function linkVertical(): Link; /** - * Constructs a new link generator with vertical tangents, for example, to visualize links in a tree diagram - * rooted on the top edge of the display. + * Shorthand for d3.link with d3.curveBumpY; suitable for visualizing links in a tree diagram rooted on the top edge of the display. * * Important: Ensure that the accessor functions are configured to work with the link and node datum types * specified in the generics. @@ -1990,8 +2019,7 @@ export function linkVertical(): Link; // tslint:disable-next-line:no-unnecessary-generics export function linkVertical(): Link; /** - * Constructs a new link generator with vertical tangents, for example, to visualize links in a tree diagram - * rooted on the top edge of the display. + * Shorthand for d3.link with d3.curveBumpY; suitable for visualizing links in a tree diagram rooted on the top edge of the display. * * Important: Ensure that the accessor functions are configured to work with the link and node datum types * specified in the generics. @@ -2006,8 +2034,7 @@ export function linkVertical(): Link(): Link; /** - * A link generator for a radial coordinate system. The link shape generates a smooth cubic Bézier curve from a - * source point to a target point. The tangents of the curve at the start and end are radial. + * Shorthand for d3.link with d3.curveBumpY; suitable for visualizing links in a tree diagram rooted on the top edge of the display. * * The first generic corresponds to the type of the "this" context within which the radial link generator and its accessor functions will be invoked. * @@ -2287,45 +2314,86 @@ export function symbol( ): Symbol; /** - * An array containing the set of all built-in symbol types: circle, cross, diamond, square, star, triangle, and wye. + * An array containing a set of symbol types designed for filling: circle, cross, diamond, square, star, triangle, and wye. * Useful for constructing the range of an ordinal scale should you wish to use a shape encoding for categorical data. */ -export const symbols: SymbolType[]; +export const symbolsFill: SymbolType[]; /** - * The circle symbol type. - */ -export const symbolCircle: SymbolType; - -/** - * The Greek cross symbol type, with arms of equal length. - */ -export const symbolCross: SymbolType; - -/** - * The rhombus symbol type. - */ -export const symbolDiamond: SymbolType; - -/** - * The square symbol type. - */ -export const symbolSquare: SymbolType; - -/** - * The pentagonal star (pentagram) symbol type. + * An array containing a set of symbol types designed for stroking: circle, plus, x, triangle2, asterisk, square2, and diamond2. + * Useful for constructing the range of an ordinal scale should you wish to use a shape encoding for categorical data. */ -export const symbolStar: SymbolType; +export const symbolsStroke: SymbolType[]; /** - * The up-pointing triangle symbol type. + * @deprecated Use symbolsFill */ -export const symbolTriangle: SymbolType; +export const symbols: SymbolType[]; /** - * The Y-shape symbol type. - */ -export const symbolWye: SymbolType; + * The asterisk symbol type; intended for stroking. + */ + export const symbolAsterisk: SymbolType; + + /** + * The circle symbol type; intended for either filling or stroking. + */ + export const symbolCircle: SymbolType; + + /** + * The Greek cross symbol type, with arms of equal length; intended for filling. + */ + export const symbolCross: SymbolType; + + /** + * The rhombus symbol type; intended for filling. + */ + export const symbolDiamond: SymbolType; + + /** + * The rotated square symbol type; intended for stroking. + */ + export const symbolDiamond2: SymbolType; + + /** + * The plus symbol type; intended for stroking. + */ + export const symbolPlus: SymbolType; + + /** + * The square symbol type; intended for filling. + */ + export const symbolSquare: SymbolType; + + /** + * The square2 symbol type; intended for stroking. + */ + export const symbolSquare2: SymbolType; + + /** + * The pentagonal star (pentagram) symbol type; intended for filling. + */ + export const symbolStar: SymbolType; + + /** + * The up-pointing triangle symbol type; intended for filling. + */ + export const symbolTriangle: SymbolType; + + /** + * The up-pointing triangle symbol type; intended for stroking. + */ + export const symbolTriangle2: SymbolType; + + /** + * The Y-shape symbol type; intended for filling. + */ + export const symbolWye: SymbolType; + + /** + * The X-shape symbol type; intended for stroking. + */ + export const symbolX: SymbolType; // ----------------------------------------------------------------------------------- // pointRadial diff --git a/types/d3/index.d.ts b/types/d3/index.d.ts index f0611938a2d438..6a13693f697a8a 100644 --- a/types/d3/index.d.ts +++ b/types/d3/index.d.ts @@ -1,13 +1,14 @@ -// Type definitions for D3JS d3 standard bundle 7.1 +// Type definitions for D3JS d3 standard bundle 7.4 // Project: https://github.com/d3/d3, https://d3js.org // Definitions by: Tom Wanzek // Alex Ford // Boris Yankov // denisname // Nathan Bierema +// Fil // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// Last module patch version validated against: 7.1.0 +// Last module patch version validated against: 7.4.4 export as namespace d3;