Improve d3's types.

This commit is contained in:
Utkarsh Upadhyay
2013-07-14 02:00:35 +02:00
parent 17f058521f
commit 06c68fb372
2 changed files with 604 additions and 80 deletions
Vendored
+237 -80
View File
@@ -424,7 +424,7 @@ declare module D3 {
/**
* Returns a built-in easing function of the specified type
*/
ease: (type: string, ...arrs: any[]) => Transition;
ease: (type: string, ...arrs: any[]) => D3.Transition.Transition;
/**
* Constructs a new RGB color.
*/
@@ -487,8 +487,14 @@ declare module D3 {
* gets the touch positions relative to a specified container.
*/
touches(container: any): Array<number>;
functor<T>(value: T): T;
functor<T>(value: () => T): T;
/**
* If the specified value is a function, returns the specified value.
* Otherwise, returns a function that returns the specified value.
*/
functor<R,T>(value: (p : R) => T): (p : R) => T;
functor<T>(value: T): (p : any) => T;
map(object?: any): Map;
set(array?: Array<any>): Set;
dispatch(...types: Array<string>): Dispatch;
@@ -659,6 +665,7 @@ declare module D3 {
(name: string): string;
(name: string, value: any): Selection;
(name: string, valueFunction: (data: any, index: number) => any): Selection;
(attrValueMap : any): Selection;
};
classed: {
@@ -696,8 +703,8 @@ declare module D3 {
remove: () => Selection;
data: {
(values: (data: any, index: number) => any): UpdateSelection;
(values: any[], key?: (data: any, index: number) => any): UpdateSelection;
(values: (data: any, index?: number) => any[], key?: (data: any, index?: number) => string): UpdateSelection;
(values: any[], key?: (data: any, index?: number) => string): UpdateSelection;
};
datum: {
@@ -732,7 +739,7 @@ declare module D3 {
append: (name: string) => Selection;
insert: (name: string, before: string) => Selection;
select: (selector: string) => Selection;
empty: () => bool;
empty: () => boolean;
node: () => HTMLElementSVGLocatable;
}
@@ -742,13 +749,21 @@ declare module D3 {
exit: () => Selection;
}
export interface Nest {
key(keyFunction: (data: any, index: number) => any): Nest;
rollup(rollupFunction: (data: any, index: number) => any): Nest;
map(values: any[]): Nest;
export interface NestKeyValue {
key: string;
values: any;
}
export interface Map{
export interface Nest {
key(keyFunction: (data: any, index: number) => any): Nest;
sortKeys(comparator: (d1: any, d2: any) => number): Nest;
sortValues(comparator: (d1: any, d2: any) => number): Nest;
rollup(rollupFunction: (data: any, index: number) => any): Nest;
map(values: any[]): any;
entries(values: any[]): NestKeyValue[];
}
export interface Map {
has(key: string): boolean;
get(key: string): any;
set<T>(key: string, value: T): T;
@@ -805,6 +820,7 @@ declare module D3 {
(name: string): string;
(name: string, value: any): Transition;
(name: string, valueFunction: (data: any, index: number) => any): Transition;
(attrValueMap : any): Transition;
};
style: {
(name: string): string;
@@ -944,19 +960,19 @@ declare module D3 {
export module Layout {
export interface Layout {
/**
* Creates a new Stack layout
* Creates a new Stack layout
*/
stack(): StackLayout;
/**
* Creates a new pie layout
* Creates a new pie layout
*/
pie(): PieLayout;
/**
* Creates a new force layout
* Creates a new force layout
*/
force(): ForceLayout;
/**
* Creates a new tree layout
* Creates a new tree layout
*/
tree(): TreeLayout;
bundle(): BundleLayout;
@@ -1052,11 +1068,15 @@ declare module D3 {
(): number;
(angle: number): D3.Svg.Arc;
(angle: () => number): D3.Svg.Arc;
(angle: (d : any) => number): D3.Svg.Arc;
(angle: (d : any, i: number) => number): D3.Svg.Arc;
};
endAngle: {
(): number;
(angle: number): D3.Svg.Arc;
(angle: () => number): D3.Svg.Arc;
(angle: (d : any) => number): D3.Svg.Arc;
(angle: (d : any, i: number) => number): D3.Svg.Arc;
};
}
@@ -1082,7 +1102,7 @@ declare module D3 {
startAngle: number;
endAngle: number;
value: number;
fixed: bool;
fixed: boolean;
children: GraphNode[];
_children: GraphNode[];
parent: GraphNode;
@@ -1489,11 +1509,11 @@ declare module D3 {
/**
* Gets the current brush extent
*/
(): Array<Array<number>>;
(): any[];
/**
* Sets the current brush extent
*/
(values: Array<Array<number>>): Brush;
(values: any[]): Brush;
};
/**
* Clears the extent, making the brush extent empty.
@@ -1541,41 +1561,48 @@ declare module D3 {
}
export interface Arc {
(options?: ArcOptions): string;
innerRadius: {
(): number;
/**
* Returns the path data string
*
* @param data Array of data elements
* @param index Optional index
*/
(data: any, index?: number): string;
innerRadius: {
(): (data: any, index?: number) => number;
(radius: number): Arc;
(radius: () => number): Arc;
(radius: (data: any) => number): Arc;
(radius: (data: any, index: number) => number): Arc;
};
outerRadius: {
(): number;
(): (data: any, index?: number) => number;
(radius: number): Arc;
(radius: () => number): Arc;
(radius: (data: any) => number): Arc;
(radius: (data: any, index: number) => number): Arc;
};
startAngle: {
(): number;
(): (data: any, index?: number) => number;
(angle: number): Arc;
(angle: () => number): Arc;
(angle: (data: any) => number): Arc;
(angle: (data: any, index: number) => number): Arc;
};
endAngle: {
(): number;
(): (data: any, index?: number) => number;
(angle: number): Arc;
(angle: () => number): Arc;
(angle: (data: any) => number): Arc;
(angle: (data: any, index: number) => number): Arc;
};
centroid(options?: ArcOptions): number[];
}
export interface ArcOptions {
innerRadius?: number;
outerRadius?: number;
startAngle?: number;
endAngle?: number;
centroid(data: any, index?: number): number[];
}
export interface Line {
/**
* Returns the path data string
*
*
* @param data Array of data elements
* @param index Optional index
*/
@@ -1587,13 +1614,20 @@ declare module D3 {
/**
* Get the x-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Line;
(accessor: (data: any) => number): Line;
(accessor: (data: any, index: number) => number): Line;
/**
* Set the x-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): Line;
};
/**
* Get or set the y-coordinate accessor.
@@ -1602,13 +1636,20 @@ declare module D3 {
/**
* Get the y-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Line;
(accessor: (data: any) => number): Line;
(accessor: (data: any, index: number) => number): Line;
/**
* Set the y-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): Line;
};
/**
* Get or set the interpolation mode.
@@ -1647,20 +1688,20 @@ declare module D3 {
/**
* Get the accessor function that controls where the line is defined.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => boolean;
/**
* Set the accessor function that controls where the area is defined.
*
* @param defined The new accessor function
*/
(defined: (data: any) => any): Line;
(defined: (data: any) => boolean): Line;
};
}
export interface LineRadial {
/**
* Returns the path data string
*
*
* @param data Array of data elements
* @param index Optional index
*/
@@ -1672,13 +1713,21 @@ declare module D3 {
/**
* Get the x-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): LineRadial;
(accessor: (data: any) => number): LineRadial;
(accessor: (data: any, index: number) => number): LineRadial;
/**
* Set the x-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): LineRadial;
};
/**
* Get or set the y-coordinate accessor.
@@ -1687,13 +1736,20 @@ declare module D3 {
/**
* Get the y-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): LineRadial;
(accessor: (data: any) => number): LineRadial;
(accessor: (data: any, index: number) => number): LineRadial;
/**
* Set the y-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): LineRadial;
};
/**
* Get or set the interpolation mode.
@@ -1741,13 +1797,15 @@ declare module D3 {
(defined: (data: any) => any): LineRadial;
};
radius: {
(): (d: any, i: any) => number;
(): (d: any, i?: number) => number;
(radius: number): LineRadial;
(radius: (d: any, i: any) => number): LineRadial;
(radius: (d: any) => number): LineRadial;
(radius: (d: any, i: number) => number): LineRadial;
}
angle: {
(): (d: any, i: any) => number;
(): (d: any, i?: any) => number;
(angle: number): LineRadial;
(angle: (d: any) => number): LineRadial;
(angle: (d: any, i: any) => number): LineRadial;
}
}
@@ -1764,13 +1822,20 @@ declare module D3 {
/**
* Get the x-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Area;
(accessor: (data: any) => number): Area;
(accessor: (data: any, index: number) => number): Area;
/**
* Set the x-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): Area;
};
/**
* Get or set the x0-coordinate (baseline) accessor.
@@ -1779,13 +1844,20 @@ declare module D3 {
/**
* Get the x0-coordinate (baseline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x0-coordinate (baseline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Area;
(accessor: (data: any) => number): Area;
(accessor: (data: any, index: number) => number): Area;
/**
* Set the x0-coordinate (baseline) to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): Area;
};
/**
* Get or set the x1-coordinate (topline) accessor.
@@ -1794,13 +1866,20 @@ declare module D3 {
/**
* Get the x1-coordinate (topline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x1-coordinate (topline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Area;
(accessor: (data: any) => number): Area;
(accessor: (data: any, index: number) => number): Area;
/**
* Set the x1-coordinate (topline) to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): Area;
};
/**
* Get or set the y-coordinate accessor.
@@ -1809,13 +1888,20 @@ declare module D3 {
/**
* Get the y-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Area;
(accessor: (data: any) => number): Area;
(accessor: (data: any, index: number) => number): Area;
/**
* Set the y-coordinate to a constant.
*
* @param cnst The constant value
*/
(cnst: number): Area;
};
/**
* Get or set the y0-coordinate (baseline) accessor.
@@ -1824,13 +1910,20 @@ declare module D3 {
/**
* Get the y0-coordinate (baseline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y0-coordinate (baseline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Area;
(accessor: (data: any) => number): Area;
(accessor: (data: any, index: number) => number): Area;
/**
* Set the y0-coordinate (baseline) to a constant.
*
* @param cnst The constant value
*/
(cnst: number): Area;
};
/**
* Get or set the y1-coordinate (topline) accessor.
@@ -1839,13 +1932,20 @@ declare module D3 {
/**
* Get the y1-coordinate (topline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y1-coordinate (topline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): Area;
(accessor: (data: any) => number): Area;
(accessor: (data: any, index: number) => number): Area;
/**
* Set the y1-coordinate (baseline) to a constant.
*
* @param cnst The constant value
*/
(cnst: number): Area;
};
/**
* Get or set the interpolation mode.
@@ -1906,13 +2006,20 @@ declare module D3 {
/**
* Get the x-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): AreaRadial;
(accessor: (data: any) => number): AreaRadial;
(accessor: (data: any, index: number) => number): AreaRadial;
/**
* Set the x-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): AreaRadial;
};
/**
* Get or set the x0-coordinate (baseline) accessor.
@@ -1921,13 +2028,20 @@ declare module D3 {
/**
* Get the x0-coordinate (baseline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x0-coordinate (baseline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): AreaRadial;
(accessor: (data: any) => number): AreaRadial;
(accessor: (data: any, index: number) => number): AreaRadial;
/**
* Set the x0-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): AreaRadial;
};
/**
* Get or set the x1-coordinate (topline) accessor.
@@ -1936,13 +2050,20 @@ declare module D3 {
/**
* Get the x1-coordinate (topline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the x1-coordinate (topline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): AreaRadial;
(accessor: (data: any) => number): AreaRadial;
(accessor: (data: any, index: number) => number): AreaRadial;
/**
* Set the x1-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): AreaRadial;
};
/**
* Get or set the y-coordinate accessor.
@@ -1951,13 +2072,20 @@ declare module D3 {
/**
* Get the y-coordinate accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y-coordinate accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): AreaRadial;
(accessor: (data: any) => number): AreaRadial;
(accessor: (data: any, index: number) => number): AreaRadial;
/**
* Set the y-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): AreaRadial;
};
/**
* Get or set the y0-coordinate (baseline) accessor.
@@ -1966,13 +2094,20 @@ declare module D3 {
/**
* Get the y0-coordinate (baseline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y0-coordinate (baseline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): AreaRadial;
(accessor: (data: any) => number): AreaRadial;
(accessor: (data: any, index: number) => number): AreaRadial;
/**
* Set the y0-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): AreaRadial;
};
/**
* Get or set the y1-coordinate (topline) accessor.
@@ -1981,13 +2116,20 @@ declare module D3 {
/**
* Get the y1-coordinate (topline) accessor.
*/
(): (data: any) => any;
(): (data: any, index ?: number) => number;
/**
* Set the y1-coordinate (topline) accessor.
*
* @param accessor The new accessor function
*/
(accessor: (data: any) => any): AreaRadial;
(accessor: (data: any) => number): AreaRadial;
(accessor: (data: any, index: number) => number): AreaRadial;
/**
* Set the y1-coordinate to a constant.
*
* @param cnst The new constant value.
*/
(cnst: number): AreaRadial;
};
/**
* Get or set the interpolation mode.
@@ -2038,31 +2180,43 @@ declare module D3 {
(): number;
(radius: number): AreaRadial;
(radius: () => number): AreaRadial;
(radius: (data: any) => number): AreaRadial;
(radius: (data: any, index: number) => number): AreaRadial;
};
innerRadius: {
(): number;
(radius: number): AreaRadial;
(radius: () => number): AreaRadial;
(radius: (data: any) => number): AreaRadial;
(radius: (data: any, index: number) => number): AreaRadial;
};
outerRadius: {
(): number;
(radius: number): AreaRadial;
(radius: () => number): AreaRadial;
(radius: (data: any) => number): AreaRadial;
(radius: (data: any, index: number) => number): AreaRadial;
};
angle: {
(): number;
(angle: number): AreaRadial;
(angle: () => number): AreaRadial;
(angle: (data: any) => number): AreaRadial;
(angle: (data: any, index: number) => number): AreaRadial;
};
startAngle: {
(): number;
(angle: number): AreaRadial;
(angle: () => number): AreaRadial;
(angle: (data: any) => number): AreaRadial;
(angle: (data: any, index: number) => number): AreaRadial;
};
endAngle: {
(): number;
(angle: number): AreaRadial;
(angle: () => number): AreaRadial;
(angle: (data: any) => number): AreaRadial;
(angle: (data: any, index: number) => number): AreaRadial;
};
}
@@ -2098,18 +2252,21 @@ declare module D3 {
export interface Diagonal {
(datum: any, index?: number): string;
projection: {
(): Array<number>;
(radius: (d: any, i?: number) => Array<number>): Diagonal;
(): (datum: any, index?: number) => Array<number>;
(proj: (datum: any) => Array<number>): Diagonal;
(proj: (datum: any, index: number) => Array<number>): Diagonal;
};
source: {
(): any;
(angle: any): Diagonal;
(angle: (d: any, i?: number) => any): Diagonal;
(): (datum: any, index?: number) => any;
(src: (datum: any) => any): Diagonal;
(src: (datum: any, index: number) => any): Diagonal;
(src: any): Diagonal;
};
target: {
(): any;
(angle: any): Diagonal;
(angle: (d: any, i?: number) => any): Diagonal;
(): (datum: any, index?: number) => any;
(target: (d: any) => any): Diagonal;
(target: (d: any, i: number) => any): Diagonal;
(target: any): Diagonal;
};
}
}
@@ -2980,7 +3137,7 @@ declare module D3 {
(accesor: (d: any) => any): Quadtree;
}
y: {
y: {
(): (d: any) => any;
(accesor: (d: any) => any): Quadtree;