Skip to content

Commit 675fc6b

Browse files
Filmbostock
andauthored
document projection (#1374)
* document projection * edits --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent 12ac7b4 commit 675fc6b

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

src/plot.d.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,19 @@ export interface PlotOptions extends ScaleDefaults {
240240
length?: ScaleOptions;
241241

242242
/**
243-
* Options for projection. A projection is an alternative to the *x* and *y*
244-
* scales for encoding position, and is typically used to convert polygonal
245-
* geometry in spherical coordinates to a planar visual representation.
243+
* Options for projection; one of:
244+
*
245+
* - a named built-in projection such as *albers-usa*
246+
* - a projection implementation, implementing the projection.*stream* method
247+
* - a function that returns a projection implementation
248+
* - a projection options object
249+
* - null, for no projection
250+
*
251+
* A projection is an alternative to the *x* and *y* scales for encoding
252+
* position, and is typically used to convert polygonal geometry in spherical
253+
* coordinates to a planar visual representation. For planar (projected)
254+
* coordinates, use the *identity* projection, or the *reflect-y* projection
255+
* if *y* points up.
246256
*/
247257
projection?: ProjectionOptions | ProjectionName | ProjectionFactory | ProjectionImplementation | null;
248258

src/projection.d.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
import type {GeoPermissibleObjects, GeoStreamWrapper} from "d3";
22
import type {InsetOptions} from "./inset.js";
33

4+
/**
5+
* The built-in projection implementations; one of:
6+
*
7+
* - *albers-usa* - a U.S.-centric composite projection with insets for Alaska and Hawaii
8+
* - *albers* - a U.S.-centric *conic-equal-area* projection
9+
* - *azimuthal-equal-area* - the azimuthal equal-area projection
10+
* - *azimuthal-equidistant* - the azimuthal equidistant projection
11+
* - *conic-conformal* - the conic conformal projection
12+
* - *conic-equal-area* - the conic equal-area projection
13+
* - *conic-equidistant* - the conic equidistant projection
14+
* - *equal-earth* - the Equal Earth projection Šavrič et al., 2018
15+
* - *equirectangular* - the equirectangular (plate carrée) projection
16+
* - *gnomonic* - the gnomonic projection
17+
* - *identity* - the identity projection
18+
* - *reflect-y* - the identity projection, but flipping *y*
19+
* - *mercator* - the spherical Mercator projection
20+
* - *orthographic* - the orthographic projection
21+
* - *stereographic* - the stereographic projection
22+
* - *transverse-mercator* - the transverse spherical Mercator projection
23+
*/
424
export type ProjectionName =
525
| "albers-usa"
626
| "albers"
@@ -19,14 +39,76 @@ export type ProjectionName =
1939
| "stereographic"
2040
| "transverse-mercator";
2141

42+
/** An instantiated projection, implementing a stream method. */
2243
export type ProjectionImplementation = GeoStreamWrapper;
2344

45+
/** A function returning an instantiated projection. */
2446
export type ProjectionFactory = (options: any) => ProjectionImplementation;
2547

48+
/** Options for projection. */
2649
export interface ProjectionOptions extends InsetOptions {
50+
/**
51+
* The desired projection; one of:
52+
*
53+
* - a named built-in projection such as *albers-usa*
54+
* - a function that returns a projection implementation
55+
* - null, for no projection
56+
*
57+
* When specified as a name, the projection is scaled and translated to fit
58+
* the **domain** to the plot’s frame (minus insets). If a function, it
59+
* receives a configuration object ({width, height, ...options}) and must
60+
* return an object that implements the *projection*.stream method.
61+
*
62+
* For example, to use the [Bertin 1953 projection][1]:
63+
*
64+
* ```js
65+
* {type: ({width, height, domain}) => d3.geoBertin1953().fitSize([width, height], domain)}
66+
* ```
67+
*
68+
* [1]: https://observablehq.com/@d3/geo-bertin-1953
69+
*/
2770
type?: ProjectionName | ProjectionFactory | null;
71+
72+
/**
73+
* A GeoJSON object to fit to the plot’s frame (minus insets); defaults to a
74+
* Sphere for spherical projections (outline of the the whole globe).
75+
*/
2876
domain?: GeoPermissibleObjects;
77+
78+
/**
79+
* A rotation of the sphere before projection; defaults to [0, 0, 0].
80+
* Specified as Euler angles λ (yaw, or reference longitude), φ (pitch, or
81+
* reference latitude), and optionally γ (roll), in degrees.
82+
*/
2983
rotate?: [x: number, y: number, z?: number];
84+
85+
/**
86+
* The [standard parallels][1]. For conic projections only.
87+
*
88+
* [1]: https://github.com/d3/d3-geo/blob/main/README.md#conic_parallels
89+
*/
3090
parallels?: [y1: number, y2: number];
91+
92+
/**
93+
* The projection’s [sampling threshold][1].
94+
*
95+
* [1]: https://github.com/d3/d3-geo/blob/main/README.md#projection_precision
96+
*/
97+
precision?: number;
98+
99+
/**
100+
* The projection’s clipping method; one of:
101+
*
102+
* - *frame* or true (default) - clip to the plot’s frame (including margins but not insets)
103+
* - a number - clip to a circle of the given radius in degrees centered around the origin
104+
* - null or false - do not clip
105+
*
106+
* Some projections (such as [*armadillo*][1] and [*berghaus*][2]) require
107+
* spherical clipping: in that case set the marks’ **clip** option to
108+
* *sphere*.
109+
*
110+
* [1]: https://observablehq.com/@d3/armadillo
111+
* [2]: https://observablehq.com/@d3/berghaus-star
112+
*/
31113
clip?: boolean | number | "frame" | null;
32114
}

0 commit comments

Comments
 (0)