UNPKG

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