Merge pull request #24271 from tomwanzek/d3-contour-default-generics

refactor(d3-contour): use generic parameter defaults
This commit is contained in:
Arthur Ozga
2018-03-15 12:41:31 -07:00
committed by GitHub
2 changed files with 15 additions and 12 deletions
+5 -1
View File
@@ -113,7 +113,11 @@ 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();
// tslint:disable-next-line: use-default-type-parameter
const contDensDefaultCopy: d3Contour.ContourDensity<[number, number]> = contDensDefault;
// test with explicit generic parameter
let contDensCustom: d3Contour.ContourDensity<CustomDatum> = d3Contour.contourDensity<CustomDatum>();
// Configure contour generator =================================================
+10 -11
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>;