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:
Tom Wanzek
2018-03-13 13:30:43 -04:00
parent 5dc41ce74c
commit 3a7f961a89
2 changed files with 14 additions and 12 deletions

View File

@@ -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 =================================================

View File

@@ -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>;