From 9d69000f3cdf804287223d19d264e9955e1ae8e8 Mon Sep 17 00:00:00 2001 From: Brian Malehorn Date: Mon, 21 Jul 2014 17:25:10 -0700 Subject: [PATCH 1/2] updated d3.d.ts, but broke everything Incremental bugfixes we put into d3.d.ts are blown away. I'm going to fix them, but I should have this checkpoint. --- tsd.json | 2 +- typings/d3/d3.d.ts | 323 +++++++++++++++++++++++++++++++-------------- 2 files changed, 223 insertions(+), 102 deletions(-) diff --git a/tsd.json b/tsd.json index 1a7a705f82..e57de906e5 100644 --- a/tsd.json +++ b/tsd.json @@ -8,7 +8,7 @@ "commit": "16dd1ab76fb4c65e532ca820dd45c875636521b6" }, "d3/d3.d.ts": { - "commit": "16dd1ab76fb4c65e532ca820dd45c875636521b6" + "commit": "f2ce08f2bf86d5f234dd180318ea790512ec41e5" }, "mocha/mocha.d.ts": { "commit": "16dd1ab76fb4c65e532ca820dd45c875636521b6" diff --git a/typings/d3/d3.d.ts b/typings/d3/d3.d.ts index c2bd987c05..598cd9f34b 100644 --- a/typings/d3/d3.d.ts +++ b/typings/d3/d3.d.ts @@ -42,18 +42,19 @@ declare module D3 { }; } - export interface Event { + export interface D3Event extends Event{ dx: number; dy: number; clientX: number; clientY: number; translate: number[]; scale: number; - sourceEvent: Event; + sourceEvent: D3Event; x: number; y: number; keyCode: number; altKey: any; + type: string; } export interface Base extends Selectors { @@ -64,7 +65,7 @@ declare module D3 { /** * Access the current user event for interaction */ - event: Event; + event: D3Event; /** * Compare two values for sorting. @@ -242,7 +243,7 @@ declare module D3 { * * @param map Array of objects to get the values from */ - values(map: any): any[]; + values(map: any[]): any[]; /** * List the key-value entries of an associative array. * @@ -528,7 +529,7 @@ declare module D3 { /** * gets the touch positions relative to a specified container. */ - touches(container: any): Array; + touches(container: any): Array>; /** * If the specified value is a function, returns the specified value. @@ -709,7 +710,7 @@ declare module D3 { (name: string): string; (name: string, value: any): Selection; (name: string, valueFunction: (data: any, index: number) => any): Selection; - (attrValueMap : any): Selection; + (attrValueMap : Object): Selection; }; classed: { @@ -722,12 +723,14 @@ declare module D3 { (name: string): string; (name: string, value: any, priority?: string): Selection; (name: string, valueFunction: (data: any, index: number) => any, priority?: string): Selection; + (styleValueMap : Object): Selection; }; property: { (name: string): void; (name: string, value: any): Selection; (name: string, valueFunction: (data: any, index: number) => any): Selection; + (propertyValueMap : Object): Selection; }; text: { @@ -746,9 +749,10 @@ declare module D3 { insert: (name: string, before: string) => Selection; remove: () => Selection; empty: () => boolean; + data: { - (values: (data: any, index?: number) => any[], key?: (data: any, index?: number) => string): UpdateSelection; - (values: any[], key?: (data: any, index?: number) => string): UpdateSelection; + (values: (data: any, index?: number) => any[], key?: (data: any, index?: number) => any): UpdateSelection; + (values: any[], key?: (data: any, index?: number) => any): UpdateSelection; (): any[]; }; @@ -763,7 +767,7 @@ declare module D3 { //(filter: string): UpdateSelection; }; - call(callback: (selection: Selection) => void ): Selection; + call(callback: (selection: Selection, ...args: any[]) => void, ...args: any[]): Selection; each(eachFunction: (data: any, index: number) => any): Selection; on: { (type: string): (data: any, index: number) => any; @@ -807,10 +811,12 @@ declare module D3 { export interface EnterSelection { append: (name: string) => Selection; - insert: (name: string, before: string) => Selection; + insert: (name: string, before?: string) => Selection; select: (selector: string) => Selection; empty: () => boolean; node: () => Element; + call: (callback: (selection: EnterSelection) => void) => EnterSelection; + size: () => number; } export interface UpdateSelection extends Selection { @@ -997,9 +1003,29 @@ declare module D3 { fridays: Range; saturdays: Range; format: { - + /** + * Constructs a new local time formatter using the given specifier. + */ (specifier: string): TimeFormat; - utc: (specifier: string) => TimeFormat; + /** + * Returns a new multi-resolution time format given the specified array of predicated formats. + */ + multi: (formats: any[][]) => TimeFormat; + + utc: { + /** + * Constructs a new local time formatter using the given specifier. + */ + (specifier: string): TimeFormat; + /** + * Returns a new multi-resolution UTC time format given the specified array of predicated formats. + */ + multi: (formats: any[][]) => TimeFormat; + }; + + /** + * The full ISO 8601 UTC time format: "%Y-%m-%dT%H:%M:%S.%LZ". + */ iso: TimeFormat; }; @@ -1028,7 +1054,7 @@ declare module D3 { ceil: (date: Date) => Date; range: Range; offset: (date: Date, step: number) => Date; - utc: Interval; + utc?: Interval; } export interface TimeFormat { @@ -1063,7 +1089,7 @@ declare module D3 { histogram(): HistogramLayout; pack(): PackLayout; partition(): PartitionLayout; - treeMap(): TreeMapLayout; + treemap(): TreeMapLayout; } export interface StackLayout { @@ -1263,7 +1289,7 @@ declare module D3 { } export interface BundleLayout{ - (links: Array): Array; + (links: Array): Array>; } export interface ChordLayout { @@ -1276,15 +1302,15 @@ declare module D3 { (padding: number): ChordLayout; } sortGroups: { - (): Array; + (): (a: number, b: number) => number; (comparator: (a: number, b: number) => number): ChordLayout; } sortSubgroups: { - (): Array; + (): (a: number, b: number) => number; (comparator: (a: number, b: number) => number): ChordLayout; } sortChords: { - (): Array; + (): (a: number, b: number) => number; (comparator: (a: number, b: number) => number): ChordLayout; } chords(): Array; @@ -1457,7 +1483,7 @@ declare module D3 { /** * decrease lightness by some exponential factor (gamma) */ - darker(k: number): Color; + darker(k?: number): Color; /** * convert the color to a string. */ @@ -1594,6 +1620,7 @@ declare module D3 { export interface Symbol { type: (string:string) => Symbol; size: (number:number) => Symbol; + (datum:any, index:number): string; } export interface Brush { @@ -1684,35 +1711,19 @@ declare module D3 { (...arguments: any[]): Axis; }; - tickValues: { - (): any[]; - (...arguments: any[]): Axis; - }; - - tickSize: { - (): number; - (inner: number, outer?: number): Axis; - } - - innerTickSize: { - (): number; - (value: number): Axis; - } - - outerTickSize: { - (): number; - (value: number): Axis; - } - tickPadding: { (): number; (padding: number): Axis; }; - tickFormat: { - (): (value: any) => string; - (formatter: (value: any) => string): Axis; + tickValues: { + (): any[]; + (values: any[]): Axis; }; + + tickSubdivide(count: number): Axis; + tickSize(major?: number, minor?: number, end?: number): Axis; + tickFormat(formatter: (value: any) => string): Axis; } export interface Arc { @@ -2493,7 +2504,7 @@ declare module D3 { (values: any[]): Scale; (): any[]; }; - invertExtent(y: any): any[]; + invertExtent?(y: any): any[]; copy(): Scale; } @@ -2554,32 +2565,31 @@ declare module D3 { (factory: D3.Transition.Interpolate): QuantitiveScale; }; /** - * Enable or disable clamping of the output range, or query clamp status. + * enable or disable clamping of the output range. * - * @param clamp Enable or disable. If not supplied, gets current clamp status instead. + * @param clamp Enable or disable */ - clamp(clamp?: boolean): QuantitiveScale; + clamp(clamp: boolean): QuantitiveScale; /** * extend the scale domain to nice round numbers. - * + * * @param count Optional number of ticks to exactly fit the domain */ nice(count?: number): QuantitiveScale; /** * get representative values from the input domain. * - * @param count Aproximate representative values to return. Defaults to 10. + * @param count Aproximate representative values to return. */ - ticks(count?: number): any[]; + ticks(count: number): any[]; /** * get a formatter for displaying tick values * - * @param count Aproximate representative values to return. - * @param format? The format specifier to use. + * @param count Aproximate representative values to return */ - tickFormat(count: number, format?: string): (n: number) => string; + tickFormat(count: number): (n: number) => string; /** - * create a new scale from an existing scale. + * create a new scale from an existing scale.. */ copy(): QuantitiveScale; } @@ -2593,13 +2603,31 @@ declare module D3 { (value: number): number; } - export interface IdentityScale extends QuantitiveScale { + export interface IdentityScale extends Scale { /** * Get the range value corresponding to a given domain value. * * @param value Domain Value */ (value: number): number; + /** + * Get the domain value corresponding to a given range value. + * + * @param value Range Value + */ + invert(value: number): number; + /** + * get representative values from the input domain. + * + * @param count Aproximate representative values to return. + */ + ticks(count: number): any[]; + /** + * get a formatter for displaying tick values + * + * @param count Aproximate representative values to return + */ + tickFormat(count: number): (n: number) => string; } export interface SqrtScale extends QuantitiveScale { @@ -2733,14 +2761,13 @@ declare module D3 { (): D3.Transition.Interpolate; (factory: D3.Transition.InterpolateFactory): TimeScale; }; - clamp(clamp?: boolean): TimeScale; + clamp(clamp: boolean): TimeScale; ticks: { (count: number): any[]; - (range: Range, count: number): any[]; + (range: D3.Time.Range, count: number): any[]; }; tickFormat(count: number): (n: number) => string; copy(): TimeScale; - nice(count?: number): TimeScale; } } @@ -2925,11 +2952,11 @@ declare module D3 { /** * create a standard projection from a raw projection. */ - projection(raw: (lambda: any, phi: any) => any): Projection; + projection(raw: RawProjection): Projection; /** * create a standard projection from a mutable raw projection. */ - projectionMutator(rawFactory: (lambda: number, phi: number) => Array): Projection; + projectionMutator(rawFactory: RawProjection): ProjectionMutator; /** * the Albers equal-area conic projection. */ @@ -2943,82 +2970,82 @@ declare module D3 { */ azimuthalEqualArea: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * the azimuthal equidistant projection. */ azimuthalEquidistant: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * the conic conformal projection. */ conicConformal: { (): Projection; - raw(): Projection; + raw(phi1:number, phi2:number): RawProjection; } /** * the conic equidistant projection. */ conicEquidistant: { (): Projection; - raw(): Projection; + raw(phi1:number, phi2:number): RawProjection; } /** * the conic equal-area (a.k.a. Albers) projection. */ conicEqualArea: { (): Projection; - raw(): Projection; + raw(phi1:number, phi2:number): RawProjection; } /** * the equirectangular (plate carreƩ) projection. */ equirectangular: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * the gnomonic projection. */ gnomonic: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * the spherical Mercator projection. */ mercator: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * the azimuthal orthographic projection. */ - othographic: { + orthographic: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * the azimuthal stereographic projection. */ stereographic: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * the transverse Mercator projection. */ transverseMercator: { (): Projection; - raw(): Projection; + raw: RawProjection; } /** * convert a GeoJSON object to a geometry stream. */ - stream(object: GeoJSON, listener: any): Stream; + stream(object: GeoJSON, listener: Stream): void; /** * */ @@ -3026,7 +3053,7 @@ declare module D3 { /** * */ - greatArc: GreatArc; + greatArc(): GreatArc; /** * */ @@ -3122,7 +3149,7 @@ declare module D3 { export interface Graticule{ (): GeoJSON; - lines(): GeoJSON; + lines(): Array; outline(): GeoJSON; extent: { (): Array>; @@ -3176,9 +3203,14 @@ declare module D3 { type: string; } + export interface RawProjection { + (lambda: number, phi: number): Array; + invert?(x: number, y: number): Array; + } + export interface Projection { (coordinates: Array): Array; - invert(point: Array): Array; + invert?(point: Array): Array; rotate: { (): Array; (rotation: Array): Projection; @@ -3187,6 +3219,10 @@ declare module D3 { (): Array; (location: Array): Projection; }; + parallels: { + (): Array; + (location: Array): Projection; + }; translate: { (): Array; (point: Array): Projection; @@ -3207,7 +3243,7 @@ declare module D3 { (): number; (precision: number): Projection; }; - stream(listener?: any): Stream; + stream(listener?: Stream): Stream; } export interface Stream { @@ -3223,15 +3259,20 @@ declare module D3 { (location: Array): Rotation; invert(location: Array): Rotation; } + + export interface ProjectionMutator { + (lambda: number, phi: number): Projection; + } } // Geometry export module Geom { export interface Geom { + voronoi(): Voronoi; /** * compute the Voronoi diagram for the specified points. */ - voronoi: Voronoi + voronoi(vertices: Array): Array; /** * compute the Delaunay triangulation for the specified points. */ @@ -3239,15 +3280,25 @@ declare module D3 { /** * constructs a quadtree for an array of points. */ - quadtree: Quadtree; + quadtree(): QuadtreeFactory; + /** + * Constructs a new quadtree for the specified array of points. + */ + quadtree(points: Array, x1: number, y1: number, x2: number, y2: number): Quadtree; /** - * constructs a polygon + * Constructs a new quadtree for the specified array of points. + */ + quadtree(points: Array, width: number, height: number): Quadtree; + /** + * Returns the input array of vertices with additional methods attached */ - polygon: Polygon; + polygon(vertices:Array): Polygon; /** * creates a new hull layout with the default settings. */ - hull: Hull; + hull(): Hull; + + hull(vertices:Array): Array; } export interface Vertice extends Array { @@ -3258,10 +3309,6 @@ declare module D3 { } export interface Polygon extends Array { - /** - * Returns the input array of vertices with additional methods attached - */ - (vertices: Array): Polygon; /** * Returns the signed area of this polygon */ @@ -3276,7 +3323,7 @@ declare module D3 { clip(subject: Polygon): Polygon; } - export interface Quadtree { + export interface QuadtreeFactory { /** * Constructs a new quadtree for the specified array of points. */ @@ -3289,22 +3336,29 @@ declare module D3 { * Constructs a new quadtree for the specified array of points. */ (points: Array, width: number, height: number): Quadtree; - /** - * Adds a new point to the quadtree. - */ - add(point: Point): Quadtree; - visit(callback: any): Quadtree; + x: { (): (d: any) => any; - (accesor: (d: any) => any): Quadtree; + (accesor: (d: any) => any): QuadtreeFactory; } y: { (): (d: any) => any; - (accesor: (d: any) => any): Quadtree; + (accesor: (d: any) => any): QuadtreeFactory; } - size(size: Array): Quadtree; + size(): Array; + size(size: Array): QuadtreeFactory; + extent(): Array>; + extent(points: Array>): QuadtreeFactory; + } + + export interface Quadtree { + /** + * Adds a new point to the quadtree. + */ + add(point: Point): void; + visit(callback: any): void; } export interface Point { @@ -3312,20 +3366,87 @@ declare module D3 { y: number; } - export interface Voronoi { - (vertices?: Array): Array; + export interface Voronoi { + /** + * Compute the Voronoi diagram for the specified data. + */ + (data: Array): Array; + /** + * Compute the graph links for the Voronoi diagram for the specified data. + */ + links(data: Array): Array; + /** + * Compute the triangles for the Voronoi diagram for the specified data. + */ + triangles(data: Array): Array>; x: { - (): (d: any) => any; - (accesor: (d: any) => any): any; + /** + * Get the x-coordinate accessor. + */ + (): (data: T, index ?: number) => number; + + /** + * Set the x-coordinate accessor. + * + * @param accessor The new accessor function + */ + (accessor: (data: T, index: number) => number): Voronoi; + + /** + * Set the x-coordinate to a constant. + * + * @param constant The new constant value. + */ + (constant: number): Voronoi; } y: { - (): (d: any) => any; - (accesor: (d: any) => any): any; + /** + * Get the y-coordinate accessor. + */ + (): (data: T, index ?: number) => number; + + /** + * Set the y-coordinate accessor. + * + * @param accessor The new accessor function + */ + (accessor: (data: T, index: number) => number): Voronoi; + + /** + * Set the y-coordinate to a constant. + * + * @param constant The new constant value. + */ + (constant: number): Voronoi; + } + clipExtent: { + /** + * Get the clip extent. + */ + (): Array>; + /** + * Set the clip extent. + * + * @param extent The new clip extent. + */ + (extent: Array>): Voronoi; + } + size: { + /** + * Get the size. + */ + (): Array; + /** + * Set the size, equivalent to a clip extent starting from (0,0). + * + * @param size The new size. + */ + (size: Array): Voronoi; } } export interface Hull { - (vertices: Array): Hull; + (vertices: Array): Array; x: { (): (d: any) => any; (accesor: (d: any) => any): any; From ec032c47a0966f4e297e135a4d95a6d0201d2e67 Mon Sep 17 00:00:00 2001 From: Brian Malehorn Date: Mon, 21 Jul 2014 17:43:45 -0700 Subject: [PATCH 2/2] corrected a bunch of bugs in d3.d.ts Now compiling. Will submit PR to DefinitelyTyped soon. --- plottable.d.ts | 2 +- src/interactions/keyEventListener.ts | 2 +- src/interactions/keyInteraction.ts | 2 +- test/interactions/interactionTests.ts | 4 ++-- typings/d3/d3.d.ts | 25 ++++++++++++++++++++----- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/plottable.d.ts b/plottable.d.ts index 886acb9313..14c4d85579 100644 --- a/plottable.d.ts +++ b/plottable.d.ts @@ -2214,7 +2214,7 @@ declare module Plottable { declare module Plottable { module Core { interface IKeyEventListenerCallback { - (e: D3.Event): any; + (e: D3.D3Event): any; } module KeyEventListener { function initialize(): void; diff --git a/src/interactions/keyEventListener.ts b/src/interactions/keyEventListener.ts index 314cb0426f..4641f89b4f 100644 --- a/src/interactions/keyEventListener.ts +++ b/src/interactions/keyEventListener.ts @@ -3,7 +3,7 @@ module Plottable { export module Core { export interface IKeyEventListenerCallback { - (e: D3.Event): any + (e: D3.D3Event): any } export module KeyEventListener { diff --git a/src/interactions/keyInteraction.ts b/src/interactions/keyInteraction.ts index b231dd3ff7..8d03e80da1 100644 --- a/src/interactions/keyInteraction.ts +++ b/src/interactions/keyInteraction.ts @@ -28,7 +28,7 @@ export module Interaction { this.activated = false; }); - Core.KeyEventListener.addCallback(this.keyCode, (e: D3.Event) => { + Core.KeyEventListener.addCallback(this.keyCode, (e: D3.D3Event) => { if (this.activated && this._callback != null) { this._callback(); } diff --git a/test/interactions/interactionTests.ts b/test/interactions/interactionTests.ts index 6740572c34..07380a9185 100644 --- a/test/interactions/interactionTests.ts +++ b/test/interactions/interactionTests.ts @@ -3,8 +3,8 @@ var assert = chai.assert; -function makeFakeEvent(x: number, y: number): D3.Event { - return { +function makeFakeEvent(x: number, y: number): D3.D3Event { + return { dx: 0, dy: 0, clientX: x, diff --git a/typings/d3/d3.d.ts b/typings/d3/d3.d.ts index 598cd9f34b..8da827f4e6 100644 --- a/typings/d3/d3.d.ts +++ b/typings/d3/d3.d.ts @@ -243,7 +243,7 @@ declare module D3 { * * @param map Array of objects to get the values from */ - values(map: any[]): any[]; + values(map: any): any[]; /** * List the key-value entries of an associative array. * @@ -1720,10 +1720,21 @@ declare module D3 { (): any[]; (values: any[]): Axis; }; - tickSubdivide(count: number): Axis; - tickSize(major?: number, minor?: number, end?: number): Axis; + tickSize: { + (): number; + (inner: number, outer?: number): Axis; + } + innerTickSize: { + (): number; + (value: number): Axis; + } + outerTickSize: { + (): number; + (value: number): Axis; + } tickFormat(formatter: (value: any) => string): Axis; + nice(count?: number): Axis; } export interface Arc { @@ -2569,7 +2580,10 @@ declare module D3 { * * @param clamp Enable or disable */ - clamp(clamp: boolean): QuantitiveScale; + clamp: { + (): boolean; + (clamp: boolean): QuantitiveScale; + } /** * extend the scale domain to nice round numbers. * @@ -2587,7 +2601,7 @@ declare module D3 { * * @param count Aproximate representative values to return */ - tickFormat(count: number): (n: number) => string; + tickFormat(count: number, format?: string): (n: number) => string; /** * create a new scale from an existing scale.. */ @@ -2768,6 +2782,7 @@ declare module D3 { }; tickFormat(count: number): (n: number) => string; copy(): TimeScale; + nice(count?: number): TimeScale; } }