1 | // Type definitions for D3JS d3-shape module 3.0
|
2 | // Project: https://github.com/d3/d3-shape/, https://d3js.org/d3-shape
|
3 | // Definitions by: Tom Wanzek <https://github.com/tomwanzek>
|
4 | // Alex Ford <https://github.com/gustavderdrache>
|
5 | // Boris Yankov <https://github.com/borisyankov>
|
6 | // denisname <https://github.com/denisname>
|
7 | // Nathan Bierema <https://github.com/Methuselah96>
|
8 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
9 |
|
10 | // Last module patch version validated against: 3.0.1
|
11 |
|
12 | import { Path } from 'd3-path';
|
13 |
|
14 | declare global {
|
15 | interface CanvasRenderingContext2D {} // tslint:disable-line no-empty-interface
|
16 | }
|
17 |
|
18 | // -----------------------------------------------------------------------------------
|
19 | // Shared Types and Interfaces
|
20 | // -----------------------------------------------------------------------------------
|
21 |
|
22 | /**
|
23 | * @deprecated
|
24 | * This interface is used to bridge the gap between two incompatible versions of TypeScript (see [#25944](https://github.com/Microsoft/TypeScript/pull/25944)).
|
25 | * Use `CanvasPathMethods` instead with TS <= 3.0 and `CanvasPath` with TS >= 3.1.
|
26 | */
|
27 | export interface CanvasPath_D3Shape {
|
28 | arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
|
29 | arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
30 | bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
|
31 | closePath(): void;
|
32 | ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
|
33 | lineTo(x: number, y: number): void;
|
34 | moveTo(x: number, y: number): void;
|
35 | quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
|
36 | rect(x: number, y: number, w: number, h: number): void;
|
37 | }
|
38 |
|
39 | // -----------------------------------------------------------------------------------
|
40 | // Arc Generator
|
41 | // -----------------------------------------------------------------------------------
|
42 |
|
43 | /**
|
44 | * Interface corresponding to the minimum data type assumed by the accessor functions of the Arc generator.
|
45 | */
|
46 | export interface DefaultArcObject {
|
47 | /**
|
48 | * Inner radius of arc.
|
49 | */
|
50 | innerRadius: number;
|
51 | /**
|
52 | * Outer radius of arc.
|
53 | */
|
54 | outerRadius: number;
|
55 | /**
|
56 | * Start angle of arc. The angle is specified in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
57 | */
|
58 | startAngle: number;
|
59 | /**
|
60 | * End angle of arc. The angle is specified in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
61 | */
|
62 | endAngle: number;
|
63 | /**
|
64 | * Optional. Pad angle of arc in radians.
|
65 | */
|
66 | padAngle?: number | undefined;
|
67 | }
|
68 |
|
69 | /**
|
70 | * The arc generator produces a circular or annular sector, as in a pie or donut chart.
|
71 | *
|
72 | * If the difference between the start and end angles (the angular span) is greater than τ, the arc generator will produce a complete circle or annulus.
|
73 | * If it is less than τ, arcs may have rounded corners and angular padding. Arcs are always centered at ⟨0,0⟩; use a transform (see: SVG, Canvas) to move the arc to a different position.
|
74 | *
|
75 | * See also the pie generator, which computes the necessary angles to represent an array of data as a pie or donut chart; these angles can then be passed to an arc generator.
|
76 | *
|
77 | * The first generic corresponds to the type of the "this" context within which the arc generator and its accessor functions will be invoked.
|
78 | *
|
79 | * The second generic corresponds to the datum type for which the arc is to be generated.
|
80 | */
|
81 | export interface Arc<This, Datum> {
|
82 | /**
|
83 | * Generates an arc for the given arguments.
|
84 | *
|
85 | * IMPORTANT: If the rendering context of the arc generator is null,
|
86 | * then the arc is returned as a path data string.
|
87 | *
|
88 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
89 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
90 | *
|
91 | * @param d The datum for which the arc is to be generated.
|
92 | */
|
93 | (this: This, d: Datum, ...args: any[]): string | null;
|
94 | /**
|
95 | * Generates an arc for the given arguments.
|
96 | *
|
97 | * IMPORTANT: If the arc generator has been configured with a rendering context,
|
98 | * then the arc is rendered to this context as a sequence of path method calls and this function returns void.
|
99 | *
|
100 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
101 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
102 | *
|
103 | * @param d The datum for which the arc is to be generated.
|
104 | */
|
105 | (this: This, d: Datum, ...args: any[]): void;
|
106 |
|
107 | /**
|
108 | * Computes the midpoint [x, y] of the center line of the arc that would be generated by the given arguments.
|
109 | *
|
110 | * To be consistent with the generated arc, the accessors must be deterministic, i.e., return the same value given the same arguments.
|
111 | * The midpoint is defined as (startAngle + endAngle) / 2 and (innerRadius + outerRadius) / 2.
|
112 | *
|
113 | * Note that this is not the geometric center of the arc, which may be outside the arc;
|
114 | * this method is merely a convenience for positioning labels.
|
115 | *
|
116 | * The method is invoked in the same "this" context as the generator was invoked in and
|
117 | * receives the same arguments that are passed into the arc generator.
|
118 | *
|
119 | * @param d The datum for which the arc is to be generated.
|
120 | */
|
121 | centroid(d: Datum, ...args: any[]): [number, number];
|
122 |
|
123 | /**
|
124 | * Returns the current inner radius accessor, which defaults to a function returning the innerRadius property
|
125 | * of the first argument passed into it.
|
126 | */
|
127 | innerRadius(): (this: This, d: Datum, ...args: any[]) => number;
|
128 | /**
|
129 | * Sets the inner radius to the specified number and returns this arc generator.
|
130 | *
|
131 | * Specifying the inner radius as a function is useful for constructing a stacked polar bar chart, often in conjunction with a sqrt scale.
|
132 | * More commonly, a constant inner radius is used for a donut or pie chart. If the outer radius is smaller than the inner radius, the inner and outer radii are swapped.
|
133 | * A negative value is treated as zero.
|
134 | *
|
135 | * @param radius Constant radius.
|
136 | */
|
137 | innerRadius(radius: number): this;
|
138 | /**
|
139 | * Sets the inner radius to the specified function and returns this arc generator.
|
140 | *
|
141 | * Specifying the inner radius as a function is useful for constructing a stacked polar bar chart, often in conjunction with a sqrt scale.
|
142 | * More commonly, a constant inner radius is used for a donut or pie chart. If the outer radius is smaller than the inner radius, the inner and outer radii are swapped.
|
143 | * A negative value is treated as zero.
|
144 | *
|
145 | * @param radius An accessor function returning a number to be used as a radius. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
146 | * receives the same arguments that were passed into the arc generator.
|
147 | */
|
148 | innerRadius(radius: (this: This, d: Datum, ...args: any[]) => number): this;
|
149 |
|
150 | /**
|
151 | * Returns the current outer radius accessor, which defaults to a function returning the outerRadius property
|
152 | * of the first argument passed into it.
|
153 | */
|
154 | outerRadius(): (this: This, d: Datum, ...args: any[]) => number;
|
155 | /**
|
156 | * Sets the outer radius to the specified number and returns this arc generator.
|
157 | *
|
158 | * Specifying the outer radius as a function is useful for constructing a coxcomb or polar bar chart,
|
159 | * often in conjunction with a sqrt scale. More commonly, a constant outer radius is used for a pie or donut chart.
|
160 | * If the outer radius is smaller than the inner radius, the inner and outer radii are swapped.
|
161 | * A negative value is treated as zero.
|
162 | *
|
163 | * @param radius Constant radius.
|
164 | */
|
165 | outerRadius(radius: number): this;
|
166 | /**
|
167 | * Sets the outer radius to the specified function and returns this arc generator.
|
168 | *
|
169 | * Specifying the outer radius as a function is useful for constructing a coxcomb or polar bar chart,
|
170 | * often in conjunction with a sqrt scale. More commonly, a constant outer radius is used for a pie or donut chart.
|
171 | * If the outer radius is smaller than the inner radius, the inner and outer radii are swapped.
|
172 | * A negative value is treated as zero.
|
173 | *
|
174 | * @param radius An accessor function returning a number to be used as a radius. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
175 | * receives the same arguments that were passed into the arc generator.
|
176 | */
|
177 | outerRadius(radius: (this: This, d: Datum, ...args: any[]) => number): this;
|
178 |
|
179 | /**
|
180 | * Returns the current corner radius accessor, which defaults to a function returning a constant value of zero.
|
181 | */
|
182 | cornerRadius(): (this: This, d: Datum, ...args: any[]) => number;
|
183 | /**
|
184 | * Sets the corner radius to the specified number and returns this arc generator.
|
185 | *
|
186 | * If the corner radius is greater than zero, the corners of the arc are rounded using circles of the given radius.
|
187 | * For a circular sector, the two outer corners are rounded; for an annular sector, all four corners are rounded.
|
188 | *
|
189 | * The corner radius may not be larger than (outerRadius - innerRadius) / 2.
|
190 | * In addition, for arcs whose angular span is less than π, the corner radius may be reduced as two adjacent rounded corners intersect.
|
191 | * This is occurs more often with the inner corners.
|
192 | *
|
193 | * @param radius Constant radius.
|
194 | */
|
195 | cornerRadius(radius: number): this;
|
196 | /**
|
197 | * Sets the corner radius to the specified function and returns this arc generator.
|
198 | *
|
199 | * The corner radius may not be larger than (outerRadius - innerRadius) / 2.
|
200 | * In addition, for arcs whose angular span is less than π, the corner radius may be reduced as two adjacent rounded corners intersect.
|
201 | * This is occurs more often with the inner corners.
|
202 | *
|
203 | * @param radius An accessor function returning a number to be used as a radius. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
204 | * receives the same arguments that were passed into the arc generator.
|
205 | */
|
206 | cornerRadius(radius: (this: This, d: Datum, ...args: any[]) => number): this;
|
207 |
|
208 | /**
|
209 | * Returns the current start angle accessor, which defaults to a function returning the startAngle property
|
210 | * of the first argument passed into it.
|
211 | */
|
212 | startAngle(): (this: This, d: Datum, ...args: any[]) => number;
|
213 | /**
|
214 | * Sets the start angle to the specified number and returns this arc generator.
|
215 | *
|
216 | * The angle is specified in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
217 | * If |endAngle - startAngle| ≥ τ, a complete circle or annulus is generated rather than a sector.
|
218 | *
|
219 | * @param angle Constant angle in radians.
|
220 | */
|
221 | startAngle(angle: number): this;
|
222 | /**
|
223 | * Sets the start angle to the specified function and returns this arc generator.
|
224 | *
|
225 | * The angle is specified in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
226 | * If |endAngle - startAngle| ≥ τ, a complete circle or annulus is generated rather than a sector.
|
227 | *
|
228 | * @param angle An accessor function returning a number in radians to be used as an angle. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
229 | * receives the same arguments that were passed into the arc generator.
|
230 | */
|
231 | startAngle(angle: (this: This, d: Datum, ...args: any[]) => number): this;
|
232 |
|
233 | /**
|
234 | * Returns the current end angle accessor, which defaults to a function returning the endAngle property
|
235 | * of the first argument passed into it.
|
236 | */
|
237 | endAngle(): (this: This, d: Datum, ...args: any[]) => number;
|
238 | /**
|
239 | * Sets the end angle to the specified number and returns this arc generator.
|
240 | *
|
241 | * The angle is specified in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
242 | * If |endAngle - startAngle| ≥ τ, a complete circle or annulus is generated rather than a sector.
|
243 | *
|
244 | * @param angle Constant angle in radians.
|
245 | */
|
246 | endAngle(angle: number): this;
|
247 | /**
|
248 | * Sets the end angle to the specified function and returns this arc generator.
|
249 | *
|
250 | * The angle is specified in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
251 | * If |endAngle - startAngle| ≥ τ, a complete circle or annulus is generated rather than a sector.
|
252 | *
|
253 | * @param angle An accessor function returning a number in radians to be used as an angle. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
254 | * receives the same arguments that were passed into the arc generator.
|
255 | */
|
256 | endAngle(angle: (this: This, d: Datum, ...args: any[]) => number): this;
|
257 |
|
258 | /**
|
259 | * Returns the current pad angle accessor, which defaults to a function returning the padAngle property
|
260 | * of the first argument passed into it, or false if no data are passed in or the property is not defined.
|
261 | */
|
262 | padAngle(): (this: This, d: Datum, ...args: any[]) => number | undefined;
|
263 | /**
|
264 | * Sets the pad angle to the specified number and returns this arc generator.
|
265 | *
|
266 | * The pad angle is converted to a fixed linear distance separating adjacent arcs, defined as padRadius * padAngle. This distance is subtracted equally from the start and end of the arc.
|
267 | * If the arc forms a complete circle or annulus, as when |endAngle - startAngle| ≥ τ, the pad angle is ignored. If the inner radius or angular span is small relative to the pad angle,
|
268 | * it may not be possible to maintain parallel edges between adjacent arcs. In this case, the inner edge of the arc may collapse to a point, similar to a circular sector.
|
269 | * For this reason, padding is typically only applied to annular sectors (i.e., when innerRadius is positive).
|
270 | *
|
271 | * The recommended minimum inner radius when using padding is outerRadius * padAngle / sin(θ), where θ is the angular span of the smallest arc before padding.
|
272 | * For example, if the outer radius is 200 pixels and the pad angle is 0.02 radians, a reasonable θ is 0.04 radians, and a reasonable inner radius is 100 pixels.
|
273 | *
|
274 | * Often, the pad angle is not set directly on the arc generator, but is instead computed by the pie generator so as to ensure that the area of padded arcs is proportional to their value;
|
275 | * see pie.padAngle. See the pie padding animation for illustration.
|
276 | * If you apply a constant pad angle to the arc generator directly, it tends to subtract disproportionately from smaller arcs, introducing distortion.
|
277 | *
|
278 | * @param angle Constant angle in radians.
|
279 | */
|
280 | padAngle(angle: number | undefined): this;
|
281 | /**
|
282 | * Sets the pad angle to the specified function and returns this arc generator.
|
283 | *
|
284 | * The pad angle is converted to a fixed linear distance separating adjacent arcs, defined as padRadius * padAngle. This distance is subtracted equally from the start and end of the arc.
|
285 | * If the arc forms a complete circle or annulus, as when |endAngle - startAngle| ≥ τ, the pad angle is ignored. If the inner radius or angular span is small relative to the pad angle,
|
286 | * it may not be possible to maintain parallel edges between adjacent arcs. In this case, the inner edge of the arc may collapse to a point, similar to a circular sector.
|
287 | * For this reason, padding is typically only applied to annular sectors (i.e., when innerRadius is positive).
|
288 | *
|
289 | * The recommended minimum inner radius when using padding is outerRadius * padAngle / sin(θ), where θ is the angular span of the smallest arc before padding.
|
290 | * For example, if the outer radius is 200 pixels and the pad angle is 0.02 radians, a reasonable θ is 0.04 radians, and a reasonable inner radius is 100 pixels.
|
291 | *
|
292 | * Often, the pad angle is not set directly on the arc generator, but is instead computed by the pie generator so as to ensure that the area of padded arcs is proportional to their value;
|
293 | * see pie.padAngle. See the pie padding animation for illustration.
|
294 | * If you apply a constant pad angle to the arc generator directly, it tends to subtract disproportionately from smaller arcs, introducing distortion.
|
295 | *
|
296 | * @param angle An accessor function returning a number in radians to be used as an angle. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
297 | * receives the same arguments that were passed into the arc generator.
|
298 | */
|
299 | padAngle(angle: (this: This, d: Datum, ...args: any[]) => number | undefined): this;
|
300 |
|
301 | /**
|
302 | * Returns the current pad radius accessor, which defaults to null, indicating that the pad radius should be automatically computed as sqrt(innerRadius * innerRadius + outerRadius * outerRadius).
|
303 | */
|
304 | padRadius(): ((this: This, d: Datum, ...args: any[]) => number) | null;
|
305 | /**
|
306 | * Sets the pad radius to null indicating that the pad radius should be automatically computed as sqrt(innerRadius * innerRadius + outerRadius * outerRadius), and returns this arc generator.
|
307 | *
|
308 | * The pad radius determines the fixed linear distance separating adjacent arcs, defined as padRadius * padAngle.
|
309 | *
|
310 | * @param radius null to set automatic pad radius calculation.
|
311 | */
|
312 | padRadius(radius: null): this;
|
313 | /**
|
314 | * Sets the pad radius to the specified number, and returns this arc generator.
|
315 | *
|
316 | * The pad radius determines the fixed linear distance separating adjacent arcs, defined as padRadius * padAngle.
|
317 | *
|
318 | * @param radius A constant radius.
|
319 | */
|
320 | padRadius(radius: number): this;
|
321 |
|
322 | /*
|
323 | * Sets the pad radius to the specified function, and returns this arc generator.
|
324 | *
|
325 | * @param radius An accessor function returning a number to be used as a radius. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
326 | * receives the same arguments that were passed into the arc generator.
|
327 | */
|
328 | padRadius(radius: (this: This, d: Datum, ...args: any[]) => number): this;
|
329 |
|
330 | /**
|
331 | * Returns the current rendering context, which defaults to null.
|
332 | */
|
333 | context(): CanvasRenderingContext2D | null;
|
334 | /**
|
335 | * Sets the rendering context and returns this arc generator.
|
336 | *
|
337 | * If the context is not null, then the generated arc is rendered to this context as a sequence of path method calls.
|
338 | *
|
339 | * @param context The rendering context.
|
340 | */
|
341 | context(context: CanvasRenderingContext2D): this;
|
342 | /**
|
343 | * Sets the rendering context to null and returns this arc generator.
|
344 | *
|
345 | * A path data string representing the generated arc will be returned when the generator is invoked with data.
|
346 | *
|
347 | * @param context null, to remove rendering context.
|
348 | */
|
349 | context(context: null): this;
|
350 | }
|
351 |
|
352 | /**
|
353 | * Constructs a new arc generator with the default settings.
|
354 | *
|
355 | * Ensure that the accessors used with the arc generator correspond to the arguments passed into them,
|
356 | * or set them to constants as appropriate.
|
357 | */
|
358 | export function arc(): Arc<any, DefaultArcObject>;
|
359 | /**
|
360 | * Constructs a new arc generator with the default settings.
|
361 | *
|
362 | * Ensure that the accessors used with the arc generator correspond to the arguments passed into them,
|
363 | * or set them to constants as appropriate.
|
364 | *
|
365 | * The generic corresponds to the datum type representing a arc.
|
366 | */
|
367 | export function arc<Datum>(): Arc<any, Datum>;
|
368 | /**
|
369 | * Constructs a new arc generator with the default settings.
|
370 | *
|
371 | * Ensure that the accessors used with the arc generator correspond to the arguments passed into them,
|
372 | * or set them to constants as appropriate.
|
373 | *
|
374 | * The first generic corresponds to the type of the "this" context within which the arc generator and its accessor functions will be invoked.
|
375 | *
|
376 | * The second generic corresponds to the datum type representing a arc.
|
377 | */
|
378 | export function arc<This, Datum>(): Arc<This, Datum>;
|
379 |
|
380 | // -----------------------------------------------------------------------------------
|
381 | // Pie Generator
|
382 | // -----------------------------------------------------------------------------------
|
383 |
|
384 | /**
|
385 | * Element of the Arc Datums Array created by invoking the Pie generator.
|
386 | *
|
387 | * The generic refers to the data type of an element in the input array passed into the Pie generator.
|
388 | */
|
389 | export interface PieArcDatum<T> {
|
390 | /**
|
391 | * The input datum; the corresponding element in the input data array of the Pie generator.
|
392 | */
|
393 | data: T;
|
394 | /**
|
395 | * The numeric value of the arc.
|
396 | */
|
397 | value: number;
|
398 | /**
|
399 | * The zero-based sorted index of the arc.
|
400 | */
|
401 | index: number;
|
402 | /**
|
403 | * The start angle of the arc.
|
404 | * If the pie generator was configured to be used for the arc generator,
|
405 | * then the units are in radians with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
406 | */
|
407 | startAngle: number;
|
408 | /**
|
409 | * The end angle of the arc.
|
410 | * If the pie generator was configured to be used for the arc generator,
|
411 | * then the units are in radians with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
412 | */
|
413 | endAngle: number;
|
414 | /**
|
415 | * The pad angle of the arc. If the pie generator was configured to be used for the arc generator, than the units are in radians.
|
416 | */
|
417 | padAngle: number;
|
418 | }
|
419 |
|
420 | /**
|
421 | * The pie generator does not produce a shape directly, but instead computes the necessary angles to represent a tabular dataset as a pie or donut chart;
|
422 | * these angles can then be passed to an arc generator.
|
423 | *
|
424 | * The first generic corresponds to the type of the "this" context within which the pie generator and its accessor functions will be invoked.
|
425 | *
|
426 | * The second generic refers to the data type of an element in the input array passed into the Pie generator.
|
427 | */
|
428 | export interface Pie<This, Datum> {
|
429 | /**
|
430 | * Generates a pie for the given array of data, returning an array of objects representing each datum’s arc angles.
|
431 | * Any additional arguments are arbitrary; they are simply propagated to the pie generator’s accessor functions along with the this object.
|
432 | * The length of the returned array is the same as data, and each element i in the returned array corresponds to the element i in the input data.
|
433 | *
|
434 | * This representation is designed to work with the arc generator’s default startAngle, endAngle and padAngle accessors.
|
435 | * The angular units are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator,
|
436 | * you should specify angles in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
437 | *
|
438 | * @param data Array of data elements.
|
439 | */
|
440 | (this: This, data: Datum[], ...args: any[]): Array<PieArcDatum<Datum>>;
|
441 |
|
442 | /**
|
443 | * Returns the current value accessor, which defaults to a function returning the first argument passed into it.
|
444 | * The default value accessor assumes that the input data are numbers, or that they are coercible to numbers using valueOf.
|
445 | */
|
446 | value(): (d: Datum, i: number, data: Datum[]) => number;
|
447 | /**
|
448 | * Sets the value accessor to use the specified constant number and returns this pie generator.
|
449 | *
|
450 | * @param value Constant value to be used.
|
451 | */
|
452 | value(value: number): this;
|
453 | /**
|
454 | * Sets the value accessor to use the specified function and returns this pie generator.
|
455 | *
|
456 | * When a pie is generated, the value accessor will be invoked for each element in the input data array.
|
457 | * The default value accessor assumes that the input data are numbers, or that they are coercible to numbers using valueOf.
|
458 | * If your data are not simply numbers, then you should specify an accessor that returns the corresponding numeric value for a given datum.
|
459 | *
|
460 | * @param value A value accessor function, which is invoked for each element in the input data array, being passed the element d, the index i, and the array data as three arguments.
|
461 | * It returns a numeric value.
|
462 | */
|
463 | value(value: (d: Datum, i: number, data: Datum[]) => number): this;
|
464 |
|
465 | /**
|
466 | * Returns the current data comparator, which defaults to null.
|
467 | */
|
468 | sort(): ((a: Datum, b: Datum) => number) | null;
|
469 | /**
|
470 | * Sets the data comparator to the specified function and returns this pie generator.
|
471 | *
|
472 | * If both the data comparator and the value comparator are null, then arcs are positioned in the original input order.
|
473 | * Otherwise, the data is sorted according to the data comparator, and the resulting order is used. Setting the data comparator implicitly sets the value comparator to null.
|
474 | *
|
475 | * Sorting does not affect the order of the generated arc array which is always in the same order as the input data array; it merely affects the computed angles of each arc.
|
476 | * The first arc starts at the start angle and the last arc ends at the end angle.
|
477 | *
|
478 | * @param comparator A compare function takes two arguments a and b, each elements from the input data array.
|
479 | * If the arc for a should be before the arc for b, then the comparator must return a number less than zero;
|
480 | * if the arc for a should be after the arc for b, then the comparator must return a number greater than zero;
|
481 | * returning zero means that the relative order of a and b is unspecified.
|
482 | */
|
483 | sort(comparator: (a: Datum, b: Datum) => number): this;
|
484 | /**
|
485 | * Sets the data comparator to null and returns this pie generator.
|
486 | *
|
487 | * If both the data comparator and the value comparator are null, then arcs are positioned in the original input order.
|
488 | *
|
489 | * @param comparator null, to set the pie generator to use the original input order or use the sortValues comparator, if any.
|
490 | */
|
491 | sort(comparator: null): this;
|
492 |
|
493 | /**
|
494 | * Returns the current value comparator, which defaults to descending value.
|
495 | */
|
496 | sortValues(): ((a: number, b: number) => number) | null;
|
497 | /**
|
498 | * Sets the value comparator to the specified function and returns this pie generator.
|
499 | *
|
500 | * If both the data comparator and the value comparator are null, then arcs are positioned in the original input order.
|
501 | * Otherwise, the data is sorted according to the data comparator, and the resulting order is used.
|
502 | * Setting the value comparator implicitly sets the data comparator to null.
|
503 | *
|
504 | * Sorting does not affect the order of the generated arc array which is always in the same order as the input data array;
|
505 | * it merely affects the computed angles of each arc. The first arc starts at the start angle and the last arc ends at the end angle.
|
506 | *
|
507 | * @param comparator The value comparator takes two arguments a and b which are values derived from the input data array using the value accessor, not the data elements.
|
508 | * If the arc for a should be before the arc for b, then the comparator must return a number less than zero;
|
509 | * if the arc for a should be after the arc for b, then the comparator must return a number greater than zero; returning zero means that the relative order of a and b is unspecified.
|
510 | */
|
511 | sortValues(comparator: (a: number, b: number) => number): this;
|
512 | /**
|
513 | * Sets the value comparator to null and returns this pie generator.
|
514 | *
|
515 | * If both the data comparator and the value comparator are null, then arcs are positioned in the original input order.
|
516 | *
|
517 | * @param comparator null, to set the pie generator to use the original input order or use the data comparator, if any.
|
518 | */
|
519 | sortValues(comparator: null): this;
|
520 |
|
521 | /**
|
522 | * Returns the current start angle accessor, which defaults to a function returning a constant zero.
|
523 | */
|
524 | startAngle(): (this: This, data: Datum[], ...args: any[]) => number;
|
525 | /**
|
526 | * Sets the overall start angle of the pie to the specified number and returns this pie generator.
|
527 | *
|
528 | * The default start angle is zero.
|
529 | *
|
530 | * The start angle here means the overall start angle of the pie, i.e., the start angle of the first arc.
|
531 | * The start angle accessor is invoked once, being passed the same arguments and this context as the pie generator.
|
532 | * The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator,
|
533 | * you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
534 | *
|
535 | * @param angle A constant angle.
|
536 | */
|
537 | startAngle(angle: number): this;
|
538 | /**
|
539 | * Sets the overall start angle of the pie to the specified function and returns this pie generator.
|
540 | *
|
541 | * The default start angle is zero.
|
542 | *
|
543 | * The start angle here means the overall start angle of the pie, i.e., the start angle of the first arc.
|
544 | * The start angle accessor is invoked once, being passed the same arguments and this context as the pie generator.
|
545 | * The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator,
|
546 | * you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
547 | *
|
548 | * @param angle An angle accessor function, which is invoked once, being passed the same arguments and this context as the pie generator.
|
549 | */
|
550 | startAngle(angle: (this: This, data: Datum[], ...args: any[]) => number): this;
|
551 |
|
552 | /**
|
553 | * Returns the current end angle accessor, which defaults to a function returning a constant 2*pi.
|
554 | */
|
555 | endAngle(): (this: This, data: Datum[], ...args: any[]) => number;
|
556 | /**
|
557 | * Sets the overall end angle of the pie to the specified number and returns this pie generator.
|
558 | *
|
559 | * The default end angle is 2*pi.
|
560 | *
|
561 | * The end angle here means the overall end angle of the pie, i.e., the end angle of the last arc.
|
562 | * The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator,
|
563 | * you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
564 | *
|
565 | * The value of the end angle is constrained to startAngle ± τ, such that |endAngle - startAngle| ≤ τ.
|
566 | *
|
567 | * @param angle A constant angle.
|
568 | */
|
569 | endAngle(angle: number): this;
|
570 | /**
|
571 | * Sets the overall end angle of the pie to the specified function and returns this pie generator.
|
572 | *
|
573 | * The default end angle is 2*pi.
|
574 | *
|
575 | * The end angle here means the overall end angle of the pie, i.e., the end angle of the last arc.
|
576 | * The end angle accessor is invoked once, being passed the same arguments and this context as the pie generator.
|
577 | * The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator,
|
578 | * you should specify an angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
579 | *
|
580 | * The value of the end angle is constrained to startAngle ± τ, such that |endAngle - startAngle| ≤ τ.
|
581 | *
|
582 | * @param angle An angle accessor function, which is invoked once, being passed the same arguments and this context as the pie generator.
|
583 | */
|
584 | endAngle(angle: (this: This, data: Datum[], ...args: any[]) => number): this;
|
585 |
|
586 | /**
|
587 | * Returns the current pad angle accessor, which defaults to a function returning a constant zero.
|
588 | */
|
589 | padAngle(): (this: This, data: Datum[], ...args: any[]) => number;
|
590 | /**
|
591 | * Sets the pad angle to the specified number and returns this pie generator.
|
592 | *
|
593 | * The pad angle here means the angular separation between each adjacent arc.
|
594 | * The total amount of padding reserved is the specified angle times the number of elements in the input data array, and at most |endAngle - startAngle|;
|
595 | * the remaining space is then divided proportionally by value such that the relative area of each arc is preserved.
|
596 | * The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians.
|
597 | *
|
598 | * @param angle A constant angle.
|
599 | */
|
600 | padAngle(angle: number): this;
|
601 | /**
|
602 | * Sets the pad angle to the specified function and returns this pie generator.
|
603 | *
|
604 | * The pad angle here means the angular separation between each adjacent arc.
|
605 | * The total amount of padding reserved is the specified angle times the number of elements in the input data array, and at most |endAngle - startAngle|;
|
606 | * the remaining space is then divided proportionally by value such that the relative area of each arc is preserved.
|
607 | * The pad angle accessor is invoked once, being passed the same arguments and this context as the pie generator.
|
608 | * The units of angle are arbitrary, but if you plan to use the pie generator in conjunction with an arc generator, you should specify an angle in radians.
|
609 | *
|
610 | * @param angle An angle accessor function, which is invoked once, being passed the same arguments and this context as the pie generator.
|
611 | */
|
612 | padAngle(angle: (this: This, data: Datum[], ...args: any[]) => number): this;
|
613 | }
|
614 |
|
615 | /**
|
616 | * Constructs a new pie generator with the default settings.
|
617 | *
|
618 | * Ensure that the accessors used with the pie generator correspond to the arguments passed into them,
|
619 | * or set them to constants as appropriate.
|
620 | */
|
621 | export function pie(): Pie<any, number | { valueOf(): number }>;
|
622 | /**
|
623 | * Constructs a new pie generator with the default settings.
|
624 | *
|
625 | * Ensure that the accessors used with the pie generator correspond to the arguments passed into them,
|
626 | * or set them to constants as appropriate.
|
627 | *
|
628 | * The generic refers to the data type of an element in the input array passed into the Pie generator.
|
629 | */
|
630 | export function pie<Datum>(): Pie<any, Datum>;
|
631 | /**
|
632 | * Constructs a new pie generator with the default settings.
|
633 | *
|
634 | * Ensure that the accessors used with the pie generator correspond to the arguments passed into them,
|
635 | * or set them to constants as appropriate.
|
636 | *
|
637 | * The first generic corresponds to the type of the "this" context within which the pie generator and its accessor functions will be invoked.
|
638 | *
|
639 | * The second generic refers to the data type of an element in the input array passed into the Pie generator.
|
640 | */
|
641 | export function pie<This, Datum>(): Pie<This, Datum>;
|
642 |
|
643 | // -----------------------------------------------------------------------------------
|
644 | // Line Generators
|
645 | // -----------------------------------------------------------------------------------
|
646 |
|
647 | /**
|
648 | * The line generator produces a spline or polyline, as in a line chart.
|
649 | * Lines also appear in many other visualization types, such as the links in hierarchical edge bundling.
|
650 | *
|
651 | * The generic refers to the data type of an element in the input array passed into the line generator.
|
652 | */
|
653 | export interface Line<Datum> {
|
654 | /**
|
655 | * Generates a line for the given array of data. Depending on this line generator’s associated curve,
|
656 | * the given input data may need to be sorted by x-value before being passed to the line generator.
|
657 | *
|
658 | * IMPORTANT: If the rendering context of the line generator is null,
|
659 | * then the line is returned as a path data string.
|
660 | *
|
661 | * @param data Array of data elements.
|
662 | */
|
663 | (data: Iterable<Datum> | Datum[]): string | null;
|
664 | /**
|
665 | * Generates a line for the given array of data. Depending on this line generator’s associated curve,
|
666 | * the given input data may need to be sorted by x-value before being passed to the line generator.
|
667 | *
|
668 | * IMPORTANT: If the line generator has been configured with a rendering context,
|
669 | * then the line is rendered to this context as a sequence of path method calls and this function returns void.
|
670 | *
|
671 | * @param data Array of data elements.
|
672 | */
|
673 | (data: Iterable<Datum> | Datum[]): void;
|
674 |
|
675 | /**
|
676 | * Returns the current x-coordinate accessor function, which defaults to a function returning first element of a two-element array of numbers.
|
677 | */
|
678 | x(): (d: Datum, index: number, data: Datum[]) => number;
|
679 | /**
|
680 | * Sets the x accessor to the specified number and returns this line generator.
|
681 | *
|
682 | * @param x A constant x-coordinate value.
|
683 | */
|
684 | x(x: number): this;
|
685 | /**
|
686 | * Sets the x accessor to the specified function and returns this line generator.
|
687 | *
|
688 | * When a line is generated, the x accessor will be invoked for each defined element in the input data array.
|
689 | *
|
690 | * The default x accessor assumes that the input data are two-element arrays of numbers. If your data are in a different format, or if you wish to transform the data before rendering,
|
691 | * then you should specify a custom accessor.
|
692 | *
|
693 | * @param x A coordinate accessor function which returns the x-coordinate value. The x accessor will be invoked for each defined element in the input data array,
|
694 | * being passed the element d, the index i, and the array data as three arguments.
|
695 | */
|
696 | x(x: (d: Datum, index: number, data: Datum[]) => number): this;
|
697 |
|
698 | /**
|
699 | * Returns the current y-coordinate accessor function, which defaults to a function returning second element of a two-element array of numbers.
|
700 | */
|
701 | y(): (d: Datum, index: number, data: Datum[]) => number;
|
702 | /**
|
703 | * Sets the y accessor to the specified number and returns this line generator.
|
704 | *
|
705 | * @param y A constant y-coordinate value.
|
706 | */
|
707 | y(y: number): this;
|
708 | /**
|
709 | * Sets the y accessor to the specified function and returns this line generator.
|
710 | *
|
711 | * When a line is generated, the y accessor will be invoked for each defined element in the input data array.
|
712 | *
|
713 | * The default y accessor assumes that the input data are two-element arrays of numbers. If your data are in a different format, or if you wish to transform the data before rendering,
|
714 | * then you should specify a custom accessor.
|
715 | *
|
716 | * @param y A coordinate accessor function which returns the y-coordinate value. The y accessor will be invoked for each defined element in the input data array,
|
717 | * being passed the element d, the index i, and the array data as three arguments.
|
718 | */
|
719 | y(y: (d: Datum, index: number, data: Datum[]) => number): this;
|
720 |
|
721 | /**
|
722 | * Returns the current defined accessor, which defaults to a function returning a constant boolean value of true.
|
723 | */
|
724 | defined(): (d: Datum, index: number, data: Datum[]) => boolean;
|
725 | /**
|
726 | * Sets the defined accessor to the specified boolean and returns this line generator.
|
727 | *
|
728 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
729 | *
|
730 | * When a line is generated, the defined accessor will be invoked for each element in the input data array,
|
731 | * being passed the element d, the index i, and the array data as three arguments.
|
732 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
733 | * the x and y accessors will subsequently be evaluated and the point will be added to the current line segment.
|
734 | * Otherwise, the element will be skipped, the current line segment will be ended, and a new line segment will be generated for the next defined point.
|
735 | * As a result, the generated line may have several discrete segments.
|
736 | *
|
737 | * Note that if a line segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
738 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
739 | *
|
740 | * @param defined A boolean constant.
|
741 | */
|
742 | defined(defined: boolean): this;
|
743 | /**
|
744 | * Sets the defined accessor to the specified function and returns this line generator.
|
745 | *
|
746 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
747 | *
|
748 | * When a line is generated, the defined accessor will be invoked for each element in the input data array,
|
749 | * being passed the element d, the index i, and the array data as three arguments.
|
750 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
751 | * the x and y accessors will subsequently be evaluated and the point will be added to the current line segment.
|
752 | * Otherwise, the element will be skipped, the current line segment will be ended, and a new line segment will be generated for the next defined point.
|
753 | * As a result, the generated line may have several discrete segments.
|
754 | *
|
755 | * Note that if a line segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
756 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
757 | *
|
758 | * @param defined An accessor function which returns a boolean value. The accessor will be invoked for each defined element in the input data array,
|
759 | * being passed the element d, the index i, and the array data as three arguments.
|
760 | */
|
761 | defined(defined: (d: Datum, index: number, data: Datum[]) => boolean): this;
|
762 |
|
763 | /**
|
764 | * Returns the current curve factory, which defaults to curveLinear.
|
765 | */
|
766 | curve(): CurveFactory | CurveFactoryLineOnly;
|
767 | /**
|
768 | * Returns the current curve factory, which defaults to curveLinear.
|
769 | *
|
770 | * The generic allows to cast the curve factory to a specific type, if known.
|
771 | */
|
772 | curve<C extends CurveFactory | CurveFactoryLineOnly>(): C;
|
773 | /**
|
774 | * Sets the curve factory and returns this line generator.
|
775 | *
|
776 | * @param curve A valid curve factory.
|
777 | */
|
778 | curve(curve: CurveFactory | CurveFactoryLineOnly): this;
|
779 |
|
780 | /**
|
781 | * Returns the current rendering context, which defaults to null.
|
782 | */
|
783 | context(): CanvasRenderingContext2D | null;
|
784 | /**
|
785 | * Sets the rendering context and returns this line generator.
|
786 | *
|
787 | * If the context is not null, then the generated line is rendered to this context as a sequence of path method calls.
|
788 | *
|
789 | * @param context The rendering context.
|
790 | */
|
791 | context(context: CanvasRenderingContext2D): this;
|
792 | /**
|
793 | * Sets the rendering context to null and returns this line generator.
|
794 | *
|
795 | * A path data string representing the generated line will be returned when the generator is invoked with data.
|
796 | *
|
797 | * @param context null, to remove rendering context.
|
798 | */
|
799 | context(context: null): this;
|
800 | }
|
801 |
|
802 | /**
|
803 | * Constructs a new line generator with the default settings.
|
804 | *
|
805 | * If x or y are specified, sets the corresponding accessors to the specified function or number and returns this line generator.
|
806 | *
|
807 | * The generic refers to the data type of an element in the input array passed into the line generator.
|
808 | *
|
809 | * @param x Sets the x accessor
|
810 | * @param y Sets the y accessor
|
811 | */
|
812 | export function line<Datum = [number, number]>(
|
813 | x?: number | ((d: Datum, index: number, data: Datum[]) => number),
|
814 | y?: number | ((d: Datum, index: number, data: Datum[]) => number)
|
815 | ): Line<Datum>;
|
816 |
|
817 | /**
|
818 | * The radial line generator produces a spline or polyline, as in a line chart.
|
819 | *
|
820 | * A radial line generator is equivalent to the standard Cartesian line generator,
|
821 | * except the x and y accessors are replaced with angle and radius accessors.
|
822 | * Radial lines are always positioned relative to ⟨0,0⟩; use a transform (see: SVG, Canvas) to change the origin.
|
823 | *
|
824 | * The generic refers to the data type of an element in the input array passed into the line generator.
|
825 | */
|
826 | export interface LineRadial<Datum> {
|
827 | /**
|
828 | * Generates a radial line for the given array of data. Depending on this radial line generator’s associated curve,
|
829 | * the given input data may need to be sorted by x-value before being passed to the line generator.
|
830 | *
|
831 | * IMPORTANT: If the rendering context of the radial line generator is null,
|
832 | * then the radial line is returned as a path data string.
|
833 | *
|
834 | * @param data Array of data elements.
|
835 | */
|
836 | (data: Iterable<Datum> | Datum[]): string | null;
|
837 | /**
|
838 | * Generates a radial line for the given array of data. Depending on this radial line generator’s associated curve,
|
839 | * the given input data may need to be sorted by x-value before being passed to the radial line generator.
|
840 | *
|
841 | * IMPORTANT: If the radial line generator has been configured with a rendering context,
|
842 | * then the radial line is rendered to this context as a sequence of path method calls and this function returns void.
|
843 | *
|
844 | * @param data Array of data elements.
|
845 | */
|
846 | (data: Iterable<Datum> | Datum[]): void;
|
847 |
|
848 | /**
|
849 | * Returns the current angle accessor function, which defaults to a function returning first element of a two-element array of numbers.
|
850 | */
|
851 | angle(): (d: Datum, index: number, data: Datum[]) => number;
|
852 | /**
|
853 | * Sets the angle accessor to the specified number and returns this radial line generator.
|
854 | *
|
855 | * @param angle A constant angle value in radians, with 0 at -y (12 o’clock).
|
856 | */
|
857 | angle(angle: number): this;
|
858 | /**
|
859 | * Sets the angle accessor to the specified function and returns this radial line generator.
|
860 | *
|
861 | * When a radial line is generated, the angle accessor will be invoked for each defined element in the input data array.
|
862 | *
|
863 | * The default angle accessor assumes that the input data are two-element arrays of numbers. If your data are in a different format, or if you wish to transform the data before rendering,
|
864 | * then you should specify a custom accessor.
|
865 | *
|
866 | * @param angle An angle accessor function which returns the angle value in radians, with 0 at -y (12 o’clock). The angle accessor will be invoked for each defined element in the input data array,
|
867 | * being passed the element d, the index i, and the array data as three arguments.
|
868 | */
|
869 | angle(angle: (d: Datum, index: number, data: Datum[]) => number): this;
|
870 |
|
871 | /**
|
872 | * Returns the current radius accessor function, which defaults to a function returning second element of a two-element array of numbers.
|
873 | */
|
874 | radius(): (d: Datum, index: number, data: Datum[]) => number;
|
875 | /**
|
876 | * Sets the radius accessor to the specified number and returns this radial line generator.
|
877 | *
|
878 | * @param radius A constant radius value.
|
879 | */
|
880 | radius(radius: number): this;
|
881 | /**
|
882 | * Sets the radius accessor to the specified function and returns this radial line generator.
|
883 | *
|
884 | * When a radial line is generated, the radius accessor will be invoked for each defined element in the input data array.
|
885 | *
|
886 | * The default radius accessor assumes that the input data are two-element arrays of numbers. If your data are in a different format, or if you wish to transform the data before rendering,
|
887 | * then you should specify a custom accessor.
|
888 | *
|
889 | * @param radius A radius accessor function which returns the radius value. The radius accessor will be invoked for each defined element in the input data array,
|
890 | * being passed the element d, the index i, and the array data as three arguments.
|
891 | */
|
892 | radius(radius: (d: Datum, index: number, data: Datum[]) => number): this;
|
893 |
|
894 | /**
|
895 | * Returns the current defined accessor, which defaults to a function returning a constant boolean value of true.
|
896 | */
|
897 | defined(): (d: Datum, index: number, data: Datum[]) => boolean;
|
898 | /**
|
899 | * Sets the defined accessor to the specified boolean and returns this radial line generator.
|
900 | *
|
901 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
902 | *
|
903 | * When a radial line is generated, the defined accessor will be invoked for each element in the input data array,
|
904 | * being passed the element d, the index i, and the array data as three arguments.
|
905 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
906 | * the angle and radius accessors will subsequently be evaluated and the point will be added to the current radial line segment.
|
907 | * Otherwise, the element will be skipped, the current radial line segment will be ended, and a new radial line segment will be generated for the next defined point.
|
908 | * As a result, the generated radial line may have several discrete segments.
|
909 | *
|
910 | * Note that if a radial line segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
911 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
912 | *
|
913 | * @param defined A boolean constant.
|
914 | */
|
915 | defined(defined: boolean): this;
|
916 | /**
|
917 | * Sets the defined accessor to the specified function and returns this radial line generator.
|
918 | *
|
919 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
920 | *
|
921 | * When a radial line is generated, the defined accessor will be invoked for each element in the input data array,
|
922 | * being passed the element d, the index i, and the array data as three arguments.
|
923 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
924 | * the angle and radius accessors will subsequently be evaluated and the point will be added to the current radial line segment.
|
925 | * Otherwise, the element will be skipped, the current radial line segment will be ended, and a new radial line segment will be generated for the next defined point.
|
926 | * As a result, the generated radial line may have several discrete segments.
|
927 | *
|
928 | * Note that if a radial line segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
929 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
930 | *
|
931 | * @param defined An accessor function which returns a boolean value. The accessor will be invoked for each defined element in the input data array,
|
932 | * being passed the element d, the index i, and the array data as three arguments.
|
933 | */
|
934 | defined(defined: (d: Datum, index: number, data: Datum[]) => boolean): this;
|
935 |
|
936 | /**
|
937 | * Returns the current curve factory, which defaults to curveLinear.
|
938 | */
|
939 | curve(): CurveFactory | CurveFactoryLineOnly;
|
940 | /**
|
941 | * Returns the current curve factory, which defaults to curveLinear.
|
942 | *
|
943 | * The generic allows to cast the curve factory to a specific type, if known.
|
944 | */
|
945 | curve<C extends CurveFactory | CurveFactoryLineOnly>(): C;
|
946 | /**
|
947 | * Sets the curve factory and returns this radial line generator.
|
948 | *
|
949 | * Note that curveMonotoneX or curveMonotoneY are not recommended for radial lines because they assume that the data is monotonic in x or y,
|
950 | * which is typically untrue of radial lines.
|
951 | *
|
952 | * @param curve A valid curve factory.
|
953 | */
|
954 | curve(curve: CurveFactory | CurveFactoryLineOnly): this;
|
955 |
|
956 | /**
|
957 | * Returns the current rendering context, which defaults to null.
|
958 | */
|
959 | context(): CanvasRenderingContext2D | null;
|
960 | /**
|
961 | * Sets the rendering context and returns this radial line generator.
|
962 | *
|
963 | * If the context is not null, then the generated radial line is rendered to this context as a sequence of path method calls.
|
964 | *
|
965 | * @param context The rendering context.
|
966 | */
|
967 | context(context: CanvasRenderingContext2D): this;
|
968 | /**
|
969 | * Sets the rendering context to null and returns this radial line generator.
|
970 | *
|
971 | * A path data string representing the generated radial line will be returned when the generator is invoked with data.
|
972 | *
|
973 | * @param context null, to remove rendering context.
|
974 | */
|
975 | context(context: null): this;
|
976 | }
|
977 |
|
978 | /**
|
979 | * Constructs a new radial line generator with the default settings.
|
980 | *
|
981 | * Ensure that the accessors used with the radial line generator correspond to the arguments passed into them,
|
982 | * or set them to constants as appropriate.
|
983 | */
|
984 | export function lineRadial(): LineRadial<[number, number]>;
|
985 | /**
|
986 | * Constructs a new radial line generator with the default settings.
|
987 | *
|
988 | * Ensure that the accessors used with the radial line generator correspond to the arguments passed into them,
|
989 | * or set them to constants as appropriate.
|
990 | *
|
991 | * The generic refers to the data type of an element in the input array passed into the radial line generator.
|
992 | */
|
993 | export function lineRadial<Datum>(): LineRadial<Datum>;
|
994 |
|
995 | /**
|
996 | * @deprecated Use LineRadial<Datum>
|
997 | */
|
998 | export type RadialLine<Datum> = LineRadial<Datum>;
|
999 |
|
1000 | /**
|
1001 | * @deprecated Use lineRadial()
|
1002 | */
|
1003 | export function radialLine(): RadialLine<[number, number]>;
|
1004 | /**
|
1005 | * @deprecated Use lineRadial<Datum>()
|
1006 | */
|
1007 | export function radialLine<Datum>(): RadialLine<Datum>;
|
1008 |
|
1009 | // -----------------------------------------------------------------------------------
|
1010 | // Area Generators
|
1011 | // -----------------------------------------------------------------------------------
|
1012 |
|
1013 | /**
|
1014 | * The area generator produces an area, as in an area chart. An area is defined by two bounding lines, either splines or polylines.
|
1015 | * Typically, the two lines share the same x-values (x0 = x1), differing only in y-value (y0 and y1); most commonly, y0 is defined as a constant representing zero.
|
1016 | * The first line (the topline) is defined by x1 and y1 and is rendered first; the second line (the baseline) is defined by x0 and y0 and is rendered second, with the points in reverse order.
|
1017 | * With a curveLinear curve, this produces a clockwise polygon.
|
1018 | *
|
1019 | * The generic refers to the data type of an element in the input array passed into the area generator.
|
1020 | */
|
1021 | export interface Area<Datum> {
|
1022 | /**
|
1023 | * Generates an area for the given array of data. Depending on this area generator’s associated curve,
|
1024 | * the given input data may need to be sorted by x-value before being passed to the area generator.
|
1025 | *
|
1026 | * IMPORTANT: If the rendering context of the area generator is null,
|
1027 | * then the area is returned as a path data string.
|
1028 | *
|
1029 | * @param data Array of data elements.
|
1030 | */
|
1031 | (data: Iterable<Datum> | Datum[]): string | null;
|
1032 | /**
|
1033 | * Generates an area for the given array of data. Depending on this area generator’s associated curve,
|
1034 | * the given input data may need to be sorted by x-value before being passed to the area generator.
|
1035 | *
|
1036 | * IMPORTANT: If the area generator has been configured with a rendering context,
|
1037 | * then the area is rendered to this context as a sequence of path method calls and this function returns void.
|
1038 | *
|
1039 | * @param data Array of data elements.
|
1040 | */
|
1041 | (data: Iterable<Datum> | Datum[]): void;
|
1042 |
|
1043 | /**
|
1044 | * Returns the current x0 accessor. The default x0 accessor is a function returning the first element of a
|
1045 | * two-element array of numbers.
|
1046 | */
|
1047 | x(): (d: Datum, index: number, data: Datum[]) => number;
|
1048 | /**
|
1049 | * Sets x0 to a constant number x and x1 to null and returns this area generator.
|
1050 | *
|
1051 | * Setting x1 to null indicates that the previously-computed x0 value should be reused for the x1 value.
|
1052 | *
|
1053 | * @param x A constant value to be used for x0.
|
1054 | */
|
1055 | x(x: number): this;
|
1056 | /**
|
1057 | * Sets x0 to the specified function x and x1 to null and returns this area generator.
|
1058 | *
|
1059 | * The default x0 accessor assumes that the input data are two-element arrays of numbers and returns the first element.
|
1060 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1061 | *
|
1062 | * @param x An accessor function returning a value to be used for x0. The accessor will be invoked for each defined element in the input data array,
|
1063 | * being passed the element d, the index i, and the array data as three arguments.
|
1064 | */
|
1065 | x(x: (d: Datum, index: number, data: Datum[]) => number): this;
|
1066 |
|
1067 | /**
|
1068 | * Returns the current x0 accessor. The default x0 accessor is a function returning the first element of a
|
1069 | * two-element array of numbers.
|
1070 | */
|
1071 | x0(): (d: Datum, index: number, data: Datum[]) => number;
|
1072 | /**
|
1073 | * Sets x0 to a constant number and returns this area generator.
|
1074 | *
|
1075 | * @param x A constant value.
|
1076 | */
|
1077 | x0(x: number): this;
|
1078 | /**
|
1079 | * Sets x0 to the specified function and returns this area generator.
|
1080 | *
|
1081 | * The default x0 accessor assumes that the input data are two-element arrays of numbers and returns the first element.
|
1082 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1083 | *
|
1084 | * @param x An accessor function returning a value to be used for x0. The accessor will be invoked for each defined element in the input data array,
|
1085 | * being passed the element d, the index i, and the array data as three arguments.
|
1086 | */
|
1087 | x0(x: (d: Datum, index: number, data: Datum[]) => number): this;
|
1088 |
|
1089 | /**
|
1090 | * Returns the current x1 accessor, which defaults to null, indicating that the previously-computed x0 value should be reused for the x1 value.
|
1091 | */
|
1092 | x1(): ((d: Datum, index: number, data: Datum[]) => number) | null;
|
1093 | /**
|
1094 | * Sets x1 to null and returns this area generator.
|
1095 | *
|
1096 | * Setting x1 to null indicates that the previously-computed x0 value should be reused for the x1 value.
|
1097 | *
|
1098 | * @param x null.
|
1099 | */
|
1100 | x1(x: null): this;
|
1101 | /**
|
1102 | * Sets x1 to a constant number and returns this area generator.
|
1103 | *
|
1104 | * @param x A constant value.
|
1105 | */
|
1106 | x1(x: number): this;
|
1107 | /**
|
1108 | * Sets x1 to the specified function and returns this area generator.
|
1109 | *
|
1110 | * The default x1 accessor is null, indicating that the previously-computed x0 value should be reused for the x1 value.
|
1111 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1112 | *
|
1113 | * @param x An accessor function returning a value to be used for x1. The accessor will be invoked for each defined element in the input data array,
|
1114 | * being passed the element d, the index i, and the array data as three arguments.
|
1115 | */
|
1116 | x1(x: (d: Datum, index: number, data: Datum[]) => number): this;
|
1117 |
|
1118 | /**
|
1119 | * Returns the current y0 accessor. The default y0 accessor is a function returning a constant value of zero.
|
1120 | */
|
1121 | y(): (d: Datum, index: number, data: Datum[]) => number;
|
1122 | /**
|
1123 | * Sets y0 to a constant number y and y1 to null and returns this area generator.
|
1124 | *
|
1125 | * Setting y1 to null indicates that the previously-computed y0 value should be reused for the y1 value.
|
1126 | *
|
1127 | * @param y A constant value to be used for y0.
|
1128 | */
|
1129 | y(y: number): this;
|
1130 | /**
|
1131 | * Sets y0 to the accessor function y and y1 to null and returns this area generator.
|
1132 | *
|
1133 | * The default y0 accessor returns a constant value of zero.
|
1134 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1135 | *
|
1136 | * @param y An accessor function returning a value to be used for y0. The accessor will be invoked for each defined element in the input data array,
|
1137 | * being passed the element d, the index i, and the array data as three arguments.
|
1138 | */
|
1139 | y(y: (d: Datum, index: number, data: Datum[]) => number): this;
|
1140 |
|
1141 | /**
|
1142 | * Returns the current y0 accessor. The default y0 accessor is a function a constant value of zero.
|
1143 | */
|
1144 | y0(): (d: Datum, index: number, data: Datum[]) => number;
|
1145 | /**
|
1146 | * Sets y0 to a constant number and returns this area generator.
|
1147 | *
|
1148 | * @param y A constant value.
|
1149 | */
|
1150 | y0(y: number): this;
|
1151 | /**
|
1152 | * Sets y0 to the specified function and returns this area generator.
|
1153 | *
|
1154 | * The default y0 accessor is a function which returns a constant value of zero.
|
1155 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1156 | *
|
1157 | * @param y An accessor function returning a value to be used for y0. The accessor will be invoked for each defined element in the input data array,
|
1158 | * being passed the element d, the index i, and the array data as three arguments.
|
1159 | */
|
1160 | y0(y: (d: Datum, index: number, data: Datum[]) => number): this;
|
1161 |
|
1162 | /**
|
1163 | * Returns the current y1 accessor or null. The default y1 accessor is a function returning the second element of a
|
1164 | * two-element array of numbers.
|
1165 | *
|
1166 | * If the y1 accessor is null, the previously-computed y0 value is reused for the y1 value.
|
1167 | */
|
1168 | y1(): ((d: Datum, index: number, data: Datum[]) => number) | null;
|
1169 | /**
|
1170 | * Sets y1 to null and returns this area generator.
|
1171 | *
|
1172 | * Setting y1 to null indicates that the previously-computed y0 value should be reused for the y1 value.
|
1173 | *
|
1174 | * @param y null.
|
1175 | */
|
1176 | y1(y: null): this;
|
1177 | /**
|
1178 | * Sets y1 to a constant number and returns this area generator.
|
1179 | *
|
1180 | * @param y A constant value.
|
1181 | */
|
1182 | y1(y: number): this;
|
1183 | /**
|
1184 | * Sets y1 to the specified function and returns this area generator.
|
1185 | *
|
1186 | * The default y1 accessor assumes that the input data are two-element arrays of numbers and returns the second element.
|
1187 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1188 | *
|
1189 | * @param y An accessor function returning a value to be used for y1. The accessor will be invoked for each defined element in the input data array,
|
1190 | * being passed the element d, the index i, and the array data as three arguments.
|
1191 | */
|
1192 | y1(y: (d: Datum, index: number, data: Datum[]) => number): this;
|
1193 |
|
1194 | /**
|
1195 | * Returns the current defined accessor, which defaults to a function returning a constant boolean value of true.
|
1196 | */
|
1197 | defined(): (d: Datum, index: number, data: Datum[]) => boolean;
|
1198 | /**
|
1199 | * Sets the defined accessor to the specified boolean and returns this area generator.
|
1200 | *
|
1201 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
1202 | * When an area is generated, the defined accessor will be invoked for each element in the input data array, being passed the element d, the index i, and the array data as three arguments.
|
1203 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
1204 | * the x0, x1, y0 and y1 accessors will subsequently be evaluated and the point will be added to the current area segment.
|
1205 | * Otherwise, the element will be skipped, the current area segment will be ended, and a new area segment will be generated for the next defined point.
|
1206 | * As a result, the generated area may have several discrete segments.
|
1207 | *
|
1208 | * Note that if an area segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
1209 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
1210 | *
|
1211 | * @param defined A boolean constant.
|
1212 | */
|
1213 | defined(defined: boolean): this;
|
1214 | /**
|
1215 | * Sets the defined accessor to the specified function and returns this area generator.
|
1216 | *
|
1217 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
1218 | *
|
1219 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
1220 | * When an area is generated, the defined accessor will be invoked for each element in the input data array,
|
1221 | * being passed the element d, the index i, and the array data as three arguments.
|
1222 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
1223 | * the x0, x1, y0 and y1 accessors will subsequently be evaluated and the point will be added to the current area segment.
|
1224 | * Otherwise, the element will be skipped, the current area segment will be ended, and a new area segment will be generated for the next defined point.
|
1225 | * As a result, the generated area may have several discrete segments.
|
1226 | *
|
1227 | * Note that if an area segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
1228 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
1229 | *
|
1230 | * @param defined An accessor function which returns a boolean value. The accessor will be invoked for each defined element in the input data array,
|
1231 | * being passed the element d, the index i, and the array data as three arguments.
|
1232 | */
|
1233 | defined(defined: (d: Datum, index: number, data: Datum[]) => boolean): this;
|
1234 |
|
1235 | /**
|
1236 | * Returns the current curve factory, which defaults to curveLinear.
|
1237 | */
|
1238 | curve(): CurveFactory;
|
1239 | /**
|
1240 | * Returns the current curve factory, which defaults to curveLinear.
|
1241 | *
|
1242 | * The generic allows to cast the curve factory to a specific type, if known.
|
1243 | */
|
1244 | curve<C extends CurveFactory>(): C;
|
1245 | /**
|
1246 | * Sets the curve factory and returns this area generator.
|
1247 | *
|
1248 | * @param curve A valid curve factory.
|
1249 | */
|
1250 | curve(curve: CurveFactory): this;
|
1251 |
|
1252 | /**
|
1253 | * Returns the current rendering context, which defaults to null.
|
1254 | */
|
1255 | context(): CanvasRenderingContext2D | null;
|
1256 | /**
|
1257 | * Sets the rendering context and returns this area generator.
|
1258 | *
|
1259 | * If the context is not null, then the generated area is rendered to this context as a sequence of path method calls.
|
1260 | *
|
1261 | * @param context The rendering context.
|
1262 | */
|
1263 | context(context: CanvasRenderingContext2D): this;
|
1264 | /**
|
1265 | * Sets the rendering context to null and returns this area generator.
|
1266 | *
|
1267 | * A path data string representing the generated area will be returned when the generator is invoked with data.
|
1268 | *
|
1269 | * @param context null, to remove rendering context.
|
1270 | */
|
1271 | context(context: null): this;
|
1272 |
|
1273 | /**
|
1274 | * Returns a new line generator that has this area generator’s current defined accessor, curve and context.
|
1275 | * The line’s x-accessor is this area’s x0-accessor, and the line’s y-accessor is this area’s y0-accessor.
|
1276 | */
|
1277 | lineX0(): Line<Datum>;
|
1278 | /**
|
1279 | * Returns a new line generator that has this area generator’s current defined accessor, curve and context.
|
1280 | * The line’s x-accessor is this area’s x0-accessor, and the line’s y-accessor is this area’s y0-accessor.
|
1281 | */
|
1282 | lineY0(): Line<Datum>;
|
1283 |
|
1284 | /**
|
1285 | * Returns a new line generator that has this area generator’s current defined accessor, curve and context.
|
1286 | * The line’s x-accessor is this area’s x1-accessor, and the line’s y-accessor is this area’s y0-accessor.
|
1287 | */
|
1288 | lineX1(): Line<Datum>;
|
1289 | /**
|
1290 | * Returns a new line generator that has this area generator’s current defined accessor, curve and context.
|
1291 | * The line’s x-accessor is this area’s x0-accessor, and the line’s y-accessor is this area’s y1-accessor.
|
1292 | */
|
1293 | lineY1(): Line<Datum>;
|
1294 | }
|
1295 |
|
1296 | /**
|
1297 | * Constructs a new area generator with the default settings.
|
1298 | *
|
1299 | * If x, y0 or y1 are specified, sets the corresponding accessors to the specified function or number and returns this area generator.
|
1300 | *
|
1301 | * The generic refers to the data type of an element in the input array passed into the area generator.
|
1302 | *
|
1303 | * @param x Sets the x accessor.
|
1304 | * @param y0 Sets the y0 accessor.
|
1305 | * @param y1 Sets the y1 accessor.
|
1306 | */
|
1307 | export function area<Datum = [number, number]>(
|
1308 | x?: number | ((d: Datum, index: number, data: Datum[]) => number),
|
1309 | y0?: number | ((d: Datum, index: number, data: Datum[]) => number),
|
1310 | y1?: number | ((d: Datum, index: number, data: Datum[]) => number)
|
1311 | ): Area<Datum>;
|
1312 |
|
1313 | /**
|
1314 | * A radial area generator.
|
1315 | *
|
1316 | * A radial area generator is equivalent to the standard Cartesian area generator,
|
1317 | * except the x and y accessors are replaced with angle and radius accessors.
|
1318 | * Radial areas are always positioned relative to ⟨0,0⟩; use a transform (see: SVG, Canvas) to change the origin.
|
1319 | *
|
1320 | * The generic refers to the data type of an element in the input array passed into the area generator.
|
1321 | */
|
1322 | export interface AreaRadial<Datum> {
|
1323 | /**
|
1324 | * Generates a radial area for the given array of data.
|
1325 | *
|
1326 | * IMPORTANT: If the rendering context of the radial area generator is null,
|
1327 | * then the radial area is returned as a path data string.
|
1328 | *
|
1329 | * @param data Array of data elements.
|
1330 | */
|
1331 | (data: Iterable<Datum> | Datum[]): string | null;
|
1332 | /**
|
1333 | * Generates a radial area for the given array of data.
|
1334 | *
|
1335 | * IMPORTANT: If the radial area generator has been configured with a rendering context,
|
1336 | * then the radial area is rendered to this context as a sequence of path method calls and this function returns void.
|
1337 | *
|
1338 | * @param data Array of data elements.
|
1339 | */
|
1340 | (data: Iterable<Datum> | Datum[]): void;
|
1341 |
|
1342 | /**
|
1343 | * Returns the current startAngle accessor. The default startAngle accessor is a function returning the first element of a
|
1344 | * two-element array of numbers.
|
1345 | */
|
1346 | angle(): (d: Datum, index: number, data: Datum[]) => number;
|
1347 | /**
|
1348 | * Sets startAngle to a constant number angle and endAngle to null and returns this radial area generator.
|
1349 | *
|
1350 | * Setting endAngle to null indicates that the previously-computed startAngle value should be reused for the endAngle value.
|
1351 | *
|
1352 | * @param angle A constant value in radians with 0 at -y (12 o’clock).
|
1353 | */
|
1354 | angle(angle: number): this;
|
1355 | /**
|
1356 | * Sets startAngle to the specified function angle and endAngle to null and returns this radial area generator.
|
1357 | *
|
1358 | * The default startAngle accessor assumes that the input data are two-element arrays of numbers and returns the first element.
|
1359 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1360 | *
|
1361 | * @param angle An accessor function returning a value to be used for startAngle in radians with 0 at -y (12 o’clock).
|
1362 | * The accessor will be invoked for each defined element in the input data array,
|
1363 | * being passed the element d, the index i, and the array data as three arguments.
|
1364 | */
|
1365 | angle(angle: (d: Datum, index: number, data: Datum[]) => number): this;
|
1366 |
|
1367 | /**
|
1368 | * Returns the current startAngle accessor. The default startAngle accessor is a function returning the first element of a
|
1369 | * two-element array of numbers.
|
1370 | */
|
1371 | startAngle(): (d: Datum, index: number, data: Datum[]) => number;
|
1372 | /**
|
1373 | * Sets startAngle to a constant number and returns this radial area generator.
|
1374 | *
|
1375 | * @param angle A constant value in radians with 0 at -y (12 o’clock).
|
1376 | */
|
1377 | startAngle(angle: number): this;
|
1378 | /**
|
1379 | * Sets startAngle to the specified function and returns this radial area generator.
|
1380 | *
|
1381 | * The default startAngle accessor assumes that the input data are two-element arrays of numbers and returns the first element.
|
1382 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1383 | *
|
1384 | * @param angle An accessor function returning a value to be used for startAngle in radians with 0 at -y (12 o’clock).
|
1385 | * The accessor will be invoked for each defined element in the input data array,
|
1386 | * being passed the element d, the index i, and the array data as three arguments.
|
1387 | */
|
1388 | startAngle(angle: (d: Datum, index: number, data: Datum[]) => number): this;
|
1389 |
|
1390 | /**
|
1391 | * Returns the current endAngle accessor, which defaults to null, indicating that the previously-computed startAngle value should be reused for the endAngle value.
|
1392 | */
|
1393 | endAngle(): ((d: Datum, index: number, data: Datum[]) => number) | null;
|
1394 | /**
|
1395 | * Sets endAngle to null and returns this radial area generator.
|
1396 | *
|
1397 | * Setting endAngle to null indicates that the previously-computed startAngle value should be reused for the endAngle value.
|
1398 | *
|
1399 | * @param angle null.
|
1400 | */
|
1401 | endAngle(angle: null): this;
|
1402 | /**
|
1403 | * Sets endAngle to a constant number and returns this radial area generator.
|
1404 | *
|
1405 | * @param angle A constant value in radians with 0 at -y (12 o’clock).
|
1406 | */
|
1407 | endAngle(angle: number): this;
|
1408 | /**
|
1409 | * Sets endAngle to the specified function and returns this radial area generator.
|
1410 | *
|
1411 | * The default endAngle accessor is null, indicating that the previously-computed startAngle value should be reused for the endAngle value.
|
1412 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1413 | *
|
1414 | * @param angle An accessor function returning a value to be used for endAngle in radians with 0 at -y (12 o’clock).
|
1415 | * The accessor will be invoked for each defined element in the input data array,
|
1416 | * being passed the element d, the index i, and the array data as three arguments.
|
1417 | */
|
1418 | endAngle(angle: (d: Datum, index: number, data: Datum[]) => number): this;
|
1419 |
|
1420 | /**
|
1421 | * Returns the current innerRadius accessor. The default innerRadius accessor is a function returning a constant value of zero.
|
1422 | */
|
1423 | radius(): (d: Datum, index: number, data: Datum[]) => number;
|
1424 | /**
|
1425 | * Sets innerRadius to a constant number radius and outerRadius to null and returns this radial area generator.
|
1426 | *
|
1427 | * Setting outerRadius to null indicates that the previously-computed innerRadius value should be reused for the outerRadius value.
|
1428 | *
|
1429 | * @param radius A constant value to be used for innerRadius.
|
1430 | */
|
1431 | radius(radius: number): this;
|
1432 | /**
|
1433 | * Sets innerRadius to the accessor function radius and outerRadius to null and returns this radial area generator.
|
1434 | *
|
1435 | * The default innerRadius accessor returns a constant value of zero.
|
1436 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1437 | *
|
1438 | * @param radius An accessor function returning a value to be used for innerRadius. The accessor will be invoked for each defined element in the input data array,
|
1439 | * being passed the element d, the index i, and the array data as three arguments.
|
1440 | */
|
1441 | radius(radius: (d: Datum, index: number, data: Datum[]) => number): this;
|
1442 |
|
1443 | /**
|
1444 | * Returns the current innerRadius accessor. The default innerRadius accessor is a function a constant value of zero.
|
1445 | */
|
1446 | innerRadius(): (d: Datum, index: number, data: Datum[]) => number;
|
1447 | /**
|
1448 | * Sets innerRadius to a constant number and returns this radial area generator.
|
1449 | *
|
1450 | * @param radius A constant value.
|
1451 | */
|
1452 | innerRadius(radius: number): this;
|
1453 | /**
|
1454 | * Sets innerRadius to the specified function and returns this radial area generator.
|
1455 | *
|
1456 | * The default innerRadius accessor is a function which returns a constant value of zero.
|
1457 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1458 | *
|
1459 | * @param radius An accessor function returning a value to be used for innerRadius. The accessor will be invoked for each defined element in the input data array,
|
1460 | * being passed the element d, the index i, and the array data as three arguments.
|
1461 | */
|
1462 | innerRadius(radius: (d: Datum, index: number, data: Datum[]) => number): this;
|
1463 |
|
1464 | /**
|
1465 | * Returns the current outerRadius accessor or null. The default outerRadius accessor is a function returning the second element of a
|
1466 | * two-element array of numbers.
|
1467 | *
|
1468 | * If the outerRadius accessor is null, the previously-computed innerRadius value is reused for the outerRadius value.
|
1469 | */
|
1470 | outerRadius(): ((d: Datum, index: number, data: Datum[]) => number) | null;
|
1471 | /**
|
1472 | * Sets outerRadius to null and returns this radial area generator.
|
1473 | *
|
1474 | * Setting outerRadius to null indicates that the previously-computed innerRadius value should be reused for the outerRadius value.
|
1475 | *
|
1476 | * @param radius null.
|
1477 | */
|
1478 | outerRadius(radius: null): this;
|
1479 | /**
|
1480 | * Sets outerRadius to a constant number and returns this radial area generator.
|
1481 | *
|
1482 | * @param radius A constant value.
|
1483 | */
|
1484 | outerRadius(radius: number): this;
|
1485 | /**
|
1486 | * Sets outerRadius to the specified function and returns this radial area generator.
|
1487 | *
|
1488 | * The default outerRadius accessor assumes that the input data are two-element arrays of numbers and returns the second element.
|
1489 | * If your data are in a different format, or if you wish to transform the data before rendering, then you should specify a custom accessor.
|
1490 | *
|
1491 | * @param radius An accessor function returning a value to be used for outerRadius. The accessor will be invoked for each defined element in the input data array,
|
1492 | * being passed the element d, the index i, and the array data as three arguments.
|
1493 | */
|
1494 | outerRadius(radius: (d: Datum, index: number, data: Datum[]) => number): this;
|
1495 |
|
1496 | /**
|
1497 | * Returns the current defined accessor, which defaults to a function returning a constant boolean value of true.
|
1498 | */
|
1499 | defined(): (d: Datum, index: number, data: Datum[]) => boolean;
|
1500 | /**
|
1501 | * Sets the defined accessor to the specified boolean and returns this radial area generator.
|
1502 | *
|
1503 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
1504 | *
|
1505 | * When a radial area is generated, the defined accessor will be invoked for each element in the input data array, being passed the element d, the index i, and the array data as three arguments.
|
1506 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
1507 | * the startAngle, endAngle, innerRadius and outerRadius accessors will subsequently be evaluated and the point will be added to the current area segment.
|
1508 | *
|
1509 | * Otherwise, the element will be skipped, the current area segment will be ended, and a new area segment will be generated for the next defined point.
|
1510 | * As a result, the generated area may have several discrete segments.
|
1511 | *
|
1512 | * Note that if an area segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
1513 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
1514 | *
|
1515 | * @param defined A boolean constant.
|
1516 | */
|
1517 | defined(defined: boolean): this;
|
1518 | /**
|
1519 | * Sets the defined accessor to the specified function and returns this radial area generator.
|
1520 | *
|
1521 | * The default accessor for defined returns a constant boolean value of true, thus assumes that the input data is always defined.
|
1522 | *
|
1523 | * When a radial area is generated, the defined accessor will be invoked for each element in the input data array, being passed the element d, the index i, and the array data as three arguments.
|
1524 | * If the given element is defined (i.e., if the defined accessor returns a truthy value for this element),
|
1525 | * the startAngle, endAngle, innerRadius and outerRadius accessors will subsequently be evaluated and the point will be added to the current area segment.
|
1526 | *
|
1527 | * Otherwise, the element will be skipped, the current area segment will be ended, and a new area segment will be generated for the next defined point.
|
1528 | * As a result, the generated area may have several discrete segments.
|
1529 | *
|
1530 | * Note that if an area segment consists of only a single point, it may appear invisible unless rendered with rounded or square line caps.
|
1531 | * In addition, some curves such as curveCardinalOpen only render a visible segment if it contains multiple points.
|
1532 | *
|
1533 | * @param defined An accessor function which returns a boolean value. The accessor will be invoked for each defined element in the input data array,
|
1534 | * being passed the element d, the index i, and the array data as three arguments.
|
1535 | */
|
1536 | defined(defined: (d: Datum, index: number, data: Datum[]) => boolean): this;
|
1537 |
|
1538 | /**
|
1539 | * Returns the current curve factory, which defaults to curveLinear.
|
1540 | */
|
1541 | curve(): CurveFactory;
|
1542 | /**
|
1543 | * Returns the current curve factory, which defaults to curveLinear.
|
1544 | *
|
1545 | * The generic allows to cast the curve factory to a specific type, if known.
|
1546 | */
|
1547 | curve<C extends CurveFactory>(): C;
|
1548 | /**
|
1549 | * Sets the curve factory and returns this radial area generator.
|
1550 | *
|
1551 | * Note that curveMonotoneX or curveMonotoneY are not recommended for radial areas because they assume that the data is monotonic in x or y, which is typically untrue of radial areas.
|
1552 | *
|
1553 | * @param curve A valid curve factory.
|
1554 | */
|
1555 | curve(curve: CurveFactory): this;
|
1556 |
|
1557 | /**
|
1558 | * Returns the current rendering context, which defaults to null.
|
1559 | */
|
1560 | context(): CanvasRenderingContext2D | null;
|
1561 | /**
|
1562 | * Sets the rendering context and returns this radial area generator.
|
1563 | *
|
1564 | * If the context is not null, then the generated radial area is rendered to this context as a sequence of path method calls.
|
1565 | *
|
1566 | * @param context The rendering context.
|
1567 | */
|
1568 | context(context: CanvasRenderingContext2D): this;
|
1569 | /**
|
1570 | * Sets the rendering context to null and returns this radial area generator.
|
1571 | *
|
1572 | * A path data string representing the generated radial area will be returned when the generator is invoked with data.
|
1573 | *
|
1574 | * @param context null, to remove rendering context.
|
1575 | */
|
1576 | context(context: null): this;
|
1577 |
|
1578 | /**
|
1579 | * Returns a new radial line generator that has this radial area generator’s current defined accessor, curve and context.
|
1580 | * The line’s angle accessor is this area’s start angle accessor, and the line’s radius accessor is this area’s inner radius accessor.
|
1581 | */
|
1582 | lineStartAngle(): LineRadial<Datum>;
|
1583 |
|
1584 | /**
|
1585 | * Returns a new radial line generator that has this radial area generator’s current defined accessor, curve and context.
|
1586 | * The line’s angle accessor is this area’s start angle accessor, and the line’s radius accessor is this area’s inner radius accessor.
|
1587 | */
|
1588 | lineInnerRadius(): LineRadial<Datum>;
|
1589 |
|
1590 | /**
|
1591 | * Returns a new radial line generator that has this radial area generator’s current defined accessor, curve and context.
|
1592 | * The line’s angle accessor is this area’s end angle accessor, and the line’s radius accessor is this area’s inner radius accessor.
|
1593 | */
|
1594 | lineEndAngle(): LineRadial<Datum>;
|
1595 |
|
1596 | /**
|
1597 | * Returns a new radial line generator that has this radial area generator’s current defined accessor, curve and context.
|
1598 | * The line’s angle accessor is this area’s start angle accessor, and the line’s radius accessor is this area’s outer radius accessor.
|
1599 | */
|
1600 | lineOuterRadius(): LineRadial<Datum>;
|
1601 | }
|
1602 |
|
1603 | /**
|
1604 | * Constructs a new radial area generator with the default settings.
|
1605 | *
|
1606 | * Ensure that the accessors used with the area generator correspond to the arguments passed into them,
|
1607 | * or set them to constants as appropriate.
|
1608 | */
|
1609 | export function areaRadial(): AreaRadial<[number, number]>;
|
1610 | /**
|
1611 | * Constructs a new radial area generator with the default settings.
|
1612 | *
|
1613 | * Ensure that the accessors used with the area generator correspond to the arguments passed into them,
|
1614 | * or set them to constants as appropriate.
|
1615 | *
|
1616 | * The generic refers to the data type of an element in the input array passed into the radial area generator.
|
1617 | */
|
1618 | export function areaRadial<Datum>(): AreaRadial<Datum>;
|
1619 |
|
1620 | /**
|
1621 | * @deprecated Use AreaRadial interface
|
1622 | */
|
1623 | export type RadialArea<Datum> = AreaRadial<Datum>;
|
1624 |
|
1625 | /**
|
1626 | * @deprecated Use areaRadial()
|
1627 | */
|
1628 | export function radialArea(): RadialArea<[number, number]>;
|
1629 | /**
|
1630 | * @deprecated Use areaRadial<Datum>()
|
1631 | */
|
1632 | export function radialArea<Datum>(): RadialArea<Datum>;
|
1633 |
|
1634 | // -----------------------------------------------------------------------------------
|
1635 | // Curve Factories
|
1636 | // -----------------------------------------------------------------------------------
|
1637 |
|
1638 | /**
|
1639 | * A minimal interface for a curve generator which supports only the rendering of lines.
|
1640 | * Methods for related to the rendering of areas are not implemented in this minimal interface.
|
1641 | *
|
1642 | * While lines are defined as a sequence of two-dimensional [x, y] points,
|
1643 | * there remains the task of transforming this discrete representation into a continuous shape: i.e., how to interpolate between the points.
|
1644 | * A curve generator serves this purpose.
|
1645 | *
|
1646 | * Curves are typically not constructed or used directly, instead being passed to line.curve.
|
1647 | */
|
1648 | export interface CurveGeneratorLineOnly {
|
1649 | /**
|
1650 | * Indicates the start of a new line segment. Zero or more points will follow.
|
1651 | */
|
1652 | lineStart(): void;
|
1653 | /**
|
1654 | * Indicates the end of the current line segment.
|
1655 | */
|
1656 | lineEnd(): void;
|
1657 | /**
|
1658 | * Indicates a new point in the current line segment with the given x- and y-values.
|
1659 | */
|
1660 | point(x: number, y: number): void;
|
1661 | }
|
1662 |
|
1663 | /**
|
1664 | * A factory for curve generators addressing only lines, but not areas.
|
1665 | */
|
1666 | export type CurveFactoryLineOnly =
|
1667 | /**
|
1668 | * Returns a "lines only" curve generator which renders to the specified context.
|
1669 | *
|
1670 | * @param context A rendering context.
|
1671 | */
|
1672 | (context: CanvasRenderingContext2D | Path) => CurveGeneratorLineOnly;
|
1673 |
|
1674 | /**
|
1675 | * A minimal interface for a curve generator which supports the rendering of lines and areas.
|
1676 | *
|
1677 | * While lines are defined as a sequence of two-dimensional [x, y] points,
|
1678 | * and areas are similarly defined by a topline and a baseline,
|
1679 | * there remains the task of transforming this discrete representation into a continuous shape: i.e., how to interpolate between the points.
|
1680 | * A curve generator serves this purpose.
|
1681 | *
|
1682 | * Curves are typically not constructed or used directly, instead being passed to line.curve and area.curve.
|
1683 | */
|
1684 | export interface CurveGenerator extends CurveGeneratorLineOnly {
|
1685 | /**
|
1686 | * Indicates the start of a new area segment.
|
1687 | * Each area segment consists of exactly two line segments: the topline, followed by the baseline, with the baseline points in reverse order.
|
1688 | */
|
1689 | areaStart(): void;
|
1690 | /**
|
1691 | * Indicates the end of the current area segment.
|
1692 | */
|
1693 | areaEnd(): void;
|
1694 | }
|
1695 |
|
1696 | /**
|
1697 | * A factory for curve generators addressing both lines and areas.
|
1698 | */
|
1699 | export type CurveFactory =
|
1700 | /**
|
1701 | * Returns a curve generator which renders to the specified context.
|
1702 | *
|
1703 | * @param context A rendering context.
|
1704 | */
|
1705 | (context: CanvasRenderingContext2D | Path) => CurveGenerator;
|
1706 |
|
1707 | /**
|
1708 | * A curve factory for cubic basis spline generators.
|
1709 | *
|
1710 | * The curve generators produce a cubic basis spline using the specified control points.
|
1711 | * The first and last points are triplicated such that the spline starts at the first point and ends at the last point,
|
1712 | * and is tangent to the line between the first and second points, and to the line between the penultimate and last points.
|
1713 | */
|
1714 | export const curveBasis: CurveFactory;
|
1715 |
|
1716 | /**
|
1717 | * A curve factory for closed cubic basis spline generators.
|
1718 | *
|
1719 | * The curve generators produce a closed cubic basis spline using the specified control points.
|
1720 | * When a line segment ends, the first three control points are repeated, producing a closed loop with C2 continuity.
|
1721 | */
|
1722 | export const curveBasisClosed: CurveFactory;
|
1723 |
|
1724 | /**
|
1725 | * A curve factory for open cubic basis spline generators.
|
1726 | *
|
1727 | * The curve generators produce a cubic basis spline using the specified control points.
|
1728 | * Unlike basis, the first and last points are not repeated, and thus the curve typically does not intersect these points.
|
1729 | */
|
1730 | export const curveBasisOpen: CurveFactory;
|
1731 |
|
1732 | /**
|
1733 | * Produces a Bézier curve between each pair of points, with horizontal tangents at each point.
|
1734 | */
|
1735 | export const curveBumpX: CurveFactory;
|
1736 |
|
1737 | /**
|
1738 | * Produces a Bézier curve between each pair of points, with vertical tangents at each point.
|
1739 | */
|
1740 | export const curveBumpY: CurveFactory;
|
1741 |
|
1742 | /**
|
1743 | * A curve factory for straightened cubic basis spline generators.
|
1744 | *
|
1745 | * The curve generators produce a straightened cubic basis spline using the specified control points,
|
1746 | * with the spline straightened according to the curve’s beta, which defaults to 0.85.
|
1747 | * This curve is typically used in hierarchical edge bundling to disambiguate connections,
|
1748 | * as proposed by Danny Holten in Hierarchical Edge Bundles: Visualization of Adjacency Relations in Hierarchical Data.
|
1749 | *
|
1750 | * This curve does not implement curve.areaStart and curve.areaEnd; it is intended to work with d3.line, not d3.area.
|
1751 | */
|
1752 | export interface CurveBundleFactory extends CurveFactoryLineOnly {
|
1753 | /**
|
1754 | * Returns a bundle curve factory with the specified beta in the range [0, 1], representing the bundle strength.
|
1755 | * If beta equals zero, a straight line between the first and last point is produced; if beta equals one,
|
1756 | * a standard basis spline is produced.
|
1757 | *
|
1758 | * @param beta A constant value in the [0, 1] interval.
|
1759 | */
|
1760 | beta(beta: number): this;
|
1761 | }
|
1762 |
|
1763 | /**
|
1764 | * A curve factory for straightened cubic basis spline generators.
|
1765 | *
|
1766 | * The curve generators produce a straightened cubic basis spline using the specified control points,
|
1767 | * with the spline straightened according to the curve’s beta, which defaults to 0.85.
|
1768 | * This curve is typically used in hierarchical edge bundling to disambiguate connections,
|
1769 | * as proposed by Danny Holten in Hierarchical Edge Bundles: Visualization of Adjacency Relations in Hierarchical Data.
|
1770 | *
|
1771 | * This curve does not implement curve.areaStart and curve.areaEnd; it is intended to work with d3.line, not d3.area.
|
1772 | */
|
1773 | export const curveBundle: CurveBundleFactory;
|
1774 |
|
1775 | /**
|
1776 | * A curve factory for cubic cardinal spline generators.
|
1777 | */
|
1778 | export interface CurveCardinalFactory extends CurveFactory {
|
1779 | /**
|
1780 | * Returns a cardinal curve factory with the specified tension in the range [0, 1].
|
1781 | * The tension determines the length of the tangents: a tension of one yields all zero tangents, equivalent to curveLinear; a tension of zero produces a uniform Catmull–Rom spline.
|
1782 | *
|
1783 | * @param tension A constant in the [0, 1] interval.
|
1784 | */
|
1785 | tension(tension: number): this;
|
1786 | }
|
1787 |
|
1788 | /**
|
1789 | * A curve factory for cubic cardinal spline generators.
|
1790 | *
|
1791 | * The curve generators produce a cubic cardinal spline using the specified control points, with one-sided differences used for the first and last piece.
|
1792 | * The default tension is 0.
|
1793 | */
|
1794 | export const curveCardinal: CurveCardinalFactory;
|
1795 |
|
1796 | /**
|
1797 | * A curve factory for closed cubic cardinal spline generators.
|
1798 | *
|
1799 | * The curve generators produce closed cubic cardinal spline using the specified control points.
|
1800 | * When a line segment ends, the first three control points are repeated, producing a closed loop.
|
1801 | * The default tension is 0.
|
1802 | */
|
1803 | export const curveCardinalClosed: CurveCardinalFactory;
|
1804 |
|
1805 | /**
|
1806 | * A curve factory for open cubic cardinal spline generators.
|
1807 | *
|
1808 | * The curve generators produce a cubic cardinal spline using the specified control points.
|
1809 | * Unlike curveCardinal, one-sided differences are not used for the first and last piece,
|
1810 | * and thus the curve starts at the second point and ends at the penultimate point.
|
1811 | * The default tension is 0.
|
1812 | */
|
1813 | export const curveCardinalOpen: CurveCardinalFactory;
|
1814 |
|
1815 | /**
|
1816 | * A curve factory for cubic Catmull–Rom spline generators.
|
1817 | */
|
1818 | export interface CurveCatmullRomFactory extends CurveFactory {
|
1819 | /**
|
1820 | * Returns a cubic Catmull–Rom curve factory with the specified alpha in the range [0, 1].
|
1821 | * If alpha is zero, produces a uniform spline, equivalent to curveCardinal with a tension of zero;
|
1822 | * if alpha is one, produces a chordal spline; if alpha is 0.5, produces a centripetal spline.
|
1823 | * Centripetal splines are recommended to avoid self-intersections and overshoot.
|
1824 | *
|
1825 | * @param alpha A constant in the [0, 1] interval.
|
1826 | */
|
1827 | alpha(alpha: number): this;
|
1828 | }
|
1829 |
|
1830 | /**
|
1831 | * A curve factory for cubic Catmull–Rom spline generators.
|
1832 | *
|
1833 | * The curve generators produce a cubic Catmull–Rom spline using the specified control points and the parameter alpha,
|
1834 | * which defaults to 0.5, as proposed by Yuksel et al. in On the Parameterization of Catmull–Rom Curves,
|
1835 | * with one-sided differences used for the first and last piece.
|
1836 | */
|
1837 | export const curveCatmullRom: CurveCatmullRomFactory;
|
1838 |
|
1839 | /**
|
1840 | * A curve factory for cubic Catmull–Rom spline generators.
|
1841 | *
|
1842 | * The curve generators produce a closed cubic Catmull–Rom spline using the specified control points and the parameter alpha,
|
1843 | * which defaults to 0.5, as proposed by Yuksel et al. When a line segment ends,
|
1844 | * the first three control points are repeated, producing a closed loop.
|
1845 | */
|
1846 | export const curveCatmullRomClosed: CurveCatmullRomFactory;
|
1847 |
|
1848 | /**
|
1849 | * A curve factory for cubic Catmull–Rom spline generators.
|
1850 | *
|
1851 | * The curve generators produce a cubic Catmull–Rom spline using the specified control points and the parameter alpha,
|
1852 | * which defaults to 0.5, as proposed by Yuksel et al. Unlike curveCatmullRom, one-sided differences are not used for the first and last piece,
|
1853 | * and thus the curve starts at the second point and ends at the penultimate point.
|
1854 | */
|
1855 | export const curveCatmullRomOpen: CurveCatmullRomFactory;
|
1856 |
|
1857 | /**
|
1858 | * A curve factory for polyline generators.
|
1859 | *
|
1860 | * The curve generators produce a polyline through the specified points.
|
1861 | */
|
1862 | export const curveLinear: CurveFactory;
|
1863 |
|
1864 | /**
|
1865 | * A curve factory for closed polyline generators.
|
1866 | *
|
1867 | * The curve generators produce a closed polyline through the specified points by repeating the first point when the line segment ends.
|
1868 | */
|
1869 | export const curveLinearClosed: CurveFactory;
|
1870 |
|
1871 | /**
|
1872 | * A curve factory for cubic spline generators preserving monotonicity in y.
|
1873 | *
|
1874 | * The curve generators produce a cubic spline that preserves monotonicity in y, assuming monotonicity in x, as proposed by Steffen in A simple method for monotonic interpolation in one dimension:
|
1875 | * “a smooth curve with continuous first-order derivatives that passes through any given set of data points without spurious oscillations.
|
1876 | * Local extrema can occur only at grid points where they are given by the data, but not in between two adjacent grid points.”
|
1877 | */
|
1878 | export const curveMonotoneX: CurveFactory;
|
1879 |
|
1880 | /**
|
1881 | * A curve factory for cubic spline generators preserving monotonicity in x.
|
1882 | *
|
1883 | * The curve generators produce a cubic spline that preserves monotonicity in x, assuming monotonicity in y, as proposed by Steffen in A simple method for monotonic interpolation in one dimension:
|
1884 | * “a smooth curve with continuous first-order derivatives that passes through any given set of data points without spurious oscillations.
|
1885 | * Local extrema can occur only at grid points where they are given by the data, but not in between two adjacent grid points.”
|
1886 | */
|
1887 | export const curveMonotoneY: CurveFactory;
|
1888 |
|
1889 | /**
|
1890 | * A curve factory for natural cubic spline generators.
|
1891 | *
|
1892 | * The curve generators produce a natural cubic spline with the second derivative of the spline set to zero at the endpoints.
|
1893 | */
|
1894 | export const curveNatural: CurveFactory;
|
1895 |
|
1896 | /**
|
1897 | * A curve factory for step function (midpoint) generators.
|
1898 | *
|
1899 | * The curve generators produce a piecewise constant function (a step function) consisting of alternating horizontal and vertical lines.
|
1900 | * The y-value changes at the midpoint of each pair of adjacent x-values.
|
1901 | */
|
1902 | export const curveStep: CurveFactory;
|
1903 |
|
1904 | /**
|
1905 | * A curve factory for step function (after) generators.
|
1906 | *
|
1907 | * The curve generators produce a piecewise constant function (a step function) consisting of alternating horizontal and vertical lines.
|
1908 | * The y-value changes after the x-value.
|
1909 | */
|
1910 | export const curveStepAfter: CurveFactory;
|
1911 |
|
1912 | /**
|
1913 | * A curve factory for step function (before) generators.
|
1914 | *
|
1915 | * The curve generators produce a piecewise constant function (a step function) consisting of alternating horizontal and vertical lines.
|
1916 | * The y-value changes before the x-value.
|
1917 | */
|
1918 | export const curveStepBefore: CurveFactory;
|
1919 |
|
1920 | // -----------------------------------------------------------------------------------
|
1921 | // LINKS
|
1922 | // -----------------------------------------------------------------------------------
|
1923 |
|
1924 | /**
|
1925 | * An interface describing the default Link Data structure expected
|
1926 | * by the Link and LinkRadial generators.
|
1927 | */
|
1928 | export interface DefaultLinkObject {
|
1929 | /**
|
1930 | * Source node of the link.
|
1931 | *
|
1932 | * For a link in a Cartesian coordinate system, the two element array contains
|
1933 | * the coordinates [x, y].
|
1934 | *
|
1935 | * For a radial link, the two element array contains
|
1936 | * the coordinates [angle, radius]. The angle is stated in radians, with 0 at -y (12 o’clock).
|
1937 | * The radius measures the distance from the origin ⟨0,0⟩.
|
1938 | */
|
1939 | source: [number, number];
|
1940 | /**
|
1941 | * Target node of the link.
|
1942 | *
|
1943 | * For a link in a Cartesian coordinate system, the two element array contains
|
1944 | * the coordinates [x, y].
|
1945 | *
|
1946 | * For a radial link, the two element array contains
|
1947 | * the coordinates [angle, radius]. The angle is stated in radians, with 0 at -y (12 o’clock).
|
1948 | * The radius measures the distance from the origin ⟨0,0⟩.
|
1949 | */
|
1950 | target: [number, number];
|
1951 | }
|
1952 |
|
1953 | /**
|
1954 | * A link generator for a Cartesian coordinate system. The link shape generates a smooth cubic Bézier curve from a
|
1955 | * source point to a target point. The tangents of the curve at the start and end are either vertical, horizontal.
|
1956 | *
|
1957 | * The first generic corresponds to the type of the "this" context within which the link generator and its accessor functions will be invoked.
|
1958 | *
|
1959 | * The second generic corresponds to the datum type of the link object for which the link is to be generated.
|
1960 | *
|
1961 | * The third generic corresponds to the datum type of the source/target node contained in the link object.
|
1962 | */
|
1963 | export interface Link<This, LinkDatum, NodeDatum> {
|
1964 | /**
|
1965 | * Generates a link for the given arguments.
|
1966 | *
|
1967 | * IMPORTANT: If the rendering context of the link generator is null,
|
1968 | * then the link is returned as a path data string.
|
1969 | *
|
1970 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
1971 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
1972 | *
|
1973 | * @param d The datum for which the link is to be generated.
|
1974 | */
|
1975 | (this: This, d: LinkDatum, ...args: any[]): string | null;
|
1976 | /**
|
1977 | * Generates an link for the given arguments.
|
1978 | *
|
1979 | * IMPORTANT: If the link generator has been configured with a rendering context,
|
1980 | * then the link is rendered to this context as a sequence of path method calls and this function returns void.
|
1981 | *
|
1982 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
1983 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
1984 | *
|
1985 | * @param d The datum for which the link is to be generated.
|
1986 | */
|
1987 | (this: This, d: LinkDatum, ...args: any[]): void;
|
1988 |
|
1989 | /**
|
1990 | * Returns the current source node accessor function.
|
1991 | * The default source accessor function returns a two element array [x, y].
|
1992 | */
|
1993 | source(): (this: This, d: LinkDatum, ...args: any[]) => NodeDatum;
|
1994 | /**
|
1995 | * Sets the source accessor to the specified function and returns this link generator.
|
1996 | *
|
1997 | * @param source Source node accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
1998 | * receives the same arguments that were passed into the link generator. The default target accessor function returns a two element array [x, y].
|
1999 | */
|
2000 | source(source: (this: This, d: LinkDatum, ...args: any[]) => NodeDatum): this;
|
2001 |
|
2002 | /**
|
2003 | * Returns the current target node accessor function.
|
2004 | * The default target accessor function returns a two element array [x, y].
|
2005 | */
|
2006 | target(): (this: This, d: LinkDatum, ...args: any[]) => NodeDatum;
|
2007 | /**
|
2008 | * Sets the target accessor to the specified function and returns this link generator.
|
2009 | *
|
2010 | * @param target Target node accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2011 | * receives the same arguments that were passed into the link generator. The default target accessor function returns a two element array [x, y].
|
2012 | */
|
2013 | target(target: (this: This, d: LinkDatum, ...args: any[]) => NodeDatum): this;
|
2014 |
|
2015 | /**
|
2016 | * Returns the current x-accessor, which defaults to a function accepting an number array
|
2017 | * as its argument an returning the first element of the array.
|
2018 | */
|
2019 | x(): (this: This, node: NodeDatum, ...args: any[]) => number;
|
2020 | /**
|
2021 | * Sets the x-accessor to the specified function and returns this link generator.
|
2022 | *
|
2023 | * @param x x-coordinate accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2024 | * receives as its first argument a node object followed by all additional arguments that were passed into the link generator.
|
2025 | */
|
2026 | x(x: (this: This, node: NodeDatum, ...args: any[]) => number): this;
|
2027 |
|
2028 | /**
|
2029 | * Returns the current y-accessor, which defaults to a function accepting an number array
|
2030 | * as its argument an returning the second element of the array.
|
2031 | */
|
2032 | y(): (this: This, node: NodeDatum, ...args: any[]) => number;
|
2033 | /**
|
2034 | * Sets the y-accessor to the specified function and returns this link generator.
|
2035 | *
|
2036 | * @param y y-coordinate accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2037 | * receives as its first argument a node object followed by all additional arguments that were passed into the link generator.
|
2038 | */
|
2039 | y(y: (this: This, node: NodeDatum, ...args: any[]) => number): this;
|
2040 |
|
2041 | /**
|
2042 | * Returns the current rendering context, which defaults to null.
|
2043 | */
|
2044 | context(): CanvasRenderingContext2D | null;
|
2045 | /**
|
2046 | * Sets the rendering context and returns this link generator.
|
2047 | *
|
2048 | * If the context is not null, then the generated link is rendered to this context as a sequence of path method calls.
|
2049 | *
|
2050 | * @param context The rendering context.
|
2051 | */
|
2052 | context(context: CanvasRenderingContext2D): this;
|
2053 | /**
|
2054 | * Sets the rendering context to null and returns this link generator.
|
2055 | *
|
2056 | * A path data string representing the generated link will be returned when the generator is invoked with data.
|
2057 | *
|
2058 | * @param context null, to remove rendering context.
|
2059 | */
|
2060 | context(context: null): this;
|
2061 | }
|
2062 |
|
2063 | /**
|
2064 | * Constructs a new default link generator with horizontal tangents, for example, to visualize links in a tree diagram
|
2065 | * rooted on the left edge of the display.
|
2066 | *
|
2067 | * With the default settings the link generator accepts a link object conforming to the DefaultLinkObject interface.
|
2068 | */
|
2069 | export function linkHorizontal(): Link<any, DefaultLinkObject, [number, number]>;
|
2070 | /**
|
2071 | * Constructs a new link generator with horizontal tangents, for example, to visualize links in a tree diagram
|
2072 | * rooted on the left edge of the display.
|
2073 | *
|
2074 | * Important: Ensure that the accessor functions are configured to work with the link and node datum types
|
2075 | * specified in the generics.
|
2076 | *
|
2077 | * The first generic corresponds to the datum type of the link object for which the link is to be generated.
|
2078 | *
|
2079 | * The second generic corresponds to the datum type of the source/target node contained in the link object.
|
2080 | */
|
2081 | export function linkHorizontal<LinkDatum, NodeDatum>(): Link<any, LinkDatum, NodeDatum>;
|
2082 | /**
|
2083 | * Constructs a new link generator with horizontal tangents, for example, to visualize links in a tree diagram
|
2084 | * rooted on the left edge of the display.
|
2085 | *
|
2086 | * Important: Ensure that the accessor functions are configured to work with the link and node datum types
|
2087 | * specified in the generics.
|
2088 | *
|
2089 | * The first generic corresponds to the type of the "this" context within which the link generator and its accessor functions will be invoked.
|
2090 | *
|
2091 | * The second generic corresponds to the datum type of the link object for which the link is to be generated.
|
2092 | *
|
2093 | * The third generic corresponds to the datum type of the source/target node contained in the link object.
|
2094 | */
|
2095 | export function linkHorizontal<This, LinkDatum, NodeDatum>(): Link<This, LinkDatum, NodeDatum>;
|
2096 |
|
2097 | /**
|
2098 | * Constructs a new default link generator with vertical tangents, for example, to visualize links in a tree diagram
|
2099 | * rooted on the top edge of the display.
|
2100 | *
|
2101 | * With the default settings the link generator accepts a link object conforming to the DefaultLinkObject interface.
|
2102 | */
|
2103 | export function linkVertical(): Link<any, DefaultLinkObject, [number, number]>;
|
2104 | /**
|
2105 | * Constructs a new link generator with vertical tangents, for example, to visualize links in a tree diagram
|
2106 | * rooted on the top edge of the display.
|
2107 | *
|
2108 | * Important: Ensure that the accessor functions are configured to work with the link and node datum types
|
2109 | * specified in the generics.
|
2110 | *
|
2111 | * The first generic corresponds to the datum type of the link object for which the link is to be generated.
|
2112 | *
|
2113 | * The second generic corresponds to the datum type of the source/target node contained in the link object.
|
2114 | */
|
2115 | export function linkVertical<LinkDatum, NodeDatum>(): Link<any, LinkDatum, NodeDatum>;
|
2116 | /**
|
2117 | * Constructs a new link generator with vertical tangents, for example, to visualize links in a tree diagram
|
2118 | * rooted on the top edge of the display.
|
2119 | *
|
2120 | * Important: Ensure that the accessor functions are configured to work with the link and node datum types
|
2121 | * specified in the generics.
|
2122 | *
|
2123 | * The first generic corresponds to the type of the "this" context within which the link generator and its accessor functions will be invoked.
|
2124 | *
|
2125 | * The second generic corresponds to the datum type of the link object for which the link is to be generated.
|
2126 | *
|
2127 | * The third generic corresponds to the datum type of the source/target node contained in the link object.
|
2128 | */
|
2129 | export function linkVertical<This, LinkDatum, NodeDatum>(): Link<This, LinkDatum, NodeDatum>;
|
2130 |
|
2131 | /**
|
2132 | * A link generator for a radial coordinate system. The link shape generates a smooth cubic Bézier curve from a
|
2133 | * source point to a target point. The tangents of the curve at the start and end are radial.
|
2134 | *
|
2135 | * The first generic corresponds to the type of the "this" context within which the radial link generator and its accessor functions will be invoked.
|
2136 | *
|
2137 | * The second generic corresponds to the datum type of the link object for which the link is to be generated.
|
2138 | *
|
2139 | * The third generic corresponds to the datum type of the source/target node contained in the link object.
|
2140 | */
|
2141 | export interface LinkRadial<This, LinkDatum, NodeDatum> {
|
2142 | /**
|
2143 | * Generates a radial link for the given arguments.
|
2144 | *
|
2145 | * IMPORTANT: If the rendering context of the radial link generator is null,
|
2146 | * then the link is returned as a path data string.
|
2147 | *
|
2148 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
2149 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
2150 | *
|
2151 | * @param d The datum for which the link is to be generated.
|
2152 | */
|
2153 | (this: This, d: LinkDatum, ...args: any[]): string | null;
|
2154 | /**
|
2155 | * Generates an link for the given arguments.
|
2156 | *
|
2157 | * IMPORTANT: If the radial link generator has been configured with a rendering context,
|
2158 | * then the link is rendered to this context as a sequence of path method calls and this function returns void.
|
2159 | *
|
2160 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
2161 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
2162 | *
|
2163 | * @param d The datum for which the link is to be generated.
|
2164 | */
|
2165 | (this: This, d: LinkDatum, ...args: any[]): void;
|
2166 |
|
2167 | /**
|
2168 | * Returns the current source node accessor function.
|
2169 | * The default source accessor function returns a two element array [x, y].
|
2170 | */
|
2171 | source(): (this: This, d: LinkDatum, ...args: any[]) => NodeDatum;
|
2172 | /**
|
2173 | * Sets the source accessor to the specified function and returns this radial link generator.
|
2174 | *
|
2175 | * @param source Source node accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2176 | * receives the same arguments that were passed into the radial link generator. The default target accessor function returns a two element array [x, y].
|
2177 | */
|
2178 | source(source: (this: This, d: LinkDatum, ...args: any[]) => NodeDatum): this;
|
2179 |
|
2180 | /**
|
2181 | * Returns the current target node accessor function.
|
2182 | * The default target accessor function returns a two element array [x, y].
|
2183 | */
|
2184 | target(): (this: This, d: LinkDatum, ...args: any[]) => NodeDatum;
|
2185 | /**
|
2186 | * Sets the target accessor to the specified function and returns this radial link generator.
|
2187 | *
|
2188 | * @param target Target node accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2189 | * receives the same arguments that were passed into the radial link generator. The default target accessor function returns a two element array [x, y].
|
2190 | */
|
2191 | target(target: (this: This, d: LinkDatum, ...args: any[]) => NodeDatum): this;
|
2192 |
|
2193 | /**
|
2194 | * Returns the current angle accessor, which defaults to a function accepting an number array
|
2195 | * as its argument an returning the first element of the array.
|
2196 | */
|
2197 | angle(): (this: This, node: NodeDatum, ...args: any[]) => number;
|
2198 | /**
|
2199 | * Sets the angle accessor to the specified function and returns this radial link generator.
|
2200 | * The angle is stated in radians, with 0 at -y (12 o’clock).
|
2201 | *
|
2202 | * @param angle Angle accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2203 | * receives as its first argument a node object followed by all additional arguments that were passed into the radial link generator.
|
2204 | */
|
2205 | angle(angle: (this: This, node: NodeDatum, ...args: any[]) => number): this;
|
2206 |
|
2207 | /**
|
2208 | * Returns the current radius accessor, which defaults to a function accepting an number array
|
2209 | * as its argument an returning the second element of the array.
|
2210 | */
|
2211 | radius(): (this: This, node: NodeDatum, ...args: any[]) => number;
|
2212 | /**
|
2213 | * Sets the radius accessor to the specified function and returns this radial link generator.
|
2214 | * The radius is measured as the distance from the origin ⟨0,0⟩.
|
2215 | *
|
2216 | * @param radius Radius accessor function. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2217 | * receives as its first argument a node object followed by all additional arguments that were passed into the radial link generator.
|
2218 | */
|
2219 | radius(radius: (this: This, node: NodeDatum, ...args: any[]) => number): this;
|
2220 |
|
2221 | /**
|
2222 | * Returns the current rendering context, which defaults to null.
|
2223 | */
|
2224 | context(): CanvasRenderingContext2D | null;
|
2225 | /**
|
2226 | * Sets the rendering context and returns this radial link generator.
|
2227 | *
|
2228 | * If the context is not null, then the generated radial area is rendered to this context as a sequence of path method calls.
|
2229 | *
|
2230 | * @param context The rendering context.
|
2231 | */
|
2232 | context(context: CanvasRenderingContext2D): this;
|
2233 | /**
|
2234 | * Sets the rendering context to null and returns this radial link generator.
|
2235 | *
|
2236 | * A path data string representing the generated radial link will be returned when the generator is invoked with data.
|
2237 | *
|
2238 | * @param context null, to remove rendering context.
|
2239 | */
|
2240 | context(context: null): this;
|
2241 | }
|
2242 |
|
2243 | /**
|
2244 | * @deprecated Use LinkRadial interface
|
2245 | */
|
2246 | export type RadialLink<This, LinkDatum, NodeDatum> = LinkRadial<This, LinkDatum, NodeDatum>;
|
2247 |
|
2248 | /**
|
2249 | * Constructs a new default link generator with radial tangents, for example, to visualize links in a tree diagram
|
2250 | * rooted in the center of the display.
|
2251 | *
|
2252 | * With the default settings the link generator accepts a link object conforming to the DefaultLinkObject interface.
|
2253 | */
|
2254 | export function linkRadial(): LinkRadial<any, DefaultLinkObject, [number, number]>;
|
2255 | /**
|
2256 | * Constructs a new link generator with radial tangents, for example, to visualize links in a tree diagram
|
2257 | * rooted in the center of the display.
|
2258 | *
|
2259 | * Important: Ensure that the accessor functions are configured to work with the link and node datum types
|
2260 | * specified in the generics.
|
2261 | *
|
2262 | * The first generic corresponds to the datum type of the link object for which the link is to be generated.
|
2263 | *
|
2264 | * The second generic corresponds to the datum type of the source/target node contained in the link object.
|
2265 | */
|
2266 | export function linkRadial<LinkDatum, NodeDatum>(): LinkRadial<any, LinkDatum, NodeDatum>;
|
2267 | /**
|
2268 | * Constructs a new link generator with radial tangents, for example, to visualize links in a tree diagram
|
2269 | * rooted in the center of the display.
|
2270 | *
|
2271 | * Important: Ensure that the accessor functions are configured to work with the link and node datum types
|
2272 | * specified in the generics.
|
2273 | *
|
2274 | * The first generic corresponds to the type of the "this" context within which the link generator and its accessor functions will be invoked.
|
2275 | *
|
2276 | * The second generic corresponds to the datum type of the link object for which the link is to be generated.
|
2277 | *
|
2278 | * The third generic corresponds to the datum type of the source/target node contained in the link object.
|
2279 | */
|
2280 | export function linkRadial<This, LinkDatum, NodeDatum>(): LinkRadial<This, LinkDatum, NodeDatum>;
|
2281 |
|
2282 | // -----------------------------------------------------------------------------------
|
2283 | // SYMBOLS
|
2284 | // -----------------------------------------------------------------------------------
|
2285 |
|
2286 | /**
|
2287 | * A Symbol Type.
|
2288 | *
|
2289 | * Symbol types are typically not used directly, instead being passed to symbol.type.
|
2290 | * However, you can define your own symbol type implementation should none of the built-in types satisfy your needs using the following interface.
|
2291 | * You can also use this low-level interface with a built-in symbol type as an alternative to the symbol generator.
|
2292 | */
|
2293 | export interface SymbolType {
|
2294 | /**
|
2295 | * Renders this symbol type to the specified context with the specified size in square pixels. The context implements the CanvasPath interface.
|
2296 | * (Note that this is a subset of the CanvasRenderingContext2D interface!)
|
2297 | *
|
2298 | * @param context A rendering context implementing CanvasPath.
|
2299 | * @param size Size of the symbol to draw.
|
2300 | */
|
2301 | draw(context: CanvasPath_D3Shape, size: number): void;
|
2302 | }
|
2303 |
|
2304 | /**
|
2305 | * A symbol generator.
|
2306 | *
|
2307 | * Symbols provide a categorical shape encoding as is commonly used in scatterplots. Symbols are always centered at ⟨0,0⟩;
|
2308 | * use a transform (see: SVG, Canvas) to move the arc to a different position.
|
2309 | *
|
2310 | * The first generic corresponds to the "this" context within which the symbol generator is invoked.
|
2311 | * The second generic corresponds to the data type of the datum underlying the symbol.
|
2312 | */
|
2313 | export interface Symbol<This, Datum> {
|
2314 | /**
|
2315 | * Generates a symbol for the given arguments.
|
2316 | *
|
2317 | * IMPORTANT: If the rendering context of the symbol generator is null,
|
2318 | * then the symbol is returned as a path data string.
|
2319 | *
|
2320 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
2321 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
2322 | *
|
2323 | * For example, with the default settings, no arguments are needed to produce a circle with area 64 square pixels.
|
2324 | *
|
2325 | * @param d The datum for which the symbol is to be generated.
|
2326 | */
|
2327 | (this: This, d?: Datum, ...args: any[]): string | null;
|
2328 | /**
|
2329 | * Generates an symbol for the given arguments.
|
2330 | *
|
2331 | * IMPORTANT: If the symbol generator has been configured with a rendering context,
|
2332 | * then the symbol is rendered to this context as a sequence of path method calls and this function returns void.
|
2333 | *
|
2334 | * The "this" context within which this function is invoked, will be the context within which the accessor methods of the generator are invoked.
|
2335 | * All arguments passed into this function, will be passed to the accessor functions of the generator.
|
2336 | *
|
2337 | * For example, with the default settings, no arguments are needed to produce a circle with area 64 square pixels.
|
2338 | *
|
2339 | * @param d The datum for which the symbol is to be generated.
|
2340 | */
|
2341 | (this: This, d?: Datum, ...args: any[]): void;
|
2342 | /**
|
2343 | * Returns the current size accessor, which defaults to a function returning a constant value of 64.
|
2344 | */
|
2345 | size(): (this: This, d: Datum, ...args: any[]) => number;
|
2346 | /**
|
2347 | * Sets the size to the specified number and returns this symbol generator.
|
2348 | *
|
2349 | * @param size A fixed size (area in square pixels).
|
2350 | */
|
2351 | size(size: number): this;
|
2352 | /**
|
2353 | * Sets the size to the specified function and returns this symbol generator.
|
2354 | *
|
2355 | * Specifying the size as a function is useful for constructing a scatterplot with a size encoding.
|
2356 | * If you wish to scale the symbol to fit a given bounding box, rather than by area, try SVG’s getBBox.
|
2357 | *
|
2358 | * @param size An accessor function returning a number to be used as a symbol size. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2359 | * receives the same arguments that were passed into the symbol generator.
|
2360 | */
|
2361 | size(size: (this: This, d: Datum, ...args: any[]) => number): this;
|
2362 |
|
2363 | /**
|
2364 | * Returns the current symbol type accessor, which defaults to a function returning the circle symbol type.
|
2365 | */
|
2366 | type(): (this: This, d: Datum, ...args: any[]) => SymbolType;
|
2367 | /**
|
2368 | * Sets the symbol type to the specified symbol type and returns this symbol generator.
|
2369 | *
|
2370 | * @param type A constant symbol type.
|
2371 | */
|
2372 | type(type: SymbolType): this;
|
2373 | /**
|
2374 | * Sets the symbol type to the specified function and returns this symbol generator.
|
2375 | *
|
2376 | * @param type An accessor function returning a symbol type. The accessor function is invoked in the same "this" context as the generator was invoked in and
|
2377 | * receives the same arguments that were passed into the symbol generator. See symbols for the set of built-in symbol types.
|
2378 | * To implement a custom symbol type, return an object that implements symbolType.draw.
|
2379 | */
|
2380 | type(type: (this: This, d: Datum, ...args: any[]) => SymbolType): this;
|
2381 |
|
2382 | /**
|
2383 | * Returns the current rendering context, which defaults to null.
|
2384 | */
|
2385 | context(): CanvasRenderingContext2D | null;
|
2386 | /**
|
2387 | * Sets the rendering context and returns this symbol generator.
|
2388 | *
|
2389 | * If the context is not null, then the generated symbol is rendered to this context as a sequence of path method calls.
|
2390 | *
|
2391 | * @param context The rendering context.
|
2392 | */
|
2393 | context(context: CanvasRenderingContext2D): this;
|
2394 | /**
|
2395 | * Sets the rendering context to null and returns this symbol generator.
|
2396 | *
|
2397 | * A path data string representing the generated symbol will be returned when the generator is invoked with data.
|
2398 | *
|
2399 | * @param context null, to remove rendering context.
|
2400 | */
|
2401 | context(context: null): this;
|
2402 | }
|
2403 |
|
2404 | /**
|
2405 | * Constructs a new symbol generator of the specified type and size.
|
2406 | * If not specified, type defaults to a circle, and size defaults to 64.
|
2407 | *
|
2408 | * The first generic corresponds to the "this" context within which the symbol generator is invoked.
|
2409 | * The second generic corresponds to the data type of the datum underlying the symbol.
|
2410 | *
|
2411 | * @param type The specified type.
|
2412 | * @param size The specified size.
|
2413 | */
|
2414 | export function symbol<Datum = any>(
|
2415 | type?: SymbolType | ((this: any, d: Datum, ...args: any[]) => SymbolType),
|
2416 | size?: number | ((this: any, d: Datum, ...args: any[]) => number)
|
2417 | ): Symbol<any, Datum>;
|
2418 |
|
2419 | /**
|
2420 | * Constructs a new symbol generator of the specified type and size.
|
2421 | * If not specified, type defaults to a circle, and size defaults to 64.
|
2422 | *
|
2423 | * The first generic corresponds to the "this" context within which the symbol generator is invoked.
|
2424 | * The second generic corresponds to the data type of the datum underlying the symbol.
|
2425 | *
|
2426 | * @param type The specified type.
|
2427 | * @param size The specified size.
|
2428 | */
|
2429 | export function symbol<This, Datum>(
|
2430 | type?: SymbolType | ((this: This, d: Datum, ...args: any[]) => SymbolType),
|
2431 | size?: number | ((this: This, d: Datum, ...args: any[]) => number)
|
2432 | ): Symbol<This, Datum>;
|
2433 |
|
2434 | /**
|
2435 | * An array containing the set of all built-in symbol types: circle, cross, diamond, square, star, triangle, and wye.
|
2436 | * Useful for constructing the range of an ordinal scale should you wish to use a shape encoding for categorical data.
|
2437 | */
|
2438 | export const symbols: SymbolType[];
|
2439 |
|
2440 | /**
|
2441 | * The circle symbol type.
|
2442 | */
|
2443 | export const symbolCircle: SymbolType;
|
2444 |
|
2445 | /**
|
2446 | * The Greek cross symbol type, with arms of equal length.
|
2447 | */
|
2448 | export const symbolCross: SymbolType;
|
2449 |
|
2450 | /**
|
2451 | * The rhombus symbol type.
|
2452 | */
|
2453 | export const symbolDiamond: SymbolType;
|
2454 |
|
2455 | /**
|
2456 | * The square symbol type.
|
2457 | */
|
2458 | export const symbolSquare: SymbolType;
|
2459 |
|
2460 | /**
|
2461 | * The pentagonal star (pentagram) symbol type.
|
2462 | */
|
2463 | export const symbolStar: SymbolType;
|
2464 |
|
2465 | /**
|
2466 | * The up-pointing triangle symbol type.
|
2467 | */
|
2468 | export const symbolTriangle: SymbolType;
|
2469 |
|
2470 | /**
|
2471 | * The Y-shape symbol type.
|
2472 | */
|
2473 | export const symbolWye: SymbolType;
|
2474 |
|
2475 | // -----------------------------------------------------------------------------------
|
2476 | // pointRadial
|
2477 | // -----------------------------------------------------------------------------------
|
2478 |
|
2479 | /**
|
2480 | * Returns the point [x, y] for the given angle and the given radius.
|
2481 | * @param angle Angle in radians, with 0 at -y (12 o’clock) and positive angles proceeding clockwise.
|
2482 | * @param radius Radius.
|
2483 | */
|
2484 | export function pointRadial(angle: number, radius: number): [number, number];
|
2485 |
|
2486 | // -----------------------------------------------------------------------------------
|
2487 | // STACKS
|
2488 | // -----------------------------------------------------------------------------------
|
2489 |
|
2490 | /**
|
2491 | * Each series point j in a stack chart corresponds to the jth element in the input data.
|
2492 | * Each point is represented as an array [y0, y1] where y0 is the lower value (baseline) and y1 is the upper value (topline);
|
2493 | * the difference between y0 and y1 corresponds to the computed value for this point.
|
2494 | *
|
2495 | * SeriesPoint is a [number, number] two-element Array with added data and index properties
|
2496 | * related to the data element which formed the basis for theSeriesPoint.
|
2497 | */
|
2498 | export interface SeriesPoint<Datum> extends Array<number> {
|
2499 | /**
|
2500 | * Corresponds to y0, the lower value (baseline).
|
2501 | */
|
2502 | 0: number;
|
2503 | /**
|
2504 | * Corresponds to y1, the upper value (topline).
|
2505 | */
|
2506 | 1: number;
|
2507 | /**
|
2508 | * The data element underlying the series point.
|
2509 | */
|
2510 | data: Datum;
|
2511 | }
|
2512 |
|
2513 | /**
|
2514 | * The series are determined by the keys accessor; each series i in the returned array corresponds to the ith key.
|
2515 | * Each series is an array of points, where each point j corresponds to the jth element in the input data.
|
2516 | *
|
2517 | * The key for each series is available as series.key, and the index as series.index.
|
2518 | */
|
2519 | export interface Series<Datum, Key> extends Array<SeriesPoint<Datum>> {
|
2520 | /**
|
2521 | * Key of the series.
|
2522 | */
|
2523 | key: Key;
|
2524 | /**
|
2525 | * Index of the series in the series array returned by stack generator.
|
2526 | */
|
2527 | index: number;
|
2528 | }
|
2529 |
|
2530 | /**
|
2531 | * A stack generator.
|
2532 | *
|
2533 | * Some shape types can be stacked, placing one shape adjacent to another.
|
2534 | * For example, a bar chart of monthly sales might be broken down into a multi-series bar chart by product category, stacking bars vertically.
|
2535 | * This is equivalent to subdividing a bar chart by an ordinal dimension (such as product category) and applying a color encoding.
|
2536 | *
|
2537 | * Stacked charts can show overall value and per-category value simultaneously; however, it is typically harder to compare across categories, as only the bottom layer of the stack is aligned.
|
2538 | * So, chose the stack order carefully, and consider a streamgraph. (See also grouped charts.)
|
2539 | *
|
2540 | * Like the pie generator, the stack generator does not produce a shape directly. Instead it computes positions which you can then pass to an area generator or use directly, say to position bars.
|
2541 | *
|
2542 | * The first generic corresponds to the "this" context in which the stack generator and its accessor functions are invoked.
|
2543 | *
|
2544 | * The second generic corresponds to the data type of an element in the data array passed into the stack generator.
|
2545 | *
|
2546 | * The third generic corresponds to the data type of key used to identify a series.
|
2547 | */
|
2548 | export interface Stack<This, Datum, Key> {
|
2549 | /**
|
2550 | * Generates a stack for the given array of data, returning an array representing each series.
|
2551 | * The resulting array has one element per series. Each series in then typically passed to an area generator to render an area chart,
|
2552 | * or used to construct rectangles for a bar chart.
|
2553 | *
|
2554 | * Any additional arguments are arbitrary; they are simply propagated to the generator’s accessor functions along with the this object.
|
2555 | *
|
2556 | * @param data Array of data elements.
|
2557 | */
|
2558 | (data: Iterable<Datum>, ...args: any[]): Array<Series<Datum, Key>>;
|
2559 |
|
2560 | /**
|
2561 | * Returns the current keys accessor, which defaults to the empty array.
|
2562 | */
|
2563 | keys(): (this: This, data: Datum[], ...args: any[]) => Key[];
|
2564 | /**
|
2565 | * Sets the keys accessor to the specified function or array and returns this stack generator.
|
2566 | *
|
2567 | * A series (layer) is generated for each key. Keys are typically strings, but they may be arbitrary values.
|
2568 | * The series’ key is passed to the value accessor, along with each data point, to compute the point’s value.
|
2569 | *
|
2570 | * @param keys An array of keys.
|
2571 | */
|
2572 | keys(keys: Iterable<Key>): this;
|
2573 | /**
|
2574 | * Sets the keys accessor to the specified function or array and returns this stack generator.
|
2575 | *
|
2576 | * A series (layer) is generated for each key. Keys are typically strings, but they may be arbitrary values.
|
2577 | * The series’ key is passed to the value accessor, along with each data point, to compute the point’s value.
|
2578 | *
|
2579 | * @param keys An accessor function returning the array of keys.
|
2580 | * The accessor function is invoked with the "this" context of the Stack generator and passed the same arguments passed into the generator.
|
2581 | */
|
2582 | keys(keys: (this: This, data: Datum[], ...args: any[]) => Key[]): this;
|
2583 |
|
2584 | /**
|
2585 | * Returns the current value accessor, which defaults to a function return the property corresponding to the relevant key from the data element.
|
2586 | *
|
2587 | * Thus, by default the stack generator assumes that the input data is an array of objects, with each object exposing named properties with numeric values; see stack for an example.
|
2588 | */
|
2589 | value(): (d: Datum, key: Key, i: number, data: Datum[]) => number;
|
2590 | /**
|
2591 | * Sets the value accessor to the specified number and returns this stack generator.
|
2592 | *
|
2593 | * @param value A constant value.
|
2594 | */
|
2595 | value(value: number): this;
|
2596 | /**
|
2597 | * Sets the value accessor to the specified function and returns this stack generator.
|
2598 | *
|
2599 | * @param value A value accessor function which returns the numeric value for a given data element and key combination. The accessor function is invoked for each data element and key being passed
|
2600 | * the datum, the key, index of the data element in the input data array, and the complete data array.
|
2601 | */
|
2602 | value(value: (d: Datum, key: Key, i: number, data: Datum[]) => number): this;
|
2603 |
|
2604 | /**
|
2605 | * Returns the current order accessor, which defaults to stackOrderNone; this uses the order given by the key accessor.
|
2606 | */
|
2607 | order(): (series: Series<Datum, Key>) => Iterable<number>;
|
2608 | /**
|
2609 | * Reset the order to use stackOrderNone; this uses the order given by the key accessor.
|
2610 | *
|
2611 | * @param order null to set to the default stackOrderNone.
|
2612 | */
|
2613 | order(order: null): this;
|
2614 | /**
|
2615 | * Sets the order accessor to the specified array and returns this stack generator.
|
2616 | *
|
2617 | * The stack order is computed prior to the offset; thus, the lower value for all points is zero at the time the order is computed.
|
2618 | * The index attribute for each series is also not set until after the order is computed.
|
2619 | *
|
2620 | * @param order An array of numeric indexes representing the stack order.
|
2621 | */
|
2622 | order(order: Iterable<number>): this;
|
2623 | /**
|
2624 | * Sets the order accessor to the specified function and returns this stack generator.
|
2625 | *
|
2626 | * The stack order is computed prior to the offset; thus, the lower value for all points is zero at the time the order is computed.
|
2627 | * The index attribute for each series is also not set until after the order is computed.
|
2628 | *
|
2629 | * See stack orders for the built-in orders.
|
2630 | *
|
2631 | * @param order A function returning a sort order array. It is passed the generated series array and must return an array of numeric indexes representing the stack order.
|
2632 | */
|
2633 | order(order: (series: Series<Datum, Key>) => Iterable<number>): this;
|
2634 |
|
2635 | /**
|
2636 | * Returns the current offset accessor, which defaults to stackOffsetNone; this uses a zero baseline.
|
2637 | */
|
2638 | offset(): (series: Series<Datum, Key>, order: number[]) => void;
|
2639 | /**
|
2640 | * Reset the offset to use stackOffsetNone; this uses a zero baseline.
|
2641 | *
|
2642 | * @param offset null to set to the default stackOffsetNone.
|
2643 | */
|
2644 | offset(offset: null): this;
|
2645 | /**
|
2646 | * Sets the offset accessor to the specified function and returns this stack generator.
|
2647 | *
|
2648 | * @param offset A function which is passed the generated series array and the order index array;
|
2649 | * it is then responsible for updating the lower and upper values in the series array.
|
2650 | */
|
2651 | offset(offset: (series: Series<Datum, Key>, order: number[]) => void): this;
|
2652 | }
|
2653 |
|
2654 | /**
|
2655 | * Constructs a new stack generator with the default settings.
|
2656 | *
|
2657 | * Ensure that the accessors used with the stack generator correspond to the arguments passed into them.
|
2658 | */
|
2659 | export function stack(): Stack<any, { [key: string]: number }, string>;
|
2660 | /**
|
2661 | * Constructs a new stack generator with the default settings.
|
2662 | *
|
2663 | * Ensure that the accessors used with the stack generator correspond to the arguments passed into them.
|
2664 | *
|
2665 | * The generic corresponds to the data type of an element in the data array passed into the stack generator.
|
2666 | */
|
2667 | export function stack<Datum>(): Stack<any, Datum, string>;
|
2668 | /**
|
2669 | * Constructs a new stack generator with the default settings.
|
2670 | *
|
2671 | * Ensure that the accessors used with the stack generator correspond to the arguments passed into them.
|
2672 | *
|
2673 | * The first generic corresponds to the data type of an element in the data array passed into the stack generator.
|
2674 | *
|
2675 | * The second generic corresponds to the data type of key used to identify a series.
|
2676 | */
|
2677 | export function stack<Datum, Key>(): Stack<any, Datum, Key>;
|
2678 | /**
|
2679 | * Constructs a new stack generator with the default settings.
|
2680 | *
|
2681 | * Ensure that the accessors used with the stack generator correspond to the arguments passed into them.
|
2682 | *
|
2683 | * The first generic corresponds to the "this" context in which the stack generator and its accessor functions are invoked.
|
2684 | *
|
2685 | * The second generic corresponds to the data type of an element in the data array passed into the stack generator.
|
2686 | *
|
2687 | * The third generic corresponds to the data type of key used to identify a series.
|
2688 | */
|
2689 | export function stack<This, Datum, Key>(): Stack<This, Datum, Key>;
|
2690 |
|
2691 | /**
|
2692 | * Returns a series order such that the earliest series (according to the maximum value) is at the bottom.
|
2693 | *
|
2694 | * @param series A series generated by a stack generator.
|
2695 | */
|
2696 | export function stackOrderAppearance(series: Series<any, any>): number[];
|
2697 |
|
2698 | /**
|
2699 | * Returns a series order such that the smallest series (according to the sum of values) is at the bottom.
|
2700 | *
|
2701 | * @param series A series generated by a stack generator.
|
2702 | */
|
2703 | export function stackOrderAscending(series: Series<any, any>): number[];
|
2704 |
|
2705 | /**
|
2706 | * Returns a series order such that the largest series (according to the sum of values) is at the bottom.
|
2707 | *
|
2708 | * @param series A series generated by a stack generator.
|
2709 | */
|
2710 | export function stackOrderDescending(series: Series<any, any>): number[];
|
2711 |
|
2712 | /**
|
2713 | * Returns a series order such that the larger series (according to the sum of values) are on the inside and the smaller series are on the outside.
|
2714 | * This order is recommended for streamgraphs in conjunction with the wiggle offset. See Stacked Graphs—Geometry & Aesthetics by Byron & Wattenberg for more information.
|
2715 | *
|
2716 | * @param series A series generated by a stack generator.
|
2717 | */
|
2718 | export function stackOrderInsideOut(series: Series<any, any>): number[];
|
2719 |
|
2720 | /**
|
2721 | * Returns the given series order [0, 1, … n - 1] where n is the number of elements in series. Thus, the stack order is given by the key accessor.
|
2722 | *
|
2723 | * @param series A series generated by a stack generator.
|
2724 | */
|
2725 | export function stackOrderNone(series: Series<any, any>): number[];
|
2726 |
|
2727 | /**
|
2728 | * Returns the reverse of the given series order [n - 1, n - 2, … 0] where n is the number of elements in series. Thus, the stack order is given by the reverse of the key accessor.
|
2729 | *
|
2730 | * @param series A series generated by a stack generator.
|
2731 | */
|
2732 | export function stackOrderReverse(series: Series<any, any>): number[];
|
2733 |
|
2734 | /**
|
2735 | * Applies a zero baseline and normalizes the values for each point such that the topline is always one.
|
2736 | *
|
2737 | * @param series A series generated by a stack generator.
|
2738 | * @param order An array of numeric indexes representing the stack order.
|
2739 | */
|
2740 | export function stackOffsetExpand(series: Series<any, any>, order: Iterable<number>): void;
|
2741 |
|
2742 | /**
|
2743 | * Positive values are stacked above zero, while negative values are stacked below zero.
|
2744 | *
|
2745 | * @param series A series generated by a stack generator.
|
2746 | * @param order An array of numeric indexes representing the stack order.
|
2747 | */
|
2748 | export function stackOffsetDiverging(series: Series<any, any>, order: Iterable<number>): void;
|
2749 |
|
2750 | /**
|
2751 | * Applies a zero baseline.
|
2752 | *
|
2753 | * @param series A series generated by a stack generator.
|
2754 | * @param order An array of numeric indexes representing the stack order.
|
2755 | */
|
2756 | export function stackOffsetNone(series: Series<any, any>, order: Iterable<number>): void;
|
2757 |
|
2758 | /**
|
2759 | * Shifts the baseline down such that the center of the streamgraph is always at zero.
|
2760 | *
|
2761 | * @param series A series generated by a stack generator.
|
2762 | * @param order An array of numeric indexes representing the stack order.
|
2763 | */
|
2764 | export function stackOffsetSilhouette(series: Series<any, any>, order: Iterable<number>): void;
|
2765 |
|
2766 | /**
|
2767 | * Shifts the baseline so as to minimize the weighted wiggle of layers. This offset is recommended for streamgraphs in conjunction with the inside-out order.
|
2768 | * See Stacked Graphs—Geometry & Aesthetics by Bryon & Wattenberg for more information.
|
2769 | *
|
2770 | * @param series A series generated by a stack generator.
|
2771 | * @param order An array of numeric indexes representing the stack order.
|
2772 | */
|
2773 | export function stackOffsetWiggle(series: Series<any, any>, order: Iterable<number>): void;
|