UNPKG

declarations

Version:

[![npm version](https://badge.fury.io/js/declarations.svg)](https://www.npmjs.com/package/declarations)

1,045 lines (867 loc) 132 kB
// Type definitions for d3JS // Project: http://d3js.org/ // Definitions by: Alex Ford <https://github.com/gustavderdrache>, Boris Yankov <https://github.com/borisyankov> // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace d3 { /** * The current version of D3.js. */ export var version: string; /** * Find the first element that matches the given selector string. */ export function select(selector: string): Selection<any>; /** * Create a selection from the given node reference. */ export function select(node: EventTarget): Selection<any>; /** * Find all elements that match the given selector string. */ export function selectAll(selector: string): Selection<any>; /** * Create a selection from the given list of nodes. */ export function selectAll(nodes: EventTarget[]): Selection<any>; /** * Returns the root selection (as if by d3.select(document.documentElement)). This function may be used for 'instanceof' tests, and extending its prototype will add properties to all selections. */ export function selection(): Selection<any>; namespace selection { export var prototype: Selection<any>; /** * Selections are grouped into arrays of nodes, with the parent tracked in the 'parentNode' property. */ interface Group extends Array<EventTarget> { parentNode: EventTarget; } interface Update<Datum> { /** * Retrieve a grouped selection. */ [index: number]: Group; /** * The number of groups in this selection. */ length: number; /** * Retrieve the value of the given attribute for the first node in the selection. * * @param name The attribute name to query. May be prefixed (see d3.ns.prefix). */ attr(name: string): string; /** * For all nodes, set the attribute to the specified constant value. Use null to remove. * * @param name The attribute name, optionally prefixed. * @param value The attribute value to use. Note that this is coerced to a string automatically. */ attr(name: string, value: Primitive): Update<Datum>; /** * Derive an attribute value for each node in the selection based on bound data. * * @param name The attribute name, optionally prefixed. * @param value The function of the datum (the bound data item), index (the position in the subgrouping), and outer index (overall position in nested selections) which computes the attribute value. If the function returns null, the attribute is removed. */ attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Update<Datum>; /** * Set multiple properties at once using an Object. D3 iterates over all enumerable properties and either sets or computes the attribute's value based on the corresponding entry in the Object. * * @param obj A key-value mapping corresponding to attributes and values. If the value is a simple string or number, it is taken as a constant. Otherwise, it is a function that derives the attribute value. */ attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Update<Datum>; /** * Returns true if the first node in this selection has the given class list. If multiple classes are specified (i.e., "foo bar"), then returns true only if all classes match. * * @param name The class list to query. */ classed(name: string): boolean; /** * Adds (or removes) the given class list. * * @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes. * @param value If true, add the classes. If false, remove them. */ classed(name: string, value: boolean): Update<Datum>; /** * Determine if the given class list should be toggled for each node in the selection. * * @param name The class list. Spaces separate multiple class names. * @param value The function to run for each node. Should return true to add the class to the node, or false to remove it. */ classed(name: string, value: (datum: Datum, index: number, outerIndex: number) => boolean): Update<Datum>; /** * Set or derive classes for multiple class lists at once. * * @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans. */ classed(obj: { [key: string]: boolean | ((datum: Datum, index: number, outerIndex: number) => boolean) }): Update<Datum>; /** * Retrieve the computed style value for the first node in the selection. * @param name The CSS property name to query */ style(name: string): string; /** * Set a style property for all nodes in the selection. * @param name the CSS property name * @param value the property value * @param priority if specified, either null or the string "important" (no exclamation mark) */ style(name: string, value: Primitive, priority?: string): Update<Datum>; /** * Derive a property value for each node in the selection. * @param name the CSS property name * @param value the function to derive the value * @param priority if specified, either null or the string "important" (no exclamation mark) */ style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Update<Datum>; /** * Set a large number of CSS properties from an object. * * @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values * @param priority if specified, either null or the string "important" (no exclamation mark) */ style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Update<Datum>; /** * Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes. * * @param name the node's property to retrieve */ property(name: string): any; /** * For each node, set the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. * * @param name the property name * @param value the property value */ property(name: string, value: any): Update<Datum>; /** * For each node, derive the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. * * @param name the property name * @param value the function used to derive the property's value */ property(name: string, value: (datum: Datum, index: number, outerIndex: number) => any): Update<Datum>; /** * Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__. * * @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value. */ property(obj: { [key: string]: any | ((datum: Datum, index: number, outerIndex: number) => any) }): Update<Datum>; /** * Retrieve the textContent of the first node in the selection. */ text(): string; /** * Set the textContent of each node in the selection. * @param value the text to use for all nodes */ text(value: Primitive): Update<Datum>; /** * Compute the textContent of each node in the selection. * @param value the function which will compute the text */ text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Update<Datum>; /** * Retrieve the HTML content of the first node in the selection. Uses 'innerHTML' internally and will not work with SVG or other elements without a polyfill. */ html(): string; /** * Set the HTML content of every node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. * @param value the HTML content to use. */ html(value: string): Selection<Datum>; /** * Compute the HTML content for each node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. * @param value the function to compute HTML content */ html(value: (datum: Datum, index: number, outerIndex: number) => string): Selection<Datum>; /** * Appends a new child to each node in the selection. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. * * @param name the element name to append. May be prefixed (see d3.ns.prefix). */ append(name: string): Selection<Datum>; /** * Appends a new child to each node in the selection by computing a new node. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. * * @param name the function to compute a new element */ append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>; /** * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the element name to append. May be prefixed (see d3.ns.prefix). * @param before the selector to determine position (e.g., ":first-child") */ insert(name: string, before: string): Update<Datum>; /** * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the element name to append. May be prefixed (see d3.ns.prefix). * @param before a function to determine the node to use as the next sibling */ insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>; /** * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the function to compute a new child * @param before the selector to determine position (e.g., ":first-child") */ insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: string): Update<Datum>; /** * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the function to compute a new child * @param before a function to determine the node to use as the next sibling */ insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>; /** * Removes the elements from the DOM. They are in a detached state and may be re-added (though there is currently no dedicated API for doing so). */ remove(): Update<Datum>; /** * Retrieves the data bound to the first group in this selection. */ data(): Datum[]; /** * Binds data to this selection. * @param data the array of data to bind to this selection * @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element. */ data<NewDatum>(data: NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): Update<NewDatum>; /** * Derives data to bind to this selection. * @param data the function to derive data. Must return an array. * @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element. */ data<NewDatum>(data: (datum: Datum, index: number, outerIndex: number) => NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): Update<NewDatum>; /** * Filters the selection, returning only those nodes that match the given CSS selector. * @param selector the CSS selector */ filter(selector: string): Update<Datum>; /** * Filters the selection, returning only those nodes for which the given function returned true. * @param selector the filter function */ filter(selector: (datum: Datum, index: number, outerIndex: number) => boolean): Update<Datum>; /** * Return the data item bound to the first element in the selection. */ datum(): Datum; /** * Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute. * @param value the function to compute data for each node */ datum<NewDatum>(value: (datum: Datum, index: number, outerIndex: number) => NewDatum): Update<NewDatum>; /** * Set the data item for each node in the selection. * @param value the constant element to use for each node */ datum<NewDatum>(value: NewDatum): Update<NewDatum>; /** * Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted. * @param comparator the comparison function, which defaults to d3.ascending */ sort(comparator?: (a: Datum, b: Datum) => number): Update<Datum>; /** * Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered. */ order(): Update<Datum>; /** * Returns the listener (if any) for the given event. * @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end. */ on(type: string): (datum: Datum, index: number, outerIndex: number) => any; /** * Adds a listener for the specified event. If one was already registered, it is removed before the new listener is added. The return value of the listener function is ignored. * @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end. * @param listener an event listener function, or null to unregister * @param capture sets the DOM useCapture flag */ on(type: string, listener: (datum: Datum, index: number, outerIndex: number) => any, capture?: boolean): Update<Datum>; /** * Begins a new transition. Interrupts any active transitions of the same name. * @param name the transition name (defaults to "") */ transition(name?: string): Transition<Datum>; /** * Interrupts the active transition of the provided name. Does not cancel scheduled transitions. * @param name the transition name (defaults to "") */ interrupt(name?: string): Update<Datum>; /** * Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited. * @param selector the CSS selector to match against */ select(selector: string): Update<Datum>; /** * Creates a subselection by using a function to find descendent elements. Bound data is inherited. * @param selector the function to find matching descendants */ select(selector: (datum: Datum, index: number, outerIndex: number) => EventTarget): Update<Datum>; /** * Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited. * @param selector the CSS selector to match against */ selectAll(selector: string): Update<Datum>; /** * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. * @param selector the function to find matching descendents */ selectAll(selector: (datum: Datum, index: number, outerIndex: number) => Array<EventTarget> | NodeList): Update<any>; /** * Invoke the given function for each element in the selection. The return value of the function is ignored. * @param func the function to invoke */ each(func: (datum: Datum, index: number, outerIndex: number) => any): Update<Datum>; /** * Call a function on the selection. sel.call(foo) is equivalent to foo(sel). * @param func the function to call on the selection * @param args any optional args */ call(func: (sel: Update<Datum>, ...args: any[]) => any, ...args: any[]): Update<Datum>; /** * Returns true if the current selection is empty. */ empty(): boolean; /** * Returns the first non-null element in the selection, or null otherwise. */ node(): Node; /** * Returns the total number of elements in the selection. */ size(): number; /** * Returns the placeholder nodes for each data element for which no corresponding DOM element was found. */ enter(): Enter<Datum>; /** * Returns a selection for those DOM nodes for which no new data element was found. */ exit(): Selection<Datum>; } interface Enter<Datum> { append(name: string): Selection<Datum>; append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; insert(name: string, before?: string): Selection<Datum>; insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before?: string): Selection<Datum>; insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; select(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; call(func: (selection: Enter<Datum>, ...args: any[]) => any, ...args: any[]): Enter<Datum>; empty(): boolean; size(): number; } } /** * Administrivia: JavaScript primitive types, or "things that toString() predictably". */ export type Primitive = number | string | boolean; /** * Administrivia: anything with a valueOf(): number method is comparable, so we allow it in numeric operations */ interface Numeric { valueOf(): number; } /** * A grouped array of nodes. * @param Datum the data bound to this selection. */ interface Selection<Datum> { /** * Retrieve a grouped selection. */ [index: number]: selection.Group; /** * The number of groups in this selection. */ length: number; /** * Retrieve the value of the given attribute for the first node in the selection. * * @param name The attribute name to query. May be prefixed (see d3.ns.prefix). */ attr(name: string): string; /** * For all nodes, set the attribute to the specified constant value. Use null to remove. * * @param name The attribute name, optionally prefixed. * @param value The attribute value to use. Note that this is coerced to a string automatically. */ attr(name: string, value: Primitive): Selection<Datum>; /** * Derive an attribute value for each node in the selection based on bound data. * * @param name The attribute name, optionally prefixed. * @param value The function of the datum (the bound data item), index (the position in the subgrouping), and outer index (overall position in nested selections) which computes the attribute value. If the function returns null, the attribute is removed. */ attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Selection<Datum>; /** * Set multiple properties at once using an Object. D3 iterates over all enumerable properties and either sets or computes the attribute's value based on the corresponding entry in the Object. * * @param obj A key-value mapping corresponding to attributes and values. If the value is a simple string or number, it is taken as a constant. Otherwise, it is a function that derives the attribute value. */ attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Selection<Datum>; /** * Returns true if the first node in this selection has the given class list. If multiple classes are specified (i.e., "foo bar"), then returns true only if all classes match. * * @param name The class list to query. */ classed(name: string): boolean; /** * Adds (or removes) the given class list. * * @param name The class list to toggle. Spaces separate class names: "foo bar" is a list of two classes. * @param value If true, add the classes. If false, remove them. */ classed(name: string, value: boolean): Selection<Datum>; /** * Determine if the given class list should be toggled for each node in the selection. * * @param name The class list. Spaces separate multiple class names. * @param value The function to run for each node. Should return true to add the class to the node, or false to remove it. */ classed(name: string, value: (datum: Datum, index: number, outerIndex: number) => boolean): Selection<Datum>; /** * Set or derive classes for multiple class lists at once. * * @param obj An Object mapping class lists to values that are either plain booleans or functions that return booleans. */ classed(obj: { [key: string]: boolean | ((datum: Datum, index: number, outerIndex: number) => boolean) }): Selection<Datum>; /** * Retrieve the computed style value for the first node in the selection. * @param name The CSS property name to query */ style(name: string): string; /** * Set a style property for all nodes in the selection. * @param name the CSS property name * @param value the property value * @param priority if specified, either null or the string "important" (no exclamation mark) */ style(name: string, value: Primitive, priority?: string): Selection<Datum>; /** * Derive a property value for each node in the selection. * @param name the CSS property name * @param value the function to derive the value * @param priority if specified, either null or the string "important" (no exclamation mark) */ style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Selection<Datum>; /** * Set a large number of CSS properties from an object. * * @param obj an Object whose keys correspond to CSS property names and values are either constants or functions that derive property values * @param priority if specified, either null or the string "important" (no exclamation mark) */ style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Selection<Datum>; /** * Retrieve an arbitrary node property such as the 'checked' property of checkboxes, or the 'value' of text boxes. * * @param name the node's property to retrieve */ property(name: string): any; /** * For each node, set the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. * * @param name the property name * @param value the property value */ property(name: string, value: any): Selection<Datum>; /** * For each node, derive the property value. Internally, this sets the node property directly (e.g., node[name] = value), so take care not to mutate special properties like __proto__. * * @param name the property name * @param value the function used to derive the property's value */ property(name: string, value: (datum: Datum, index: number, outerIndex: number) => any): Selection<Datum>; /** * Set multiple node properties. Caveats apply: take care not to mutate special properties like __proto__. * * @param obj an Object whose keys correspond to node properties and values are either constants or functions that will compute a value. */ property(obj: { [key: string]: any | ((datum: Datum, index: number, innerInder: number) => any) }): Selection<Datum>; /** * Retrieve the textContent of the first node in the selection. */ text(): string; /** * Set the textContent of each node in the selection. * @param value the text to use for all nodes */ text(value: Primitive): Selection<Datum>; /** * Compute the textContent of each node in the selection. * @param value the function which will compute the text */ text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Selection<Datum>; /** * Retrieve the HTML content of the first node in the selection. Uses 'innerHTML' internally and will not work with SVG or other elements without a polyfill. */ html(): string; /** * Set the HTML content of every node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. * @param value the HTML content to use. */ html(value: string): Selection<Datum>; /** * Compute the HTML content for each node in the selection. Uses 'innerHTML' internally and thus will not work with SVG or other elements without a polyfill. * @param value the function to compute HTML content */ html(value: (datum: Datum, index: number, outerIndex: number) => string): Selection<Datum>; /** * Appends a new child to each node in the selection. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. * * @param name the element name to append. May be prefixed (see d3.ns.prefix). */ append(name: string): Selection<Datum>; /** * Appends a new child to each node in the selection by computing a new node. This child will inherit the parent's data (if available). Returns a fresh selection consisting of the newly-appended children. * * @param name the function to compute a new element */ append(name: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; /** * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the element name to append. May be prefixed (see d3.ns.prefix). * @param before the selector to determine position (e.g., ":first-child") */ insert(name: string, before: string): Selection<Datum>; /** * Inserts a new child to each node in the selection. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the element name to append. May be prefixed (see d3.ns.prefix). * @param before a function to determine the node to use as the next sibling */ insert(name: string, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; /** * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the function to compute a new child * @param before the selector to determine position (e.g., ":first-child") */ insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: string): Selection<Datum>; /** * Inserts a new child to the end of each node in the selection by computing a new node. This child will inherit its parent's data (if available). Returns a fresh selection consisting of the newly-inserted children. * @param name the function to compute a new child * @param before a function to determine the node to use as the next sibling */ insert(name: (datum: Datum, index: number, outerIndex: number) => EventTarget, before: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; /** * Removes the elements from the DOM. They are in a detached state and may be re-added (though there is currently no dedicated API for doing so). */ remove(): Selection<Datum>; /** * Retrieves the data bound to the first group in this selection. */ data(): Datum[]; /** * Binds data to this selection. * @param data the array of data to bind to this selection * @param key the optional function to determine the unique key for each piece of data. When unspecified, uses the index of the element. */ data<NewDatum>(data: NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): selection.Update<NewDatum>; /** * Derives data to bind to this selection. * @param data the function to derive data. Must return an array. * @param key the optional function to determine the unique key for each data item. When unspecified, uses the index of the element. */ data<NewDatum>(data: (datum: Datum, index: number, outerIndex: number) => NewDatum[], key?: (datum: NewDatum, index: number, outerIndex: number) => string): selection.Update<NewDatum>; /** * Filters the selection, returning only those nodes that match the given CSS selector. * @param selector the CSS selector */ filter(selector: string): Selection<Datum>; /** * Filters the selection, returning only those nodes for which the given function returned true. * @param selector the filter function */ filter(selector: (datum: Datum, index: number, outerIndex: number) => boolean): Selection<Datum>; /** * Return the data item bound to the first element in the selection. */ datum(): Datum; /** * Derive the data item for each node in the selection. Useful for situations such as the HTML5 'dataset' attribute. * @param value the function to compute data for each node */ datum<NewDatum>(value: (datum: Datum, index: number, outerIndex: number) => NewDatum): Selection<NewDatum>; /** * Set the data item for each node in the selection. * @param value the constant element to use for each node */ datum<NewDatum>(value: NewDatum): Selection<NewDatum>; /** * Reorders nodes in the selection based on the given comparator. Nodes are re-inserted into the document once sorted. * @param comparator the comparison function, which defaults to d3.ascending */ sort(comparator?: (a: Datum, b: Datum) => number): Selection<Datum>; /** * Reorders nodes in the document to match the selection order. More efficient than calling sort() if the selection is already ordered. */ order(): Selection<Datum>; /** * Returns the listener (if any) for the given event. * @param type the type of event to load the listener for. May have a namespace (e.g., ".foo") at the end. */ on(type: string): (datum: Datum, index: number, outerIndex: number) => any; /** * Adds a listener for the specified event. If one was already registered, it is removed before the new listener is added. The return value of the listener function is ignored. * @param type the of event to listen to. May have a namespace (e.g., ".foo") at the end. * @param listener an event listener function, or null to unregister * @param capture sets the DOM useCapture flag */ on(type: string, listener: (datum: Datum, index: number, outerIndex: number) => any, capture?: boolean): Selection<Datum>; /** * Begins a new transition. Interrupts any active transitions of the same name. * @param name the transition name (defaults to "") */ transition(name?: string): Transition<Datum>; /** * Interrupts the active transition of the provided name. Does not cancel scheduled transitions. * @param name the transition name (defaults to "") */ interrupt(name?: string): Selection<Datum>; /** * Creates a subselection by finding the first descendent matching the selector string. Bound data is inherited. * @param selector the CSS selector to match against */ select(selector: string): Selection<Datum>; /** * Creates a subselection by using a function to find descendent elements. Bound data is inherited. * @param selector the function to find matching descendants */ select(selector: (datum: Datum, index: number, outerIndex: number) => EventTarget): Selection<Datum>; /** * Creates a subselection by finding all descendents that match the given selector. Bound data is not inherited. * @param selector the CSS selector to match against */ selectAll(selector: string): Selection<any>; /** * Creates a subselection by finding all descendants that match the given selector. Bound data is not inherited. * * Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over. */ selectAll<T>(selector: string): Selection<T>; /** * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. * @param selector the function to find matching descendents */ selectAll(selector: (datum: Datum, index: number, outerIndex: number) => Array<EventTarget> | NodeList): Selection<any>; /** * Creates a subselection by using a function to find descendent elements. Bound data is not inherited. * * Use this overload when data-binding a subselection (that is, sel.selectAll('.foo').data(d => ...)). The type will carry over. * @param selector the function to find matching descendents */ selectAll<T>(selector: (datum: Datum, index: number, outerIndex: number) => Array<EventTarget> | NodeList): Selection<T>; /** * Invoke the given function for each element in the selection. The return value of the function is ignored. * @param func the function to invoke */ each(func: (datum: Datum, index: number, outerIndex: number) => any): Selection<Datum>; /** * Call a function on the selection. sel.call(foo) is equivalent to foo(sel). * @param func the function to call on the selection * @param args any optional args */ call(func: (sel: Selection<Datum>, ...args: any[]) => any, ...args: any[]): Selection<Datum>; /** * Returns true if the current selection is empty. */ empty(): boolean; /** * Returns the first non-null element in the selection, or null otherwise. */ node(): Node; /** * Returns the total number of elements in the selection. */ size(): number; } export function transition(): Transition<any>; namespace transition { export var prototype: Transition<any>; } interface Transition<Datum> { transition(): Transition<Datum>; delay(): number; delay(delay: number): Transition<Datum>; delay(delay: (datum: Datum, index: number, outerIndex: number) => number): Transition<Datum>; duration(): number; duration(duration: number): Transition<Datum>; duration(duration: (datum: Datum, index: number, outerIndex: number) => number): Transition<Datum>; ease(): (t: number) => number; ease(value: string, ...args: any[]): Transition<Datum>; ease(value: (t: number) => number): Transition<Datum>; attr(name: string, value: Primitive): Transition<Datum>; attr(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive): Transition<Datum>; attr(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }): Transition<Datum>; attrTween(name: string, tween: (datum: Datum, index: number, attr: string) => (t: number) => Primitive): Transition<Datum>; style(name: string, value: Primitive, priority?: string): Transition<Datum>; style(name: string, value: (datum: Datum, index: number, outerIndex: number) => Primitive, priority?: string): Transition<Datum>; style(obj: { [key: string]: Primitive | ((datum: Datum, index: number, outerIndex: number) => Primitive) }, priority?: string): Transition<Datum>; styleTween(name: string, tween: (datum: Datum, index: number, attr: string) => (t: number) => Primitive, priority?: string): Transition<Datum>; text(value: Primitive): Transition<Datum>; text(value: (datum: Datum, index: number, outerIndex: number) => Primitive): Transition<Datum>; tween(name: string, factory: () => (t: number) => any): Transition<Datum>; remove(): Transition<Datum>; select(selector: string): Transition<Datum>; select(selector: (d: Datum, i: number) => EventTarget): Transition<Datum>; selectAll(selector: string): Transition<any>; selectAll(selector: (d: Datum, i: number) => EventTarget[]): Transition<any>; filter(selector: string): Transition<Datum>; filter(selector: (d: Datum, i: number) => boolean): Transition<Datum>; each(type: string, listener: (d: Datum, i: number) => any): Transition<Datum>; each(listener: (d: Datum, i: number) => any): Transition<Datum>; call(func: (transition: Transition<Datum>, ...args: any[]) => any, ...args: any[]): Transition<Datum>; empty(): boolean; node(): Node; size(): number; } export function ease(type: 'linear'): (t: number) => number; export function ease(type: 'linear-in'): (t: number) => number; export function ease(type: 'linear-out'): (t: number) => number; export function ease(type: 'linear-in-out'): (t: number) => number; export function ease(type: 'linear-out-in'): (t: number) => number; export function ease(type: 'poly', k: number): (t: number) => number; export function ease(type: 'poly-in', k: number): (t: number) => number; export function ease(type: 'poly-out', k: number): (t: number) => number; export function ease(type: 'poly-in-out', k: number): (t: number) => number; export function ease(type: 'poly-out-in', k: number): (t: number) => number; export function ease(type: 'quad'): (t: number) => number; export function ease(type: 'quad-in'): (t: number) => number; export function ease(type: 'quad-out'): (t: number) => number; export function ease(type: 'quad-in-out'): (t: number) => number; export function ease(type: 'quad-out-in'): (t: number) => number; export function ease(type: 'cubic'): (t: number) => number; export function ease(type: 'cubic-in'): (t: number) => number; export function ease(type: 'cubic-out'): (t: number) => number; export function ease(type: 'cubic-in-out'): (t: number) => number; export function ease(type: 'cubic-out-in'): (t: number) => number; export function ease(type: 'sin'): (t: number) => number; export function ease(type: 'sin-in'): (t: number) => number; export function ease(type: 'sin-out'): (t: number) => number; export function ease(type: 'sin-in-out'): (t: number) => number; export function ease(type: 'sin-out-in'): (t: number) => number; export function ease(type: 'circle'): (t: number) => number; export function ease(type: 'circle-in'): (t: number) => number; export function ease(type: 'circle-out'): (t: number) => number; export function ease(type: 'circle-in-out'): (t: number) => number; export function ease(type: 'circle-out-in'): (t: number) => number; export function ease(type: 'elastic', a?: number, b?: number): (t: number) => number; export function ease(type: 'elastic-in', a?: number, b?: number): (t: number) => number; export function ease(type: 'elastic-out', a?: number, b?: number): (t: number) => number; export function ease(type: 'elastic-in-out', a?: number, b?: number): (t: number) => number; export function ease(type: 'elastic-out-in', a?: number, b?: number): (t: number) => number; export function ease(type: 'back', s: number): (t: number) => number; export function ease(type: 'back-in', s: number): (t: number) => number; export function ease(type: 'back-out', s: number): (t: number) => number; export function ease(type: 'back-in-out', s: number): (t: number) => number; export function ease(type: 'back-out-in', s: number): (t: number) => number; export function ease(type: 'bounce'): (t: number) => number; export function ease(type: 'bounce-in'): (t: number) => number; export function ease(type: 'bounce-out'): (t: number) => number; export function ease(type: 'bounce-in-out'): (t: number) => number; export function ease(type: 'bounce-out-in'): (t: number) => number; export function ease(type: string, ...args: any[]): (t: number) => number; export function timer(func: () => any, delay?: number, time?: number): void; namespace timer { export function flush(): void; } interface BaseEvent { type: string; sourceEvent?: Event; } /** * Define a D3-specific ZoomEvent per https://github.com/mbostock/d3/wiki/Zoom-Behavior#event */ interface ZoomEvent extends BaseEvent { scale: number; translate: [number, number]; } /** * Define a D3-specific DragEvent per https://github.com/mbostock/d3/wiki/Drag-Behavior#on */ interface DragEvent extends BaseEvent { x: number; y: number; dx: number; dy: number; } /** * The current event's value. Use this variable in a handler registered with `selection.on`. */ export var event: Event | BaseEvent; /** * Returns the x and y coordinates of the mouse relative to the provided container element, using d3.event for the mouse's position on the page. * @param container the container element (e.g. an SVG <g> element) */ export function mouse(container: EventTarget): [number, number]; /** * Given a container element and a touch identifier, determine the x and y coordinates of the touch. * @param container the container element (e.g., an SVG <svg> element) * @param identifier the given touch identifier */ export function touch(container: EventTarget, identifer: number): [number, number]; /** * Given a container element, a list of touches, and a touch identifier, determine the x and y coordinates of the touch. * @param container the container element (e.g., an SVG <svg> element) * @param identifier the given touch identifier */ export function touch(container: EventTarget, touches: TouchList, identifer: number): [number, number]; /** * Given a container element and an optional list of touches, return the position of every touch relative to the container. * @param container the container element * @param touches an optional list of touches (defaults to d3.event.touches) */ export function touches(container: EventTarget, touches?: TouchList): Array<[number, number]>; // NB. this is limited to primitive values due to D3's use of the <, >, and >= operators. Results get weird for object instances. /** * Compares two primitive values for sorting (in ascending order). */ export function ascending(a: Primitive, b: Primitive): number; /** * Compares two primitive values for sorting (in ascending order). */ export function descending(a: Primitive, b: Primitive): number; /** * Return the minimum value in the array using natural order. */ export function min(array: number[]): number; /** * Return the minimum value in the array using natural order. */ export function min(array: string[]): string; /** * Return the minimum value in the array using natural order. */ export function min<T extends Numeric>(array: T[]): T; /** * Return the minimum value in the array using natural order. */ export function min<T>(array: T[], accessor: (datum: T, index: number) => number): number; /** * Return the minimum value in the array using natural order. */ export function min<T>(array: T[], accessor: (datum: T, index: number) => string): string; /** * Return the minimum value in the array using natural order. */ export function min<T, U extends Numeric>(array: T[], accessor: (datum: T, index: number) => U): U; /** * Return the maximum value in the array of numbers using natural order. */ export function max(array: number[]): number; /** * Return the maximum value in the array of strings using natural order. */ export function max(array: string[]): string; /** * Return the maximum value in the array of numbers using natural order. */ export function max<T extends Numeric>(array: T[]): T; /** * Return the maximum value in the array using natural order and a projection function to map values to numbers. */ export function max<T>(array: T[], accessor: (datum: T, index: number) => number): number; /** * Return the maximum value in the array using natural order and a projection function to map values to strings. */ export function max<T>(array: T[], accessor: (datum: T, index: number) => string): st