UNPKG

5.52 kBTypeScriptView Raw
1// Type definitions for D3JS d3-path module 3.0
2// Project: https://github.com/d3/d3-path/, https://d3js.org/d3-path
3// Definitions by: Tom Wanzek <https://github.com/tomwanzek>
4// Alex Ford <https://github.com/gustavderdrache>
5// Boris Yankov <https://github.com/borisyankov>
6// Nathan Bierema <https://github.com/Methuselah96>
7// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
8
9// Last module patch version validated against: 3.0.1
10
11/**
12 * A D3 path serializer implementing CanvasPathMethods
13 */
14export interface Path {
15 /**
16 * Move to the specified point ⟨x, y⟩. Equivalent to context.moveTo and SVG’s “moveto” command.
17 *
18 * @param x x-Coordinate of point to move to
19 * @param y y-Coordinate of point to move to
20 */
21 moveTo(x: number, y: number): void;
22
23 /**
24 * 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.
25 * Equivalent to context.closePath and SVG’s “closepath” command.
26 */
27 closePath(): void;
28
29 /**
30 * Draws a straight line from the current point to the specified point ⟨x, y⟩.
31 * Equivalent to context.lineTo and SVG’s “lineto” command.
32 *
33 * @param x x-Coordinate of point to draw the line to
34 * @param y y-Coordinate of point to draw the line to
35 */
36 lineTo(x: number, y: number): void;
37
38 /**
39 * Draws a quadratic Bézier segment from the current point to the specified point ⟨x, y⟩, with the specified control point ⟨cpx, cpy⟩.
40 * Equivalent to context.quadraticCurveTo and SVG’s quadratic Bézier curve commands.
41 *
42 * @param cpx x-Coordinate of the control point for the quadratic Bézier curve
43 * @param cpy y-Coordinate of the control point for the quadratic Bézier curve
44 * @param x x-Coordinate of point to draw the curve to
45 * @param y y-Coordinate of point to draw the curve to
46 */
47 quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
48
49 /**
50 * 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⟩.
51 * Equivalent to context.bezierCurveTo and SVG’s cubic Bézier curve commands.
52 *
53 * @param cpx1 x-Coordinate of the first control point for the Bézier curve
54 * @param cpy1 y-Coordinate of the first control point for the Bézier curve
55 * @param cpx2 x-Coordinate of the second control point for the Bézier curve
56 * @param cpy2 y-Coordinate of the second control point for the Bézier curve
57 * @param x x-Coordinate of point to draw the curve to
58 * @param y y-Coordinate of point to draw the curve to
59 */
60 bezierCurveTo(cpx1: number, cpy1: number, cpx2: number, cpy2: number, x: number, y: number): void;
61
62 /**
63 * 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⟩
64 * 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,
65 * a straight line is drawn between the current point and the first tangent point. Equivalent to context.arcTo and uses SVG’s elliptical arc curve commands.
66 *
67 * @param x1 x-Coordinate of the first tangent point
68 * @param y1 y-Coordinate of the first tangent point
69 * @param x2 x-Coordinate of the second tangent point
70 * @param y2 y-Coordinate of the second tangent point
71 * @param r Radius of the arc segment
72 */
73 arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
74
75 /**
76 * Draws a circular arc segment with the specified center ⟨x, y⟩, radius, startAngle and endAngle. If anticlockwise is true,
77 * the arc is drawn in the anticlockwise direction; otherwise, it is drawn in the clockwise direction.
78 * 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.
79 * Equivalent to context.arc and uses SVG’s elliptical arc curve commands.
80 *
81 * @param x x-Coordinate of the center point of the arc segment
82 * @param y y-Coordinate of the center point of the arc segment
83 * @param startAngle Start angle of arc segment
84 * @param endAngle End angle of arc segment
85 * @param anticlockwise Flag indicating directionality (true = anti-clockwise, false = clockwise)
86 */
87 arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
88
89 /**
90 * Creates a new subpath containing just the four points ⟨x, y⟩, ⟨x + w, y⟩, ⟨x + w, y + h⟩, ⟨x, y + h⟩,
91 * with those four points connected by straight lines, and then marks the subpath as closed. Equivalent to context.rect and uses SVG’s “lineto” commands.
92 *
93 * @param x x-Coordinate of starting point for drawing the rectangle
94 * @param y y-Coordinate of starting point for drawing the rectangle
95 * @param w Width of rectangle
96 * @param h Height of rectangle
97 */
98 rect(x: number, y: number, w: number, h: number): void;
99
100 /**
101 * Returns the string representation of this path according to SVG’s path data specification.
102 */
103 toString(): string;
104}
105
106/**
107 * Construct a D3 Path serializer
108 */
109export function path(): Path;