diff --git a/types/d3-hexbin/d3-hexbin-tests.ts b/types/d3-hexbin/d3-hexbin-tests.ts index 0082ae075d..bef57a94c4 100644 --- a/types/d3-hexbin/d3-hexbin-tests.ts +++ b/types/d3-hexbin/d3-hexbin-tests.ts @@ -104,8 +104,8 @@ interface Point { } { - // hexbin.hexagon(radius) uses the current bin radius if radius is null - let path: string = d3Hexbin.hexbin().hexagon(null); + // hexbin.hexagon(radius) uses the current bin radius if radius is undefined + let path: string = d3Hexbin.hexbin().hexagon(); path = d3Hexbin.hexbin().hexagon(undefined); } @@ -146,6 +146,13 @@ interface Point { .mesh(); } +{ + // hexbin.size() + let size: [number, number] = [100, 100]; + d3Hexbin.hexbin().size(size); + size = d3Hexbin.hexbin().size(); +} + { let hb: d3Hexbin.Hexbin; let bins: Array>; diff --git a/types/d3-hexbin/index.d.ts b/types/d3-hexbin/index.d.ts index 5fa53e6145..616ca7186c 100644 --- a/types/d3-hexbin/index.d.ts +++ b/types/d3-hexbin/index.d.ts @@ -1,12 +1,22 @@ // Type definitions for D3JS d3-hexbin module 0.2 // Project: https://github.com/d3/d3-hexbin/ -// Definitions by: UNCOVER TRUTH Inc. , Tom Wanzek +// Definitions by: UNCOVER TRUTH Inc. +// Tom Wanzek +// denisname // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 -// Last module patch version validated against: 0.2.1 +// Last module patch version validated against: 0.2.2 export interface HexbinBin extends Array { + /** + * The x-coordinate of the center of the associated bin’s hexagon. + */ x: number; + + /** + * The y-coordinate of the center of the associated bin’s hexagon. + */ y: number; } @@ -15,7 +25,7 @@ export interface Hexbin { * Bins the specified array of points, returning an array of hexagonal bins. * For each point in the specified points array, the x- and y-accessors are * invoked to compute the x- and y-coordinates of the point, which is then - * used to determine which hexagonal bin to add the point. + * used to assign the point to a hexagonal bin. * If either the x- or y-coordinate is NaN, the point is ignored and will * not be in any of the returned bins. */ @@ -47,49 +57,34 @@ export interface Hexbin { mesh(): string; /** - * If x is specified, sets the x-coordinate accessor to the specified - * function and returns this hexbin generator. + * Sets the x-coordinate accessor to the specified function and returns this hexbin generator. * * The x-coordinate accessor is used by hexbin to compute the x-coordinate * of each point. The default value assumes each point is specified as * a two-element array of numbers [x, y]. */ - x(x: (d: T) => number): Hexbin; + x(x: (d: T) => number): this; /** - * If x is not specified, returns the current x-coordinate accessor, - * - * which defaults to: - * - * function x(d) { - * return d[0]; - * } + * Returns the current x-coordinate accessor, which defaults to: `x(d) => d[0]`. * * The x-coordinate accessor is used by hexbin to compute the x-coordinate * of each point. The default value assumes each point is specified as * a two-element array of numbers [x, y]. - * */ x(): (d: T) => number; /** - * If y is specified, sets the y-coordinate accessor to the specified - * function and returns this hexbin generator. + * Sets the y-coordinate accessor to the specified function and returns this hexbin generator. * * The y-coordinate accessor is used by hexbin to compute the y-coordinate * of each point. The default value assumes each point is specified as * a two-element array of numbers [x, y]. */ - y(y: (d: T) => number): Hexbin; + y(y: (d: T) => number): this; /** - * If y is not specified, returns the current y-coordinate accessor, - * - * which defaults to: - * - * function y(d) { - * return d[1]; - * } + * Returns the current y-coordinate accessor, which defaults to: `y(d) => d[1]`. * * The y-coordinate accessor is used by hexbin to compute the y-coordinate * of each point. The default value assumes each point is specified as @@ -98,18 +93,16 @@ export interface Hexbin { y(): (d: T) => number; /** - * If radius is specified, sets the radius of the hexagon to - * the specified number. + * Sets the radius of the hexagon to the specified number. * * The hexagons are pointy-topped (rather than flat-topped); * the width of each hexagon is radius × 2 × sin(π / 3) * and the height of each hexagon radius × 3 / 2. */ - radius(radius: number): Hexbin; + radius(radius: number): this; /** - * If radius is not specified, returns the current radius, - * which defaults to 1. + * Returns the current radius, which defaults to 1. * * The hexagons are pointy-topped (rather than flat-topped); * the width of each hexagon is radius × 2 × sin(π / 3) @@ -118,23 +111,42 @@ export interface Hexbin { radius(): number; /** - * If extent is specified, sets the hexbin generator’s extent to the - * specified bounds [[x0, y0], [x1, y1]] and returns the hexbin generator. + * Sets the hexbin generator’s extent to the specified bounds + * `[[x0, y0], [x1, y1]]` and returns the hexbin generator. */ - extent(extent: [[number, number], [number, number]]): Hexbin; + extent(extent: [[number, number], [number, number]]): this; /** - * If extent is not specified, returns the generator’s current - * extent [[x0, y0], [x1, y1]], where x0 and y0 are the lower bounds and - * x1 and y1 are the upper bounds. + * Returns the generator’s current extent `[[x0, y0], [x1, y1]]`, + * where `x0` and `y0` are the lower bounds and `x1` and `y1` are the upper bounds. * - * The extent defaults to [[0, 0], [1, 1]]. + * The extent defaults to `[[0, 0], [1, 1]]`. */ extent(): [[number, number], [number, number]]; + + /** + * Sets the extent to the specified bounds `[[0, 0], [dx, dy]]` and returns the hexbin generator. + * + * This is a convenience method for setting the extent. + */ + size(size: [number, number]): this; + + /** + * Returns the generator’s current size `[x1 - x0, y1 - y0]`, + * where `x0` and `y0` are the lower bounds and `x1` and `y1` are the upper bounds. + * + * The size defaults to [1, 1]. + */ + size(): [number, number]; } /** - * Constructs a new default hexbin generator. + * Creates a new hexbin generator with default radius, extent, x- and y- accessors. + * The x- and y-accessors may have to be set to correspond to the data type provided + * by the generic. + * + * The generic refers to the type of the data for the corresponding element. + * Without specifying a generic the layout is assumed to be based on data represented + * by a two-dimensional coordinate `[number, number]` for x- and y-coordinate, respectively. */ -export function hexbin(): Hexbin<[number, number]>; -export function hexbin(): Hexbin; +export function hexbin(): Hexbin; diff --git a/types/d3-hexbin/tsconfig.json b/types/d3-hexbin/tsconfig.json index 773221263b..2ac8e0c3ff 100644 --- a/types/d3-hexbin/tsconfig.json +++ b/types/d3-hexbin/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [