mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-31 03:02:04 +08:00
refactor(d3-contour): use generic defaults
Removes unnecessary function overload in favour of using generic parameter defaults for `ContourDensity<...>` and `contourDensity<...>()`
This commit is contained in:
@@ -113,7 +113,10 @@ interface CustomDatum {
|
||||
|
||||
// Get contour generator -------------------------------------------------------
|
||||
|
||||
const contDensDefault: d3Contour.ContourDensity<[number, number]> = d3Contour.contourDensity();
|
||||
// test generic parameter defaults for ContourDensity and contourDensity
|
||||
const contDensDefault: d3Contour.ContourDensity = d3Contour.contourDensity();
|
||||
const contDensDefaultCopy: d3Contour.ContourDensity<[number, number]> = contDensDefault;
|
||||
// test with explicit generic parameter
|
||||
let contDensCustom: d3Contour.ContourDensity<CustomDatum> = d3Contour.contourDensity<CustomDatum>();
|
||||
|
||||
// Configure contour generator =================================================
|
||||
|
||||
21
types/d3-contour/index.d.ts
vendored
21
types/d3-contour/index.d.ts
vendored
@@ -120,8 +120,13 @@ export function contours(): Contours;
|
||||
|
||||
/**
|
||||
* A contour generator for density estimates.
|
||||
*
|
||||
* The generic refers to the data type of an element in the data array
|
||||
* used with the density contour generator. If omitted, the default setting assumes that,
|
||||
* the elements of the data array used with the density contour generator are two-element arrays.
|
||||
* The first element corresponds to the x-dimension, the second to the y-dimension.
|
||||
*/
|
||||
export interface ContourDensity<Datum> {
|
||||
export interface ContourDensity<Datum = [number, number]> {
|
||||
/**
|
||||
* Estimates the density contours for the given array of data, returning an array of GeoJSON MultiPolygon geometry objects.
|
||||
* Each geometry object represents the area where the estimated number of points per square pixel is greater than or equal to
|
||||
@@ -238,21 +243,15 @@ export interface ContourDensity<Datum> {
|
||||
bandwidth(bandwidth: number): this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new contour generator for density estimates with the default settings.
|
||||
*
|
||||
* The default settings assume that, the elements of the data array used
|
||||
* with the density contour generator are two-element arrays. The first element
|
||||
* corresponds to the x-dimension, the second to the y-dimension.
|
||||
*/
|
||||
export function contourDensity(): ContourDensity<[number, number]>;
|
||||
/**
|
||||
* Construct a new contour generator for density estimates.
|
||||
*
|
||||
* The generic refers to the data type of an element in the data array
|
||||
* used with the density contour generator.
|
||||
* used with the density contour generator. If omitted, the default setting assumes that,
|
||||
* the elements of the data array used with the density contour generator are two-element arrays.
|
||||
* The first element corresponds to the x-dimension, the second to the y-dimension.
|
||||
*
|
||||
* Important: ensure that the x- and y-accessor functions are configured to
|
||||
* match the data type used for the generic Datum.
|
||||
*/
|
||||
export function contourDensity<Datum>(): ContourDensity<Datum>;
|
||||
export function contourDensity<Datum = [number, number]>(): ContourDensity<Datum>;
|
||||
|
||||
Reference in New Issue
Block a user