UNPKG

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