This repository has been archived by the owner on Jul 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.d.ts
358 lines (280 loc) · 16.4 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
// Type definitions for D3JS d3-geo module v1.2.4
// Project: https://github.com/d3/d3-geo/
// Definitions by: Hugues Stefanski <https://github.com/Ledragon>, Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="geojson" />
// ----------------------------------------------------------------------
// Shared Interfaces and Types
// ----------------------------------------------------------------------
/**
* A basic geometry for a sphere, which is supported by d3-geo
* beyond the GeoJSON geometries.
*/
export interface GeoSphere {
type: 'Sphere';
}
/**
* Type Alias for GeoJSON Geometry Object and GeoSphere additional
* geometry supported by d3-geo
*/
export type GeoGeometryObjects = GeoJSON.GeometryObject | GeoSphere;
/**
* A GeoJSON-style GeometryCollection which supports GeoJSON geometry objects
* and additionally GeoSphere
*/
export interface ExtendedGeometryCollection<GeometryType extends GeoGeometryObjects> {
type: string;
bbox?: number[];
crs?: GeoJSON.CoordinateReferenceSystem;
geometries: GeometryType[];
}
/**
* A GeoJSON-style Feature which support features built on GeoJSON GeometryObjects
* or GeoSphere
*/
export interface ExtendedFeature<GeometryType extends GeoGeometryObjects, Properties> extends GeoJSON.GeoJsonObject {
geometry: GeometryType;
properties: Properties;
id?: string;
}
/**
* A GeoJSON-style FeatureCollection which supports GeoJSON features
* and features built on GeoSphere
*/
export interface ExtendedFeatureCollection<FeatureType extends ExtendedFeature<GeoGeometryObjects, any>> extends GeoJSON.GeoJsonObject {
features: FeatureType[];
}
/**
* Type Alias for permissible objects which can be used with d3-geo
* methods
*/
export type GeoPermissibleObjects = GeoGeometryObjects | ExtendedGeometryCollection<GeoGeometryObjects> | ExtendedFeature<GeoGeometryObjects, any> | ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>;
// ----------------------------------------------------------------------
// Spherical Math
// ----------------------------------------------------------------------
/**Returns the spherical area of the specified GeoJSON feature in steradians. */
export function geoArea(feature: ExtendedFeature<GeoGeometryObjects, any>): number;
export function geoArea(feature: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): number;
export function geoArea(feature: GeoGeometryObjects): number;
export function geoArea(feature: ExtendedGeometryCollection<GeoGeometryObjects>): number;
/**Returns the spherical bounding box for the specified GeoJSON feature. The bounding box is represented by a two-dimensional array: [[left, bottom], [right, top]], where left is the minimum longitude, bottom is the minimum latitude, right is maximum longitude, and top is the maximum latitude. All coordinates are given in degrees. */
export function geoBounds(feature: ExtendedFeature<GeoGeometryObjects, any>): [[number, number], [number, number]];
export function geoBounds(feature: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): [[number, number], [number, number]];
export function geoBounds(feature: GeoGeometryObjects): [[number, number], [number, number]];
export function geoBounds(feature: ExtendedGeometryCollection<GeoGeometryObjects>): [[number, number], [number, number]];
/**Returns the spherical centroid of the specified GeoJSON feature. See also path.centroid, which computes the projected planar centroid.*/
export function geoCentroid(feature: ExtendedFeature<GeoGeometryObjects, any>): [number, number];
export function geoCentroid(feature: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): [number, number];
export function geoCentroid(feature: GeoGeometryObjects): [number, number];
export function geoCentroid(feature: ExtendedGeometryCollection<GeoGeometryObjects>): [number, number];
/**Returns the great-arc distance in radians between the two points a and b. Each point must be specified as a two-element array [longitude, latitude] in degrees. */
export function geoDistance(a: [number, number], b: [number, number]): number;
/**Returns the great-arc length of the specified GeoJSON feature in radians.*/
export function geoLength(feature: ExtendedFeature<GeoGeometryObjects, any>): number;
export function geoLength(feature: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): number;
export function geoLength(feature: GeoGeometryObjects): number;
export function geoLength(feature: ExtendedGeometryCollection<GeoGeometryObjects>): number;
/**Returns an interpolator function given two points a and b. Each point must be specified as a two-element array [longitude, latitude] in degrees. */
export function geoInterpolate(a: [number, number], b: [number, number]): (t: number) => [number, number];
export interface GeoRotation {
(point: [number, number]): [number, number];
invert(point: [number, number]): [number, number];
}
/**Returns a rotation function for the given angles, which must be a two- or three-element array of numbers [lambda, phi, gamma] specifying the rotation angles in degrees about each spherical axis. */
export function geoRotation(angles: [number, number] | [number, number, number]): GeoRotation;
// ----------------------------------------------------------------------
// Spherical Shapes
// ----------------------------------------------------------------------
// geoCircle ============================================================
export interface GeoCircleGenerator<This, Datum> {
/**Returns a new GeoJSON geometry object of type “Polygon” approximating a circle on the surface of a sphere, with the current center, radius and precision. */
(this: This, d?: Datum, ...args: any[]): GeoJSON.Polygon;
center(): ((this: This, d: Datum, ...args: any[]) => [number, number]);
center(center: [number, number]): this;
center(center: ((this: This, d: Datum, ...args: any[]) => [number, number])): this;
radius(): ((this: This, d: Datum, ...args: any[]) => number);
radius(radius: number): this;
radius(radius: ((this: This, d: Datum, ...args: any[]) => number)): this;
precision(): ((this: This, d: Datum, ...args: any[]) => number);
precision(precision: number): this;
precision(precision: (this: This, d: Datum, ...args: any[]) => number): this;
}
export function geoCircle(): GeoCircleGenerator<any, any>;
export function geoCircle<Datum>(): GeoCircleGenerator<any, Datum>;
export function geoCircle<This, Datum>(): GeoCircleGenerator<This, Datum>;
// geoGraticule ============================================================
export interface GeoGraticuleGenerator {
/**Returns a GeoJSON MultiLineString geometry object representing all meridians and parallels for this graticule. */
(): GeoJSON.MultiLineString;
lines(): GeoJSON.LineString[];
outline(): GeoJSON.Polygon;
extent(): [[number, number], [number, number]];
extent(extent: [[number, number], [number, number]]): this;
extentMajor(): [[number, number], [number, number]];
extentMajor(extent: [[number, number], [number, number]]): this;
extentMinor(): [[number, number], [number, number]];
extentMinor(extent: [[number, number], [number, number]]): this;
step(): [number, number];
step(step: [number, number]): this;
stepMajor(): [number, number];
stepMajor(step: [number, number]): this;
stepMinor(): [number, number];
stepMinor(step: [number, number]): this;
precision(): number;
precision(angle: number): this;
}
export function geoGraticule(): GeoGraticuleGenerator;
// ----------------------------------------------------------------------
// Projections
// ----------------------------------------------------------------------
export interface GeoStream {
lineEnd(): void;
lineStart(): void;
point(x: number, y: number, z?: number): void;
polygonEnd(): void;
polygonStart(): void;
sphere?(): void;
}
export interface GeoStreamWrapper {
stream(stream: GeoStream): GeoStream;
}
export interface GeoRawProjection {
(longitude: number, latitude: number): [number, number];
invert?(x: number, y: number): [number, number];
}
export interface GeoProjection extends GeoStreamWrapper {
/**Returns a new array x, y representing the projected point of the given point. The point must be specified as a two-element array [longitude, latitude] in degrees. */
(point: [number, number]): [number, number] | null;
center(): [number, number];
center(point: [number, number]): this;
clipAngle(): number | null;
clipAngle(angle: null): this;
clipAngle(angle: number): this;
clipExtent(): [[number, number], [number, number]] | null;
clipExtent(extent: null): this;
clipExtent(extent: [[number, number], [number, number]]): this;
/**Sets the projection’s scale and translate to fit the specified GeoJSON object in the center of the given extent. */
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitExtent(extent: [[number, number], [number, number]], object: GeoGeometryObjects): this;
fitExtent(extent: [[number, number], [number, number]], object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
/**A convenience method for projection.fitExtent where the top-left corner of the extent is [0,0]. */
fitSize(size: [number, number], object: ExtendedFeature<GeoGeometryObjects, any>): this;
fitSize(size: [number, number], object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>): this;
fitSize(size: [number, number], object: GeoGeometryObjects): this;
fitSize(size: [number, number], object: ExtendedGeometryCollection<GeoGeometryObjects>): this;
/**Returns a new array [longitude, latitude] in degrees representing the unprojected point of the given projected point. */
invert?(point: [number, number]): [number, number] | null;
precision(): number;
precision(precision: number): this;
rotate(): [number, number, number];
rotate(angles: [number, number] | [number, number, number]): this;
scale(): number;
scale(scale: number): this;
translate(): [number, number];
translate(point: [number, number]): this;
}
export interface GeoConicProjection extends GeoProjection {
parallels(value: [number, number]): this;
parallels(): [number, number];
}
// geoPath ==============================================================
export interface GeoContext {
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
beginPath(): void;
closePath(): void;
lineTo(x: number, y: number): void;
moveTo(x: number, y: number): void;
}
export interface GeoPath<This, DatumObject extends GeoPermissibleObjects> {
(this: This, object: DatumObject, ...args: any[]): string;
area(object: DatumObject): number;
bounds(object: DatumObject): [[number, number], [number, number]];
centroid(object: DatumObject): [number, number];
context<C extends GeoContext>(): C | null;
context(context: GeoContext | null): this;
/**
* Get the current projection. The generic parameter can be used to cast the result to the
* correct, known type of the projection, e.g. GeoProjection or GeoConicProjection. Otherwise,
* the return type defaults to the minimum type requirement for a projection which
* can be passed into a GeoPath.
*/
projection<P extends GeoConicProjection | GeoProjection | GeoStreamWrapper>(): P | null;
/**
* Set the projection to the identity projection
*/
projection(projection: null): this;
/**
* Set the projection to be used with the geo path generator.
*/
projection(projection: GeoProjection): this;
/**
* Set the projection to be used with the geo path generator to a custom projection.
* Custom projections must minimally contain a stream method.
*/
projection(projection: GeoStreamWrapper): this;
pointRadius(): (this: This, object: DatumObject, ...args: any[]) => number;
pointRadius(value: number): this;
pointRadius(value: (this: This, object: DatumObject, ...args: any[]) => number): this;
}
export function geoPath(): GeoPath<any, GeoPermissibleObjects>;
export function geoPath<DatumObject extends GeoPermissibleObjects>(): GeoPath<any, DatumObject>;
export function geoPath<This, DatumObject extends GeoPermissibleObjects>(): GeoPath<This, DatumObject>;
// Raw Projections ========================================================
export function geoAzimuthalEqualAreaRaw(): GeoRawProjection;
export function geoAzimuthalEquidistantRaw(): GeoRawProjection;
export function geoConicConformalRaw(phi0: number, phi1: number): GeoRawProjection;
export function geoConicEqualAreaRaw(phi0: number, phi1: number): GeoRawProjection;
export function geoConicEquidistantRaw(phi0: number, phi1: number): GeoRawProjection;
export function geoEquirectangularRaw(): GeoRawProjection;
export function geoGnomonicRaw(): GeoRawProjection;
export function geoMercatorRaw(): GeoRawProjection;
export function geoOrthographicRaw(): GeoRawProjection;
export function geoStereographicRaw(): GeoRawProjection;
export function geoTransverseMercatorRaw(): GeoRawProjection;
// geoProjection ==========================================================
export function geoProjection(project: GeoRawProjection): GeoProjection;
// geoProjectionMutator ====================================================
export function geoProjectionMutator(factory: (...args: any[]) => GeoRawProjection): () => GeoProjection;
// Pre-Defined Projections =================================================
export function geoAlbers(): GeoConicProjection;
export function geoAlbersUsa(): GeoProjection;
export function geoAzimuthalEqualArea(): GeoProjection;
export function geoAzimuthalEquidistant(): GeoProjection;
export function geoConicConformal(): GeoConicProjection;
export function geoConicEqualArea(): GeoConicProjection;
export function geoConicEquidistant(): GeoConicProjection;
export function geoEquirectangular(): GeoProjection;
export function geoGnomonic(): GeoProjection;
export function geoMercator(): GeoProjection;
export function geoOrthographic(): GeoProjection;
export function geoStereographic(): GeoProjection;
export function geoTransverseMercator(): GeoProjection;
// geoClipExtent =============================================================
export interface GeoExtent {
extent(): [[number, number], [number, number]];
extent(extent: [[number, number], [number, number]]): this;
stream(stream: GeoStream): GeoStream;
}
export function geoClipExtent(): GeoExtent;
// ----------------------------------------------------------------------
// Projection Streams
// ----------------------------------------------------------------------
// geoTransform(...) ====================================================
export interface GeoTransformPrototype {
lineEnd?(this: this & { stream: GeoStream }): void;
lineStart?(this: this & { stream: GeoStream }): void;
point?(this: this & { stream: GeoStream }, x: number, y: number, z?: number): void;
polygonEnd?(this: this & { stream: GeoStream }): void;
polygonStart?(this: this & { stream: GeoStream }): void;
sphere?(this: this & { stream: GeoStream }): void;
}
// TODO: Review whether GeoStreamWrapper should be included into return value union type, i.e. ({ stream: (s: GeoStream) => (T & GeoStream & GeoStreamWrapper)})?
// It probably should be omitted for purposes of this API. The stream method added to (T & GeoStream) is more of a private member used internally to
// implement the Transform factory
export function geoTransform<T extends GeoTransformPrototype>(prototype: T): { stream: (s: GeoStream) => (T & GeoStream) };
// geoStream(...) =======================================================
export function geoStream(object: ExtendedFeature<GeoGeometryObjects, any>, stream: GeoStream): void;
export function geoStream(object: ExtendedFeatureCollection<ExtendedFeature<GeoGeometryObjects, any>>, stream: GeoStream): void;
export function geoStream(object: GeoGeometryObjects, stream: GeoStream): void;
export function geoStream(object: ExtendedGeometryCollection<GeoGeometryObjects>, stream: GeoStream): void;