DefinitelyTyped/d3-path/index.d.ts
Tom Wanzek cce6c24779 [types-2.0] D3 Batch 2 with strictNullChecks, JSDoc and Fixes (#12923)
* d3-path strictNullChecks and JSDoc
* (d3-path) [Chore] Added complete JSDoc comments
* (d3-path) [Enhancement] Validated and activated for use with `strictNullChecks`

* d3-chord: Enhancement, Fixes, Chore
* (d3-chord) [BREAKING FIX] Added additional interfaces Ribbon and RibbonSubgroup to reflect the interfaces actually assumed by default by RibbonGenerator. While the API documentation refers to passing in a Chord object when invoking the RibbonGenerator by default, this actually means the default radius accessor returns undefined, which is then coerced to NaN. To avoid this "silent" fail, Ribbon and RibbonSubgroup are now used as the datum types returned by the default `ribbon()` factory without explicit generics. This is a purposely accepted breaking change, as it means that passing in a Chord object will now fail. The correct way, will be to use the generics of the `ribbon<...>()` factory to cast the datum type to work with Chord. This should serve as a mental cue to  ensure the accessors are customized accordingly. E.g. by setting a constant radius.
* (d3-chords) [Chore]: Added JSDoc comments
* (d3-chords) [Enhancement]: Validated, updated and activated for use with `strictNullChecks`. Note,in particular the updated signatures for invoking the RibbonGenerator. These are now overloaded with one returning `void` (canvas context), and the other returning `string | null`, where the rendering context is `null`. Note that teh API suggests a string is returned in this case, however, it may actually return `null` as well as per source code. It is at the developers discretion to ensure return value expectations correspond to rendering context.
* (d3-chords) [Chore] Updated tests and bumped patch version number to indicate which version was last fully reviewed.

* d3-time: strictNullChecks, JSDoc and Fix
* (d3-time) [Fix]: Return type of method `TimeInterval.filter(...)` changed from `this` to `TimeInterval`. This corrects an earlier regression, whereby applying `filter(...)` on a `CountableTimeInterval` incorrectly returns `CountableTimeInterval`. The correct return type is restricted to `TimeInterval`. Tests updated.
* (d3-time) [Enhancement]: Validated, updated and activated for use with `strictNullChecks`. Tests updated.
* (d3-time) [Chore]: Complete JSDoc comments.
* (d3-time) [Chore]: Updated patch version to reflect latest validated release of d3-time

* d3-scale:
* (d3-scale) [Refactoring]: Added interface `ScaleContinuousNumeric<Range, Output>` to consolidate some of the repeatable properties for numeric continuous scales. Use extension and scale-specific implementations as needed
* (d3-scale) [Fix]: `ScaleLogarithmic.nice()` does not have `count` argument
* (d3-scale) [Fix]: Relaxed constraint on data type for `domain(...)` setter and scale application for `ScaleTime` to allow numeric values, which are coerced to Date internally by d3-scale.
* (d3-scale) [Enhancement]: Validated, updated and acrivated for use with `strictNullChecks`
* (d3-scale) [Chore]: JSDoc comments completed

* d3-shape
* (d3-shape) [Fix]: Signatures for invoking a generator which renders have been changed as follows: There used to be one signature which returned `string | undefined` depending on whether a rendering context was or not. This had been split into two signatures, the first returns `string | null` when creating a path string with rendering context "null", the second returns `void` when a rendering context is set. The change was made, so that the configured generator can be passed into a `Selection.attr('d', ...)` call without issues. Note that the `string | null` return type for the path string option is based on the actual code, which  may return `null` if path string generation "fails".
* (d3-shape) [Fix]: Added missing `padRadius` signature to `Arc` generator.
* (d3-shape) [Fix]: Removed `line<This, Datum>(): Line<Datum>` signature, as there is not "this" context for line generator
* (d3-shape) [Enhanced]: Where generators allow configurations of curve factories to be used, as second signature was added to  allow casting the return type of the `curve<C extends CurveFactory | CurveFactoryLineOnly>(): C` getter
* (d3-shape) [Fix]: Fixed invocation signatures for `CurveFactoryLineOnly` and `CurveFactory`. The signature  incorrectly used to allow null: `CanvasRenderingContext2D | null`. It has been changed to `CanvasRenderingContext2D | Path`, `Path` has been added as this is actually the rendering context used internally by the generators in d3-shape, when creating an SVG path string.
* (d3-shape) [Fix]: Moved `index` property from `SeriesPoint` to `Series` interface. This corresponds to actual D3 data structure/API.
* (d3-shape) [Enhancement]: Validated, updated and enhanced for use with `strictNullChecks`.
* (d3-shape) [chore] Changes related to linting, Disabled "unified-signatures" in tsling.json due to usability considerations.

* d3-chord and d3-scale:
* (d3-chord) [Fix]: Minor fixes to correct comments
* (d3-chord) [Chore]: Completed linting and added `tslint.json` to disable "unified-signatures" rule due to usability considerations.
* (d3-scale) [Chore]: Completed linting and added `tslint.json` to disable "unified-signatures" rule due to usability considerations.

* d3-shape:
* (d3-shape) [Chore]: Selectively disable linting rule for functional interfaces which are extended. (As per @gustavderdrache)

* d3-scale:
* (d3-scale) [Chore]: Selectively disable lint warning on extended functional interface
* Removed comment from `tslint.json` files.

* strictNullChecks chore
* (d3-chord) [Chore]: Use postfix to assert non-null for a test variable.
* (d3-shape) [Chore]: Use postfix to assert non-null for a test variable.

* Updated  header comments to new convention.

* d3-chord
* (d3-chord) [Chore]: Change occurrence of double-quotation mark for single-quotation mark in test file
2016-12-06 18:03:30 -08:00

107 lines
5.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Type definitions for D3JS d3-path module 1.0
// Project: https://github.com/d3/d3-path/
// Definitions by: Tom Wanzek <https://github.com/tomwanzek>, Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Last module patch version validated against: 1.0.3
/**
* A D3 path serializer implementing CanvasPathMethods
*/
export interface Path {
/**
* Move to the specified point ⟨x, y⟩. Equivalent to context.moveTo and SVGs “moveto” command.
*
* @param x x-Coordinate of point to move to
* @param y y-Coordinate of point to move to
*/
moveTo(x: number, y: number): void;
/**
* Ends the current subpath and causes an automatic straight line to be drawn from the current point to the initial point of the current subpath.
* Equivalent to context.closePath and SVGs “closepath” command.
*/
closePath(): void;
/**
* Draws a straight line from the current point to the specified point ⟨x, y⟩.
* Equivalent to context.lineTo and SVGs “lineto” command.
*
* @param x x-Coordinate of point to draw the line to
* @param y y-Coordinate of point to draw the line to
*/
lineTo(x: number, y: number): void;
/**
* Draws a quadratic Bézier segment from the current point to the specified point ⟨x, y⟩, with the specified control point ⟨cpx, cpy⟩.
* Equivalent to context.quadraticCurveTo and SVGs quadratic Bézier curve commands.
*
* @param cpx x-Coordinate of the control point for the quadratic Bézier curve
* @param cpy y-Coordinate of the control point for the quadratic Bézier curve
* @param x x-Coordinate of point to draw the curve to
* @param y y-Coordinate of point to draw the curve to
*/
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
/**
* Draws a cubic Bézier segment from the current point to the specified point ⟨x, y⟩, with the specified control points ⟨cpx1, cpy1⟩ and ⟨cpx2, cpy2⟩.
* Equivalent to context.bezierCurveTo and SVGs cubic Bézier curve commands.
*
* @param cpx1 x-Coordinate of the first control point for the Bézier curve
* @param cpy1 y-Coordinate of the first control point for the Bézier curve
* @param cpx2 x-Coordinate of the second control point for the Bézier curve
* @param cpy2 y-Coordinate of the second control point for the Bézier curve
* @param x x-Coordinate of point to draw the curve to
* @param y y-Coordinate of point to draw the curve to
*/
bezierCurveTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number): void;
/**
* Draws a circular arc segment with the specified radius that starts tangent to the line between the current point and the specified point ⟨x1, y1⟩
* and ends tangent to the line between the specified points ⟨x1, y1⟩ and ⟨x2, y2⟩. If the first tangent point is not equal to the current point,
* a straight line is drawn between the current point and the first tangent point. Equivalent to context.arcTo and uses SVGs elliptical arc curve commands.
*
* @param x1 x-Coordinate of the first tangent point
* @param y1 y-Coordinate of the first tangent point
* @param x2 x-Coordinate of the second tangent point
* @param y2 y-Coordinate of the second tangent point
* @param r Radius of the arc segment
*/
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
/**
* Draws a circular arc segment with the specified center ⟨x, y⟩, radius, startAngle and endAngle. If anticlockwise is true,
* the arc is drawn in the anticlockwise direction; otherwise, it is drawn in the clockwise direction.
* If the current point is not equal to the starting point of the arc, a straight line is drawn from the current point to the start of the arc.
* Equivalent to context.arc and uses SVGs elliptical arc curve commands.
*
* @param x x-Coordinate of the center point of the arc segment
* @param y y-Coordinate of the center point of the arc segment
* @param startAngle Start angle of arc segment
* @param endAngle End angle of arc segment
* @param anticlockwise Flag indicating directionality (true = anti-clockwise, false = clockwise)
*/
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
/**
* Creates a new subpath containing just the four points ⟨x, y⟩, ⟨x + w, y⟩, ⟨x + w, y + h⟩, ⟨x, y + h⟩,
* with those four points connected by straight lines, and then marks the subpath as closed. Equivalent to context.rect and uses SVGs “lineto” commands.
*
* @param x x-Coordinate of starting point for drawing the rectangle
* @param y y-Coordinate of starting point for drawing the rectangle
* @param w Width of rectangle
* @param h Height of rectangle
*/
rect(x: number, y: number, w: number, h: number): void;
/**
* Returns the string representation of this path according to SVGs path data specficiation.
*/
toString(): string;
}
/**
* Construct a D3 Path serializer
*/
export function path(): Path;