1 | // Type definitions for D3JS d3-brush module 3.0
|
2 | // Project: https://github.com/d3/d3-brush/, https://d3js.org/d3-brush
|
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.0
|
10 |
|
11 | import { Selection, TransitionLike, ValueFn } from 'd3-selection';
|
12 |
|
13 | /**
|
14 | * Type alias for a BrushSelection. For a two-dimensional brush, it must be defined as [[x0, y0], [x1, y1]],
|
15 | * where x0 is the minimum x-value, y0 is the minimum y-value, x1 is the maximum x-value, and y1 is the maximum y-value.
|
16 | * For an x-brush, it must be defined as [x0, x1]; for a y-brush, it must be defined as [y0, y1].
|
17 | */
|
18 | export type BrushSelection = [[number, number], [number, number]] | [number, number];
|
19 |
|
20 | /**
|
21 | * A D3 brush behavior
|
22 | *
|
23 | * The generic refers to the type of the datum for the group element on which brush behavior is defined.
|
24 | */
|
25 | export interface BrushBehavior<Datum> {
|
26 | /**
|
27 | * Applies the brush to the specified group, which must be a selection of SVG G elements.
|
28 | * This function is typically not invoked directly, and is instead invoked via selection.call.
|
29 | *
|
30 | * For details see: {@link https://github.com/d3/d3-brush#_brush}
|
31 | *
|
32 | * @param group A D3 selection of SVG G elements.
|
33 | * @param args Optional arguments to be passed in.
|
34 | */
|
35 | (group: Selection<SVGGElement, Datum, any, any>, ...args: any[]): void;
|
36 | /**
|
37 | * Clear the active selection of the brush on the specified SVG G element(s) selection.
|
38 | *
|
39 | * @param group A selection or a transition of SVG G elements
|
40 | * @param selection The selection must be defined as an array of numbers, or null to clear the brush selection.
|
41 | * For a two-dimensional brush, it must be defined as [[x0, y0], [x1, y1]], where x0 is the minimum x-value, y0 is the minimum y-value, x1 is the maximum x-value, and y1 is the maximum y-value.
|
42 | * For an x-brush, it must be defined as [x0, x1]; for a y-brush, it must be defined as [y0, y1].
|
43 | * The selection may also be specified as a function which returns such an array;
|
44 | * if a function, it is invoked for each selected element, being passed the current datum d and index i, with the this context as the current DOM element.
|
45 | * The returned array defines the brush selection for that element.
|
46 | * @param event
|
47 | */
|
48 | move(group: Selection<SVGGElement, Datum, any, any> | TransitionLike<SVGGElement, Datum>, selection: null | BrushSelection | ValueFn<SVGGElement, Datum, BrushSelection>, event?: Event): void;
|
49 |
|
50 | /**
|
51 | * Clear the active selection of the brush on the specified SVG G element(s) selection.
|
52 | *
|
53 | * @param group A D3 selection of SVG G elements.
|
54 | * @param event
|
55 | */
|
56 | clear(group: Selection<SVGGElement, Datum, any, any>, event?: Event): void;
|
57 |
|
58 | /**
|
59 | * Returns the current extent accessor.
|
60 | */
|
61 | extent(): ValueFn<SVGGElement, Datum, [[number, number], [number, number]]>;
|
62 | /**
|
63 | * Set the brushable extent to the specified array of points and returns this brush.
|
64 | *
|
65 | * The brush extent determines the size of the invisible overlay and also constrains the brush selection;
|
66 | * the brush selection cannot go outside the brush extent.
|
67 | *
|
68 | * @param extent array of points [[x0, y0], [x1, y1]], where [x0, y0] is the top-left corner
|
69 | * and [x1, y1] is the bottom-right corner.
|
70 | */
|
71 | extent(extent: [[number, number], [number, number]]): this;
|
72 | /**
|
73 | * Set the brushable extent to the specified array of points returned by the accessor function
|
74 | * evaluated for each element in the selection/transition and returns this brush.
|
75 | *
|
76 | * The brush extent determines the size of the invisible overlay and also constrains the brush selection;
|
77 | * the brush selection cannot go outside the brush extent.
|
78 | *
|
79 | * @param extent An extent accessor function which is evaluated for each selected element,
|
80 | * in order, being passed the current datum (d), the current index (i), and the current group (nodes),
|
81 | * with this as the current DOM element. The function returns an array of points [[x0, y0], [x1, y1]],
|
82 | * where [x0, y0] is the top-left corner and [x1, y1] is the bottom-right corner.
|
83 | */
|
84 | extent(extent: ValueFn<SVGGElement, Datum, [[number, number], [number, number]]>): this;
|
85 |
|
86 | /**
|
87 | * Returns the current filter function.
|
88 | */
|
89 | filter(): (this: SVGGElement, event: any, d: Datum) => boolean;
|
90 | /**
|
91 | * Sets the filter to the specified filter function and returns the brush.
|
92 | *
|
93 | * If the filter returns falsey, the initiating event is ignored and no brush gesture is started.
|
94 | * Thus, the filter determines which input events are ignored. The default filter ignores mousedown events on secondary buttons,
|
95 | * since those buttons are typically intended for other purposes, such as the context menu.
|
96 | *
|
97 | * @param filterFn A filter function which is evaluated for each selected element,
|
98 | * in order, being passed the current event `event` and datum `d`, with the `this` context as the current DOM element.
|
99 | * The function returns a boolean value.
|
100 | */
|
101 | filter(filterFn: (this: SVGGElement, event: any, d: Datum) => boolean): this;
|
102 |
|
103 | /**
|
104 | * Returns the current touch support detector, which defaults to a function returning true,
|
105 | * if the "ontouchstart" event is supported on the current element.
|
106 | */
|
107 | touchable(): ValueFn<SVGGElement, Datum, boolean>;
|
108 | /**
|
109 | * Sets the touch support detector to the specified boolean value and returns the brush.
|
110 | *
|
111 | * Touch event listeners are only registered if the detector returns truthy for the corresponding element when the brush is applied.
|
112 | * The default detector works well for most browsers that are capable of touch input, but not all; Chrome’s mobile device emulator, for example,
|
113 | * fails detection.
|
114 | *
|
115 | * @param touchable A boolean value. true when touch event listeners should be applied to the corresponding element, otherwise false.
|
116 | */
|
117 | touchable(touchable: boolean): this;
|
118 | /**
|
119 | * Sets the touch support detector to the specified function and returns the drag behavior.
|
120 | *
|
121 | * Touch event listeners are only registered if the detector returns truthy for the corresponding element when the brush is applied.
|
122 | * The default detector works well for most browsers that are capable of touch input, but not all; Chrome’s mobile device emulator, for example,
|
123 | * fails detection.
|
124 | *
|
125 | * @param touchable A touch support detector function, which returns true when touch event listeners should be applied to the corresponding element.
|
126 | * The function is evaluated for each selected element to which the brush was applied, in order, being passed the current datum (d),
|
127 | * the current index (i), and the current group (nodes), with this as the current DOM element. The function returns a boolean value.
|
128 | */
|
129 | touchable(touchable: ValueFn<SVGGElement, Datum, boolean>): this;
|
130 |
|
131 | /**
|
132 | * Returns the current key modifiers flag.
|
133 | */
|
134 | keyModifiers(): boolean;
|
135 | /**
|
136 | * Sets the key modifiers flag and returns the brush.
|
137 | *
|
138 | * The key modifiers flag determines whether the brush listens to key events during brushing.
|
139 | * The default value is true.
|
140 | *
|
141 | * @param modifiers New value for key modifiers flag.
|
142 | */
|
143 | keyModifiers(modifiers: boolean): this;
|
144 |
|
145 | /**
|
146 | * Returns the current handle size, which defaults to six.
|
147 | */
|
148 | handleSize(): number;
|
149 | /**
|
150 | * Sets the size of the brush handles to the specified number and returns the brush.
|
151 | *
|
152 | * This method must be called before applying the brush to a selection;
|
153 | * changing the handle size does not affect brushes that were previously rendered.
|
154 | * The default size is 6.
|
155 | *
|
156 | * @param size Size of the handle.
|
157 | */
|
158 | handleSize(size: number): this;
|
159 |
|
160 | /**
|
161 | * Returns the first currently-assigned listener matching the specified typenames, if any.
|
162 | *
|
163 | * @param typenames The typenames is a string containing one or more typename separated by whitespace.
|
164 | * Each typename is a type, optionally followed by a period (.) and a name, such as "brush.foo"" and "brush.bar";
|
165 | * the name allows multiple listeners to be registered for the same type. The type must be one of the following:
|
166 | * start (at the start of a brush gesture, such as on mousedown), brush (when the brush moves, such as on mousemove), or
|
167 | * end (at the end of a brush gesture, such as on mouseup.)
|
168 | */
|
169 | on(typenames: string): ((this: SVGGElement, event: any, d: Datum) => void) | undefined;
|
170 | /**
|
171 | * Removes the current event listeners for the specified typenames, if any.
|
172 | *
|
173 | * @param typenames The typenames is a string containing one or more typename separated by whitespace.
|
174 | * Each typename is a type, optionally followed by a period (.) and a name, such as "brush.foo"" and "brush.bar";
|
175 | * the name allows multiple listeners to be registered for the same type. The type must be one of the following:
|
176 | * start (at the start of a brush gesture, such as on mousedown), brush (when the brush moves, such as on mousemove), or
|
177 | * end (at the end of a brush gesture, such as on mouseup.)
|
178 | * @param listener Use null to remove the listener.
|
179 | */
|
180 | on(typenames: string, listener: null): this;
|
181 | /**
|
182 | * Sets the event listener for the specified typenames and returns the brush.
|
183 | * If an event listener was already registered for the same type and name,
|
184 | * the existing listener is removed before the new listener is added.
|
185 | * When a specified event is dispatched, each listener will be invoked with the same context and arguments as selection.on listeners.
|
186 | *
|
187 | * @param typenames The typenames is a string containing one or more typename separated by whitespace.
|
188 | * Each typename is a type, optionally followed by a period (.) and a name, such as "brush.foo"" and "brush.bar";
|
189 | * the name allows multiple listeners to be registered for the same type. The type must be one of the following:
|
190 | * start (at the start of a brush gesture, such as on mousedown), brush (when the brush moves, such as on mousemove), or
|
191 | * end (at the end of a brush gesture, such as on mouseup.)
|
192 | * @param listener An event listener function which is evaluated for each selected element,
|
193 | * in order, being passed the current event `event` and datum `d`, with the `this` context as the current DOM element.
|
194 | */
|
195 | on(typenames: string, listener: (this: SVGGElement, event: any, d: Datum) => void): this;
|
196 | }
|
197 |
|
198 | /**
|
199 | * Create a new two-dimensional brush.
|
200 | *
|
201 | * The generic "Datum" refers to the type of the data of the selected svg:g element to
|
202 | * which the returned BrushBehavior will be applied.
|
203 | */
|
204 | // eslint-disable-next-line no-unnecessary-generics
|
205 | export function brush<Datum>(): BrushBehavior<Datum>;
|
206 | /**
|
207 | * Creates a new one-dimensional brush along the x-dimension.
|
208 | *
|
209 | * The generic "Datum" refers to the type of the data of the selected svg:g element to
|
210 | * which the returned BrushBehavior will be applied.
|
211 | */
|
212 | // eslint-disable-next-line no-unnecessary-generics
|
213 | export function brushX<Datum>(): BrushBehavior<Datum>;
|
214 | /**
|
215 | * Creates a new one-dimensional brush along the y-dimension.
|
216 | *
|
217 | * The generic "Datum" refers to the type of the data of the selected svg:g element to
|
218 | * which the returned BrushBehavior will be applied.
|
219 | */
|
220 | // eslint-disable-next-line no-unnecessary-generics
|
221 | export function brushY<Datum>(): BrushBehavior<Datum>;
|
222 |
|
223 | /**
|
224 | * Return the current brush selection for the specified node. Internally, an element’s brush state is stored as element.__brush;
|
225 | * however, you should use this method rather than accessing it directly. If the given node has no selection, returns null.
|
226 | * Otherwise, the selection is defined as an array of numbers.
|
227 | *
|
228 | * @param node The node for which the brush selection should be returned.
|
229 | */
|
230 | export function brushSelection(node: SVGGElement): BrushSelection | null;
|
231 |
|
232 | /**
|
233 | * D3 brush event
|
234 | *
|
235 | * The generic refers to the type of the datum for the group element on which brush was defined.
|
236 | */
|
237 | export interface D3BrushEvent<Datum> {
|
238 | /**
|
239 | * The BrushBehavior associated with the event
|
240 | */
|
241 | target: BrushBehavior<Datum>;
|
242 | /**
|
243 | * The event type for the BrushEvent
|
244 | */
|
245 | type: 'start' | 'brush' | 'end' | string; // Leave failsafe string type for cases like 'brush.foo'
|
246 | /**
|
247 | * The current brush selection associated with the event.
|
248 | * This is null when the selection is empty.
|
249 | */
|
250 | selection: BrushSelection | null;
|
251 | /**
|
252 | * The underlying input event, such as mousemove or touchmove.
|
253 | */
|
254 | sourceEvent: any;
|
255 | /**
|
256 | * The mode of the brush.
|
257 | */
|
258 | mode: 'drag' | 'space' | 'handle' | 'center';
|
259 | }
|
260 |
|
\ | No newline at end of file |