From 9f5858caef71c8b6ce6496affc4adf4e08ed2caf Mon Sep 17 00:00:00 2001 From: Tom Wanzek Date: Thu, 4 May 2017 15:58:02 -0400 Subject: [PATCH] [d3-geo/d3-contour] Chores (#16324) * [d3-contour] [Chore] Add contributor * [d3-geo] Chore and Preparation for strictNullChecks * [Chore] Change geoJSON to module import * [Chore] Update return type signatures for `geoPath(...)` invocation. For the time being split the signatures for rendering to svg vs canvas. The return type for rendering is changed to `string | null`. This change corresponds to the comitted PR 98 in the d3-geo repo. The behavior and the definitions are now harmonized with d3-shape generators like `arc(...)`. * [d3-contour] Update test to reflect `geoPath` change. --- types/d3-contour/d3-contour-tests.ts | 2 +- types/d3-contour/index.d.ts | 2 +- types/d3-geo/index.d.ts | 38 +++++++++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/types/d3-contour/d3-contour-tests.ts b/types/d3-contour/d3-contour-tests.ts index a70f1f44e7..751dfe99c9 100644 --- a/types/d3-contour/d3-contour-tests.ts +++ b/types/d3-contour/d3-contour-tests.ts @@ -45,7 +45,7 @@ const thresholdArrayGen: ThresholdArrayGenerator = (values: number[], mi }; let thresholdGenerator: ThresholdArrayGenerator | ThresholdCountGenerator; -let pathStringMaybe: string | undefined; +let pathStringMaybe: string | null; let num: number; const pathSolo = geoPath(); diff --git a/types/d3-contour/index.d.ts b/types/d3-contour/index.d.ts index 2222e459a1..789ff32a5f 100644 --- a/types/d3-contour/index.d.ts +++ b/types/d3-contour/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for d3-contour 1.1 // Project: https://d3js.org/d3-contour/ -// Definitions by: Tom Wanzek +// Definitions by: Tom Wanzek , Hugues Stefanski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Last module patch version validated against: 1.1.0 diff --git a/types/d3-geo/index.d.ts b/types/d3-geo/index.d.ts index f6e4fa150d..bff408ce6b 100644 --- a/types/d3-geo/index.d.ts +++ b/types/d3-geo/index.d.ts @@ -3,10 +3,10 @@ // Definitions by: Hugues Stefanski , Tom Wanzek , Alex Ford , Boris Yankov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// - // Last module patch version validated against: 1.6.1 +import * as GeoJSON from 'geojson'; + // ---------------------------------------------------------------------- // Shared Interfaces and Types // ---------------------------------------------------------------------- @@ -926,7 +926,8 @@ export interface GeoPath { * * Any additional arguments are passed along to the pointRadius accessor. * - * If the rendering context is null, the function returns an SVG Path string, otherwise the function renders to the current context. + * IMPORTANT: If the rendering context of the geoPath generator is null, + * then the geoPath is returned as an SVG path data string. * * Separate path elements are typically slower than a single path element. However, distinct path elements are useful for styling and interation (e.g., click or mouseover). * Canvas rendering (see path.context) is typically faster than SVG, but requires more effort to implement styling and interaction. @@ -935,7 +936,36 @@ export interface GeoPath { * * @param object An object to be rendered. */ - (this: This, object: DatumObject, ...args: any[]): string | undefined; + (this: This, object: DatumObject, ...args: any[]): string | null; + /** + * Renders the given object, which may be any GeoJSON feature or geometry object: + * + * + Point - a single position. + * + MultiPoint - an array of positions. + * + LineString - an array of positions forming a continuous line. + * + MultiLineString - an array of arrays of positions forming several lines. + * + Polygon - an array of arrays of positions forming a polygon (possibly with holes). + * + MultiPolygon - a multidimensional array of positions forming multiple polygons. + * + GeometryCollection - an array of geometry objects. + * + Feature - a feature containing one of the above geometry objects. + * + FeatureCollection - an array of feature objects. + * + * The type Sphere is also supported, which is useful for rendering the outline of the globe; a sphere has no coordinates. + * + * + * Any additional arguments are passed along to the pointRadius accessor. + * + * IMPORTANT: If the geoPath generator has been configured with a rendering context, + * then the geoPath is rendered to this context as a sequence of path method calls and this function returns void. + * + * Separate path elements are typically slower than a single path element. However, distinct path elements are useful for styling and interation (e.g., click or mouseover). + * Canvas rendering (see path.context) is typically faster than SVG, but requires more effort to implement styling and interaction. + * + * The first generic type of the GeoPath generator used, must correspond to the "this" context bound to the function upon invocation. + * + * @param object An object to be rendered. + */ + (this: This, object: DatumObject, ...args: any[]): void; /** * Returns the projected planar area (typically in square pixels) for the specified GeoJSON object.