UNPKG

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