1 | // Type definitions for d3-contour 3.0
|
2 | // Project: https://d3js.org/d3-contour/
|
3 | // Definitions by: Tom Wanzek <https://github.com/tomwanzek>
|
4 | // Hugues Stefanski <https://github.com/Ledragon>
|
5 | // Nathan Bierema <https://github.com/Methuselah96>
|
6 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
7 |
|
8 | // Last module patch version validated against: 3.0.1
|
9 |
|
10 | import { MultiPolygon } from 'geojson';
|
11 | import { ThresholdNumberArrayGenerator, ThresholdCountGenerator } from 'd3-array';
|
12 |
|
13 | /**
|
14 | * An extended GeoJSON MultiPolygon representing a contour.
|
15 | */
|
16 | export interface ContourMultiPolygon extends MultiPolygon {
|
17 | /**
|
18 | * Threshold value of the contour.
|
19 | */
|
20 | value: number;
|
21 | }
|
22 |
|
23 | /**
|
24 | * A contour generator which computes contour polygons by applying marching squares to a rectangular array of numeric values.
|
25 | *
|
26 | * For each threshold value, the contour generator constructs a GeoJSON MultiPolygon geometry object representing the area
|
27 | * where the input values are greater than or equal to the threshold value.
|
28 | * The geometry is in planar coordinates, where ⟨i + 0.5, j + 0.5⟩ corresponds to element i + jn in the input values array.
|
29 | *
|
30 | */
|
31 | export interface Contours {
|
32 | /**
|
33 | * Computes the contours for the given array of values, returning an array of GeoJSON MultiPolygon geometry objects.
|
34 | * Each geometry object represents the area where the input values are greater than or equal to the corresponding threshold value;
|
35 | * the threshold value for each geometry object is exposed as geometry.value.
|
36 | *
|
37 | * The returned geometry objects are typically passed to d3.geoPath to display,
|
38 | * using null or d3.geoIdentity as the associated projection
|
39 | *
|
40 | * @param values Array of input values. The input values must be an array of length n×m where [n, m] is the contour generator’s size;
|
41 | * furthermore, each values[i + jn] must represent the value at the position ⟨i, j⟩.
|
42 | */
|
43 | (values: number[]): ContourMultiPolygon[];
|
44 |
|
45 | /**
|
46 | * Computes a single contour, returning a GeoJSON MultiPolygon geometry object.
|
47 | * This geometry object represents the area where the input values are greater than or equal to the given threshold value;
|
48 | * the threshold value for the geometry object is exposed as geometry.value.
|
49 | *
|
50 | * @param values Array of input values. The input values must be an array of length n×m where [n, m] is the contour generator’s size;
|
51 | * furthermore, each values[i + jn] must represent the value at the position ⟨i, j⟩.
|
52 | * @param threshold Threshold value.
|
53 | */
|
54 | contour(values: number[], threshold: number): ContourMultiPolygon;
|
55 |
|
56 | /**
|
57 | * Return the expected size of the input values grid, which defaults to [1,1].
|
58 | */
|
59 | size(): [number, number];
|
60 | /**
|
61 | * Sets the expected size of the input values grid to the contour generator and returns the contour generator.
|
62 | *
|
63 | * @param size Size of the input values grid specified as an array [n, m]
|
64 | * where n is the number of columns in the grid and m is the number of rows; n and m must be positive integers.
|
65 | */
|
66 | size(size: [number, number]): this;
|
67 |
|
68 | /**
|
69 | * Returns the current smoothing flag, which defaults to true.
|
70 | */
|
71 | smooth(): boolean;
|
72 | /**
|
73 | * Sets whether or not the generated contour polygons are smoothed using linear interpolation and returns the contour generator.
|
74 | *
|
75 | * @param smooth Flag to enable linear interpolation. The default is "true".
|
76 | */
|
77 | smooth(smooth: boolean): this;
|
78 |
|
79 | /**
|
80 | * Returns the current threshold generator, which by default implements Sturges’ formula.
|
81 | */
|
82 | thresholds(): ThresholdCountGenerator<number> | ThresholdNumberArrayGenerator<number>;
|
83 | /**
|
84 | * Sets the threshold generator to the specified function or array and returns this contour generator.
|
85 | * Thresholds are defined as an array of values [x0, x1, …].
|
86 | * The first generated contour corresponds to the area where the input values are greater than or equal to x0;
|
87 | * the second contour corresponds to the area where the input values are greater than or equal to x1, and so on.
|
88 | * Thus, there is exactly one generated MultiPolygon geometry object for each specified threshold value; the threshold value is exposed as geometry.value.
|
89 | * If a count is specified instead of an array of thresholds, then the input values’ extent will be uniformly divided into approximately count bins; see d3.ticks.
|
90 | */
|
91 | thresholds(thresholds: number | number[] | ThresholdCountGenerator<number> | ThresholdNumberArrayGenerator<number>): this;
|
92 | }
|
93 |
|
94 | /**
|
95 | * Construct a new contour generator with the default settings.
|
96 | */
|
97 | export function contours(): Contours;
|
98 |
|
99 | /**
|
100 | * A contour generator for density estimates.
|
101 | *
|
102 | * The generic refers to the data type of an element in the data array
|
103 | * used with the density contour generator. If omitted, the default setting assumes that,
|
104 | * the elements of the data array used with the density contour generator are two-element arrays.
|
105 | * The first element corresponds to the x-dimension, the second to the y-dimension.
|
106 | */
|
107 | export interface ContourDensity<Datum = [number, number]> {
|
108 | /**
|
109 | * Estimates the density contours for the given array of data, returning an array of GeoJSON MultiPolygon geometry objects.
|
110 | * Each geometry object represents the area where the estimated number of points per square pixel is greater than or equal to
|
111 | * the corresponding threshold value; the threshold value for each geometry object is exposed as geometry.value.
|
112 | * The returned geometry objects are typically passed to d3.geoPath to display, using null or d3.geoIdentity as the associated projection.
|
113 | * See also d3.contours.
|
114 | *
|
115 | * The x- and y-coordinate for each data point are computed using density.x and density.y.
|
116 | * The generated contours are only accurate within the estimator’s defined size.
|
117 | *
|
118 | * @param data Array of input data.
|
119 | */
|
120 | (data: Datum[]): ContourMultiPolygon[];
|
121 |
|
122 | /**
|
123 | * Returns the current x-coordinate accessor.
|
124 | * The default x-coordinate accessor is a functions which accepts as input a two-element array of numbers
|
125 | * and returns the element at index 0.
|
126 | */
|
127 | x(): (d: Datum) => number;
|
128 | /**
|
129 | * Sets the x-coordinate accessor and returns the density contour estimator.
|
130 | *
|
131 | * @param x An x-coordinate accessor function, which accepts as input an element of the input data array and returns the
|
132 | * x-coordinate.
|
133 | */
|
134 | x(x: (d: Datum) => number): this;
|
135 |
|
136 | /**
|
137 | * Returns the current y-coordinate accessor.
|
138 | * The default y-coordinate accessor is a functions which accepts as input a two-element array of numbers
|
139 | * and returns the element at index 1.
|
140 | */
|
141 | y(): (d: Datum) => number;
|
142 | /**
|
143 | * Sets the y-coordinate accessor and returns the density contour estimator.
|
144 | *
|
145 | * @param y An y-coordinate accessor function, which accepts as input an element of the input data array and returns the
|
146 | * y-coordinate.
|
147 | */
|
148 | y(y: (d: Datum) => number): this;
|
149 |
|
150 | /**
|
151 | * Returns the current point weight accessor.
|
152 | */
|
153 | weight(): (d: Datum) => number;
|
154 |
|
155 | /**
|
156 | * Sets the point weight accessor and returns the density contour estimator.
|
157 | *
|
158 | * @param weight A point weight accessor function.
|
159 | */
|
160 | weight(weight: (d: Datum) => number): this;
|
161 |
|
162 | /**
|
163 | * Returns the current size, which defaults to [960, 500].
|
164 | */
|
165 | size(): [number, number];
|
166 | /**
|
167 | * Sets the size of the density estimator to the specified bounds and returns the density contour estimator.
|
168 | *
|
169 | * @param size The size is specified as an array [width, height], where width is the maximum x-value and height is the maximum y-value.
|
170 | */
|
171 | size(size: [number, number]): this;
|
172 |
|
173 | /**
|
174 | * Returns the current cell size, which defaults to 4.
|
175 | */
|
176 | cellSize(): number;
|
177 | /**
|
178 | * Sets the size of individual cells in the underlying bin grid to the specified positive integer and returns the density contour estimator.
|
179 | *
|
180 | * The cell size is rounded down to the nearest power of two. Smaller cells produce more detailed contour polygons, but are more expensive to compute.
|
181 | *
|
182 | * @param cellSize Cell size, a positive integer.
|
183 | */
|
184 | cellSize(cellSize: number): this;
|
185 |
|
186 | /**
|
187 | * Returns the current threshold generator, which by default generates about twenty nicely-rounded density thresholds.
|
188 | */
|
189 | thresholds(): ThresholdCountGenerator<number> | ThresholdNumberArrayGenerator<number>;
|
190 | /**
|
191 | * Sets the threshold generator to the specified function or array and returns this contour generator.
|
192 | * Thresholds are defined as an array of values [x0, x1, …].
|
193 | * The first generated density contour corresponds to the area where the estimated density is greater than or equal to x0;
|
194 | * the second contour corresponds to the area where the estimated density is greater than or equal to x1, and so on.
|
195 | * Thus, there is exactly one generated MultiPolygon geometry object for each specified threshold value; the threshold value is exposed as geometry.value.
|
196 | * The first value x0 should typically be greater than zero.
|
197 | * If a count is specified instead of an array of thresholds, then approximately count uniformly-spaced nicely-rounded thresholds will be generated; see d3.ticks.
|
198 | */
|
199 | thresholds(thresholds: number | number[] | ThresholdCountGenerator<number> | ThresholdNumberArrayGenerator<number>): this;
|
200 |
|
201 | /**
|
202 | * Returns the current bandwidth, which defaults to 20.4939….
|
203 | */
|
204 | bandwidth(): number;
|
205 | /**
|
206 | * Sets the bandwidth (the standard deviation) of the Gaussian kernel and returns the density contour estimator.
|
207 | *
|
208 | * @param bandwidth Bandwidth (the standard deviation) of the Gaussian kernel.
|
209 | * The specified bandwidth is currently rounded to the nearest supported value by this implementation, and must be nonnegative.
|
210 | */
|
211 | bandwidth(bandwidth: number): this;
|
212 | }
|
213 |
|
214 | /**
|
215 | * Construct a new contour generator for density estimates.
|
216 | *
|
217 | * The generic refers to the data type of an element in the data array
|
218 | * used with the density contour generator. If omitted, the default setting assumes that,
|
219 | * the elements of the data array used with the density contour generator are two-element arrays.
|
220 | * The first element corresponds to the x-dimension, the second to the y-dimension.
|
221 | *
|
222 | * Important: ensure that the x- and y-accessor functions are configured to
|
223 | * match the data type used for the generic Datum.
|
224 | */
|
225 | // tslint:disable-next-line:no-unnecessary-generics
|
226 | export function contourDensity<Datum = [number, number]>(): ContourDensity<Datum>;
|